Skip to content

Commit 511e59d

Browse files
authored
Merge pull request #3 from Aph-CUG/dev-aph
Dev aph
2 parents 1a8e0d9 + 2015e14 commit 511e59d

File tree

4 files changed

+90
-138
lines changed

4 files changed

+90
-138
lines changed

hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/core/GraphManager.java

+3-34
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,6 @@ public final class GraphManager {
101101
private final HugeConfig conf;
102102
private final EventHub eventHub;
103103

104-
private final String preFix = "graph_creat_tx";
105-
106-
private KvClient<WatchResponse> client;
107-
108-
@Before
109-
public void setUp() {
110-
this.client = new KvClient<>(PDConfig.of("localhost:8686"));
111-
}
112104

113105
public GraphManager(HugeConfig conf, EventHub hub) {
114106
this.graphsDir = conf.get(ServerOptions.GRAPHS);
@@ -198,36 +190,13 @@ public HugeGraph createGraph(String name, String configText) {
198190
"The graph name can't be null or empty");
199191
E.checkArgument(!this.graphs().contains(name),
200192
"The graph name '%s' has existed", name);
201-
202-
CheckList checkList = new CheckList(name, configText);
203-
204-
205193
PropertiesConfiguration propConfig = ConfigUtil.buildConfig(configText);
206194
HugeConfig config = new HugeConfig(propConfig);
207195
this.checkOptions(config);
208-
209-
checkList.setConfig(config);
210-
checkList.setStage("config");
211-
212-
String json = JsonUtil.toJson(checkList);
213-
214-
try {
215-
client.put(preFix + name, json);
216-
}
217-
218-
catch (PDException e) {
219-
throw new RuntimeException(e);
220-
}
221-
222-
checkList.setStage("finish");
223-
try {
224-
client.put(preFix + name, json);
225-
}
226-
227-
catch (PDException e) {
228-
throw new RuntimeException(e);
229-
}
196+
return this.createGraph(config, name);
197+
}
230198

199+
public HugeGraph createGraphRecover(HugeConfig config, String name) {
231200
return this.createGraph(config, name);
232201
}
233202

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/StandardHugeGraph.java

+22-24
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import org.apache.hugegraph.masterelection.StandardRoleElectionStateMachine;
7373
import org.apache.hugegraph.meta.MetaManager;
7474
import org.apache.hugegraph.pd.client.KvClient;
75+
import org.apache.hugegraph.pd.client.PDConfig;
7576
import org.apache.hugegraph.pd.common.PDException;
7677
import org.apache.hugegraph.pd.grpc.kv.KResponse;
7778
import org.apache.hugegraph.pd.grpc.kv.WatchResponse;
@@ -186,8 +187,8 @@ public class StandardHugeGraph implements HugeGraph {
186187

187188
private final String schedulerType;
188189

189-
private KvClient<WatchResponse> client;
190-
190+
private KvClient<WatchResponse> client = new KvClient<>(PDConfig.of("localhost:8686"));
191+
private CheckList checkList;
191192
public StandardHugeGraph(HugeConfig config) {
192193
this.params = new StandardHugeGraphParams();
193194
this.configuration = config;
@@ -222,6 +223,7 @@ public StandardHugeGraph(HugeConfig config) {
222223
this.mode = GraphMode.NONE;
223224
this.readMode = GraphReadMode.OLTP_ONLY;
224225
this.schedulerType = config.get(CoreOptions.SCHEDULER_TYPE);
226+
this.checkList = new CheckList(this.name, this.configuration);
225227

226228
LockUtil.init(this.name);
227229

@@ -293,8 +295,10 @@ public void serverStarted(GlobalMasterInfo nodeInfo) {
293295

294296
LOG.info("Init server info [{}-{}] for graph '{}'...",
295297
nodeInfo.nodeId(), nodeInfo.nodeRole(), this.name);
296-
this.serverInfoManager().initServerInfo(nodeInfo);
297-
298+
if(!this.checkList.isInitServerInfo()) {
299+
this.serverInfoManager().initServerInfo(nodeInfo);
300+
this.checkList.setInitServerInfo();
301+
}
298302
this.initRoleStateMachine(nodeInfo.nodeId());
299303

300304
// TODO: check necessary?
@@ -434,9 +438,18 @@ public void truncateBackend() {
434438
@Override
435439
public void initSystemInfo() {
436440
try {
437-
this.taskScheduler().init();
438-
this.serverInfoManager().init();
439-
this.authManager().init();
441+
if(!this.checkList.isTaskSchedulerInit()) {
442+
this.taskScheduler().init();
443+
this.checkList.setTaskSchedulerInit();
444+
}
445+
if(!this.checkList.isServerInfoManagerInit()) {
446+
this.serverInfoManager().init();
447+
this.checkList.setTaskSchedulerInit();
448+
}
449+
if(!this.checkList.isAuthManagerInit()) {
450+
this.authManager().init();
451+
this.checkList.setAuthManagerInit();
452+
}
440453
} finally {
441454
this.closeTx();
442455
}
@@ -1011,30 +1024,15 @@ public synchronized void close() throws Exception {
10111024

10121025
@Override
10131026
public void create(String configPath, GlobalMasterInfo nodeInfo){
1014-
//CheckList checkList = new CheckList();
1015-
KResponse result = null;
1016-
try {
1017-
result = client.get(this.name);
1018-
String json = result.getValue();
1019-
CheckList checkList = JsonUtil.fromJson(json, CheckList.class);
1020-
1027+
this.checkList.setConfigPath(configPath);
1028+
this.checkList.setNodeInfo(nodeInfo);
10211029
this.initBackend();
1022-
checkList.setInitBackended(true);
1023-
checkList.setStage("initBackend");
1024-
client.put(name, JsonUtil.toJson(checkList));
10251030
this.serverStarted(nodeInfo);
1026-
checkList.setServerStarted(true);
1027-
checkList.setStage("setServerStarted");
1028-
client.put(name, JsonUtil.toJson(checkList));
1029-
10301031

10311032
// Write config to disk file
10321033
String confPath = ConfigUtil.writeToFile(configPath, this.name(),
10331034
this.configuration());
10341035
this.configuration.file(confPath);
1035-
} catch (Exception e) {
1036-
1037-
}
10381036
}
10391037

10401038
@Override

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/variables/CheckList.java

+59-34
Original file line numberDiff line numberDiff line change
@@ -2,69 +2,98 @@
22

33
import org.apache.hugegraph.config.HugeConfig;
44
import org.apache.hugegraph.masterelection.GlobalMasterInfo;
5+
import org.apache.hugegraph.pd.client.KvClient;
6+
import org.apache.hugegraph.pd.client.PDConfig;
7+
import org.apache.hugegraph.pd.common.PDException;
8+
import org.apache.hugegraph.pd.grpc.kv.WatchResponse;
9+
import org.apache.hugegraph.util.JsonUtil;
10+
import org.junit.Before;
511

612
import java.io.Serializable;
713

814
public class CheckList implements Serializable {
915

1016
private String name;
11-
private String configText;
12-
17+
1318
private HugeConfig config;
1419

15-
private boolean initBackended;
20+
private boolean taskSchedulerInit;
21+
22+
private boolean serverInfoManagerInit;
1623

17-
private boolean serverStarted;
24+
private boolean authManagerInit;
1825

19-
private String stage;
26+
private boolean initServerInfo;
2027

2128
private String configPath;
2229

2330
private GlobalMasterInfo nodeInfo;
2431

25-
boolean toCheck;
26-
String context;
27-
private boolean isBuild;
32+
private KvClient<WatchResponse> client;
33+
2834

29-
public void setBuild(boolean build) {
30-
isBuild = build;
35+
private final String preFix = "graph_creat_tx_";
36+
37+
@Before
38+
public void setUp() {
39+
this.client = new KvClient<>(PDConfig.of("localhost:8686"));
3140
}
3241

33-
public CheckList(String name, String context) {
42+
public CheckList(String name, HugeConfig config) {
3443
this.name = name;
35-
this.context = context;
44+
this.config = config;
3645
}
3746

38-
public HugeConfig getConfig() {
39-
return config;
47+
public String getName() {
48+
return name;
4049
}
4150

42-
public void setConfig(HugeConfig config) {
43-
this.config = config;
51+
public boolean isTaskSchedulerInit() {
52+
return taskSchedulerInit;
4453
}
4554

46-
public boolean isInitBackended() {
47-
return initBackended;
55+
public void setTaskSchedulerInit() {
56+
this.taskSchedulerInit = true;
57+
String json = JsonUtil.toJson(this);
58+
tryPut(json);
4859
}
4960

50-
public void setInitBackended(boolean initBackended) {
51-
this.initBackended = initBackended;
61+
public boolean isServerInfoManagerInit() {
62+
return serverInfoManagerInit;
5263
}
5364

54-
public boolean isServerStarted() {
55-
return serverStarted;
65+
public void setServerInfoManagerInit() {
66+
this.serverInfoManagerInit = true;
67+
String json = JsonUtil.toJson(this);
68+
tryPut(json);
5669
}
5770

58-
public void setServerStarted(boolean serverStarted) {
59-
this.serverStarted = serverStarted;
71+
public boolean isAuthManagerInit() {
72+
return authManagerInit;
6073
}
6174

62-
public String getStage() {
63-
return stage;
75+
public void setAuthManagerInit() {
76+
this.authManagerInit = true;
77+
String json = JsonUtil.toJson(this);
78+
tryPut(json);
6479
}
6580

66-
public void setStage(String stage) {
67-
this.stage = stage;
81+
public boolean isInitServerInfo() {
82+
return initServerInfo;
83+
}
84+
85+
public void setInitServerInfo() {
86+
this.initServerInfo = true;
87+
String json = JsonUtil.toJson(this);
88+
tryPut(json);
89+
}
90+
91+
private void tryPut(String json) {
92+
try {
93+
client.put(preFix + name, json);
94+
} catch (PDException e) {
95+
throw new RuntimeException(e);
96+
}
6897
}
6998

7099
public String getConfigPath() {
@@ -83,11 +112,7 @@ public void setNodeInfo(GlobalMasterInfo nodeInfo) {
83112
this.nodeInfo = nodeInfo;
84113
}
85114

86-
public String getName() {
87-
return name;
88-
}
89-
90-
public void setName(String name) {
91-
this.name = name;
115+
public HugeConfig getConfig() {
116+
return config;
92117
}
93118
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.apache.hugegraph;
22

3+
import jakarta.ws.rs.core.Context;
34
import org.apache.hugegraph.config.HugeConfig;
45
import org.apache.hugegraph.core.GraphManager;
56
import org.apache.hugegraph.masterelection.GlobalMasterInfo;
@@ -16,7 +17,10 @@
1617

1718

1819
public class TxScanner {
19-
private final String prefix = "graph_creat_tx";
20+
private final String prefix = "graph_creat_tx_";
21+
22+
@Context
23+
GraphManager manager;
2024

2125
private KvClient<WatchResponse> client;
2226

@@ -30,54 +34,10 @@ public void scan() {
3034
for(String key : response.getKvsMap().keySet()) {
3135
String value = response.getKvsMap().get(key);
3236
CheckList checkList = JsonUtil.fromJson(value, CheckList.class);
33-
switch (checkList.getStage()) {
34-
case "config": {
35-
configContinue(checkList);
36-
break;
37-
}
38-
case "initBackend" : {
39-
HugeConfig config = checkList.getConfig();
40-
HugeGraph graph = (HugeGraph) GraphFactory.open(config);
41-
GlobalMasterInfo globalMasterInfo = checkList.getNodeInfo();
42-
graph.serverStarted(globalMasterInfo);
43-
// Write config to disk file
44-
String confPath = ConfigUtil.writeToFile(checkList.getConfigPath(), graph.name(),
45-
(HugeConfig)graph.configuration());
46-
break;
47-
}
48-
case "setServerStarted" : {
49-
HugeConfig config = checkList.getConfig();
50-
HugeGraph graph = (HugeGraph) GraphFactory.open(config);
51-
String confPath = ConfigUtil.writeToFile(checkList.getConfigPath(), graph.name(),
52-
(HugeConfig)graph.configuration());
53-
break;
54-
}
55-
case "finish" : {
56-
client.delete(prefix + checkList.getName());
57-
break;
58-
}
59-
}
37+
HugeGraph graph = manager.createGraphRecover(checkList.getConfig(), checkList.getName());
6038
}
6139
} catch (PDException e) {
6240
throw new RuntimeException(e);
6341
}
64-
65-
}
66-
67-
private void configContinue(CheckList checkList) {
68-
HugeConfig config = checkList.getConfig();
69-
HugeGraph graph = (HugeGraph) GraphFactory.open(config);
70-
try {
71-
// Create graph instance
72-
graph = (HugeGraph) GraphFactory.open(config);
73-
String configPath = checkList.getConfigPath();
74-
GlobalMasterInfo globalMasterInfo = checkList.getNodeInfo();
75-
// Init graph and start it
76-
graph.create(configPath, globalMasterInfo);
77-
} catch (Throwable e) {
78-
throw e;
79-
}
80-
8142
}
82-
8343
}

0 commit comments

Comments
 (0)