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/03/25 13:08:20 UTC
[shardingsphere] branch master updated: Adjust disable or enable slave datasource logic (#16375)
This is an automated email from the ASF dual-hosted git repository.
zhonghongsheng 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 62eca8a Adjust disable or enable slave datasource logic (#16375)
62eca8a is described below
commit 62eca8a2060d640c1fe9df9025481cb030bfcacc
Author: zhaojinchao <zh...@apache.org>
AuthorDate: Fri Mar 25 21:07:08 2022 +0800
Adjust disable or enable slave datasource logic (#16375)
---
.../dbdiscovery/mysql/AbstractDatabaseDiscoveryType.java | 10 ----------
.../dbdiscovery/mysql/type/MGRDatabaseDiscoveryType.java | 7 +++++--
.../mysql/type/ShowSlaveStatusDatabaseDiscoveryType.java | 5 ++++-
3 files changed, 9 insertions(+), 13 deletions(-)
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/AbstractDatabaseDiscoveryType.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/AbstractDatabaseDiscoveryType.java
index e0164f9..c3bf80b 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/AbstractDatabaseDiscoveryType.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/AbstractDatabaseDiscoveryType.java
@@ -30,7 +30,6 @@ import java.sql.Statement;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
-import java.util.stream.Collectors;
/**
* Abstract database discovery type.
@@ -42,8 +41,6 @@ public abstract class AbstractDatabaseDiscoveryType implements DatabaseDiscovery
protected abstract String getPrimaryDataSourceURL(Statement statement) throws SQLException;
- protected abstract void determineMemberDataSourceState(String schemaName, Map<String, DataSource> dataSourceMap, String groupName);
-
@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);
@@ -60,13 +57,6 @@ public abstract class AbstractDatabaseDiscoveryType implements DatabaseDiscovery
}
}
- @Override
- public void updateMemberState(final String schemaName, final Map<String, DataSource> dataSourceMap, final String groupName) {
- Map<String, DataSource> activeDataSourceMap = dataSourceMap.entrySet().stream()
- .filter(each -> !each.getKey().equals(oldPrimaryDataSource)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
- determineMemberDataSourceState(schemaName, activeDataSourceMap, groupName);
- }
-
private String determinePrimaryDataSource(final Map<String, DataSource> dataSourceMap) {
String primaryDataSourceURL = findPrimaryDataSourceURL(dataSourceMap);
return findPrimaryDataSourceName(primaryDataSourceURL, dataSourceMap);
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRDatabaseDiscoveryType.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRDatabaseDiscoveryType.java
index f55e4ff..263cc10 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRDatabaseDiscoveryType.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRDatabaseDiscoveryType.java
@@ -153,7 +153,7 @@ public final class MGRDatabaseDiscoveryType extends AbstractDatabaseDiscoveryTyp
}
@Override
- protected void determineMemberDataSourceState(final String schemaName, final Map<String, DataSource> dataSourceMap, final String groupName) {
+ public void updateMemberState(final String schemaName, final Map<String, DataSource> dataSourceMap, final String groupName) {
List<String> memberDataSourceURLs = findMemberDataSourceURLs(dataSourceMap);
if (memberDataSourceURLs.isEmpty()) {
return;
@@ -163,7 +163,7 @@ public final class MGRDatabaseDiscoveryType extends AbstractDatabaseDiscoveryTyp
private List<String> findMemberDataSourceURLs(final Map<String, DataSource> dataSourceMap) {
List<String> result = new LinkedList<>();
- try (Connection connection = dataSourceMap.values().stream().findFirst().get().getConnection();
+ try (Connection connection = dataSourceMap.get(getPrimaryDataSource()).getConnection();
Statement statement = connection.createStatement()) {
ResultSet resultSet = statement.executeQuery(MEMBER_LIST);
while (resultSet.next()) {
@@ -180,6 +180,9 @@ public final class MGRDatabaseDiscoveryType extends AbstractDatabaseDiscoveryTyp
private void determineDisabledDataSource(final String schemaName, final Map<String, DataSource> dataSourceMap, final List<String> memberDataSourceURLs, final String groupName) {
for (Entry<String, DataSource> entry : dataSourceMap.entrySet()) {
+ if (entry.getKey().equals(getPrimaryDataSource())) {
+ continue;
+ }
boolean disable = true;
String url;
try (Connection connection = entry.getValue().getConnection()) {
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/ShowSlaveStatusDatabaseDiscoveryType.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/ShowSlaveStatusDatabaseDiscoveryType.java
index 0033cb6..91aabed 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/ShowSlaveStatusDatabaseDiscoveryType.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/ShowSlaveStatusDatabaseDiscoveryType.java
@@ -87,8 +87,11 @@ public final class ShowSlaveStatusDatabaseDiscoveryType extends AbstractDatabase
}
@Override
- protected void determineMemberDataSourceState(final String schemaName, final Map<String, DataSource> dataSourceMap, final String groupName) {
+ public void updateMemberState(final String schemaName, final Map<String, DataSource> dataSourceMap, final String groupName) {
for (Entry<String, DataSource> entry : dataSourceMap.entrySet()) {
+ if (entry.getKey().equals(getPrimaryDataSource())) {
+ continue;
+ }
determineDatasourceState(schemaName, entry.getKey(), entry.getValue(), groupName);
}
}