diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/HugeServerInfo.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/HugeServerInfo.java index a304b4f75b..3b3cf1ad88 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/HugeServerInfo.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/HugeServerInfo.java @@ -114,6 +114,10 @@ public void increaseLoad(int delta) { this.updated = true; } + public long expireTime() { + return this.updateTime.getTime() + EXPIRED_INTERVAL; + } + public Date updateTime() { return this.updateTime; } diff --git a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/ServerInfoManager.java b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/ServerInfoManager.java index de0d08b03a..3bcd48ac4c 100644 --- a/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/ServerInfoManager.java +++ b/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/ServerInfoManager.java @@ -107,6 +107,19 @@ public synchronized void initServerInfo(GlobalMasterInfo nodeInfo) { Id serverId = nodeInfo.nodeId(); HugeServerInfo existed = this.serverInfo(serverId); + if (existed != null && existed.alive()) { + final long now = DateUtil.now().getTime(); + if (existed.expireTime() > now + 30 * 1000) { + LOG.info("The node time maybe skew very much: {}", existed); + throw new HugeException("The server with name '%s' maybe skew very much", serverId); + } + try { + Thread.sleep(existed.expireTime() - now + 1); + } catch (InterruptedException e) { + throw new HugeException("Interrupted when waiting for server " + + "info expired", e); + } + } E.checkArgument(existed == null || !existed.alive(), "The server with name '%s' already in cluster", serverId);