zyxxoo commented on code in PR #2130:
URL: 
https://github.com/apache/incubator-hugegraph/pull/2130#discussion_r1118215113


##########
hugegraph-api/src/main/java/org/apache/hugegraph/core/GraphManager.java:
##########
@@ -428,13 +443,43 @@ private void serverStarted(HugeConfig config) {
                         "The server role can't be null or empty");
         this.server = IdGenerator.of(server);
         this.role = NodeRole.valueOf(role.toUpperCase());
+
+        initRoleStateMachine(config, server);
+
         for (String graph : this.graphs()) {
             HugeGraph hugegraph = this.graph(graph);
             assert hugegraph != null;
             hugegraph.serverStarted(this.server, this.role);
         }
     }
 
+    private void initRoleStateMachine(HugeConfig config, String server) {
+        try {
+            if (!(this.authenticator() instanceof StandardAuthenticator)) {
+                LOG.info("Current not support role state machine");
+                return;
+            }
+        } catch (IllegalStateException e) {
+            LOG.info("Current not support role state machine");
+            return;
+        }
+
+        E.checkArgument(this.roleStateMachine == null, "Repetition init");
+        Config roleStateMachineConfig = new HugeRoleStateMachineConfig(server,
+                                            
config.get(ServerOptions.EXCEEDS_FAIL_COUNT),
+                                            
config.get(ServerOptions.RANDOM_TIMEOUT_MILLISECOND),
+                                            
config.get(ServerOptions.HEARTBEAT_INTERVAL_SECOUND),
+                                            
config.get(ServerOptions.EXCEEDS_WORKER_COUNT),
+                                            
config.get(ServerOptions.BASE_TIMEOUT_MILLISECOND));
+        StandardHugeGraph graph = (StandardHugeGraph) 
this.authenticator().graph().hugegraph();
+        RoleTypeDataAdapter adapter = new 
RoleTypeDataAdapterImpl(graph.hugeGraphParams());
+        this.roleStateMachine = new 
RoleElectionStateMachineImpl(roleStateMachineConfig, adapter);

Review Comment:
   there are multiple graphs, but only one state machine



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to