Skip to content

Commit

Permalink
chore: improve
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxxoo committed Mar 6, 2023
1 parent 3b09579 commit 67b8404
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ private void transferRoleWorkerConfig(HugeConfig graphConfig, HugeConfig config)
config.get(RoleElectionOptions.RANDOM_TIMEOUT_MILLISECOND));
graphConfig.addProperty(RoleElectionOptions.HEARTBEAT_INTERVAL_SECOUND.name(),
config.get(RoleElectionOptions.HEARTBEAT_INTERVAL_SECOUND));
graphConfig.addProperty(RoleElectionOptions.EXCEEDS_WORKER_CLOCK_COUNT.name(),
config.get(RoleElectionOptions.EXCEEDS_WORKER_CLOCK_COUNT));
graphConfig.addProperty(RoleElectionOptions.MASTER_DEAD_TIMES.name(),
config.get(RoleElectionOptions.MASTER_DEAD_TIMES));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ private void transferRoleWorkerConfig(HugeConfig config) {
this.conf.get(RoleElectionOptions.RANDOM_TIMEOUT_MILLISECOND));
config.addProperty(RoleElectionOptions.HEARTBEAT_INTERVAL_SECOUND.name(),
this.conf.get(RoleElectionOptions.HEARTBEAT_INTERVAL_SECOUND));
config.addProperty(RoleElectionOptions.EXCEEDS_WORKER_CLOCK_COUNT.name(),
this.conf.get(RoleElectionOptions.EXCEEDS_WORKER_CLOCK_COUNT));
config.addProperty(RoleElectionOptions.MASTER_DEAD_TIMES.name(),
this.conf.get(RoleElectionOptions.MASTER_DEAD_TIMES));
}

private void waitGraphsReady() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import org.apache.hugegraph.config.CoreOptions;
import org.apache.hugegraph.masterelection.ClusterRoleStore;
import org.apache.hugegraph.masterelection.Config;
import org.apache.hugegraph.masterelection.HugeRoleStateMachineConfig;
import org.apache.hugegraph.masterelection.RoleElectionConfig;
import org.apache.hugegraph.masterelection.RoleElectionOptions;
import org.apache.hugegraph.masterelection.RoleElectionStateMachine;
import org.apache.hugegraph.masterelection.StandardRoleElectionStateMachine;
Expand Down Expand Up @@ -288,12 +288,12 @@ public void serverStarted(Id serverId, NodeRole serverRole) {
}

