Skip to content

Commit 2922cd3

Browse files
committed
fix(service): improve error handling for graph name format and config retrieval
1 parent c31dc4a commit 2922cd3

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2180,13 +2180,20 @@ private <T> void graphAddHandler(T response) {
21802180
.extractGraphsFromResponse(response);
21812181
for (String graphName : names) {
21822182
String[] parts = graphName.split(DELIMITER);
2183+
if (parts.length < 2) {
2184+
LOG.error("The graph name format is incorrect: {}", graphName);
2185+
continue;
2186+
}
21832187
// If the current server is not registered to the DEFAULT schema,
21842188
// it will only receive graph creation events under the registered schemas.
21852189
if (!"DEFAULT".equals(this.serviceGraphSpace) &&
21862190
!parts[0].equals(this.serviceGraphSpace)) {
21872191
LOG.warn(String.format("Listen event: graph [%s] add was discarded because " +
2188-
"it did " + "not belong to the graph space [%s] registered by " +
2189-
"the" + " current server", graphName, this.serviceGraphSpace));
2192+
"it did " +
2193+
"not belong to the graph space [%s] registered by " +
2194+
"the" + " current server", graphName,
2195+
this.serviceGraphSpace));
2196+
// TODO: further confirmation is required
21902197
return;
21912198
}
21922199
LOG.info("Accept graph add signal from etcd for {}", graphName);
@@ -2200,6 +2207,10 @@ private <T> void graphAddHandler(T response) {
22002207
graphName);
22012208
Map<String, Object> config =
22022209
this.metaManager.getGraphConfig(parts[0], parts[1]);
2210+
if (config == null) {
2211+
LOG.error("The graph config not exist: {}", graphName);
2212+
continue;
2213+
}
22032214
Object objc = config.get("creator");
22042215
String creator = null == objc ?
22052216
GraphSpace.DEFAULT_CREATOR_NAME :
@@ -2208,12 +2219,11 @@ private <T> void graphAddHandler(T response) {
22082219
// Create graph without init
22092220
try {
22102221
HugeGraph graph;
2222+
// TODO: add alias graph
22112223
// if (config.containsKey(CoreOptions.ALIAS_NAME.name())) {
2212-
// // TODO: add alias graph
22132224
// //graph = this.createAliasGraph(parts[0], parts[1], config, true);
22142225
// LOG.info("Add aliasGraph space:{} graph:{}", parts[0], parts[1]);
22152226
// } else {
2216-
22172227
// }
22182228
graph = this.createGraph(parts[0], parts[1], creator, config, false);
22192229
LOG.info("Add graph space:{} graph:{}", parts[0], parts[1]);
@@ -2247,6 +2257,10 @@ private <T> void graphRemoveHandler(T response) {
22472257

22482258
// Remove graph without clear
22492259
String[] parts = graphName.split(DELIMITER);
2260+
if (parts.length < 2) {
2261+
LOG.error("The graph name format is incorrect: {}", graphName);
2262+
continue;
2263+
}
22502264
try {
22512265
this.dropGraph(parts[0], parts[1], false);
22522266
} catch (HugeException e) {
@@ -2266,6 +2280,10 @@ private <T> void graphUpdateHandler(T response) {
22662280
HugeGraph hugeGraph = (HugeGraph) graph;
22672281
String[] values =
22682282
graphName.split(MetaManager.META_PATH_JOIN);
2283+
if (values.length < 2) {
2284+
LOG.error("The graph name format is incorrect: {}", graphName);
2285+
continue;
2286+
}
22692287
Map<String, Object> configs =
22702288
this.metaManager.getGraphConfig(values[0],
22712289
values[1]);

hugegraph-server/hugegraph-dist/src/main/java/org/apache/hugegraph/cmd/InitStore.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.apache.hugegraph.config.CoreOptions;
3232
import org.apache.hugegraph.config.HugeConfig;
3333
import org.apache.hugegraph.config.ServerOptions;
34+
import org.apache.hugegraph.constant.ServiceConstant;
3435
import org.apache.hugegraph.dist.RegisterUtil;
3536
import org.apache.hugegraph.meta.PdMetaDriver.PDAuthConfig;
3637
import org.apache.hugegraph.util.ConfigUtil;
@@ -98,11 +99,10 @@ public static void main(String[] args) throws Exception {
9899
}
99100
}
100101

101-
102102
private static void setPdAuthority(HugeConfig config) {
103103
PDAuthConfig.setAuthority(
104-
config.get(ServerOptions.SERVICE_ACCESS_PD_NAME),
105-
config.get(ServerOptions.SERVICE_ACCESS_PD_TOKEN));
104+
ServiceConstant.SERVICE_NAME,
105+
ServiceConstant.AUTHORITY);
106106
}
107107

108108
private static HugeGraph initGraph(String configPath) throws Exception {

hugegraph-server/hugegraph-dist/src/main/java/org/apache/hugegraph/dist/HugeGraphServer.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.apache.hugegraph.HugeFactory;
2222
import org.apache.hugegraph.config.HugeConfig;
2323
import org.apache.hugegraph.config.ServerOptions;
24+
import org.apache.hugegraph.constant.ServiceConstant;
2425
import org.apache.hugegraph.event.EventHub;
2526
import org.apache.hugegraph.meta.MetaManager;
2627
import org.apache.hugegraph.meta.PdMetaDriver;
@@ -59,7 +60,7 @@ public HugeGraphServer(String gremlinServerConf, String restServerConf)
5960
String graphsDir = restServerConfig.get(ServerOptions.GRAPHS);
6061
EventHub hub = new EventHub("gremlin=>hub<=rest");
6162

62-
setPdAuthority(restServerConfig);
63+
setPdAuthority();
6364
//this.metaManager.connect(cluster, MetaManager.MetaDriverType.PD,
6465
// caFile, clientCaFile, clientKeyFile,
6566
// metaEndpoints);
@@ -92,10 +93,10 @@ public HugeGraphServer(String gremlinServerConf, String restServerConf)
9293
this.memoryMonitor.start();
9394
}
9495

95-
private void setPdAuthority(HugeConfig config) {
96+
private void setPdAuthority() {
9697
PdMetaDriver.PDAuthConfig.setAuthority(
97-
config.get(ServerOptions.SERVICE_ACCESS_PD_NAME),
98-
config.get(ServerOptions.SERVICE_ACCESS_PD_TOKEN));
98+
ServiceConstant.SERVICE_NAME,
99+
ServiceConstant.AUTHORITY);
99100
}
100101

101102
public void stop() {

hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/core/CoreTestSuite.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
package org.apache.hugegraph.core;
1919

2020
import org.apache.hugegraph.HugeGraph;
21+
import org.apache.hugegraph.constant.ServiceConstant;
2122
import org.apache.hugegraph.dist.RegisterUtil;
2223
import org.apache.hugegraph.masterelection.GlobalMasterInfo;
2324
import org.apache.hugegraph.meta.MetaManager;
25+
import org.apache.hugegraph.meta.PdMetaDriver;
2426
import org.apache.hugegraph.testutil.Utils;
2527
import org.apache.hugegraph.util.Log;
2628
import org.junit.AfterClass;
@@ -71,6 +73,8 @@ public static void initEnv() {
7173

7274
@BeforeClass
7375
public static void init() {
76+
PdMetaDriver.PDAuthConfig.setAuthority(ServiceConstant.SERVICE_NAME,
77+
ServiceConstant.AUTHORITY);
7478
graph = Utils.open();
7579
graph.clearBackend();
7680
graph.initBackend();

0 commit comments

Comments
 (0)