terrymanu commented on a change in pull request #15020:
URL: https://github.com/apache/shardingsphere/pull/15020#discussion_r791336958
##########
File path:
shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/src/main/java/org/apache/shardingsphere/dbdiscovery/mgr/MGRDatabaseDiscoveryType.java
##########
@@ -114,6 +115,31 @@ private void checkIsSinglePrimaryMode(final Statement
statement) throws SQLExcep
}
}
+ private void checkDataSourceInReplicationGroup(final Statement statement,
final Map<String, DataSource> dataSourceMap) throws SQLException {
+ List<String> memberDataSourceURLs = new LinkedList<>();
+ try (ResultSet resultSet = statement.executeQuery(MEMBER_LIST)) {
+ while (resultSet.next()) {
+ memberDataSourceURLs.add(String.format("%s:%s",
resultSet.getString("MEMBER_HOST"), resultSet.getString("MEMBER_PORT")));
+ }
+ }
+ checkDataSourcesExistGroupMember(dataSourceMap, memberDataSourceURLs);
+ }
+
+ private void checkDataSourcesExistGroupMember(final Map<String,
DataSource> dataSourceMap, final List<String> memberDataSourceURLs) throws
SQLException {
+ for (Entry<String, DataSource> entry : dataSourceMap.entrySet()) {
+ boolean exist = false;
+ for (String each : memberDataSourceURLs) {
+ if
(entry.getValue().getConnection().getMetaData().getURL().contains(each)) {
+ exist = true;
+ break;
+ }
+ }
+ if (!exist) {
+ throw new ShardingSphereConfigurationException("%s is not MGR
replication group member", entry.getKey());
+ }
Review comment:
It is better to keep one loop in single method
##########
File path:
shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/src/main/java/org/apache/shardingsphere/dbdiscovery/mgr/MGRDatabaseDiscoveryType.java
##########
@@ -114,6 +115,31 @@ private void checkIsSinglePrimaryMode(final Statement
statement) throws SQLExcep
}
}
+ private void checkDataSourceInReplicationGroup(final Statement statement,
final Map<String, DataSource> dataSourceMap) throws SQLException {
+ List<String> memberDataSourceURLs = new LinkedList<>();
+ try (ResultSet resultSet = statement.executeQuery(MEMBER_LIST)) {
+ while (resultSet.next()) {
+ memberDataSourceURLs.add(String.format("%s:%s",
resultSet.getString("MEMBER_HOST"), resultSet.getString("MEMBER_PORT")));
+ }
+ }
+ checkDataSourcesExistGroupMember(dataSourceMap, memberDataSourceURLs);
+ }
+
+ private void checkDataSourcesExistGroupMember(final Map<String,
DataSource> dataSourceMap, final List<String> memberDataSourceURLs) throws
SQLException {
Review comment:
`List<String> memberDataSourceURLs` can be `Collection<String>
memberDataSourceURLs`
##########
File path:
shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/src/main/java/org/apache/shardingsphere/dbdiscovery/mgr/MGRDatabaseDiscoveryType.java
##########
@@ -114,6 +115,31 @@ private void checkIsSinglePrimaryMode(final Statement
statement) throws SQLExcep
}
}
+ private void checkDataSourceInReplicationGroup(final Statement statement,
final Map<String, DataSource> dataSourceMap) throws SQLException {
+ List<String> memberDataSourceURLs = new LinkedList<>();
Review comment:
`Collection<String> memberDataSourceURLs` can be `List<String>
memberDataSourceURLs`
##########
File path:
shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/src/main/java/org/apache/shardingsphere/dbdiscovery/mgr/MGRDatabaseDiscoveryType.java
##########
@@ -114,6 +115,31 @@ private void checkIsSinglePrimaryMode(final Statement
statement) throws SQLExcep
}
}
+ private void checkDataSourceInReplicationGroup(final Statement statement,
final Map<String, DataSource> dataSourceMap) throws SQLException {
+ Collection<String> memberDataSourceURLs = new LinkedList<>();
+ try (ResultSet resultSet = statement.executeQuery(MEMBER_LIST)) {
+ while (resultSet.next()) {
+ memberDataSourceURLs.add(String.format("%s:%s",
resultSet.getString("MEMBER_HOST"), resultSet.getString("MEMBER_PORT")));
+ }
+ }
+ for (Entry<String, DataSource> entry : dataSourceMap.entrySet()) {
+ checkDataSourceExistGroupMember(entry.getKey(), entry.getValue(),
memberDataSourceURLs);
+ }
+ }
+
+ private void checkDataSourceExistGroupMember(final String datasourceName,
final DataSource dataSource, final Collection<String> memberDataSourceURLs)
throws SQLException {
+ boolean exist = false;
Review comment:
`exist` is a verb, how about rename it as `isExisted`?
##########
File path:
shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/src/main/java/org/apache/shardingsphere/dbdiscovery/mgr/MGRDatabaseDiscoveryType.java
##########
@@ -114,6 +115,31 @@ private void checkIsSinglePrimaryMode(final Statement
statement) throws SQLExcep
}
}
+ private void checkDataSourceInReplicationGroup(final Statement statement,
final Map<String, DataSource> dataSourceMap) throws SQLException {
+ Collection<String> memberDataSourceURLs = new LinkedList<>();
+ try (ResultSet resultSet = statement.executeQuery(MEMBER_LIST)) {
+ while (resultSet.next()) {
+ memberDataSourceURLs.add(String.format("%s:%s",
resultSet.getString("MEMBER_HOST"), resultSet.getString("MEMBER_PORT")));
+ }
+ }
+ for (Entry<String, DataSource> entry : dataSourceMap.entrySet()) {
+ checkDataSourceExistGroupMember(entry.getKey(), entry.getValue(),
memberDataSourceURLs);
+ }
+ }
+
+ private void checkDataSourceExistGroupMember(final String datasourceName,
final DataSource dataSource, final Collection<String> memberDataSourceURLs)
throws SQLException {
Review comment:
It is better to rename `checkDataSourceExistGroupMember` as
`checkDataSourceExistedWithGroupMember`
##########
File path:
shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mgr/src/main/java/org/apache/shardingsphere/dbdiscovery/mgr/MGRDatabaseDiscoveryType.java
##########
@@ -114,6 +115,31 @@ private void checkIsSinglePrimaryMode(final Statement
statement) throws SQLExcep
}
}
+ private void checkDataSourceInReplicationGroup(final Statement statement,
final Map<String, DataSource> dataSourceMap) throws SQLException {
+ List<String> memberDataSourceURLs = new LinkedList<>();
Review comment:
`List<String> memberDataSourceURLs` can be `Collection<String>
memberDataSourceURLs`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]