This is an automated email from the ASF dual-hosted git repository.

zhaojinchao 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 d10e7197479 Fix NumberFormatException while new InstanceId with 
bigInteger (#17828)
d10e7197479 is described below

commit d10e7197479e37053e777e5a5ffa1a69e5d0e65c
Author: cheese8 <yinwerh...@163.com>
AuthorDate: Fri May 20 17:26:48 2022 +0800

    Fix NumberFormatException while new InstanceId with bigInteger (#17828)
    
    * For 17819
    
    * Fix UT
    
    * remove unnecessary this
---
 .../instance/definition/InstanceDefinition.java    |  2 +-
 .../infra/instance/definition/InstanceId.java      | 32 +++++++++++-----------
 .../infra/instance/definition/InstanceIdTest.java  |  8 +++---
 .../subscriber/ComputeNodeStatusSubscriber.java    |  2 +-
 .../ClusterContextManagerCoordinatorTest.java      |  2 +-
 .../ral/common/updatable/LabelInstanceHandler.java |  2 +-
 .../common/updatable/SetInstanceStatusHandler.java |  2 +-
 .../common/updatable/UnlabelInstanceHandler.java   |  2 +-
 8 files changed, 26 insertions(+), 26 deletions(-)

diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceDefinition.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceDefinition.java
index 8fdd6d6317b..b07702fd163 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceDefinition.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceDefinition.java
@@ -38,7 +38,7 @@ public final class InstanceDefinition {
     
     public InstanceDefinition(final InstanceType instanceType, final Integer 
port) {
         this.instanceType = instanceType;
-        instanceId = new InstanceId(port);
+        instanceId = new InstanceId(String.valueOf(port));
     }
     
     public InstanceDefinition(final InstanceType instanceType, final String 
id) {
diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceId.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceId.java
index d6f22e18f3d..2b7731d1fac 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceId.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/definition/InstanceId.java
@@ -39,30 +39,30 @@ public final class InstanceId {
     
     private final String ip;
     
-    private final Integer uniqueSign;
+    private final String uniqueSign;
     
-    public InstanceId(final String ip, final Integer uniqueSign) {
+    public InstanceId(final String ip, final String uniqueSign) {
         this.ip = ip;
         this.uniqueSign = uniqueSign;
-        id = String.join(DELIMITER, ip, String.valueOf(uniqueSign));
+        id = String.join(DELIMITER, ip, uniqueSign);
     }
     
-    public InstanceId(final Integer uniqueSign) {
-        this.uniqueSign = uniqueSign;
-        ip = IpUtils.getIp();
-        id = String.join(DELIMITER, ip, String.valueOf(uniqueSign));
-    }
-    
-    public InstanceId(final String id) {
-        this.id = id;
-        List<String> ids = Splitter.on("@").splitToList(id);
-        ip = ids.get(0);
-        uniqueSign = Integer.valueOf(ids.get(1));
+    public InstanceId(final String instance) {
+        if (instance.indexOf(DELIMITER) >= 0) {
+            id = instance;
+            List<String> ids = Splitter.on("@").splitToList(instance);
+            ip = ids.get(0);
+            uniqueSign = ids.get(1);
+        } else {
+            uniqueSign = instance;
+            ip = IpUtils.getIp();
+            id = String.join(DELIMITER, ip, uniqueSign);
+        }
     }
     
     public InstanceId() {
         ip = IpUtils.getIp();
-        uniqueSign = Integer.valueOf(String.join("", 
ManagementFactory.getRuntimeMXBean().getName().split(DELIMITER)[0], 
String.valueOf(ATOMIC_LONG.incrementAndGet())));
-        id = String.join(DELIMITER, ip, String.valueOf(uniqueSign));
+        uniqueSign = String.join("", 
ManagementFactory.getRuntimeMXBean().getName().split(DELIMITER)[0], 
String.valueOf(ATOMIC_LONG.incrementAndGet()));
+        id = String.join(DELIMITER, ip, uniqueSign);
     }
 }
diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/instance/definition/InstanceIdTest.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/instance/definition/InstanceIdTest.java
index b2a753448a4..595d3c11de1 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/instance/definition/InstanceIdTest.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/instance/definition/InstanceIdTest.java
@@ -27,8 +27,8 @@ public final class InstanceIdTest {
     
     @Test
     public void assertInitInstanceIdWithPort() {
-        InstanceId actual = new InstanceId(3307);
-        assertThat(actual.getUniqueSign(), is(3307));
+        InstanceId actual = new InstanceId("3307");
+        assertThat(actual.getUniqueSign(), is("3307"));
     }
     
     @Test
@@ -39,7 +39,7 @@ public final class InstanceIdTest {
     
     @Test
     public void assertInitInstanceIdWithIpAndUniqueSign() {
-        InstanceId actual = new InstanceId("127.0.0.1", 3307);
+        InstanceId actual = new InstanceId("127.0.0.1", "3307");
         assertThat(actual.getId(), is("127.0.0.1@3307"));
     }
     
@@ -47,7 +47,7 @@ public final class InstanceIdTest {
     public void assertInitInstanceIdWithExistId() {
         InstanceId actual = new InstanceId("127.0.0.1@3307");
         assertThat(actual.getIp(), is("127.0.0.1"));
-        assertThat(actual.getUniqueSign(), is(3307));
+        assertThat(actual.getUniqueSign(), is("3307"));
     }
     
     @Test
diff --git 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/subscriber/ComputeNodeStatusSubscriber.java
 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/subscriber/ComputeNodeStatus
 [...]
index 42f1bc2bceb..30ecd562ffc 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/subscriber/ComputeNodeStatusSubscriber.java
+++ 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/subscriber/ComputeNodeStatusSubscriber.java
@@ -49,7 +49,7 @@ public final class ComputeNodeStatusSubscriber {
      */
     @Subscribe
     public void update(final ComputeNodeStatusChangedEvent event) {
-        String computeStatusNodePath = 
ComputeNode.getInstanceStatusNodePath(new InstanceId(event.getIp(), 
Integer.valueOf(event.getPort())).getId());
+        String computeStatusNodePath = 
ComputeNode.getInstanceStatusNodePath(new InstanceId(event.getIp(), 
String.valueOf(event.getPort())).getId());
         String yamlContext = repository.get(computeStatusNodePath);
         Collection<String> status = Strings.isNullOrEmpty(yamlContext) ? new 
ArrayList<>() : YamlEngine.unmarshal(yamlContext, Collection.class);
         if (event.getStatus() == ComputeNodeStatus.CIRCUIT_BREAK) {
diff --git 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
index a63154b711e..9d7f292c000 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
+++ 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
@@ -310,7 +310,7 @@ public final class ClusterContextManagerCoordinatorTest {
     @Test
     public void assertRenewInstanceOfflineEvent() {
         coordinator.renew(new 
InstanceOfflineEvent(contextManager.getInstanceContext().getInstance().getInstanceDefinition()));
-        
assertThat(contextManager.getInstanceContext().getInstance().getInstanceDefinition().getInstanceId().getUniqueSign(),
 is(3307));
+        
assertThat(contextManager.getInstanceContext().getInstance().getInstanceDefinition().getInstanceId().getUniqueSign(),
 is("3307"));
     }
     
     @Test
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/LabelInstanceHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/LabelInstanceHandler.java
index 99515e11619..d18d324f18a 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/LabelInstanceHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/LabelInstanceHandler.java
@@ -42,7 +42,7 @@ public final class LabelInstanceHandler extends 
UpdatableRALBackendHandler<Label
         if (null == persistService || null == persistService.getRepository() 
|| persistService.getRepository() instanceof StandalonePersistRepository) {
             throw new UnsupportedOperationException("Labels can only be added 
in cluster mode");
         }
-        String instanceId = new InstanceId(sqlStatement.getIp(), 
Integer.valueOf(sqlStatement.getPort())).getId();
+        String instanceId = new InstanceId(sqlStatement.getIp(), 
String.valueOf(sqlStatement.getPort())).getId();
         ComputeNodeInstance instances = 
persistService.getComputeNodePersistService().loadComputeNodeInstance(new 
InstanceDefinition(InstanceType.PROXY, instanceId));
         Collection<String> labels = new 
LinkedHashSet<>(sqlStatement.getLabels());
         if (!sqlStatement.isOverwrite()) {
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/SetInstanceStatusHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/SetInstanceStatusHandler.java
index b7efae33e86..2162c85f747 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/SetInstanceStatusHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/SetInstanceStatusHandler.java
@@ -44,7 +44,7 @@ public final class SetInstanceStatusHandler extends 
UpdatableRALBackendHandler<S
         if 
(!"Cluster".equals(contextManager.getInstanceContext().getModeConfiguration().getType()))
 {
             throw new UnsupportedOperationException("Only allowed in cluster 
mode");
         }
-        InstanceId operationInstanceId = new InstanceId(sqlStatement.getIp(), 
Integer.valueOf(sqlStatement.getPort()));
+        InstanceId operationInstanceId = new InstanceId(sqlStatement.getIp(), 
String.valueOf(sqlStatement.getPort()));
         boolean isDisable = "DISABLE".equals(sqlStatement.getStatus());
         if (isDisable) {
             checkDisablingIsValid(operationInstanceId);
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/UnlabelInstanceHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/UnlabelInstanceHandler.java
index 5a96f33678a..b584e9249d5 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/UnlabelInstanceHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/UnlabelInstanceHandler.java
@@ -43,7 +43,7 @@ public final class UnlabelInstanceHandler extends 
UpdatableRALBackendHandler<Unl
         if (null == persistService || null == persistService.getRepository() 
|| persistService.getRepository() instanceof StandalonePersistRepository) {
             throw new UnsupportedOperationException("Labels can only be 
removed in cluster mode");
         }
-        String instanceId = new InstanceId(sqlStatement.getIp(), 
Integer.valueOf(sqlStatement.getPort())).getId();
+        String instanceId = new InstanceId(sqlStatement.getIp(), 
String.valueOf(sqlStatement.getPort())).getId();
         ComputeNodeInstance instances = 
persistService.getComputeNodePersistService().loadComputeNodeInstance(new 
InstanceDefinition(InstanceType.PROXY, instanceId));
         Collection<String> labels = new LinkedHashSet<>(instances.getLabels());
         if (sqlStatement.getLabels().isEmpty()) {

Reply via email to