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

duanzhengqiang 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 e3a723cab64 Support heterogeneous databases for DistSQL (#22184)
e3a723cab64 is described below

commit e3a723cab641bdde34533f5889a60ce8ddee7bc0
Author: Raigor <[email protected]>
AuthorDate: Tue Nov 15 18:58:27 2022 +0800

    Support heterogeneous databases for DistSQL (#22184)
    
    * For #22177, support heterogeneous databases for DistSQL.
    
    * Update test case.
---
 .../RegisterMigrationSourceStorageUnitUpdater.java |  2 +-
 .../props/DataSourcePropertiesValidator.java       | 22 ++++++----------------
 .../props/DataSourcePropertiesValidatorTest.java   | 11 ++---------
 .../ProcessListChangedSubscriberTest.java          |  2 +-
 .../ImportDatabaseConfigurationHandler.java        |  2 +-
 .../resource/AlterStorageUnitBackendHandler.java   |  2 +-
 .../RegisterStorageUnitBackendHandler.java         |  2 +-
 7 files changed, 13 insertions(+), 30 deletions(-)

diff --git 
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/update/RegisterMigrationSourceStorageUnitUpdater.java
 
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/update/RegisterMigrationSourceStorageUnitUpdater.java
index 37d1c398df6..ec4f784890f 100644
--- 
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/update/RegisterMigrationSourceStorageUnitUpdater.java
+++ 
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/migration/distsql/handler/update/RegisterMigrationSourceStorageUnitUpdater.java
@@ -52,7 +52,7 @@ public final class RegisterMigrationSourceStorageUnitUpdater 
implements RALUpdat
         DatabaseType databaseType = 
DatabaseTypeEngine.getDatabaseType(urlBasedDataSourceSegment.getUrl());
         Map<String, DataSourceProperties> sourcePropertiesMap = 
ResourceSegmentsConverter.convert(databaseType, dataSources);
         DataSourcePropertiesValidator validator = new 
DataSourcePropertiesValidator();
-        validator.validate(sourcePropertiesMap, databaseType);
+        validator.validate(sourcePropertiesMap);
         JOB_API.addMigrationSourceResources(sourcePropertiesMap);
     }
     
diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/props/DataSourcePropertiesValidator.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/props/DataSourcePropertiesValidator.java
index 091b649d7cb..4604659acd2 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/props/DataSourcePropertiesValidator.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/props/DataSourcePropertiesValidator.java
@@ -17,17 +17,11 @@
 
 package org.apache.shardingsphere.infra.datasource.props;
 
-import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
 import 
org.apache.shardingsphere.infra.datasource.pool.creator.DataSourcePoolCreator;
 import 
org.apache.shardingsphere.infra.datasource.pool.destroyer.DataSourcePoolDestroyer;
 import 
org.apache.shardingsphere.infra.distsql.exception.resource.InvalidResourcesException;
-import 
org.apache.shardingsphere.infra.exception.MismatchedProtocolAndDataSourceException;
-import 
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
-import 
org.apache.shardingsphere.infra.util.exception.internal.ShardingSphereInternalException;
 
 import javax.sql.DataSource;
-import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.Collection;
 import java.util.LinkedList;
@@ -43,14 +37,13 @@ public final class DataSourcePropertiesValidator {
      * Validate data source properties map.
      * 
      * @param dataSourcePropertiesMap data source properties map
-     * @param databaseType database type
      * @throws InvalidResourcesException invalid resources exception
      */
-    public void validate(final Map<String, DataSourceProperties> 
dataSourcePropertiesMap, final DatabaseType databaseType) throws 
InvalidResourcesException {
+    public void validate(final Map<String, DataSourceProperties> 
dataSourcePropertiesMap) throws InvalidResourcesException {
         Collection<String> errorMessages = new LinkedList<>();
         for (Entry<String, DataSourceProperties> entry : 
dataSourcePropertiesMap.entrySet()) {
             try {
-                validate(entry.getKey(), entry.getValue(), databaseType);
+                validate(entry.getKey(), entry.getValue());
             } catch (final InvalidDataSourcePropertiesException ex) {
                 errorMessages.add(ex.getMessage());
             }
@@ -60,11 +53,11 @@ public final class DataSourcePropertiesValidator {
         }
     }
     
-    private void validate(final String dataSourceName, final 
DataSourceProperties dataSourceProps, final DatabaseType databaseType) throws 
InvalidDataSourcePropertiesException {
+    private void validate(final String dataSourceName, final 
DataSourceProperties dataSourceProps) throws 
InvalidDataSourcePropertiesException {
         DataSource dataSource = null;
         try {
             dataSource = DataSourcePoolCreator.create(dataSourceProps);
-            checkFailFast(dataSource, databaseType);
+            checkFailFast(dataSource);
             // CHECKSTYLE:OFF
             // TODO check why catch exception here, can it simplify to catch 
SQLException and ShardingSphereInternalException?
         } catch (final Exception ex) {
@@ -77,10 +70,7 @@ public final class DataSourcePropertiesValidator {
         }
     }
     
-    private void checkFailFast(final DataSource dataSource, final DatabaseType 
databaseType) throws SQLException, ShardingSphereInternalException {
-        try (Connection connection = dataSource.getConnection()) {
-            ShardingSpherePreconditions.checkState(null == databaseType || 
DatabaseTypeEngine.getDatabaseType(connection.getMetaData().getURL()).getType().equals(databaseType.getType()),
-                    MismatchedProtocolAndDataSourceException::new);
-        }
+    private void checkFailFast(final DataSource dataSource) throws 
SQLException {
+        dataSource.getConnection();
     }
 }
diff --git 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/datasource/props/DataSourcePropertiesValidatorTest.java
 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/datasource/props/DataSourcePropertiesValidatorTest.java
index 7362d9194ee..9dcecd82e39 100644
--- 
a/infra/common/src/test/java/org/apache/shardingsphere/infra/datasource/props/DataSourcePropertiesValidatorTest.java
+++ 
b/infra/common/src/test/java/org/apache/shardingsphere/infra/datasource/props/DataSourcePropertiesValidatorTest.java
@@ -18,8 +18,6 @@
 package org.apache.shardingsphere.infra.datasource.props;
 
 import com.zaxxer.hikari.HikariDataSource;
-import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
-import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
 import 
org.apache.shardingsphere.infra.distsql.exception.resource.InvalidResourcesException;
 import org.junit.Test;
 
@@ -31,12 +29,7 @@ public final class DataSourcePropertiesValidatorTest {
     
     @Test
     public void assertValidateSuccess() throws InvalidResourcesException {
-        new 
DataSourcePropertiesValidator().validate(Collections.singletonMap("name", new 
DataSourceProperties(HikariDataSource.class.getName(), 
createValidProperties())), new H2DatabaseType());
-    }
-    
-    @Test(expected = InvalidResourcesException.class)
-    public void assertDatabaseTypeInValidateFail() throws 
InvalidResourcesException {
-        new 
DataSourcePropertiesValidator().validate(Collections.singletonMap("name", new 
DataSourceProperties(HikariDataSource.class.getName(), 
createValidProperties())), new MySQLDatabaseType());
+        new 
DataSourcePropertiesValidator().validate(Collections.singletonMap("name", new 
DataSourceProperties(HikariDataSource.class.getName(), 
createValidProperties())));
     }
     
     private Map<String, Object> createValidProperties() {
@@ -50,7 +43,7 @@ public final class DataSourcePropertiesValidatorTest {
     
     @Test(expected = InvalidResourcesException.class)
     public void assertValidateFailed() throws InvalidResourcesException {
-        new 
DataSourcePropertiesValidator().validate(Collections.singletonMap("name", new 
DataSourceProperties(HikariDataSource.class.getName(), 
createInvalidProperties())), new H2DatabaseType());
+        new 
DataSourcePropertiesValidator().validate(Collections.singletonMap("name", new 
DataSourceProperties(HikariDataSource.class.getName(), 
createInvalidProperties())));
     }
     
     private Map<String, Object> createInvalidProperties() {
diff --git 
a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ProcessListChangedSubscriberTest.java
 
b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ProcessListChangedSubscriberTest.java
index c56caa79acc..d6876b4cc60 100644
--- 
a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ProcessListChangedSubscriberTest.java
+++ 
b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ProcessListChangedSubscriberTest.java
@@ -132,7 +132,7 @@ public final class ProcessListChangedSubscriberTest {
                 "contexts:" + System.lineSeparator() + "- startTimeMillis: 0" 
+ System.lineSeparator());
         verify(repository).delete("/nodes/compute_nodes/process_trigger/" + 
instanceId + ":foo_process_id");
     }
-
+    
     @Test
     public void assertKillProcessListId() throws SQLException, 
NoSuchFieldException, IllegalAccessException {
         String instanceId = 
contextManager.getInstanceContext().getInstance().getMetaData().getId();
diff --git 
a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationHandler.java
 
b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationHandler.java
index d4bc64e4b72..9c29d5cde53 100644
--- 
a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationHandler.java
+++ 
b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationHandler.java
@@ -123,7 +123,7 @@ public final class ImportDatabaseConfigurationHandler 
extends UpdatableRALBacken
         for (Entry<String, YamlProxyDataSourceConfiguration> entry : 
yamlDataSourceMap.entrySet()) {
             dataSourcePropsMap.put(entry.getKey(), 
DataSourcePropertiesCreator.create(HikariDataSource.class.getName(), 
dataSourceConfigSwapper.swap(entry.getValue())));
         }
-        validator.validate(dataSourcePropsMap, 
getConnectionSession().getProtocolType());
+        validator.validate(dataSourcePropsMap);
         try {
             
ProxyContext.getInstance().getContextManager().addResources(databaseName, 
dataSourcePropsMap);
         } catch (final SQLException ex) {
diff --git 
a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/resource/AlterStorageUnitBackendHandler.java
 
b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/resource/AlterStorageUnitBackendHandler.java
index 468e47ea435..2520e36d74e 100644
--- 
a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/resource/AlterStorageUnitBackendHandler.java
+++ 
b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/resource/AlterStorageUnitBackendHandler.java
@@ -69,7 +69,7 @@ public final class AlterStorageUnitBackendHandler extends 
DatabaseRequiredBacken
     public ResponseHeader execute(final String databaseName, final 
AlterStorageUnitStatement sqlStatement) {
         checkSQLStatement(databaseName, sqlStatement);
         Map<String, DataSourceProperties> dataSourcePropsMap = 
ResourceSegmentsConverter.convert(databaseType, sqlStatement.getDataSources());
-        validator.validate(dataSourcePropsMap, databaseType);
+        validator.validate(dataSourcePropsMap);
         try {
             
ProxyContext.getInstance().getContextManager().updateResources(databaseName, 
dataSourcePropsMap);
         } catch (final SQLException | ShardingSphereServerException ex) {
diff --git 
a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/resource/RegisterStorageUnitBackendHandler.java
 
b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/resource/RegisterStorageUnitBackendHandler.java
index 13be0fc6d7d..dac30460abc 100644
--- 
a/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/resource/RegisterStorageUnitBackendHandler.java
+++ 
b/proxy/backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/resource/RegisterStorageUnitBackendHandler.java
@@ -66,7 +66,7 @@ public final class RegisterStorageUnitBackendHandler extends 
DatabaseRequiredBac
     public ResponseHeader execute(final String databaseName, final 
RegisterStorageUnitStatement sqlStatement) {
         checkSQLStatement(databaseName, sqlStatement);
         Map<String, DataSourceProperties> dataSourcePropsMap = 
ResourceSegmentsConverter.convert(databaseType, sqlStatement.getDataSources());
-        validator.validate(dataSourcePropsMap, databaseType);
+        validator.validate(dataSourcePropsMap);
         try {
             
ProxyContext.getInstance().getContextManager().addResources(databaseName, 
dataSourcePropsMap);
         } catch (final SQLException | ShardingSphereServerException ex) {

Reply via email to