javeme commented on code in PR #2686:
URL:
https://github.com/apache/incubator-hugegraph/pull/2686#discussion_r1818077739
##########
设计文档.md:
##########
@@ -0,0 +1,239 @@
+## 事务日志——checklist
Review Comment:
@imbajin 设计文档可以放到doc仓库,另外可以将之前文档仓库也统一放到一个地方?
##########
hugegraph-server/hugegraph-dist/src/main/java/org/apache/hugegraph/TxScanner.java:
##########
@@ -0,0 +1,79 @@
+package org.apache.hugegraph;
+
+import org.apache.hugegraph.config.HugeConfig;
+import org.apache.hugegraph.core.GraphManager;
+import org.apache.hugegraph.masterelection.GlobalMasterInfo;
+import org.apache.hugegraph.pd.client.KvClient;
+import org.apache.hugegraph.pd.common.PDException;
+import org.apache.hugegraph.pd.grpc.kv.ScanPrefixResponse;
+import org.apache.hugegraph.pd.grpc.kv.WatchResponse;
+import org.apache.hugegraph.util.ConfigUtil;
+import org.apache.hugegraph.util.Events;
+import org.apache.hugegraph.util.JsonUtil;
+import org.apache.hugegraph.variables.CheckList;
+import org.apache.tinkerpop.gremlin.structure.util.GraphFactory;
+
+
+
+public class TxScanner {
+ private final String prefix = "graph_creat_tx";
+
+ private KvClient<WatchResponse> client;
+
+ public TxScanner(KvClient<WatchResponse> client) {
+ }
+
+
+ public void scan() {
+ try {
+ ScanPrefixResponse response = this.client.scanPrefix(prefix);
+ for(String key : response.getKvsMap().keySet()) {
+ String value = response.getKvsMap().get(key);
+ CheckList checkList = JsonUtil.fromJson(value,
CheckList.class);
+ switch (checkList.getStage()) {
+ case "config": {
+ configContinue(checkList);
+ }
Review Comment:
can we add some comments that we don't expect break here and explain why
##########
hugegraph-server/hugegraph-dist/src/main/java/org/apache/hugegraph/TxScanner.java:
##########
@@ -0,0 +1,79 @@
+package org.apache.hugegraph;
+
+import org.apache.hugegraph.config.HugeConfig;
+import org.apache.hugegraph.core.GraphManager;
+import org.apache.hugegraph.masterelection.GlobalMasterInfo;
+import org.apache.hugegraph.pd.client.KvClient;
+import org.apache.hugegraph.pd.common.PDException;
+import org.apache.hugegraph.pd.grpc.kv.ScanPrefixResponse;
+import org.apache.hugegraph.pd.grpc.kv.WatchResponse;
+import org.apache.hugegraph.util.ConfigUtil;
+import org.apache.hugegraph.util.Events;
+import org.apache.hugegraph.util.JsonUtil;
+import org.apache.hugegraph.variables.CheckList;
+import org.apache.tinkerpop.gremlin.structure.util.GraphFactory;
+
+
+
+public class TxScanner {
+ private final String prefix = "graph_creat_tx";
+
+ private KvClient<WatchResponse> client;
+
+ public TxScanner(KvClient<WatchResponse> client) {
+ }
+
+
+ public void scan() {
+ try {
+ ScanPrefixResponse response = this.client.scanPrefix(prefix);
+ for(String key : response.getKvsMap().keySet()) {
+ String value = response.getKvsMap().get(key);
+ CheckList checkList = JsonUtil.fromJson(value,
CheckList.class);
+ switch (checkList.getStage()) {
+ case "config": {
+ configContinue(checkList);
+ }
+ case "initBackend" : {
+ HugeConfig config = checkList.getConfig();
+ HugeGraph graph = (HugeGraph)
GraphFactory.open(config);
+ GlobalMasterInfo globalMasterInfo =
checkList.getNodeInfo();
+ graph.serverStarted(globalMasterInfo);
+ // Write config to disk file
+ String confPath =
ConfigUtil.writeToFile(checkList.getConfigPath(), graph.name(),
+
(HugeConfig)graph.configuration());
+ }
+ case "setServerStarted" : {
+ HugeConfig config = checkList.getConfig();
+ HugeGraph graph = (HugeGraph)
GraphFactory.open(config);
+ String confPath =
ConfigUtil.writeToFile(checkList.getConfigPath(), graph.name(),
+
(HugeConfig)graph.configuration());
+ }
+ case "finish" : {
+ client.delete(prefix + checkList.getName());
+ }
+ }
+ }
+ } catch (PDException e) {
+ throw new RuntimeException(e);
+ }
+
+ }
+
+ private void configContinue(CheckList checkList) {
+ HugeConfig config = checkList.getConfig();
+ HugeGraph graph = (HugeGraph) GraphFactory.open(config);
+ try {
+ // Create graph instance
+ graph = (HugeGraph) GraphFactory.open(config);
+ String configPath = checkList.getConfigPath();
+ GlobalMasterInfo globalMasterInfo = checkList.getNodeInfo();
+ // Init graph and start it
+ graph.create(configPath, globalMasterInfo);
+ } catch (Throwable e) {
+ throw e;
Review Comment:
don't need to catch if we just re-throw here?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]