diff --git a/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/RedirectFilter.java b/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/RedirectFilter.java index 8d8521edc0..66a9f43c41 100644 --- a/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/RedirectFilter.java +++ b/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/RedirectFilter.java @@ -41,7 +41,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.http.client.utils.URIBuilder; import org.apache.hugegraph.core.GraphManager; -import org.apache.hugegraph.election.GlobalMasterInfo; +import org.apache.hugegraph.masterelection.GlobalMasterInfo; import org.apache.hugegraph.util.E; import org.apache.hugegraph.util.Log; import org.glassfish.hk2.api.IterableProvider; @@ -53,7 +53,7 @@ public class RedirectFilter implements ContainerRequestFilter { private static final Logger LOG = Log.logger(RedirectFilter.class); - public static final String X_HG_REDIRECT = "x-hg-redirect"; + private static final String X_HG_REDIRECT = "x-hg-redirect"; private static volatile Client client = null; diff --git a/hugegraph-api/src/main/java/org/apache/hugegraph/auth/HugeGraphAuthProxy.java b/hugegraph-api/src/main/java/org/apache/hugegraph/auth/HugeGraphAuthProxy.java index 1784fc5cd8..88b09bc7cb 100644 --- a/hugegraph-api/src/main/java/org/apache/hugegraph/auth/HugeGraphAuthProxy.java +++ b/hugegraph-api/src/main/java/org/apache/hugegraph/auth/HugeGraphAuthProxy.java @@ -37,7 +37,7 @@ import javax.security.sasl.AuthenticationException; import org.apache.commons.configuration2.Configuration; -import org.apache.hugegraph.election.RoleElectionStateMachine; +import org.apache.hugegraph.masterelection.RoleElectionStateMachine; import org.apache.tinkerpop.gremlin.process.computer.GraphComputer; import org.apache.tinkerpop.gremlin.process.traversal.Bytecode; import org.apache.tinkerpop.gremlin.process.traversal.Bytecode.Instruction; diff --git a/hugegraph-api/src/main/java/org/apache/hugegraph/auth/StandardAuthenticator.java b/hugegraph-api/src/main/java/org/apache/hugegraph/auth/StandardAuthenticator.java index be9c69b190..3255c88e25 100644 --- a/hugegraph-api/src/main/java/org/apache/hugegraph/auth/StandardAuthenticator.java +++ b/hugegraph-api/src/main/java/org/apache/hugegraph/auth/StandardAuthenticator.java @@ -126,7 +126,7 @@ public void setup(HugeConfig config) { String raftGroupPeers = config.get(ServerOptions.RAFT_GROUP_PEERS); graphConfig.addProperty(ServerOptions.RAFT_GROUP_PEERS.name(), raftGroupPeers); - this.addRoleWorkerConfig(graphConfig, config); + this.transferRoleWorkerConfig(graphConfig, config); this.graph = (HugeGraph) GraphFactory.open(graphConfig); @@ -138,19 +138,19 @@ public void setup(HugeConfig config) { } } - private void addRoleWorkerConfig(HugeConfig graphConfig, HugeConfig config) { + private void transferRoleWorkerConfig(HugeConfig graphConfig, HugeConfig config) { graphConfig.addProperty(CoreOptions.NODE_EXTERNAL_URL.name(), - config.get(ServerOptions.REST_SERVER_URL)); + config.get(ServerOptions.REST_SERVER_URL)); graphConfig.addProperty(CoreOptions.BASE_TIMEOUT_MILLISECOND.name(), - config.get(CoreOptions.BASE_TIMEOUT_MILLISECOND)); + config.get(CoreOptions.BASE_TIMEOUT_MILLISECOND)); graphConfig.addProperty(CoreOptions.EXCEEDS_FAIL_COUNT.name(), - config.get(CoreOptions.EXCEEDS_FAIL_COUNT)); + config.get(CoreOptions.EXCEEDS_FAIL_COUNT)); graphConfig.addProperty(CoreOptions.RANDOM_TIMEOUT_MILLISECOND.name(), - config.get(CoreOptions.RANDOM_TIMEOUT_MILLISECOND)); + config.get(CoreOptions.RANDOM_TIMEOUT_MILLISECOND)); graphConfig.addProperty(CoreOptions.HEARTBEAT_INTERVAL_SECOUND.name(), - config.get(CoreOptions.HEARTBEAT_INTERVAL_SECOUND)); + config.get(CoreOptions.HEARTBEAT_INTERVAL_SECOUND)); graphConfig.addProperty(CoreOptions.EXCEEDS_WORKER_COUNT.name(), - config.get(CoreOptions.EXCEEDS_WORKER_COUNT)); + config.get(CoreOptions.EXCEEDS_WORKER_COUNT)); } /** diff --git a/hugegraph-api/src/main/java/org/apache/hugegraph/core/GraphManager.java b/hugegraph-api/src/main/java/org/apache/hugegraph/core/GraphManager.java index 62b3c67bc2..20879967e4 100644 --- a/hugegraph-api/src/main/java/org/apache/hugegraph/core/GraphManager.java +++ b/hugegraph-api/src/main/java/org/apache/hugegraph/core/GraphManager.java @@ -31,9 +31,9 @@ import org.apache.commons.configuration2.PropertiesConfiguration; import org.apache.commons.lang3.StringUtils; import org.apache.hugegraph.auth.StandardAuthenticator; -import org.apache.hugegraph.election.GlobalMasterInfo; -import org.apache.hugegraph.election.StandardStateMachineCallback; -import org.apache.hugegraph.election.RoleElectionStateMachine; +import org.apache.hugegraph.masterelection.GlobalMasterInfo; +import org.apache.hugegraph.masterelection.StandardStateMachineCallback; +import org.apache.hugegraph.masterelection.RoleElectionStateMachine; import org.apache.tinkerpop.gremlin.server.auth.AuthenticationException; import org.apache.tinkerpop.gremlin.server.util.MetricManager; import org.apache.tinkerpop.gremlin.structure.Graph; @@ -371,7 +371,7 @@ private void loadGraph(String name, String graphConfPath) { String raftGroupPeers = this.conf.get(ServerOptions.RAFT_GROUP_PEERS); config.addProperty(ServerOptions.RAFT_GROUP_PEERS.name(), raftGroupPeers); - this.addRoleWorkerConfig(config); + this.transferRoleWorkerConfig(config); Graph graph = GraphFactory.open(config); this.graphs.put(name, graph); @@ -389,7 +389,7 @@ private void loadGraph(String name, String graphConfPath) { } } - private void addRoleWorkerConfig(HugeConfig config) { + private void transferRoleWorkerConfig(HugeConfig config) { config.addProperty(CoreOptions.NODE_EXTERNAL_URL.name(), this.conf.get(ServerOptions.REST_SERVER_URL)); config.addProperty(CoreOptions.BASE_TIMEOUT_MILLISECOND.name(), diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/HugeGraph.java b/hugegraph-core/src/main/java/org/apache/hugegraph/HugeGraph.java index 4e67502e9b..9c4614f459 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/HugeGraph.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/HugeGraph.java @@ -28,7 +28,7 @@ import org.apache.hugegraph.backend.store.BackendFeatures; import org.apache.hugegraph.backend.store.BackendStoreInfo; import org.apache.hugegraph.backend.store.raft.RaftGroupManager; -import org.apache.hugegraph.election.RoleElectionStateMachine; +import org.apache.hugegraph.masterelection.RoleElectionStateMachine; import org.apache.hugegraph.rpc.RpcServiceConfig4Client; import org.apache.hugegraph.rpc.RpcServiceConfig4Server; import org.apache.hugegraph.task.TaskScheduler; diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/StandardHugeGraph.java b/hugegraph-core/src/main/java/org/apache/hugegraph/StandardHugeGraph.java index 0bead70cfd..dacbe704c7 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/StandardHugeGraph.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/StandardHugeGraph.java @@ -45,12 +45,12 @@ import org.apache.hugegraph.backend.tx.GraphTransaction; import org.apache.hugegraph.backend.tx.SchemaTransaction; import org.apache.hugegraph.config.CoreOptions; -import org.apache.hugegraph.election.ClusterRoleStore; -import org.apache.hugegraph.election.Config; -import org.apache.hugegraph.election.HugeRoleStateMachineConfig; -import org.apache.hugegraph.election.RoleElectionStateMachine; -import org.apache.hugegraph.election.StandardRoleElectionStateMachine; -import org.apache.hugegraph.election.StandardClusterRoleStore; +import org.apache.hugegraph.masterelection.ClusterRoleStore; +import org.apache.hugegraph.masterelection.Config; +import org.apache.hugegraph.masterelection.HugeRoleStateMachineConfig; +import org.apache.hugegraph.masterelection.RoleElectionStateMachine; +import org.apache.hugegraph.masterelection.StandardRoleElectionStateMachine; +import org.apache.hugegraph.masterelection.StandardClusterRoleStore; import org.apache.hugegraph.io.HugeGraphIoRegistry; import org.apache.hugegraph.rpc.RpcServiceConfig4Client; import org.apache.hugegraph.rpc.RpcServiceConfig4Server; @@ -294,8 +294,8 @@ private void initRoleStateWorker(Id serverId) { this.configuration.get(CoreOptions.HEARTBEAT_INTERVAL_SECOUND), this.configuration.get(CoreOptions.EXCEEDS_WORKER_COUNT), this.configuration.get(CoreOptions.BASE_TIMEOUT_MILLISECOND)); - ClusterRoleStore adapter = new StandardClusterRoleStore(this.params); - this.roleElectionStateMachine = new StandardRoleElectionStateMachine(roleStateMachineConfig, adapter); + ClusterRoleStore clusterRoleStore = new StandardClusterRoleStore(this.params); + this.roleElectionStateMachine = new StandardRoleElectionStateMachine(roleStateMachineConfig, clusterRoleStore); } @Override @@ -1090,7 +1090,6 @@ public String toString() { return StringFactory.graphString(this, this.name()); } - @Override public final void proxy(HugeGraph graph) { this.params.graph(graph); diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/election/ClusterRole.java b/hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/ClusterRole.java similarity index 98% rename from hugegraph-core/src/main/java/org/apache/hugegraph/election/ClusterRole.java rename to hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/ClusterRole.java index 420229da82..c22020a83a 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/election/ClusterRole.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/ClusterRole.java @@ -15,7 +15,7 @@ * under the License. */ -package org.apache.hugegraph.election; +package org.apache.hugegraph.masterelection; import java.util.Objects; @@ -24,7 +24,6 @@ public class ClusterRole { private String node; private long clock; private int epoch; - private String url; public ClusterRole(String node, String url, int epoch) { diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/election/ClusterRoleStore.java b/hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/ClusterRoleStore.java similarity index 95% rename from hugegraph-core/src/main/java/org/apache/hugegraph/election/ClusterRoleStore.java rename to hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/ClusterRoleStore.java index 10526d6905..638dbf49fd 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/election/ClusterRoleStore.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/ClusterRoleStore.java @@ -15,7 +15,7 @@ * under the License. */ -package org.apache.hugegraph.election; +package org.apache.hugegraph.masterelection; import java.util.Optional; diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/election/Config.java b/hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/Config.java similarity index 95% rename from hugegraph-core/src/main/java/org/apache/hugegraph/election/Config.java rename to hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/Config.java index 1618c1b193..1c158760e2 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/election/Config.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/Config.java @@ -15,7 +15,7 @@ * under the License. */ -package org.apache.hugegraph.election; +package org.apache.hugegraph.masterelection; public interface Config { diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/election/GlobalMasterInfo.java b/hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/GlobalMasterInfo.java similarity index 97% rename from hugegraph-core/src/main/java/org/apache/hugegraph/election/GlobalMasterInfo.java rename to hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/GlobalMasterInfo.java index 2c6d0aad39..9d8f85a9b2 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/election/GlobalMasterInfo.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/GlobalMasterInfo.java @@ -15,7 +15,7 @@ * under the License. */ -package org.apache.hugegraph.election; +package org.apache.hugegraph.masterelection; public class GlobalMasterInfo { diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/election/HugeRoleStateMachineConfig.java b/hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/HugeRoleStateMachineConfig.java similarity index 98% rename from hugegraph-core/src/main/java/org/apache/hugegraph/election/HugeRoleStateMachineConfig.java rename to hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/HugeRoleStateMachineConfig.java index d99ce967a4..da15d45096 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/election/HugeRoleStateMachineConfig.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/HugeRoleStateMachineConfig.java @@ -15,7 +15,7 @@ * under the License. */ -package org.apache.hugegraph.election; +package org.apache.hugegraph.masterelection; public class HugeRoleStateMachineConfig implements Config { diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/election/RoleElectionStateMachine.java b/hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/RoleElectionStateMachine.java similarity index 95% rename from hugegraph-core/src/main/java/org/apache/hugegraph/election/RoleElectionStateMachine.java rename to hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/RoleElectionStateMachine.java index 70ea67f979..920bc104f1 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/election/RoleElectionStateMachine.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/RoleElectionStateMachine.java @@ -15,7 +15,7 @@ * under the License. */ -package org.apache.hugegraph.election; +package org.apache.hugegraph.masterelection; public interface RoleElectionStateMachine { diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/election/StandardClusterRoleStore.java b/hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/StandardClusterRoleStore.java similarity index 98% rename from hugegraph-core/src/main/java/org/apache/hugegraph/election/StandardClusterRoleStore.java rename to hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/StandardClusterRoleStore.java index 434248bf65..06519829b3 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/election/StandardClusterRoleStore.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/StandardClusterRoleStore.java @@ -15,7 +15,7 @@ * under the License. */ -package org.apache.hugegraph.election; +package org.apache.hugegraph.masterelection; import java.util.ArrayList; import java.util.Iterator; @@ -43,7 +43,7 @@ public class StandardClusterRoleStore implements ClusterRoleStore { private static final Logger LOG = Log.logger(StandardClusterRoleStore.class); - public static final int RETRY_QUERY_TIMEOUT = 200; + private static final int RETRY_QUERY_TIMEOUT = 200; private final HugeGraphParams graph; private final Schema schema; diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/election/StandardRoleElectionStateMachine.java b/hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/StandardRoleElectionStateMachine.java similarity index 98% rename from hugegraph-core/src/main/java/org/apache/hugegraph/election/StandardRoleElectionStateMachine.java rename to hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/StandardRoleElectionStateMachine.java index d797c1dced..c9a8c4faa3 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/election/StandardRoleElectionStateMachine.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/StandardRoleElectionStateMachine.java @@ -15,7 +15,7 @@ * under the License. */ -package org.apache.hugegraph.election; +package org.apache.hugegraph.masterelection; import java.security.SecureRandom; import java.util.Optional; @@ -27,16 +27,16 @@ public class StandardRoleElectionStateMachine implements RoleElectionStateMachine { + private static final Logger LOG = Log.logger(StandardRoleElectionStateMachine.class); + private volatile boolean shutdown; private final Config config; private volatile RoleState state; private final ClusterRoleStore clusterRoleStore; - private static final Logger LOG = Log.logger(StandardRoleElectionStateMachine.class); - - public StandardRoleElectionStateMachine(Config config, ClusterRoleStore adapter) { + public StandardRoleElectionStateMachine(Config config, ClusterRoleStore clusterRoleStore) { this.config = config; - this.clusterRoleStore = adapter; + this.clusterRoleStore = clusterRoleStore; this.state = new UnknownState(null); this.shutdown = false; } diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/election/StandardStateMachineCallback.java b/hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/StandardStateMachineCallback.java similarity index 98% rename from hugegraph-core/src/main/java/org/apache/hugegraph/election/StandardStateMachineCallback.java rename to hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/StandardStateMachineCallback.java index 9eea4461f2..1713919f42 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/election/StandardStateMachineCallback.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/StandardStateMachineCallback.java @@ -15,7 +15,7 @@ * under the License. */ -package org.apache.hugegraph.election; +package org.apache.hugegraph.masterelection; import org.apache.hugegraph.task.TaskManager; import org.apache.hugegraph.util.Log; diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/election/StateMachineCallback.java b/hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/StateMachineCallback.java similarity index 96% rename from hugegraph-core/src/main/java/org/apache/hugegraph/election/StateMachineCallback.java rename to hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/StateMachineCallback.java index 806a7ac63f..35abbe3402 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/election/StateMachineCallback.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/StateMachineCallback.java @@ -15,7 +15,7 @@ * under the License. */ -package org.apache.hugegraph.election; +package org.apache.hugegraph.masterelection; public interface StateMachineCallback { diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/election/StateMachineContext.java b/hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/StateMachineContext.java similarity index 96% rename from hugegraph-core/src/main/java/org/apache/hugegraph/election/StateMachineContext.java rename to hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/StateMachineContext.java index e2d036d52a..b4ffa717a2 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/election/StateMachineContext.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/masterelection/StateMachineContext.java @@ -15,7 +15,7 @@ * under the License. */ -package org.apache.hugegraph.election; +package org.apache.hugegraph.masterelection; public interface StateMachineContext { diff --git a/hugegraph-test/src/main/java/org/apache/hugegraph/core/RoleElectionStateMachineTest.java b/hugegraph-test/src/main/java/org/apache/hugegraph/core/RoleElectionStateMachineTest.java index ba99a62bbf..3911864453 100644 --- a/hugegraph-test/src/main/java/org/apache/hugegraph/core/RoleElectionStateMachineTest.java +++ b/hugegraph-test/src/main/java/org/apache/hugegraph/core/RoleElectionStateMachineTest.java @@ -30,13 +30,13 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.locks.LockSupport; -import org.apache.hugegraph.election.ClusterRoleStore; -import org.apache.hugegraph.election.Config; -import org.apache.hugegraph.election.RoleElectionStateMachine; -import org.apache.hugegraph.election.StandardRoleElectionStateMachine; -import org.apache.hugegraph.election.ClusterRole; -import org.apache.hugegraph.election.StateMachineCallback; -import org.apache.hugegraph.election.StateMachineContext; +import org.apache.hugegraph.masterelection.ClusterRoleStore; +import org.apache.hugegraph.masterelection.Config; +import org.apache.hugegraph.masterelection.RoleElectionStateMachine; +import org.apache.hugegraph.masterelection.StandardRoleElectionStateMachine; +import org.apache.hugegraph.masterelection.ClusterRole; +import org.apache.hugegraph.masterelection.StateMachineCallback; +import org.apache.hugegraph.masterelection.StateMachineContext; import org.apache.hugegraph.testutil.Assert; import org.apache.hugegraph.testutil.Utils; import org.junit.Test; @@ -206,7 +206,7 @@ public void error(StateMachineContext context, Throwable e) { }; final List clusterRoleLogs = Collections.synchronizedList(new ArrayList<>(100)); - final ClusterRoleStore adapter = new ClusterRoleStore() { + final ClusterRoleStore clusterRoleStore = new ClusterRoleStore() { volatile int epoch = 0; @@ -263,7 +263,7 @@ public Optional query() { Thread node1 = new Thread(() -> { Config config = new TestConfig("1"); RoleElectionStateMachine stateMachine = - new StandardRoleElectionStateMachine(config, adapter); + new StandardRoleElectionStateMachine(config, clusterRoleStore); machines[1] = stateMachine; stateMachine.apply(callback); stop.countDown(); @@ -272,7 +272,7 @@ public Optional query() { Thread node2 = new Thread(() -> { Config config = new TestConfig("2"); RoleElectionStateMachine stateMachine = - new StandardRoleElectionStateMachine(config, adapter); + new StandardRoleElectionStateMachine(config, clusterRoleStore); machines[2] = stateMachine; stateMachine.apply(callback); stop.countDown(); @@ -281,7 +281,7 @@ public Optional query() { Thread node3 = new Thread(() -> { Config config = new TestConfig("3"); RoleElectionStateMachine stateMachine = - new StandardRoleElectionStateMachine(config, adapter); + new StandardRoleElectionStateMachine(config, clusterRoleStore); machines[3] = stateMachine; stateMachine.apply(callback); stop.countDown();