javeme commented on code in PR #2130: URL: https://github.com/apache/incubator-hugegraph/pull/2130#discussion_r1118867884
########## hugegraph-core/src/main/java/org/apache/hugegraph/config/CoreOptions.java: ########## @@ -627,4 +626,45 @@ public static synchronized CoreOptions instance() { CollectionType::valueOf, "EC" ); + + public static final ConfigOption<Integer> EXCEEDS_FAIL_COUNT = + new ConfigOption<>( + "server.role.fail_count", + "The role state machine fail count exceeds", + rangeInt(0, Integer.MAX_VALUE), + 2 + ); + + public static final ConfigOption<Integer> RANDOM_TIMEOUT_MILLISECOND = + new ConfigOption<>( + "server.role.random.timeout", Review Comment: keep random_timeout style ########## hugegraph-core/src/main/java/org/apache/hugegraph/election/StandardRoleTypeDataAdapter.java: ########## @@ -40,12 +38,12 @@ import org.apache.tinkerpop.gremlin.structure.T; import org.apache.tinkerpop.gremlin.structure.Vertex; -public class RoleTypeDataAdapterImpl implements RoleTypeDataAdapter { +public class StandardRoleTypeDataAdapter implements RoleTypeDataAdapter { private final HugeGraphParams graphParams; private final Schema schema; - public RoleTypeDataAdapterImpl(HugeGraphParams graphParams) { + public StandardRoleTypeDataAdapter(HugeGraphParams graphParams) { Review Comment: rename graphParams to graph ########## hugegraph-core/src/main/java/org/apache/hugegraph/config/CoreOptions.java: ########## @@ -627,4 +626,45 @@ public static synchronized CoreOptions instance() { CollectionType::valueOf, "EC" ); + + public static final ConfigOption<Integer> EXCEEDS_FAIL_COUNT = + new ConfigOption<>( + "server.role.fail_count", + "The role state machine fail count exceeds", + rangeInt(0, Integer.MAX_VALUE), + 2 + ); + + public static final ConfigOption<Integer> RANDOM_TIMEOUT_MILLISECOND = + new ConfigOption<>( + "server.role.random.timeout", + "The role state machine random timeout millisecond time", + rangeInt(0, Integer.MAX_VALUE), + 400 + ); + + public static final ConfigOption<Integer> HEARTBEAT_INTERVAL_SECOUND = + new ConfigOption<>( + "server.role.heartbeat.interval", Review Comment: ditto ########## hugegraph-core/src/main/java/org/apache/hugegraph/StandardHugeGraph.java: ########## @@ -262,6 +270,8 @@ public void serverStarted(Id serverId, NodeRole serverRole) { serverId, serverRole, this.name); this.serverInfoManager().initServerInfo(serverId, serverRole); + initRoleStateWorker(serverId); Review Comment: keep "this." prefix ########## hugegraph-api/src/main/java/org/apache/hugegraph/core/GraphManager.java: ########## @@ -428,11 +439,49 @@ 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()); + + boolean supportRoleStateWorker = this.supportRoleStateWorker(); + if (supportRoleStateWorker) { + this.role = NodeRole.WORKER; + } + for (String graph : this.graphs()) { HugeGraph hugegraph = this.graph(graph); assert hugegraph != null; hugegraph.serverStarted(this.server, this.role); } + + if (supportRoleStateWorker) { + this.initRoleStateWorker(); + } + } + + private void initRoleStateWorker() { + E.checkArgument(this.roleStateWorker == null, "Repetition init"); + this.applyThread = Executors.newSingleThreadExecutor(); + this.roleStateWorker = this.authenticator().graph().roleElectionStateMachine(); + this.applyThread.execute(() -> { Review Comment: can move applyThread to RoleElectionStateMachine class? -- 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