Compare commits
1 Commits
fix_finali
...
add-coordi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af2003f974 |
@@ -3025,9 +3025,17 @@ class ReplicationQuery : public memgraph::query::Query {
|
||||
static const utils::TypeInfo kType;
|
||||
const utils::TypeInfo &GetTypeInfo() const override { return kType; }
|
||||
|
||||
enum class Action { SET_REPLICATION_ROLE, SHOW_REPLICATION_ROLE, REGISTER_REPLICA, DROP_REPLICA, SHOW_REPLICAS };
|
||||
enum class Action {
|
||||
SET_REPLICATION_ROLE,
|
||||
SHOW_REPLICATION_ROLE,
|
||||
REGISTER_REPLICA,
|
||||
REGISTER_MAIN,
|
||||
DROP_REPLICA,
|
||||
SHOW_REPLICAS,
|
||||
SHOW_REPLICATION_CLUSTER
|
||||
};
|
||||
|
||||
enum class ReplicationRole { MAIN, REPLICA };
|
||||
enum class ReplicationRole { MAIN, REPLICA, COORDINATOR };
|
||||
|
||||
enum class SyncMode { SYNC, ASYNC };
|
||||
|
||||
|
||||
@@ -317,8 +317,9 @@ antlrcpp::Any CypherMainVisitor::visitSetReplicationRole(MemgraphCypher::SetRepl
|
||||
auto *replication_query = storage_->Create<ReplicationQuery>();
|
||||
replication_query->action_ = ReplicationQuery::Action::SET_REPLICATION_ROLE;
|
||||
if (ctx->MAIN()) {
|
||||
if (ctx->WITH() || ctx->PORT()) {
|
||||
throw SemanticException("Main can't set a port!");
|
||||
// Can set a port only if query is executed on coordinator
|
||||
if (ctx->port->numberLiteral() && ctx->port->numberLiteral()->integerLiteral()) {
|
||||
replication_query->port_ = std::any_cast<Expression *>(ctx->port->accept(this));
|
||||
}
|
||||
replication_query->role_ = ReplicationQuery::ReplicationRole::MAIN;
|
||||
} else if (ctx->REPLICA()) {
|
||||
@@ -330,6 +331,12 @@ antlrcpp::Any CypherMainVisitor::visitSetReplicationRole(MemgraphCypher::SetRepl
|
||||
throw SyntaxException("Port must be an integer literal!");
|
||||
}
|
||||
}
|
||||
} else if (ctx->COORDINATOR()) {
|
||||
replication_query->role_ = ReplicationQuery::ReplicationRole::COORDINATOR;
|
||||
if (ctx->WITH() || ctx->PORT()) {
|
||||
throw SyntaxException("Coordinator shouldn't have port as an integer literal!");
|
||||
}
|
||||
replication_query->port_ = std::any_cast<Expression *>(ctx->port->accept(this));
|
||||
}
|
||||
return replication_query;
|
||||
}
|
||||
@@ -358,6 +365,16 @@ antlrcpp::Any CypherMainVisitor::visitRegisterReplica(MemgraphCypher::RegisterRe
|
||||
return replication_query;
|
||||
}
|
||||
|
||||
antlrcpp::Any CypherMainVisitor::visitRegisterMain(MemgraphCypher::RegisterMainContext *ctx) {
|
||||
auto *replication_query = storage_->Create<ReplicationQuery>();
|
||||
replication_query->action_ = ReplicationQuery::Action::REGISTER_MAIN;
|
||||
if (!ctx->socketAddress()->literal()->StringLiteral()) {
|
||||
throw SemanticException("Socket address should be a string literal!");
|
||||
}
|
||||
replication_query->socket_address_ = std::any_cast<Expression *>(ctx->socketAddress()->accept(this));
|
||||
return replication_query;
|
||||
}
|
||||
|
||||
antlrcpp::Any CypherMainVisitor::visitDropReplica(MemgraphCypher::DropReplicaContext *ctx) {
|
||||
auto *replication_query = storage_->Create<ReplicationQuery>();
|
||||
replication_query->action_ = ReplicationQuery::Action::DROP_REPLICA;
|
||||
@@ -371,6 +388,12 @@ antlrcpp::Any CypherMainVisitor::visitShowReplicas(MemgraphCypher::ShowReplicasC
|
||||
return replication_query;
|
||||
}
|
||||
|
||||
antlrcpp::Any CypherMainVisitor::visitShowReplicationCluster(MemgraphCypher::ShowReplicationClusterContext *ctx) {
|
||||
auto *replication_query = storage_->Create<ReplicationQuery>();
|
||||
replication_query->action_ = ReplicationQuery::Action::SHOW_REPLICATION_CLUSTER;
|
||||
return replication_query;
|
||||
}
|
||||
|
||||
antlrcpp::Any CypherMainVisitor::visitLockPathQuery(MemgraphCypher::LockPathQueryContext *ctx) {
|
||||
auto *lock_query = storage_->Create<LockPathQuery>();
|
||||
if (ctx->STATUS()) {
|
||||
|
||||
@@ -221,6 +221,11 @@ class CypherMainVisitor : public antlropencypher::MemgraphCypherBaseVisitor {
|
||||
*/
|
||||
antlrcpp::Any visitRegisterReplica(MemgraphCypher::RegisterReplicaContext *ctx) override;
|
||||
|
||||
/**
|
||||
* @return ReplicationQuery*
|
||||
*/
|
||||
antlrcpp::Any visitRegisterMain(MemgraphCypher::RegisterMainContext *ctx) override;
|
||||
|
||||
/**
|
||||
* @return ReplicationQuery*
|
||||
*/
|
||||
@@ -231,6 +236,11 @@ class CypherMainVisitor : public antlropencypher::MemgraphCypherBaseVisitor {
|
||||
*/
|
||||
antlrcpp::Any visitShowReplicas(MemgraphCypher::ShowReplicasContext *ctx) override;
|
||||
|
||||
/**
|
||||
* @return ReplicationQuery*
|
||||
*/
|
||||
antlrcpp::Any visitShowReplicationCluster(MemgraphCypher::ShowReplicationClusterContext *ctx) override;
|
||||
|
||||
/**
|
||||
* @return LockPathQuery*
|
||||
*/
|
||||
|
||||
@@ -42,6 +42,7 @@ memgraphCypherKeyword : cypherKeyword
|
||||
| CONSUMER_GROUP
|
||||
| CREATE_DELETE
|
||||
| CREDENTIALS
|
||||
| COORDINATOR
|
||||
| CSV
|
||||
| DATA
|
||||
| DELIMITER
|
||||
@@ -181,6 +182,8 @@ replicationQuery : setReplicationRole
|
||||
| registerReplica
|
||||
| dropReplica
|
||||
| showReplicas
|
||||
| registerMain
|
||||
| showReplicationCluster
|
||||
;
|
||||
|
||||
triggerQuery : createTrigger
|
||||
@@ -359,7 +362,7 @@ dumpQuery : DUMP DATABASE ;
|
||||
|
||||
analyzeGraphQuery : ANALYZE GRAPH ( ON LABELS ( listOfColonSymbolicNames | ASTERISK ) ) ? ( DELETE STATISTICS ) ? ;
|
||||
|
||||
setReplicationRole : SET REPLICATION ROLE TO ( MAIN | REPLICA )
|
||||
setReplicationRole : SET REPLICATION ROLE TO ( MAIN | REPLICA | COORDINATOR )
|
||||
( WITH PORT port=literal ) ? ;
|
||||
|
||||
showReplicationRole : SHOW REPLICATION ROLE ;
|
||||
@@ -371,10 +374,14 @@ socketAddress : literal ;
|
||||
registerReplica : REGISTER REPLICA replicaName ( SYNC | ASYNC )
|
||||
TO socketAddress ;
|
||||
|
||||
registerMain : REGISTER MAIN TO socketAddress ;
|
||||
|
||||
dropReplica : DROP REPLICA replicaName ;
|
||||
|
||||
showReplicas : SHOW REPLICAS ;
|
||||
|
||||
showReplicationCluster : SHOW REPLICATION CLUSTER ;
|
||||
|
||||
lockPathQuery : ( LOCK | UNLOCK ) DATA DIRECTORY | DATA DIRECTORY LOCK STATUS;
|
||||
|
||||
freeMemoryQuery : FREE MEMORY ;
|
||||
|
||||
@@ -753,6 +753,9 @@ Callback HandleReplicationQuery(ReplicationQuery *repl_query, const Parameters &
|
||||
case ReplicationQuery::ReplicationRole::REPLICA: {
|
||||
return std::vector<std::vector<TypedValue>>{{TypedValue("replica")}};
|
||||
}
|
||||
case ReplicationQuery::ReplicationRole::COORDINATOR: {
|
||||
return std::vector<std::vector<TypedValue>>{{TypedValue("coordinator")}};
|
||||
}
|
||||
}
|
||||
};
|
||||
return callback;
|
||||
@@ -830,6 +833,12 @@ Callback HandleReplicationQuery(ReplicationQuery *repl_query, const Parameters &
|
||||
};
|
||||
return callback;
|
||||
}
|
||||
case ReplicationQuery::Action::REGISTER_MAIN: {
|
||||
throw QueryException("Not yet implemented");
|
||||
}
|
||||
case ReplicationQuery::Action::SHOW_REPLICATION_CLUSTER: {
|
||||
throw QueryException("Show replicaiton cluster not yet implemented");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user