You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ma...@apache.org on 2022/08/18 00:47:09 UTC
[shardingsphere] branch master updated: Optimize the generation of worker-id when proxy is re-registered in cluster mode (#20241)
This is an automated email from the ASF dual-hosted git repository.
machen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 72a5e1d4cca Optimize the generation of worker-id when proxy is re-registered in cluster mode (#20241)
72a5e1d4cca is described below
commit 72a5e1d4cca6774df63e80eb0212335ac04734e8
Author: gin <ja...@163.com>
AuthorDate: Thu Aug 18 08:47:02 2022 +0800
Optimize the generation of worker-id when proxy is re-registered in cluster mode (#20241)
---
.../apache/shardingsphere/infra/instance/ComputeNodeInstance.java | 7 +++++--
.../cluster/zookeeper/listener/SessionConnectionListener.java | 8 +++++++-
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/ComputeNodeInstance.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/ComputeNodeInstance.java
index 178ce4b151b..c0293b7837b 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/ComputeNodeInstance.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/ComputeNodeInstance.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.infra.instance;
import lombok.Getter;
-import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData;
import org.apache.shardingsphere.infra.state.StateContext;
@@ -30,7 +29,6 @@ import java.util.Collection;
/**
* Instance of compute node.
*/
-@RequiredArgsConstructor
@Getter
@Setter
public final class ComputeNodeInstance {
@@ -43,6 +41,11 @@ public final class ComputeNodeInstance {
private volatile long workerId;
+ public ComputeNodeInstance(final InstanceMetaData metaData) {
+ this.metaData = metaData;
+ workerId = -1L;
+ }
+
/**
* Set labels.
*
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-provider/shardingsphere-cluster-mode-repository-zookeeper-curator/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/listener/SessionConnectionListener.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-reposit [...]
index a814810c694..b8186520731 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-provider/shardingsphere-cluster-mode-repository-zookeeper-curator/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/listener/SessionConnectionListener.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-provider/shardingsphere-cluster-mode-repository-zookeeper-curator/src/main/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/listener/SessionConnectionListener.java
@@ -58,7 +58,9 @@ public final class SessionConnectionListener implements ConnectionStateListener
private boolean reRegister(final CuratorFramework client) {
try {
if (client.getZookeeperClient().blockUntilConnectedOrTimedOut()) {
- instanceContext.generateWorkerId(new Properties());
+ if (isNeedGenerateWorkerId()) {
+ instanceContext.generateWorkerId(new Properties());
+ }
repository.persistEphemeral(ComputeNode.getOnlineInstanceNodePath(instanceContext.getInstance().getCurrentInstanceId(),
instanceContext.getInstance().getMetaData().getType()), instanceContext.getInstance().getMetaData().getAttributes());
return true;
@@ -71,6 +73,10 @@ public final class SessionConnectionListener implements ConnectionStateListener
}
}
+ private boolean isNeedGenerateWorkerId() {
+ return -1L != instanceContext.getInstance().getWorkerId();
+ }
+
@SneakyThrows(InterruptedException.class)
private void sleepInterval() {
TimeUnit.SECONDS.sleep(RECONNECT_INTERVAL_SECONDS);