You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hugegraph.apache.org by "zyxxoo (via GitHub)" <gi...@apache.org> on 2023/02/27 02:23:53 UTC

[GitHub] [incubator-hugegraph] zyxxoo commented on a diff in pull request #2130: feat: support task auto manage by server role state machine

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


##########
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) {

Review Comment:
   The StateMachine is independent moduleļ¼Œ the init method pefer  put it outside



##########
hugegraph-api/src/main/java/org/apache/hugegraph/core/StateMachineCallbackImpl.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.core;
+
+import org.apache.hugegraph.election.StateMachineCallback;
+import org.apache.hugegraph.election.StateMachineContext;
+import org.apache.hugegraph.task.TaskManager;
+import org.apache.hugegraph.util.Log;
+import org.slf4j.Logger;
+
+public class StateMachineCallbackImpl implements StateMachineCallback {

Review Comment:
   This file is mainly responsible for state machine and external interactions, so it was not previously committed



##########
hugegraph-api/src/main/java/org/apache/hugegraph/core/StateMachineCallbackImpl.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.core;
+
+import org.apache.hugegraph.election.StateMachineCallback;
+import org.apache.hugegraph.election.StateMachineContext;
+import org.apache.hugegraph.task.TaskManager;
+import org.apache.hugegraph.util.Log;
+import org.slf4j.Logger;
+
+public class StateMachineCallbackImpl implements StateMachineCallback {
+
+    private static final Logger LOG = Log.logger(StateMachineCallbackImpl.class);
+
+    private final TaskManager taskManager;
+
+    boolean isMaster = false;

Review Comment:
   the filed only use on one thread, so don't volatile



##########
hugegraph-api/src/main/java/org/apache/hugegraph/core/RoleTypeDataAdapterImpl.java:
##########
@@ -0,0 +1,189 @@
+/*
+ * 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.core;
+
+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.election.RoleTypeData;
+import org.apache.hugegraph.election.RoleTypeDataAdapter;
+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.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.T;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+
+public class RoleTypeDataAdapterImpl implements RoleTypeDataAdapter {

Review Comment:
   yes, the adapter responsibility mainly applies to storage



-- 
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-unsubscribe@hugegraph.apache.org

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