private void initRoleStateWorker(Id serverId) {
Config roleStateMachineConfig = new HugeRoleStateMachineConfig(serverId.toString(),
Config roleStateMachineConfig = new RoleElectionConfig(serverId.toString(),
this.configuration.get(RoleElectionOptions.NODE_EXTERNAL_URL),
this.configuration.get(RoleElectionOptions.EXCEEDS_FAIL_COUNT),
this.configuration.get(RoleElectionOptions.RANDOM_TIMEOUT_MILLISECOND),
this.configuration.get(RoleElectionOptions.HEARTBEAT_INTERVAL_SECOUND),
this.configuration.get(RoleElectionOptions.EXCEEDS_WORKER_CLOCK_COUNT),
this.configuration.get(RoleElectionOptions.MASTER_DEAD_TIMES),
this.configuration.get(RoleElectionOptions.BASE_TIMEOUT_MILLISECOND));
ClusterRoleStore clusterRoleStore = new StandardClusterRoleStore(this.params);
this.roleElectionStateMachine = new StandardRoleElectionStateMachine(roleStateMachineConfig, clusterRoleStore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public interface Config {

long heartBeatIntervalSecond();

int exceedsWorkerCount();
int masterDeadTimes();

long baseTimeoutMillisecond();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,28 @@

package org.apache.hugegraph.masterelection;

public class HugeRoleStateMachineConfig implements Config {
public class RoleElectionConfig implements Config {

private String node;
private String url;
private int exceedsFailCount;
private long randomTimeoutMillisecond;
private long heartBeatIntervalSecond;
private int exceedsWorkerCount;
private int masterDeadTimes;
private long baseTimeoutMillisecond;

public HugeRoleStateMachineConfig(String node, String url, int exceedsFailCount,
long randomTimeoutMillisecond, long heartBeatIntervalSecond,
int exceedsWorkerCount, long baseTimeoutMillisecond) {
public RoleElectionConfig(String node, String url, int exceedsFailCount,
long randomTimeoutMillisecond, long heartBeatIntervalSecond,
int masterDeadTimes, long baseTimeoutMillisecond) {
this.node = node;
this.url = url;
this.exceedsFailCount = exceedsFailCount;
this.randomTimeoutMillisecond = randomTimeoutMillisecond;
this.heartBeatIntervalSecond = heartBeatIntervalSecond;
this.exceedsWorkerCount = exceedsWorkerCount;
this.masterDeadTimes = masterDeadTimes;
this.baseTimeoutMillisecond = baseTimeoutMillisecond;
}


@Override
public String node() {
return this.node;
Expand All @@ -66,8 +65,8 @@ public long heartBeatIntervalSecond() {
}

@Override
public int exceedsWorkerCount() {
return this.exceedsWorkerCount;
public int masterDeadTimes() {
return this.masterDeadTimes;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,50 +43,52 @@ public static synchronized RoleElectionOptions instance() {
public static final ConfigOption<Integer> EXCEEDS_FAIL_COUNT =
new ConfigOption<>(
"server.role.fail_count",
"The role state machine fail count exceeds",
"When the node failed count of update or query heartbeat " +
"is reaches this threshold, the node will become abdication state to guard" +
"safe property.",
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",
"The url of external accessibility.",
disallowEmpty(),
"127.0.0.1:8080"
"http://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",
"The random timeout in ms that be used when candidate 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",
"The role state machine heartbeat interval second time.",
rangeInt(0, Integer.MAX_VALUE),
2
);

public static final ConfigOption<Integer> EXCEEDS_WORKER_CLOCK_COUNT =
public static final ConfigOption<Integer> MASTER_DEAD_TIMES =
new ConfigOption<>(
"server.role.worker_count",
"server.role.master_dead_times",
"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",
"the master node fails to update heartbeat reaches this threshold, " +
"the worker node will become 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",
"The role state machine candidate state base timeout time.",
rangeInt(0, Integer.MAX_VALUE),
500
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public Optional<ClusterRole> query() {
// If query nothing, retry once
try {
Thread.sleep(RETRY_QUERY_TIMEOUT);
} catch (InterruptedException ignore) {
} catch (InterruptedException ignored) {
}

vertex = this.queryVertex();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public RoleState transform(StateMachineContext context) {
RoleState nextState = new UnknownState(this.clusterRole.epoch()).transform(context);
if (nextState instanceof WorkerState) {
this.merge((WorkerState) nextState);
if (this.clock > context.config().exceedsWorkerCount()) {
if (this.clock > context.config().masterDeadTimes()) {
return new CandidateState(this.clusterRole.epoch() + 1);
} else {
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.commons.configuration2.PropertiesConfiguration;
import org.apache.commons.configuration2.builder.fluent.Configurations;
import org.apache.commons.configuration2.ex.ConfigurationException;
import org.apache.hugegraph.masterelection.RoleElectionOptions;
import org.slf4j.Logger;

import org.apache.hugegraph.HugeException;
Expand All @@ -45,6 +46,7 @@ public class RegisterUtil {
static {
OptionSpace.register("core", CoreOptions.instance());
OptionSpace.register("dist", DistOptions.instance());
OptionSpace.register("masterElection", RoleElectionOptions.instance());
}

public static void registerBackends() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public long heartBeatIntervalSecond() {
}

@Override
public int exceedsWorkerCount() {
public int masterDeadTimes() {
return 5;
}

Expand Down

0 comments on commit 67b8404

Please sign in to comment.