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


##########
hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/RoleElectionOptions.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hugegraph.masterelection;
+
+import org.apache.hugegraph.config.ConfigOption;
+import org.apache.hugegraph.config.OptionHolder;
+
+import static org.apache.hugegraph.config.OptionChecker.disallowEmpty;
+import static org.apache.hugegraph.config.OptionChecker.rangeInt;
+
+public class RoleElectionOptions  extends OptionHolder {
+
+    private RoleElectionOptions() {
+        super();
+    }
+
+    private static volatile RoleElectionOptions instance;
+
+    public static synchronized RoleElectionOptions instance() {
+        if (instance == null) {
+            instance = new RoleElectionOptions();
+            // Should initialize all static members first, then register.
+            instance.registerOptions();
+        }
+        return instance;
+    }
+
+    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),
+                    5
+            );
+
+    public static final ConfigOption<String> NODE_EXTERNAL_URL =
+            new ConfigOption<>(
+                    "server.role.node_external_url",
+                    "The url of external accessibility",
+                    disallowEmpty(),
+                    "127.0.0.1:8080"
+            );
+
+    public static final ConfigOption<Integer> RANDOM_TIMEOUT_MILLISECOND =
+            new ConfigOption<>(
+                    "server.role.random_timeout",
+                    "The random timeout time that be used when candidate state 
node request " +
+                    "to become master state to reduce competitive voting",
+                    rangeInt(0, Integer.MAX_VALUE),
+                    1000
+            );
+
+    public static final ConfigOption<Integer> HEARTBEAT_INTERVAL_SECOUND =
+            new ConfigOption<>(
+                    "server.role.heartbeat_interval",
+                    "The role state machine heartbeat interval second time",
+                    rangeInt(0, Integer.MAX_VALUE),
+                    2
+            );
+
+    public static final ConfigOption<Integer> EXCEEDS_WORKER_CLOCK_COUNT =
+            new ConfigOption<>(
+                    "server.role.worker_count",

Review Comment:
   also rename this name



##########
hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/RoleElectionOptions.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hugegraph.masterelection;
+
+import org.apache.hugegraph.config.ConfigOption;
+import org.apache.hugegraph.config.OptionHolder;
+
+import static org.apache.hugegraph.config.OptionChecker.disallowEmpty;
+import static org.apache.hugegraph.config.OptionChecker.rangeInt;
+
+public class RoleElectionOptions  extends OptionHolder {
+
+    private RoleElectionOptions() {
+        super();
+    }
+
+    private static volatile RoleElectionOptions instance;
+
+    public static synchronized RoleElectionOptions instance() {
+        if (instance == null) {
+            instance = new RoleElectionOptions();
+            // Should initialize all static members first, then register.
+            instance.registerOptions();
+        }
+        return instance;
+    }
+
+    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),
+                    5
+            );
+
+    public static final ConfigOption<String> NODE_EXTERNAL_URL =
+            new ConfigOption<>(
+                    "server.role.node_external_url",
+                    "The url of external accessibility",
+                    disallowEmpty(),
+                    "127.0.0.1:8080"
+            );
+
+    public static final ConfigOption<Integer> RANDOM_TIMEOUT_MILLISECOND =
+            new ConfigOption<>(
+                    "server.role.random_timeout",
+                    "The random timeout time that be used when candidate state 
node request " +
+                    "to become master state to reduce competitive voting",
+                    rangeInt(0, Integer.MAX_VALUE),
+                    1000
+            );
+
+    public static final ConfigOption<Integer> HEARTBEAT_INTERVAL_SECOUND =
+            new ConfigOption<>(
+                    "server.role.heartbeat_interval",
+                    "The role state machine heartbeat interval second time",
+                    rangeInt(0, Integer.MAX_VALUE),
+                    2
+            );
+
+    public static final ConfigOption<Integer> EXCEEDS_WORKER_CLOCK_COUNT =
+            new ConfigOption<>(
+                    "server.role.worker_count",
+                    "When the worker node detects that the number of times " +
+                    "the master node fails to update heartbeat information 
reaches this threshold, " +
+                    "the working node will be converted to a candidate node",
+                    rangeInt(0, Integer.MAX_VALUE),
+                    10
+            );
+
+    public static final ConfigOption<Integer> BASE_TIMEOUT_MILLISECOND =
+            new ConfigOption<>(
+                    "server.role.base_timeout",
+                    "The role state machine candidate state base timeout time",

Review Comment:
   and "." at the end



##########
hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/RoleElectionOptions.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hugegraph.masterelection;
+
+import org.apache.hugegraph.config.ConfigOption;
+import org.apache.hugegraph.config.OptionHolder;
+
+import static org.apache.hugegraph.config.OptionChecker.disallowEmpty;
+import static org.apache.hugegraph.config.OptionChecker.rangeInt;
+
+public class RoleElectionOptions  extends OptionHolder {
+
+    private RoleElectionOptions() {
+        super();
+    }
+
+    private static volatile RoleElectionOptions instance;
+
+    public static synchronized RoleElectionOptions instance() {
+        if (instance == null) {
+            instance = new RoleElectionOptions();
+            // Should initialize all static members first, then register.
+            instance.registerOptions();
+        }
+        return instance;
+    }
+
+    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),
+                    5
+            );
+
+    public static final ConfigOption<String> NODE_EXTERNAL_URL =
+            new ConfigOption<>(
+                    "server.role.node_external_url",
+                    "The url of external accessibility",
+                    disallowEmpty(),
+                    "127.0.0.1:8080"
+            );
+
+    public static final ConfigOption<Integer> RANDOM_TIMEOUT_MILLISECOND =
+            new ConfigOption<>(
+                    "server.role.random_timeout",
+                    "The random timeout time that be used when candidate state 
node request " +

Review Comment:
   `candidate state node` => `candidate node`



##########
hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/HugeRoleStateMachineConfig.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hugegraph.masterelection;
+
+public class HugeRoleStateMachineConfig implements Config {
+
+    private String node;
+    private String url;
+    private int exceedsFailCount;
+    private long randomTimeoutMillisecond;
+    private long heartBeatIntervalSecond;
+    private int exceedsWorkerCount;
+    private long baseTimeoutMillisecond;
+
+    public HugeRoleStateMachineConfig(String node, String url, int 
exceedsFailCount,
+                                      long randomTimeoutMillisecond, long 
heartBeatIntervalSecond,
+                                      int exceedsWorkerCount, long 
baseTimeoutMillisecond) {
+        this.node = node;
+        this.url = url;
+        this.exceedsFailCount = exceedsFailCount;
+        this.randomTimeoutMillisecond = randomTimeoutMillisecond;
+        this.heartBeatIntervalSecond = heartBeatIntervalSecond;
+        this.exceedsWorkerCount = exceedsWorkerCount;
+        this.baseTimeoutMillisecond = baseTimeoutMillisecond;
+    }
+
+

Review Comment:
   2 blank lines



##########
hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/RoleElectionOptions.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hugegraph.masterelection;
+
+import org.apache.hugegraph.config.ConfigOption;
+import org.apache.hugegraph.config.OptionHolder;
+
+import static org.apache.hugegraph.config.OptionChecker.disallowEmpty;
+import static org.apache.hugegraph.config.OptionChecker.rangeInt;
+
+public class RoleElectionOptions  extends OptionHolder {
+
+    private RoleElectionOptions() {
+        super();
+    }
+
+    private static volatile RoleElectionOptions instance;
+
+    public static synchronized RoleElectionOptions instance() {

Review Comment:
   not called?



##########
hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/RoleElectionOptions.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hugegraph.masterelection;
+
+import org.apache.hugegraph.config.ConfigOption;
+import org.apache.hugegraph.config.OptionHolder;
+
+import static org.apache.hugegraph.config.OptionChecker.disallowEmpty;
+import static org.apache.hugegraph.config.OptionChecker.rangeInt;
+
+public class RoleElectionOptions  extends OptionHolder {
+
+    private RoleElectionOptions() {
+        super();
+    }
+
+    private static volatile RoleElectionOptions instance;
+
+    public static synchronized RoleElectionOptions instance() {
+        if (instance == null) {
+            instance = new RoleElectionOptions();
+            // Should initialize all static members first, then register.
+            instance.registerOptions();
+        }
+        return instance;
+    }
+
+    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),
+                    5
+            );
+
+    public static final ConfigOption<String> NODE_EXTERNAL_URL =
+            new ConfigOption<>(
+                    "server.role.node_external_url",
+                    "The url of external accessibility",
+                    disallowEmpty(),
+                    "127.0.0.1:8080"
+            );
+
+    public static final ConfigOption<Integer> RANDOM_TIMEOUT_MILLISECOND =
+            new ConfigOption<>(
+                    "server.role.random_timeout",
+                    "The random timeout time that be used when candidate state 
node request " +
+                    "to become master state to reduce competitive voting",
+                    rangeInt(0, Integer.MAX_VALUE),
+                    1000
+            );
+
+    public static final ConfigOption<Integer> HEARTBEAT_INTERVAL_SECOUND =
+            new ConfigOption<>(
+                    "server.role.heartbeat_interval",
+                    "The role state machine heartbeat interval second time",
+                    rangeInt(0, Integer.MAX_VALUE),
+                    2
+            );
+
+    public static final ConfigOption<Integer> EXCEEDS_WORKER_CLOCK_COUNT =
+            new ConfigOption<>(
+                    "server.role.worker_count",
+                    "When the worker node detects that the number of times " +
+                    "the master node fails to update heartbeat information 
reaches this threshold, " +
+                    "the working node will be converted to a candidate node",

Review Comment:
   keep `worker node` style:
   "the worker node will become to a candidate node."



##########
hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/RoleElectionOptions.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hugegraph.masterelection;
+
+import org.apache.hugegraph.config.ConfigOption;
+import org.apache.hugegraph.config.OptionHolder;
+
+import static org.apache.hugegraph.config.OptionChecker.disallowEmpty;
+import static org.apache.hugegraph.config.OptionChecker.rangeInt;
+
+public class RoleElectionOptions  extends OptionHolder {
+
+    private RoleElectionOptions() {
+        super();
+    }
+
+    private static volatile RoleElectionOptions instance;
+
+    public static synchronized RoleElectionOptions instance() {
+        if (instance == null) {
+            instance = new RoleElectionOptions();
+            // Should initialize all static members first, then register.
+            instance.registerOptions();
+        }
+        return instance;
+    }
+
+    public static final ConfigOption<Integer> EXCEEDS_FAIL_COUNT =
+            new ConfigOption<>(
+                    "server.role.fail_count",
+                    "The role state machine fail count exceeds",

Review Comment:
   can also add more details? same as other options



##########
hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/RoleElectionOptions.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hugegraph.masterelection;
+
+import org.apache.hugegraph.config.ConfigOption;
+import org.apache.hugegraph.config.OptionHolder;
+
+import static org.apache.hugegraph.config.OptionChecker.disallowEmpty;
+import static org.apache.hugegraph.config.OptionChecker.rangeInt;
+
+public class RoleElectionOptions  extends OptionHolder {
+
+    private RoleElectionOptions() {
+        super();
+    }
+
+    private static volatile RoleElectionOptions instance;
+
+    public static synchronized RoleElectionOptions instance() {
+        if (instance == null) {
+            instance = new RoleElectionOptions();
+            // Should initialize all static members first, then register.
+            instance.registerOptions();
+        }
+        return instance;
+    }
+
+    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),
+                    5
+            );
+
+    public static final ConfigOption<String> NODE_EXTERNAL_URL =
+            new ConfigOption<>(
+                    "server.role.node_external_url",
+                    "The url of external accessibility",
+                    disallowEmpty(),
+                    "127.0.0.1:8080"
+            );
+
+    public static final ConfigOption<Integer> RANDOM_TIMEOUT_MILLISECOND =
+            new ConfigOption<>(
+                    "server.role.random_timeout",
+                    "The random timeout time that be used when candidate state 
node request " +
+                    "to become master state to reduce competitive voting",
+                    rangeInt(0, Integer.MAX_VALUE),
+                    1000
+            );
+
+    public static final ConfigOption<Integer> HEARTBEAT_INTERVAL_SECOUND =
+            new ConfigOption<>(
+                    "server.role.heartbeat_interval",
+                    "The role state machine heartbeat interval second time",
+                    rangeInt(0, Integer.MAX_VALUE),
+                    2
+            );
+
+    public static final ConfigOption<Integer> EXCEEDS_WORKER_CLOCK_COUNT =
+            new ConfigOption<>(
+                    "server.role.worker_count",
+                    "When the worker node detects that the number of times " +
+                    "the master node fails to update heartbeat information 
reaches this threshold, " +

Review Comment:
   `update heartbeat information` => `update heartbeat`



##########
hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/RoleElectionOptions.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hugegraph.masterelection;
+
+import org.apache.hugegraph.config.ConfigOption;
+import org.apache.hugegraph.config.OptionHolder;
+
+import static org.apache.hugegraph.config.OptionChecker.disallowEmpty;
+import static org.apache.hugegraph.config.OptionChecker.rangeInt;
+
+public class RoleElectionOptions  extends OptionHolder {
+
+    private RoleElectionOptions() {
+        super();
+    }
+
+    private static volatile RoleElectionOptions instance;
+
+    public static synchronized RoleElectionOptions instance() {
+        if (instance == null) {
+            instance = new RoleElectionOptions();
+            // Should initialize all static members first, then register.
+            instance.registerOptions();
+        }
+        return instance;
+    }
+
+    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),
+                    5
+            );
+
+    public static final ConfigOption<String> NODE_EXTERNAL_URL =
+            new ConfigOption<>(
+                    "server.role.node_external_url",
+                    "The url of external accessibility",
+                    disallowEmpty(),
+                    "127.0.0.1:8080"
+            );
+
+    public static final ConfigOption<Integer> RANDOM_TIMEOUT_MILLISECOND =
+            new ConfigOption<>(
+                    "server.role.random_timeout",
+                    "The random timeout time that be used when candidate state 
node request " +
+                    "to become master state to reduce competitive voting",
+                    rangeInt(0, Integer.MAX_VALUE),
+                    1000
+            );
+
+    public static final ConfigOption<Integer> HEARTBEAT_INTERVAL_SECOUND =
+            new ConfigOption<>(
+                    "server.role.heartbeat_interval",
+                    "The role state machine heartbeat interval second time",
+                    rangeInt(0, Integer.MAX_VALUE),
+                    2
+            );
+
+    public static final ConfigOption<Integer> EXCEEDS_WORKER_CLOCK_COUNT =

Review Comment:
   try this name `master_dead_times`?



##########
hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/RoleElectionOptions.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hugegraph.masterelection;
+
+import org.apache.hugegraph.config.ConfigOption;
+import org.apache.hugegraph.config.OptionHolder;
+
+import static org.apache.hugegraph.config.OptionChecker.disallowEmpty;
+import static org.apache.hugegraph.config.OptionChecker.rangeInt;
+
+public class RoleElectionOptions  extends OptionHolder {
+
+    private RoleElectionOptions() {
+        super();
+    }
+
+    private static volatile RoleElectionOptions instance;
+
+    public static synchronized RoleElectionOptions instance() {
+        if (instance == null) {
+            instance = new RoleElectionOptions();
+            // Should initialize all static members first, then register.
+            instance.registerOptions();
+        }
+        return instance;
+    }
+
+    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),
+                    5
+            );
+
+    public static final ConfigOption<String> NODE_EXTERNAL_URL =
+            new ConfigOption<>(
+                    "server.role.node_external_url",
+                    "The url of external accessibility",
+                    disallowEmpty(),
+                    "127.0.0.1:8080"
+            );
+
+    public static final ConfigOption<Integer> RANDOM_TIMEOUT_MILLISECOND =
+            new ConfigOption<>(
+                    "server.role.random_timeout",
+                    "The random timeout time that be used when candidate state 
node request " +

Review Comment:
   `The random timeout in ms that ...`



##########
hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/HugeRoleStateMachineConfig.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hugegraph.masterelection;
+
+public class HugeRoleStateMachineConfig implements Config {

Review Comment:
   prefer short name like RoleElectionConfig?



##########
hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/StandardClusterRoleStore.java:
##########
@@ -0,0 +1,215 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hugegraph.masterelection;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+
+import org.apache.hugegraph.HugeGraphParams;
+import org.apache.hugegraph.auth.SchemaDefine;
+import org.apache.hugegraph.backend.query.Condition;
+import org.apache.hugegraph.backend.query.ConditionQuery;
+import org.apache.hugegraph.backend.store.BackendEntry;
+import org.apache.hugegraph.backend.tx.GraphTransaction;
+import org.apache.hugegraph.schema.VertexLabel;
+import org.apache.hugegraph.structure.HugeVertex;
+import org.apache.hugegraph.type.HugeType;
+import org.apache.hugegraph.type.define.DataType;
+import org.apache.hugegraph.type.define.HugeKeys;
+import org.apache.hugegraph.util.Log;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.T;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.slf4j.Logger;
+
+public class StandardClusterRoleStore implements ClusterRoleStore {
+
+    private static final Logger LOG = 
Log.logger(StandardClusterRoleStore.class);
+    private static final int RETRY_QUERY_TIMEOUT = 200;
+
+    private final HugeGraphParams graph;
+    private final Schema schema;
+
+    private boolean firstTime;
+
+    public StandardClusterRoleStore(HugeGraphParams graph) {
+        this.graph = graph;
+        this.schema = new Schema(graph);
+        this.schema.initSchemaIfNeeded();
+        this.firstTime = true;
+    }
+
+    @Override
+    public boolean updateIfNodePresent(ClusterRole clusterRole) {
+        // if epoch increase, update and return true
+        // if epoch equal, ignore different node, return false
+        Optional<Vertex> oldClusterRoleOpt = this.queryVertex();
+        if (oldClusterRoleOpt.isPresent()) {
+            ClusterRole oldClusterRole = this.from(oldClusterRoleOpt.get());
+            if (clusterRole.epoch() < oldClusterRole.epoch()) {
+                return false;
+            }
+
+            if (clusterRole.epoch() == oldClusterRole.epoch() &&
+                !Objects.equals(clusterRole.node(), oldClusterRole.node())) {
+                return false;
+            }
+            LOG.trace("Server {} epoch {} begin remove data old epoch {}, ",
+                       clusterRole.node(), clusterRole.epoch(), 
oldClusterRole.epoch());
+            this.graph.systemTransaction().removeVertex((HugeVertex) 
oldClusterRoleOpt.get());
+            this.graph.systemTransaction().commitOrRollback();
+            LOG.trace("Server {} epoch {} success remove data old epoch {}, ",
+                       clusterRole.node(), clusterRole.epoch(), 
oldClusterRole.epoch());
+        }
+        try {
+            GraphTransaction tx = this.graph.systemTransaction();
+            tx.doUpdateIfAbsent(this.constructEntry(clusterRole));
+            tx.commitOrRollback();
+            LOG.trace("Server {} epoch {} success update data", 
clusterRole.node(), clusterRole.epoch());
+        } catch (Throwable ignore){
+            LOG.trace("Server {} epoch {} fail update data", 
clusterRole.node(), clusterRole.epoch());
+            return false;
+        }
+
+        return true;
+    }
+
+    private BackendEntry constructEntry(ClusterRole clusterRole) {
+        List<Object> list = new ArrayList<>(8);
+        list.add(T.label);
+        list.add(P.ROLE_DATA);
+
+        list.add(P.NODE);
+        list.add(clusterRole.node());
+
+        list.add(P.URL);
+        list.add(clusterRole.url());
+
+        list.add(P.CLOCK);
+        list.add(clusterRole.clock());
+
+        list.add(P.EPOCH);
+        list.add(clusterRole.epoch());
+
+        list.add(P.TYPE);
+        list.add("default");
+
+        HugeVertex vertex = this.graph.systemTransaction()
+                                      .constructVertex(false, list.toArray());
+
+        return this.graph.serializer().writeVertex(vertex);
+    }
+
+    @Override
+    public Optional<ClusterRole> query() {
+        Optional<Vertex> vertex = this.queryVertex();
+        if (!vertex.isPresent() && !this.firstTime) {
+            // If query nothing, retry once
+            try {
+                Thread.sleep(RETRY_QUERY_TIMEOUT);
+            } catch (InterruptedException ignore) {

Review Comment:
   keep "ignored" style



-- 
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