You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/08/15 12:18:28 UTC

[shardingsphere] branch master updated: Add : add mysql server id generator to retrieve unique server id (#20185)

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

zhangliang 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 1f7e77f02a9 Add : add mysql server id generator to retrieve unique server id (#20185)
1f7e77f02a9 is described below

commit 1f7e77f02a926f2d51d19eb46a13cd96c5aafa8a
Author: 孙念君 Nianjun Sun <su...@sphere-ex.com>
AuthorDate: Mon Aug 15 20:18:22 2022 +0800

    Add : add mysql server id generator to retrieve unique server id (#20185)
    
    * Add : add mysql server id generator to retrieve unique server id.(#19627)
    
    * Remove : remove spelling error Java doc
    
    * Revert : revert a java doc modification
    
    * Remove : remove a error spelling
---
 .../mysql/MySQLContainerConfigurationFactory.java  |  4 +--
 .../env/container/atomic/util/CommandPartUtil.java |  4 +++
 .../container/atomic/util/DatabaseTypeUtil.java    |  3 ++
 .../container/atomic/util/MySQLContainerUtil.java  | 41 ++++++++++++++++++++++
 4 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-env/src/test/java/org/apache/shardingsphere/test/integration/env/container/atomic/storage/config/impl/mysql/MySQLContainerConfigurationFactory.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-env/src/test/java/org/apache/shardingsphere/test/integration/env/container/atomic/storage/config/impl/mysql/MySQLContainerConfigurationFactory.java
index 07d21fd7a64..b125c1cef9a 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-env/src/test/java/org/apache/shardingsphere/test/integration/env/container/atomic/storage/config/impl/mysql/MySQLContainerConfigurationFactory.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-env/src/test/java/org/apache/shardingsphere/test/integration/env/container/atomic/storage/config/impl/mysql/MySQLContainerConfigurationFactory.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.test.integration.env.container.atomic.storage.
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import org.apache.shardingsphere.test.integration.env.container.atomic.storage.config.StorageContainerConfiguration;
+import org.apache.shardingsphere.test.integration.env.container.atomic.util.MySQLContainerUtil;
 
 import java.util.Collections;
 import java.util.HashMap;
@@ -41,9 +42,8 @@ public final class MySQLContainerConfigurationFactory {
     }
     
     private static String[] getCommands() {
-        // TODO need auto set server-id by generator, now always set server-id to 1
         String[] result = new String[1];
-        result[0] = "--server-id=1";
+        result[0] = "--server-id=" + MySQLContainerUtil.generateServerId();
         return result;
     }
     
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-env/src/test/java/org/apache/shardingsphere/test/integration/env/container/atomic/util/CommandPartUtil.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-env/src/test/java/org/apache/shardingsphere/test/integration/env/container/atomic/util/CommandPartUtil.java
index 665513b29d1..b479e07e780 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-env/src/test/java/org/apache/shardingsphere/test/integration/env/container/atomic/util/CommandPartUtil.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-env/src/test/java/org/apache/shardingsphere/test/integration/env/container/atomic/util/CommandPartUtil.java
@@ -17,12 +17,16 @@
 
 package org.apache.shardingsphere.test.integration.env.container.atomic.util;
 
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
 import java.util.LinkedHashMap;
 import java.util.Map;
 
 /**
  * Command part util.
  */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
 public final class CommandPartUtil {
     
     /**
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-env/src/test/java/org/apache/shardingsphere/test/integration/env/container/atomic/util/DatabaseTypeUtil.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-env/src/test/java/org/apache/shardingsphere/test/integration/env/container/atomic/util/DatabaseTypeUtil.java
index 26d827bae2f..083a87be310 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-env/src/test/java/org/apache/shardingsphere/test/integration/env/container/atomic/util/DatabaseTypeUtil.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-env/src/test/java/org/apache/shardingsphere/test/integration/env/container/atomic/util/DatabaseTypeUtil.java
@@ -17,12 +17,15 @@
 
 package org.apache.shardingsphere.test.integration.env.container.atomic.util;
 
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
 import org.apache.commons.lang.StringUtils;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
 import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
 import org.apache.shardingsphere.infra.database.type.dialect.OpenGaussDatabaseType;
 import org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
 
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
 public final class DatabaseTypeUtil {
     
     /**
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-env/src/test/java/org/apache/shardingsphere/test/integration/env/container/atomic/util/MySQLContainerUtil.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-env/src/test/java/org/apache/shardingsphere/test/integration/env/container/atomic/util/MySQLContainerUtil.java
new file mode 100644
index 00000000000..49ec5f504d7
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-env/src/test/java/org/apache/shardingsphere/test/integration/env/container/atomic/util/MySQLContainerUtil.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.test.integration.env.container.atomic.util;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * MySQL container util.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class MySQLContainerUtil {
+    
+    private static final AtomicInteger ATOMIC_SERVER_ID = new AtomicInteger(1);
+    
+    /**
+     * Generate a unique mysql server id.
+     * 
+     * @return unique mysql server id
+     */
+    public static int generateServerId() {
+        return ATOMIC_SERVER_ID.getAndIncrement();
+    }
+}