Forbid write queries on a replica (#80)

Co-authored-by: jseljan <josip.seljan@memgraph.io>
This commit is contained in:
Josip Seljan 2021-01-25 09:13:32 +01:00 committed by GitHub
parent e866526c7a
commit 46b1783618
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1661,6 +1661,16 @@ Interpreter::PrepareResult Interpreter::Prepare(
query_execution->prepared_query->rw_type)
: "rw";
#ifdef MG_ENTERPRISE
if (const auto query_type = query_execution->prepared_query->rw_type;
interpreter_context_->db->GetReplicationRole() ==
storage::ReplicationRole::REPLICA &&
(query_type == RWType::W || query_type == RWType::RW)) {
query_execution = nullptr;
throw QueryException("Write query forbidden on the replica!");
}
#endif
return {query_execution->prepared_query->header,
query_execution->prepared_query->privileges, qid};
} catch (const utils::BasicException &) {