diff --git a/hugegraph-api/pom.xml b/hugegraph-api/pom.xml index b0de9feb99..487d8ff827 100644 --- a/hugegraph-api/pom.xml +++ b/hugegraph-api/pom.xml @@ -5,7 +5,7 @@ hugegraph com.baidu.hugegraph - 0.10.2 + 0.10.3 4.0.0 diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java index 7eb53b53b8..0b0e0b4402 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java @@ -38,12 +38,14 @@ import com.baidu.hugegraph.auth.HugeAuthenticator; import com.baidu.hugegraph.auth.HugeFactoryAuthProxy; import com.baidu.hugegraph.auth.HugeGraphAuthProxy; +import com.baidu.hugegraph.backend.BackendException; import com.baidu.hugegraph.backend.cache.Cache; import com.baidu.hugegraph.backend.cache.CacheManager; import com.baidu.hugegraph.backend.store.BackendStoreSystemInfo; import com.baidu.hugegraph.config.HugeConfig; import com.baidu.hugegraph.config.ServerOptions; import com.baidu.hugegraph.exception.NotSupportException; +import com.baidu.hugegraph.license.LicenseVerifier; import com.baidu.hugegraph.metrics.MetricsUtil; import com.baidu.hugegraph.metrics.ServerReporter; import com.baidu.hugegraph.serializer.JsonSerializer; @@ -70,6 +72,7 @@ public GraphManager(HugeConfig conf) { } this.loadGraphs(conf.getMap(ServerOptions.GRAPHS)); + this.installLicense(conf); this.checkBackendVersionOrExit(); this.restoreUncompletedTasks(); this.addMetrics(conf); @@ -135,6 +138,10 @@ public void commit(final Set graphSourceNamesToCloseTxOn) { closeTx(graphSourceNamesToCloseTxOn, Transaction.Status.COMMIT); } + private void installLicense(HugeConfig config) { + LicenseVerifier.instance().install(config, this); + } + private void closeTx(final Set graphSourceNamesToCloseTxOn, final Transaction.Status tx) { final Set graphsToCloseTxOn = new HashSet<>(); @@ -192,13 +199,12 @@ private void checkBackendVersionOrExit() { } BackendStoreSystemInfo info = new BackendStoreSystemInfo(hugegraph); if (!info.exist()) { - LOG.error("The backend store of '{}' has not been initialized", + throw new BackendException( + "The backend store of '%s' has not been initialized", hugegraph.name()); - System.exit(-1); } if (!info.checkVersion()) { - // Exit if versions are inconsistent - System.exit(-1); + throw new BackendException("Check backend store version failed"); } } } diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/license/LicenseVerifyManager.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/license/LicenseVerifyManager.java index b6cbec723d..3a0e97b0d0 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/license/LicenseVerifyManager.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/license/LicenseVerifyManager.java @@ -21,11 +21,14 @@ import java.io.IOException; import java.lang.management.ManagementFactory; +import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.List; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; +import com.baidu.hugegraph.HugeException; import com.baidu.hugegraph.config.HugeConfig; import com.baidu.hugegraph.config.ServerOptions; import com.baidu.hugegraph.core.GraphManager; @@ -64,7 +67,7 @@ public void config(HugeConfig config) { public HugeConfig config() { E.checkState(this.config != null, - "license verify manager has not been installed"); + "License verify manager has not been installed"); return this.config; } @@ -74,15 +77,18 @@ public void graphManager(GraphManager graphManager) { public GraphManager graphManager() { E.checkState(this.graphManager != null, - "license verify manager has not been installed"); + "License verify manager has not been installed"); return this.graphManager; } @Override - protected synchronized void validate(LicenseContent content) - throws LicenseContentException { + protected synchronized void validate(LicenseContent content) { // call super validate firstly - super.validate(content); + try { + super.validate(content); + } catch (LicenseContentException e) { + throw new HugeException("License valiverifydate failed"); + } // Verify the customized license parameters. List extraParams; @@ -97,14 +103,12 @@ protected synchronized void validate(LicenseContent content) LOG.debug("server id is {}", serverId); ExtraParam param = this.matchParam(serverId, extraParams); if (param == null) { - throw new LicenseContentException("The current server's id " + - "is not authorized"); + throw new HugeException("The current server's id is not authorized"); } this.checkVersion(param); this.checkGraphs(param); - this.checkIp(param); - this.checkMac(param); + this.checkIpAndMac(param); this.checkCpu(param); this.checkRam(param); this.checkThreads(param); @@ -124,7 +128,7 @@ private ExtraParam matchParam(String id, List extraParams) { return null; } - private void checkVersion(ExtraParam param) throws LicenseContentException { + private void checkVersion(ExtraParam param) { String expectVersion = param.version(); if (StringUtils.isEmpty(expectVersion)) { return; @@ -137,7 +141,7 @@ private void checkVersion(ExtraParam param) throws LicenseContentException { } } - private void checkGraphs(ExtraParam param) throws LicenseContentException { + private void checkGraphs(ExtraParam param) { int expectGraphs = param.graphs(); if (expectGraphs == NO_LIMIT) { return; @@ -150,7 +154,7 @@ private void checkGraphs(ExtraParam param) throws LicenseContentException { } } - private void checkIp(ExtraParam param) throws LicenseContentException { + private void checkIpAndMac(ExtraParam param) { String expectIp = param.ip(); if (StringUtils.isEmpty(expectIp)) { return; @@ -161,22 +165,29 @@ private void checkIp(ExtraParam param) throws LicenseContentException { "The server's ip '%s' doesn't match the authorized '%s'", actualIps, expectIp); } - } - private void checkMac(ExtraParam param) throws LicenseContentException { String expectMac = param.mac(); if (StringUtils.isEmpty(expectMac)) { return; } - List actualMacs = this.machineInfo.getMacAddress(); - if (!actualMacs.contains(expectMac)) { + String actualMac; + try { + actualMac = this.machineInfo.getMacByInetAddress( + InetAddress.getByName(expectIp)); + } catch (UnknownHostException e) { + throw newLicenseException( + "Failed to get mac address for ip '%s'", expectIp); + } + String expectFormatMac = expectMac.toUpperCase().replaceAll(":", "-"); + String actualFormatMac = actualMac.toUpperCase().replaceAll(":", "-"); + if (!actualFormatMac.equals(expectFormatMac)) { throw newLicenseException( "The server's mac '%s' doesn't match the authorized '%s'", - actualMacs, expectMac); + actualMac, expectMac); } } - private void checkCpu(ExtraParam param) throws LicenseContentException { + private void checkCpu(ExtraParam param) { int expectCpus = param.cpus(); if (expectCpus == NO_LIMIT) { return; @@ -189,7 +200,7 @@ private void checkCpu(ExtraParam param) throws LicenseContentException { } } - private void checkRam(ExtraParam param) throws LicenseContentException { + private void checkRam(ExtraParam param) { // Unit MB int expectRam = param.ram(); if (expectRam == NO_LIMIT) { @@ -205,7 +216,7 @@ private void checkRam(ExtraParam param) throws LicenseContentException { } } - private void checkThreads(ExtraParam param) throws LicenseContentException { + private void checkThreads(ExtraParam param) { int expectThreads = param.threads(); if (expectThreads == NO_LIMIT) { return; @@ -218,22 +229,25 @@ private void checkThreads(ExtraParam param) throws LicenseContentException { } } - private void checkMemory(ExtraParam param) throws LicenseContentException { + private void checkMemory(ExtraParam param) { // Unit MB int expectMemory = param.memory(); if (expectMemory == NO_LIMIT) { return; } + /* + * NOTE: this max memory will be slightly smaller than XMX, + * because only one survivor will be used + */ long actualMemory = Runtime.getRuntime().maxMemory() / Bytes.MB; if (actualMemory > expectMemory) { throw newLicenseException( - "The server's max memory(MB) '%s' exceeded the " + + "The server's max heap memory(MB) '%s' exceeded the " + "limit(MB) '%s'", actualMemory, expectMemory); } } - private LicenseContentException newLicenseException(String message, - Object... args) { - return new LicenseContentException(String.format(message, args)); + private HugeException newLicenseException(String message, Object... args) { + return new HugeException(message, args); } } diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/server/ApplicationConfig.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/server/ApplicationConfig.java index 198510566c..f8cf2fb2ca 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/server/ApplicationConfig.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/server/ApplicationConfig.java @@ -37,7 +37,6 @@ import com.baidu.hugegraph.config.HugeConfig; import com.baidu.hugegraph.core.GraphManager; import com.baidu.hugegraph.define.WorkLoad; -import com.baidu.hugegraph.license.LicenseVerifier; import com.baidu.hugegraph.util.E; import com.codahale.metrics.MetricRegistry; import com.codahale.metrics.jersey2.InstrumentedResourceMethodApplicationListener; @@ -68,10 +67,6 @@ public ApplicationConfig(HugeConfig conf) { register(new InstrumentedResourceMethodApplicationListener(registry)); } - private void installLicense(HugeConfig config, GraphManager manager) { - LicenseVerifier.instance().install(config, manager); - } - private class ConfFactory extends AbstractBinder implements Factory { @@ -110,8 +105,7 @@ public GraphManagerFactory(HugeConfig conf) { @Override public void onEvent(ApplicationEvent event) { if (event.getType() == this.EVENT_INITED) { - GraphManagerFactory.this.manager = new GraphManager(conf); - ApplicationConfig.this.installLicense(conf, manager); + manager = new GraphManager(conf); } } diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/server/RestServer.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/server/RestServer.java index e5f8b0bae3..53242c535f 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/server/RestServer.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/server/RestServer.java @@ -58,8 +58,12 @@ public void start() throws IOException { ResourceConfig rc = new ApplicationConfig(this.conf); this.httpServer = this.configHttpServer(uri, rc); - this.httpServer.start(); - + try { + this.httpServer.start(); + } catch (Throwable e) { + this.httpServer.shutdownNow(); + throw e; + } this.calcMaxWriteThreads(); } diff --git a/hugegraph-cassandra/pom.xml b/hugegraph-cassandra/pom.xml index ec94a83749..d60148945a 100644 --- a/hugegraph-cassandra/pom.xml +++ b/hugegraph-cassandra/pom.xml @@ -5,7 +5,7 @@ hugegraph com.baidu.hugegraph - 0.10.2 + 0.10.3 4.0.0 diff --git a/hugegraph-core/pom.xml b/hugegraph-core/pom.xml index 2652199060..d2548feb0a 100644 --- a/hugegraph-core/pom.xml +++ b/hugegraph-core/pom.xml @@ -5,7 +5,7 @@ com.baidu.hugegraph hugegraph - 0.10.2 + 0.10.3 ../pom.xml hugegraph-core diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskManager.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskManager.java index 31ba5ab4d9..5d1c34bd5c 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskManager.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/task/TaskManager.java @@ -73,7 +73,9 @@ public void closeScheduler(HugeGraph graph) { if (scheduler != null && scheduler.close()) { this.schedulers.remove(graph); } - this.closeTaskTx(graph); + if (!this.taskExecutor.isTerminated()) { + this.closeTaskTx(graph); + } } private void closeTaskTx(HugeGraph graph) { diff --git a/hugegraph-dist/pom.xml b/hugegraph-dist/pom.xml index 9d3bc9dcdd..e3bf2412c7 100644 --- a/hugegraph-dist/pom.xml +++ b/hugegraph-dist/pom.xml @@ -5,7 +5,7 @@ hugegraph com.baidu.hugegraph - 0.10.2 + 0.10.3 4.0.0 hugegraph-dist diff --git a/hugegraph-dist/src/assembly/static/conf/hugegraph-evaluation.license b/hugegraph-dist/src/assembly/static/conf/hugegraph-evaluation.license index bfd418967c..87a4039912 100644 Binary files a/hugegraph-dist/src/assembly/static/conf/hugegraph-evaluation.license and b/hugegraph-dist/src/assembly/static/conf/hugegraph-evaluation.license differ diff --git a/hugegraph-dist/src/assembly/static/conf/log4j2.xml b/hugegraph-dist/src/assembly/static/conf/log4j2.xml index b731ff2186..bf00865ba0 100644 --- a/hugegraph-dist/src/assembly/static/conf/log4j2.xml +++ b/hugegraph-dist/src/assembly/static/conf/log4j2.xml @@ -16,7 +16,6 @@ - diff --git a/hugegraph-dist/src/main/java/com/baidu/hugegraph/dist/HugeGraphServer.java b/hugegraph-dist/src/main/java/com/baidu/hugegraph/dist/HugeGraphServer.java index 1d67b25b60..7c83649e59 100644 --- a/hugegraph-dist/src/main/java/com/baidu/hugegraph/dist/HugeGraphServer.java +++ b/hugegraph-dist/src/main/java/com/baidu/hugegraph/dist/HugeGraphServer.java @@ -50,7 +50,11 @@ public HugeGraphServer(String gremlinServerConf, String restServerConf) this.restServer = HugeRestServer.start(restServerConf); } catch (Throwable e) { LOG.error("HugeRestServer start error: ", e); - this.gremlinServer.stop(); + try { + this.gremlinServer.stop().get(); + } catch (Throwable t) { + LOG.error("GremlinServer stop error: ", t); + } HugeGraph.shutdown(30L); throw e; } @@ -87,8 +91,8 @@ public static void main(String[] args) throws Exception { } HugeRestServer.register(); - HugeGraphServer server = new HugeGraphServer(args[0], args[1]); + HugeGraphServer server = new HugeGraphServer(args[0], args[1]); Runtime.getRuntime().addShutdownHook(new Thread(() -> { LOG.info("HugeGraphServer stopping"); server.stop(); diff --git a/hugegraph-example/pom.xml b/hugegraph-example/pom.xml index d32c740a5e..b43f5ee97e 100644 --- a/hugegraph-example/pom.xml +++ b/hugegraph-example/pom.xml @@ -5,7 +5,7 @@ hugegraph com.baidu.hugegraph - 0.10.2 + 0.10.3 4.0.0 diff --git a/hugegraph-hbase/pom.xml b/hugegraph-hbase/pom.xml index 08a87264a8..ef7bb106d3 100644 --- a/hugegraph-hbase/pom.xml +++ b/hugegraph-hbase/pom.xml @@ -5,7 +5,7 @@ hugegraph com.baidu.hugegraph - 0.10.2 + 0.10.3 4.0.0 diff --git a/hugegraph-mysql/pom.xml b/hugegraph-mysql/pom.xml index e3f5013cd4..47579c308d 100644 --- a/hugegraph-mysql/pom.xml +++ b/hugegraph-mysql/pom.xml @@ -5,7 +5,7 @@ hugegraph com.baidu.hugegraph - 0.10.2 + 0.10.3 4.0.0 diff --git a/hugegraph-palo/pom.xml b/hugegraph-palo/pom.xml index e17f890f07..69b90ef5d3 100644 --- a/hugegraph-palo/pom.xml +++ b/hugegraph-palo/pom.xml @@ -5,7 +5,7 @@ hugegraph com.baidu.hugegraph - 0.10.2 + 0.10.3 4.0.0 diff --git a/hugegraph-postgresql/pom.xml b/hugegraph-postgresql/pom.xml index 798e92eb8e..d1f88560ad 100644 --- a/hugegraph-postgresql/pom.xml +++ b/hugegraph-postgresql/pom.xml @@ -5,7 +5,7 @@ hugegraph com.baidu.hugegraph - 0.10.2 + 0.10.3 4.0.0 diff --git a/hugegraph-rocksdb/pom.xml b/hugegraph-rocksdb/pom.xml index e0286a5343..b459dde296 100644 --- a/hugegraph-rocksdb/pom.xml +++ b/hugegraph-rocksdb/pom.xml @@ -5,7 +5,7 @@ hugegraph com.baidu.hugegraph - 0.10.2 + 0.10.3 4.0.0 diff --git a/hugegraph-scylladb/pom.xml b/hugegraph-scylladb/pom.xml index 8dfb57c938..c7fb4cbd39 100644 --- a/hugegraph-scylladb/pom.xml +++ b/hugegraph-scylladb/pom.xml @@ -5,7 +5,7 @@ hugegraph com.baidu.hugegraph - 0.10.2 + 0.10.3 4.0.0 diff --git a/hugegraph-test/pom.xml b/hugegraph-test/pom.xml index 976a8a5535..39f9464dcd 100644 --- a/hugegraph-test/pom.xml +++ b/hugegraph-test/pom.xml @@ -5,7 +5,7 @@ hugegraph com.baidu.hugegraph - 0.10.2 + 0.10.3 4.0.0 diff --git a/pom.xml b/pom.xml index 503b9c86ab..9b90e1af6e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.baidu.hugegraph hugegraph - 0.10.2 + 0.10.3 pom 3.3.9