Skip to content

Commit

Permalink
optimize roleinfo retry
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxxoo committed Oct 8, 2024
1 parent 4274b72 commit 40ffcbd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ public void increaseLoad(int delta) {
this.updated = true;
}

public long expireTime() {
return this.updateTime.getTime() + EXPIRED_INTERVAL;

Check warning on line 118 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/HugeServerInfo.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/HugeServerInfo.java#L118

Added line #L118 was not covered by tests
}

public Date updateTime() {
return this.updateTime;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Check warning on line 111 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/ServerInfoManager.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/ServerInfoManager.java#L111

Added line #L111 was not covered by tests
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);

Check warning on line 114 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/ServerInfoManager.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/ServerInfoManager.java#L113-L114

Added lines #L113 - L114 were not covered by tests
}
try {
Thread.sleep(existed.expireTime() - now);
} catch (InterruptedException e) {
throw new HugeException("Interrupted when waiting for server " +

Check warning on line 119 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/ServerInfoManager.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/ServerInfoManager.java#L117-L119

Added lines #L117 - L119 were not covered by tests
"info expired", e);
}

Check warning on line 121 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/ServerInfoManager.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/ServerInfoManager.java#L121

Added line #L121 was not covered by tests
}
E.checkArgument(existed == null || !existed.alive(),
"The server with name '%s' already in cluster",
serverId);
Expand Down

0 comments on commit 40ffcbd

Please sign in to comment.