Update replication queries to follow the new replication nomenclature (#48)
* MODE -> ROLE Co-authored-by: jseljan <josip.seljan@memgraph.io>
This commit is contained in:
parent
76f0d5873b
commit
3c85319701
@ -2299,7 +2299,7 @@ cpp<#
|
|||||||
|
|
||||||
(lcp:define-class replication-query (query)
|
(lcp:define-class replication-query (query)
|
||||||
((action "Action" :scope :public)
|
((action "Action" :scope :public)
|
||||||
(mode "ReplicationMode" :scope :public)
|
(role "ReplicationRole" :scope :public)
|
||||||
(replica_name "std::string" :scope :public)
|
(replica_name "std::string" :scope :public)
|
||||||
(hostname "Expression *" :initval "nullptr" :scope :public
|
(hostname "Expression *" :initval "nullptr" :scope :public
|
||||||
:slk-save #'slk-save-ast-pointer
|
:slk-save #'slk-save-ast-pointer
|
||||||
@ -2311,10 +2311,10 @@ cpp<#
|
|||||||
|
|
||||||
(:public
|
(:public
|
||||||
(lcp:define-enum action
|
(lcp:define-enum action
|
||||||
(set-replication-mode show-replication-mode create-replica
|
(set-replication-role show-replication-role create-replica
|
||||||
drop-replica show-replicas)
|
drop-replica show-replicas)
|
||||||
(:serialize))
|
(:serialize))
|
||||||
(lcp:define-enum replication-mode
|
(lcp:define-enum replication-role
|
||||||
(main replica)
|
(main replica)
|
||||||
(:serialize))
|
(:serialize))
|
||||||
(lcp:define-enum sync-mode
|
(lcp:define-enum sync-mode
|
||||||
|
@ -206,22 +206,22 @@ antlrcpp::Any CypherMainVisitor::visitReplicationQuery(
|
|||||||
return replication_query;
|
return replication_query;
|
||||||
}
|
}
|
||||||
|
|
||||||
antlrcpp::Any CypherMainVisitor::visitSetReplicationMode(
|
antlrcpp::Any CypherMainVisitor::visitSetReplicationRole(
|
||||||
MemgraphCypher::SetReplicationModeContext *ctx) {
|
MemgraphCypher::SetReplicationRoleContext *ctx) {
|
||||||
auto *replication_query = storage_->Create<ReplicationQuery>();
|
auto *replication_query = storage_->Create<ReplicationQuery>();
|
||||||
replication_query->action_ = ReplicationQuery::Action::SET_REPLICATION_MODE;
|
replication_query->action_ = ReplicationQuery::Action::SET_REPLICATION_ROLE;
|
||||||
if (ctx->MAIN()) {
|
if (ctx->MAIN()) {
|
||||||
replication_query->mode_ = ReplicationQuery::ReplicationMode::MAIN;
|
replication_query->role_ = ReplicationQuery::ReplicationRole::MAIN;
|
||||||
} else if (ctx->REPLICA()) {
|
} else if (ctx->REPLICA()) {
|
||||||
replication_query->mode_ = ReplicationQuery::ReplicationMode::REPLICA;
|
replication_query->role_ = ReplicationQuery::ReplicationRole::REPLICA;
|
||||||
}
|
}
|
||||||
return replication_query;
|
return replication_query;
|
||||||
}
|
}
|
||||||
|
|
||||||
antlrcpp::Any CypherMainVisitor::visitShowReplicationMode(
|
antlrcpp::Any CypherMainVisitor::visitShowReplicationRole(
|
||||||
MemgraphCypher::ShowReplicationModeContext *ctx) {
|
MemgraphCypher::ShowReplicationRoleContext *ctx) {
|
||||||
auto *replication_query = storage_->Create<ReplicationQuery>();
|
auto *replication_query = storage_->Create<ReplicationQuery>();
|
||||||
replication_query->action_ = ReplicationQuery::Action::SHOW_REPLICATION_MODE;
|
replication_query->action_ = ReplicationQuery::Action::SHOW_REPLICATION_ROLE;
|
||||||
return replication_query;
|
return replication_query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,14 +195,14 @@ class CypherMainVisitor : public antlropencypher::MemgraphCypherBaseVisitor {
|
|||||||
/**
|
/**
|
||||||
* @return ReplicationQuery*
|
* @return ReplicationQuery*
|
||||||
*/
|
*/
|
||||||
antlrcpp::Any visitSetReplicationMode(
|
antlrcpp::Any visitSetReplicationRole(
|
||||||
MemgraphCypher::SetReplicationModeContext *ctx) override;
|
MemgraphCypher::SetReplicationRoleContext *ctx) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return ReplicationQuery*
|
* @return ReplicationQuery*
|
||||||
*/
|
*/
|
||||||
antlrcpp::Any visitShowReplicationMode(
|
antlrcpp::Any visitShowReplicationRole(
|
||||||
MemgraphCypher::ShowReplicationModeContext *ctx) override;
|
MemgraphCypher::ShowReplicationRoleContext *ctx) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return ReplicationQuery*
|
* @return ReplicationQuery*
|
||||||
|
@ -70,8 +70,8 @@ authQuery : createRole
|
|||||||
| showUsersForRole
|
| showUsersForRole
|
||||||
;
|
;
|
||||||
|
|
||||||
replicationQuery : setReplicationMode
|
replicationQuery : setReplicationRole
|
||||||
| showReplicationMode
|
| showReplicationRole
|
||||||
| createReplica
|
| createReplica
|
||||||
| dropReplica
|
| dropReplica
|
||||||
| showReplicas
|
| showReplicas
|
||||||
@ -117,9 +117,9 @@ showUsersForRole : SHOW USERS FOR role=userOrRoleName ;
|
|||||||
|
|
||||||
dumpQuery: DUMP DATABASE ;
|
dumpQuery: DUMP DATABASE ;
|
||||||
|
|
||||||
setReplicationMode : SET REPLICATION MODE TO ( MAIN | REPLICA ) ;
|
setReplicationRole : SET REPLICATION ROLE TO ( MAIN | REPLICA ) ;
|
||||||
|
|
||||||
showReplicationMode : SHOW REPLICATION MODE ;
|
showReplicationRole : SHOW REPLICATION ROLE ;
|
||||||
|
|
||||||
replicaName : symbolicName ;
|
replicaName : symbolicName ;
|
||||||
|
|
||||||
|
@ -61,10 +61,10 @@ class PrivilegeExtractor : public QueryVisitor<void>,
|
|||||||
|
|
||||||
void Visit(ReplicationQuery &replication_query) override {
|
void Visit(ReplicationQuery &replication_query) override {
|
||||||
switch (replication_query.action_) {
|
switch (replication_query.action_) {
|
||||||
case ReplicationQuery::Action::SET_REPLICATION_MODE:
|
case ReplicationQuery::Action::SET_REPLICATION_ROLE:
|
||||||
AddPrivilege(AuthQuery::Privilege::REPLICATION);
|
AddPrivilege(AuthQuery::Privilege::REPLICATION);
|
||||||
break;
|
break;
|
||||||
case ReplicationQuery::Action::SHOW_REPLICATION_MODE:
|
case ReplicationQuery::Action::SHOW_REPLICATION_ROLE:
|
||||||
AddPrivilege(AuthQuery::Privilege::REPLICATION);
|
AddPrivilege(AuthQuery::Privilege::REPLICATION);
|
||||||
break;
|
break;
|
||||||
case ReplicationQuery::Action::CREATE_REPLICA:
|
case ReplicationQuery::Action::CREATE_REPLICA:
|
||||||
|
@ -340,25 +340,25 @@ Callback HandleReplicationQuery(ReplicationQuery *repl_query,
|
|||||||
|
|
||||||
Callback callback;
|
Callback callback;
|
||||||
switch (repl_query->action_) {
|
switch (repl_query->action_) {
|
||||||
case ReplicationQuery::Action::SET_REPLICATION_MODE: {
|
case ReplicationQuery::Action::SET_REPLICATION_ROLE: {
|
||||||
callback.fn = [handler, mode = repl_query->mode_] {
|
callback.fn = [handler, role = repl_query->role_] {
|
||||||
if (!handler->SetReplicationMode(mode)) {
|
if (!handler->SetReplicationRole(role)) {
|
||||||
throw QueryRuntimeException(
|
throw QueryRuntimeException(
|
||||||
"Couldn't set the desired replication mode.");
|
"Couldn't set the desired replication role.");
|
||||||
}
|
}
|
||||||
return std::vector<std::vector<TypedValue>>();
|
return std::vector<std::vector<TypedValue>>();
|
||||||
};
|
};
|
||||||
return callback;
|
return callback;
|
||||||
}
|
}
|
||||||
case ReplicationQuery::Action::SHOW_REPLICATION_MODE: {
|
case ReplicationQuery::Action::SHOW_REPLICATION_ROLE: {
|
||||||
callback.header = {"replication mode"};
|
callback.header = {"replication mode"};
|
||||||
callback.fn = [handler] {
|
callback.fn = [handler] {
|
||||||
auto mode = handler->ShowReplicationMode();
|
auto mode = handler->ShowReplicationRole();
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case ReplicationQuery::ReplicationMode::MAIN: {
|
case ReplicationQuery::ReplicationRole::MAIN: {
|
||||||
return std::vector<std::vector<TypedValue>>{{TypedValue("main")}};
|
return std::vector<std::vector<TypedValue>>{{TypedValue("main")}};
|
||||||
}
|
}
|
||||||
case ReplicationQuery::ReplicationMode::REPLICA: {
|
case ReplicationQuery::ReplicationRole::REPLICA: {
|
||||||
return std::vector<std::vector<TypedValue>>{
|
return std::vector<std::vector<TypedValue>>{
|
||||||
{TypedValue("replica")}};
|
{TypedValue("replica")}};
|
||||||
}
|
}
|
||||||
|
@ -116,11 +116,11 @@ class ReplicationQueryHandler {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// @throw QueryRuntimeException if an error ocurred.
|
/// @throw QueryRuntimeException if an error ocurred.
|
||||||
virtual bool SetReplicationMode(
|
virtual bool SetReplicationRole(
|
||||||
ReplicationQuery::ReplicationMode replication_mode) = 0;
|
ReplicationQuery::ReplicationRole replication_mode) = 0;
|
||||||
|
|
||||||
/// @throw QueryRuntimeException if an error ocurred.
|
/// @throw QueryRuntimeException if an error ocurred.
|
||||||
virtual ReplicationQuery::ReplicationMode ShowReplicationMode() const = 0;
|
virtual ReplicationQuery::ReplicationRole ShowReplicationRole() const = 0;
|
||||||
|
|
||||||
/// Return false if the replica already exists.
|
/// Return false if the replica already exists.
|
||||||
/// @throw QueryRuntimeException if an error ocurred.
|
/// @throw QueryRuntimeException if an error ocurred.
|
||||||
|
@ -2472,16 +2472,16 @@ void check_replication_query(Base *ast_generator, const ReplicationQuery *query,
|
|||||||
|
|
||||||
TEST_P(CypherMainVisitorTest, TestShowReplicationMode) {
|
TEST_P(CypherMainVisitorTest, TestShowReplicationMode) {
|
||||||
auto &ast_generator = *GetParam();
|
auto &ast_generator = *GetParam();
|
||||||
std::string raw_query = "SHOW REPLICATION MODE";
|
const std::string raw_query = "SHOW REPLICATION ROLE";
|
||||||
auto *parsed_query =
|
auto *parsed_query =
|
||||||
dynamic_cast<ReplicationQuery *>(ast_generator.ParseQuery(raw_query));
|
dynamic_cast<ReplicationQuery *>(ast_generator.ParseQuery(raw_query));
|
||||||
EXPECT_EQ(parsed_query->action_,
|
EXPECT_EQ(parsed_query->action_,
|
||||||
ReplicationQuery::Action::SHOW_REPLICATION_MODE);
|
ReplicationQuery::Action::SHOW_REPLICATION_ROLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_P(CypherMainVisitorTest, TestShowReplicasQuery) {
|
TEST_P(CypherMainVisitorTest, TestShowReplicasQuery) {
|
||||||
auto &ast_generator = *GetParam();
|
auto &ast_generator = *GetParam();
|
||||||
std::string raw_query = "SHOW REPLICAS";
|
const std::string raw_query = "SHOW REPLICAS";
|
||||||
auto *parsed_query =
|
auto *parsed_query =
|
||||||
dynamic_cast<ReplicationQuery *>(ast_generator.ParseQuery(raw_query));
|
dynamic_cast<ReplicationQuery *>(ast_generator.ParseQuery(raw_query));
|
||||||
EXPECT_EQ(parsed_query->action_, ReplicationQuery::Action::SHOW_REPLICAS);
|
EXPECT_EQ(parsed_query->action_, ReplicationQuery::Action::SHOW_REPLICAS);
|
||||||
@ -2489,27 +2489,27 @@ TEST_P(CypherMainVisitorTest, TestShowReplicasQuery) {
|
|||||||
|
|
||||||
TEST_P(CypherMainVisitorTest, TestSetReplicationMode) {
|
TEST_P(CypherMainVisitorTest, TestSetReplicationMode) {
|
||||||
auto &ast_generator = *GetParam();
|
auto &ast_generator = *GetParam();
|
||||||
std::string missing_mode_query = "SET REPLICATION MODE";
|
const std::string missing_mode_query = "SET REPLICATION ROLE";
|
||||||
ASSERT_THROW(ast_generator.ParseQuery(missing_mode_query), SyntaxException);
|
ASSERT_THROW(ast_generator.ParseQuery(missing_mode_query), SyntaxException);
|
||||||
|
|
||||||
std::string bad_mode_query = "SET REPLICATION MODE TO BUTTERY";
|
const std::string bad_mode_query = "SET REPLICATION ROLE TO BUTTERY";
|
||||||
ASSERT_THROW(ast_generator.ParseQuery(bad_mode_query), SyntaxException);
|
ASSERT_THROW(ast_generator.ParseQuery(bad_mode_query), SyntaxException);
|
||||||
|
|
||||||
std::string full_query = "SET REPLICATION MODE TO MAIN";
|
const std::string full_query = "SET REPLICATION ROLE TO MAIN";
|
||||||
auto *parsed_full_query =
|
auto *parsed_full_query =
|
||||||
dynamic_cast<ReplicationQuery *>(ast_generator.ParseQuery(full_query));
|
dynamic_cast<ReplicationQuery *>(ast_generator.ParseQuery(full_query));
|
||||||
EXPECT_EQ(parsed_full_query->action_,
|
EXPECT_EQ(parsed_full_query->action_,
|
||||||
ReplicationQuery::Action::SET_REPLICATION_MODE);
|
ReplicationQuery::Action::SET_REPLICATION_ROLE);
|
||||||
EXPECT_EQ(parsed_full_query->mode_, ReplicationQuery::ReplicationMode::MAIN);
|
EXPECT_EQ(parsed_full_query->role_, ReplicationQuery::ReplicationRole::MAIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_P(CypherMainVisitorTest, TestCreateReplicationQuery) {
|
TEST_P(CypherMainVisitorTest, TestCreateReplicationQuery) {
|
||||||
auto &ast_generator = *GetParam();
|
auto &ast_generator = *GetParam();
|
||||||
|
|
||||||
std::string faulty_query = "CREATE REPLICA WITH TIMEOUT TO";
|
const std::string faulty_query = "CREATE REPLICA WITH TIMEOUT TO";
|
||||||
ASSERT_THROW(ast_generator.ParseQuery(faulty_query), SyntaxException);
|
ASSERT_THROW(ast_generator.ParseQuery(faulty_query), SyntaxException);
|
||||||
|
|
||||||
std::string no_timeout_query =
|
const std::string no_timeout_query =
|
||||||
R"(CREATE REPLICA replica1 SYNC TO "127.0.0.1")";
|
R"(CREATE REPLICA replica1 SYNC TO "127.0.0.1")";
|
||||||
auto *no_timeout_query_parsed = dynamic_cast<ReplicationQuery *>(
|
auto *no_timeout_query_parsed = dynamic_cast<ReplicationQuery *>(
|
||||||
ast_generator.ParseQuery(no_timeout_query));
|
ast_generator.ParseQuery(no_timeout_query));
|
||||||
|
Loading…
Reference in New Issue
Block a user