You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/04/23 12:00:22 UTC

[shardingsphere] branch master updated: Remove DatabaseDiscoveryEngine.updateMemberState() (#17036)

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

panjuan 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 bdca7cd5738 Remove DatabaseDiscoveryEngine.updateMemberState() (#17036)
bdca7cd5738 is described below

commit bdca7cd57383774c43cbd8e3e158c10420eb764c
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Apr 23 20:00:17 2022 +0800

    Remove DatabaseDiscoveryEngine.updateMemberState() (#17036)
---
 .../dbdiscovery/algorithm/DatabaseDiscoveryEngine.java  | 17 ++---------------
 .../dbdiscovery/heartbeat/HeartbeatJob.java             |  1 -
 .../dbdiscovery/rule/DatabaseDiscoveryRule.java         |  1 -
 ...MySQLNormalReplicationDatabaseDiscoveryTypeTest.java |  2 +-
 4 files changed, 3 insertions(+), 18 deletions(-)

diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/algorithm/DatabaseDiscoveryEngine.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/algorithm/DatabaseDiscoveryEngine.java
index 2f6070be88b..0375e9e6d24 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/algorithm/DatabaseDiscoveryEngine.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/algorithm/DatabaseDiscoveryEngine.java
@@ -92,13 +92,11 @@ public final class DatabaseDiscoveryEngine {
      */
     public void updatePrimaryDataSource(final String databaseName, final Map<String, DataSource> dataSourceMap, final Collection<String> disabledDataSourceNames, final String groupName) {
         Optional<String> newPrimaryDataSource = databaseDiscoveryType.findPrimaryDataSource(getActiveDataSourceMap(dataSourceMap, disabledDataSourceNames));
-        if (!newPrimaryDataSource.isPresent()) {
-            return;
-        }
-        if (!newPrimaryDataSource.get().equals(databaseDiscoveryType.getOldPrimaryDataSource())) {
+        if (newPrimaryDataSource.isPresent() && !newPrimaryDataSource.get().equals(databaseDiscoveryType.getOldPrimaryDataSource())) {
             databaseDiscoveryType.setOldPrimaryDataSource(newPrimaryDataSource.get());
             ShardingSphereEventBus.getInstance().post(new PrimaryDataSourceChangedEvent(new QualifiedDatabase(databaseName, groupName, newPrimaryDataSource.get())));
         }
+        databaseDiscoveryType.updateMemberState(databaseName, dataSourceMap, groupName);
     }
     
     private Map<String, DataSource> getActiveDataSourceMap(final Map<String, DataSource> dataSourceMap, final Collection<String> disabledDataSourceNames) {
@@ -109,17 +107,6 @@ public final class DatabaseDiscoveryEngine {
         return result;
     }
     
-    /**
-     * Update member state.
-     *
-     * @param databaseName database name
-     * @param dataSourceMap data source map
-     * @param groupName group name
-     */
-    public void updateMemberState(final String databaseName, final Map<String, DataSource> dataSourceMap, final String groupName) {
-        databaseDiscoveryType.updateMemberState(databaseName, dataSourceMap, groupName);
-    }
-    
     /**
      * Get primary data source.
      *
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/heartbeat/HeartbeatJob.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/heartbeat/HeartbeatJob.java
index 08516d665c6..48cb1342ad0 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/heartbeat/HeartbeatJob.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/heartbeat/HeartbeatJob.java
@@ -47,6 +47,5 @@ public final class HeartbeatJob implements SimpleJob {
     public void execute(final ShardingContext shardingContext) {
         DatabaseDiscoveryEngine engine = new DatabaseDiscoveryEngine(databaseDiscoveryType);
         engine.updatePrimaryDataSource(schemaName, dataSourceMap, disabledDataSourceNames, groupName);
-        engine.updateMemberState(schemaName, dataSourceMap, groupName);
     }
 }
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
index 3539328f05b..22e7f93d6fd 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
@@ -118,7 +118,6 @@ public final class DatabaseDiscoveryRule implements SchemaRule, DataSourceContai
             }
             engine.updatePrimaryDataSource(databaseName, originalDataSourceMap, disabledDataSourceNames, groupName);
             dataSourceRule.updatePrimaryDataSourceName(engine.getPrimaryDataSource());
-            engine.updateMemberState(databaseName, originalDataSourceMap, groupName);
         }
     }
     
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/test/java/org/apache/shardingsphere/dbdiscovery/mysql/type/replication/MySQLNormalReplicationDatabaseDiscoveryTypeTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/test/java/org/apache/shardingsphere/dbdiscovery/mysql/type/replication/MySQLNormalReplicationDatabas [...]
index 36de28ed312..904c6b11a21 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/test/java/org/apache/shardingsphere/dbdiscovery/mysql/type/replication/MySQLNormalReplicationDatabaseDiscoveryTypeTest.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/test/java/org/apache/shardingsphere/dbdiscovery/mysql/type/replication/MySQLNormalReplicationDatabaseDiscoveryTypeTest.java
@@ -57,7 +57,7 @@ public final class MySQLNormalReplicationDatabaseDiscoveryTypeTest {
         when(result.getConnection().createStatement().executeQuery("SHOW SLAVE STATUS")).thenReturn(resultSet);
         when(resultSet.next()).thenReturn(true, false);
         when(resultSet.getString("Master_Host")).thenReturn("127.0.0.1");
-        when(resultSet.getString("Master_Port")).thenReturn(Integer.toString(3306));
+        when(resultSet.getString("Master_Port")).thenReturn("3306");
         when(result.getConnection().getMetaData().getURL()).thenReturn(String.format("jdbc:mysql://127.0.0.1:%s/test?serverTimezone=UTC&useSSL=false", port));
         return result;
     }