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

[shardingsphere] branch master updated: Fix change master node not effective when use openGauss ha. (#14599)

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

menghaoran 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 ff8fa34  Fix change master node not effective when use openGauss ha. (#14599)
ff8fa34 is described below

commit ff8fa34bb3819d9e553ed8ae3f60e6f8f142cd16
Author: zhaojinchao <33...@users.noreply.github.com>
AuthorDate: Fri Jan 7 16:38:40 2022 +0800

    Fix change master node not effective when use openGauss ha. (#14599)
    
    * Fix change master node not effective.
    
    * update
---
 .../opengauss/OpenGaussDatabaseDiscoveryType.java          | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-opengauss/src/main/java/org/apache/shardingsphere/dbdiscovery/opengauss/OpenGaussDatabaseDiscoveryType.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-opengauss/src/main/java/org/apache/shardingsphere/dbdiscovery/opengauss/OpenGaussDatabaseDiscoveryType.java
index 7dbef05..b662c49 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-opengauss/src/main/java/org/apache/shardingsphere/dbdiscovery/opengauss/OpenGaussDatabaseDiscoveryType.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-opengauss/src/main/java/org/apache/shardingsphere/dbdiscovery/opengauss/OpenGaussDatabaseDiscoveryType.java
@@ -31,7 +31,6 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Collection;
-import java.util.HashMap;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Properties;
@@ -56,12 +55,9 @@ public final class OpenGaussDatabaseDiscoveryType implements DatabaseDiscoveryTy
     
     @Override
     public void updatePrimaryDataSource(final String schemaName, final Map<String, DataSource> dataSourceMap, final Collection<String> disabledDataSourceNames, final String groupName) {
-        Map<String, DataSource> activeDataSourceMap = new HashMap<>(dataSourceMap);
-        if (!disabledDataSourceNames.isEmpty()) {
-            activeDataSourceMap.entrySet().removeIf(each -> disabledDataSourceNames.contains(each.getKey()));
-        }
-        String newPrimaryDataSource = determinePrimaryDataSource(activeDataSourceMap);
+        String newPrimaryDataSource = determinePrimaryDataSource(dataSourceMap);
         if (newPrimaryDataSource.isEmpty()) {
+            oldPrimaryDataSource = "";
             return;
         }
         if (!newPrimaryDataSource.equals(oldPrimaryDataSource)) {
@@ -91,15 +87,13 @@ public final class OpenGaussDatabaseDiscoveryType implements DatabaseDiscoveryTy
     @Override
     public void updateMemberState(final String schemaName, final Map<String, DataSource> dataSourceMap, final Collection<String> disabledDataSourceNames) {
         for (Entry<String, DataSource> entry : dataSourceMap.entrySet()) {
-            if (oldPrimaryDataSource.equals(entry.getKey())) {
-                continue;
-            }
             boolean disable = true;
             try (Connection connection = entry.getValue().getConnection();
                  Statement statement = connection.createStatement();
                  ResultSet resultSet = statement.executeQuery(DB_ROLE)) {
                 if (resultSet.next()) {
-                    if (resultSet.getString("local_role").equals("Standby") && resultSet.getString("db_state").equals("Normal")) {
+                    if ((resultSet.getString("local_role").equals("Standby") && resultSet.getString("db_state").equals("Normal"))
+                            || entry.getKey().equals(oldPrimaryDataSource)) {
                         disable = false;
                     }
                 }