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 2021/01/13 03:37:33 UTC
[shardingsphere] branch master updated: Revert "8927 (#8928)"
(#9008)
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 6436859 Revert "8927 (#8928)" (#9008)
6436859 is described below
commit 6436859a2053c60b222e9d5e233caea0bfbfcd4f
Author: Liang Zhang <te...@163.com>
AuthorDate: Wed Jan 13 11:37:12 2021 +0800
Revert "8927 (#8928)" (#9008)
This reverts commit 4d5170b265018aadd6b8ec1e11705fd72f4abd63.
---
.../protocol/mysql/constant/MySQLServerInfo.java | 2 +-
.../mysql/constant/MySQLServerInfoTest.java | 2 +-
.../jdbc/metadata/JDBCQueryResultMetaData.java | 7 +-----
.../proxy/backend/context/ProxyContext.java | 18 +++++++++++++++-
.../text/TextProtocolBackendHandlerFactory.java | 5 +----
.../TextProtocolBackendHandlerFactoryTest.java | 11 ----------
.../proxy/backend/context/ProxyContextTest.java | 16 ++++++++++++++
.../impl/AbstractBootstrapInitializer.java | 25 +---------------------
.../client/netty/MySQLNegotiateHandlerTest.java | 6 +++---
9 files changed, 41 insertions(+), 51 deletions(-)
diff --git a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfo.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfo.java
index b1514eb..21dd3c4 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfo.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfo.java
@@ -36,7 +36,7 @@ public final class MySQLServerInfo {
*/
public static final int CHARSET = 0x21;
- private static final String DEFAULT_MYSQL_VERSION = "5.7.22";
+ private static final String DEFAULT_MYSQL_VERSION = "8.0.20";
private static final String PROXY_VERSION = "5.0.0-beta";
diff --git a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfoTest.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfoTest.java
index 50db84f..3b457b6 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfoTest.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerInfoTest.java
@@ -33,6 +33,6 @@ public final class MySQLServerInfoTest {
@Test
public void assertSetServerVersionForNull() {
MySQLServerInfo.setServerVersion(null);
- assertThat(MySQLServerInfo.getServerVersion(), is("5.7.22-ShardingSphere-Proxy 5.0.0-beta"));
+ assertThat(MySQLServerInfo.getServerVersion(), is("8.0.20-ShardingSphere-Proxy 5.0.0-beta"));
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/metadata/JDBCQueryResultMetaData.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/metadata/JDBCQueryResultMetaData.java
index 5597dff..6a56608 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/metadata/JDBCQueryResultMetaData.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/metadata/JDBCQueryResultMetaData.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryRe
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
-import java.sql.SQLFeatureNotSupportedException;
/**
* JDBC query result meta data.
@@ -74,11 +73,7 @@ public final class JDBCQueryResultMetaData implements QueryResultMetaData {
@Override
public boolean isSigned(final int columnIndex) throws SQLException {
- try {
- return resultSetMetaData.isSigned(columnIndex);
- } catch (SQLFeatureNotSupportedException e) {
- return false;
- }
+ return resultSetMetaData.isSigned(columnIndex);
}
@Override
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/context/ProxyContext.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/context/ProxyContext.java
index f28b333..1df8caf 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/context/ProxyContext.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/context/ProxyContext.java
@@ -27,8 +27,11 @@ import org.apache.shardingsphere.proxy.backend.exception.NoDatabaseSelectedExcep
import org.apache.shardingsphere.transaction.context.TransactionContexts;
import org.apache.shardingsphere.transaction.context.impl.StandardTransactionContexts;
+import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import java.util.Optional;
/**
* Proxy context.
@@ -101,5 +104,18 @@ public final class ProxyContext {
public List<String> getAllSchemaNames() {
return new ArrayList<>(metaDataContexts.getAllSchemaNames());
}
-
+
+ /**
+ * Get data source sample.
+ *
+ * @return data source sample
+ */
+ public Optional<DataSource> getDataSourceSample() {
+ List<String> schemaNames = getAllSchemaNames();
+ if (schemaNames.isEmpty()) {
+ return Optional.empty();
+ }
+ Map<String, DataSource> dataSources = getMetaData(schemaNames.get(0)).getResource().getDataSources();
+ return dataSources.values().stream().findFirst();
+ }
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactory.java
index 67c5c1e..ee200d3 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/TextProtocolBackendHandlerFactory.java
@@ -23,7 +23,6 @@ import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.text.admin.DatabaseAdminBackendHandlerFactory;
import org.apache.shardingsphere.proxy.backend.text.data.DatabaseBackendHandlerFactory;
import org.apache.shardingsphere.proxy.backend.text.distsql.DistSQLBackendHandlerFactory;
@@ -61,9 +60,7 @@ public final class TextProtocolBackendHandlerFactory {
if (trimSQL.toUpperCase().startsWith(ShardingCTLBackendHandlerFactory.SCTL)) {
return ShardingCTLBackendHandlerFactory.newInstance(trimSQL, backendConnection);
}
- DatabaseType backendDatabaseType =
- ProxyContext.getInstance().getMetaDataContexts().getMetaData(backendConnection.getSchemaName()).getResource().getDatabaseType();
- SQLStatement sqlStatement = new ShardingSphereSQLParserEngine(backendDatabaseType.getName()).parse(sql, false);
+ SQLStatement sqlStatement = new ShardingSphereSQLParserEngine(databaseType.getName()).parse(sql, false);
if (sqlStatement instanceof TCLStatement) {
return TransactionBackendHandlerFactory.newInstance((TCLStatement) sqlStatement, sql, backendConnection);
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/TextProtocolBackendHandlerFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/TextProtocolBackendHandlerFactoryTest.java
index f76f9a6..8a00254 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/TextProtocolBackendHandlerFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/TextProtocolBackendHandlerFactoryTest.java
@@ -18,11 +18,8 @@
package org.apache.shardingsphere.proxy.backend;
import lombok.SneakyThrows;
-import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
@@ -68,14 +65,6 @@ public final class TextProtocolBackendHandlerFactoryTest {
when(backendConnection.getTransactionStatus().getTransactionType()).thenReturn(TransactionType.LOCAL);
setTransactionContexts();
when(backendConnection.getSchemaName()).thenReturn("schema");
-
- MetaDataContexts metaDataContexts = mock(MetaDataContexts.class);
- when(metaDataContexts.getMetaData("schema")).thenReturn(mock(ShardingSphereMetaData.class));
- when(metaDataContexts.getMetaData("schema").getResource()).thenReturn(mock(ShardingSphereResource.class));
- when(metaDataContexts.getMetaData("schema").getResource().getDatabaseType()).thenReturn(databaseType);
- TransactionContexts transactionContexts = mock(TransactionContexts.class);
- ProxyContext proxyContext = ProxyContext.getInstance();
- proxyContext.init(metaDataContexts, transactionContexts);
}
@SneakyThrows(ReflectiveOperationException.class)
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java
index 9dfdf31..7df16a7 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/context/ProxyContextTest.java
@@ -27,6 +27,7 @@ import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
+import org.apache.shardingsphere.test.mock.MockedDataSource;
import org.apache.shardingsphere.proxy.backend.exception.NoDatabaseSelectedException;
import org.apache.shardingsphere.transaction.context.TransactionContexts;
import org.junit.Test;
@@ -34,9 +35,11 @@ import org.junit.Test;
import javax.sql.DataSource;
import java.lang.reflect.Field;
import java.util.Collections;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
+import java.util.Optional;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
@@ -54,6 +57,19 @@ public final class ProxyContextTest {
private static final String SCHEMA_PATTERN = "schema_%s";
@Test
+ public void assertGetDataSourceSample() throws NoSuchFieldException, IllegalAccessException {
+ Map<String, DataSource> mockDataSourceMap = new HashMap<>(2, 1);
+ mockDataSourceMap.put("ds_1", new MockedDataSource());
+ mockDataSourceMap.put("ds_2", new MockedDataSource());
+ Field metaDataContexts = ProxyContext.getInstance().getClass().getDeclaredField("metaDataContexts");
+ metaDataContexts.setAccessible(true);
+ metaDataContexts.set(ProxyContext.getInstance(),
+ new StandardMetaDataContexts(mockMetaDataMap(mockDataSourceMap), mock(ExecutorEngine.class), new DefaultAuthentication(), new ConfigurationProperties(new Properties())));
+ Optional<DataSource> actual = ProxyContext.getInstance().getDataSourceSample();
+ assertThat(actual, is(Optional.of(mockDataSourceMap.get("ds_1"))));
+ }
+
+ @Test
public void assertInit() {
MetaDataContexts metaDataContexts = mock(MetaDataContexts.class);
TransactionContexts transactionContexts = mock(TransactionContexts.class);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/AbstractBootstrapInitializer.java b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/AbstractBootstrapInitializer.java
index 49d870f..93916fa 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/AbstractBootstrapInitializer.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/AbstractBootstrapInitializer.java
@@ -23,7 +23,6 @@ import org.apache.shardingsphere.infra.config.datasource.DataSourceParameter;
import org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
import org.apache.shardingsphere.infra.context.metadata.MetaDataContextsBuilder;
-import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.datasource.factory.JDBCRawBackendDataSourceFactory;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
@@ -42,7 +41,6 @@ import java.sql.SQLException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
-import java.util.List;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -102,34 +100,13 @@ public abstract class AbstractBootstrapInitializer implements BootstrapInitializ
}
private void setDatabaseServerInfo() {
- Optional<DataSource> dataSourceSample = getBackendMySQLDatasource();
+ Optional<DataSource> dataSourceSample = ProxyContext.getInstance().getDataSourceSample();
if (dataSourceSample.isPresent()) {
DatabaseServerInfo databaseServerInfo = new DatabaseServerInfo(dataSourceSample.get());
log.info(databaseServerInfo.toString());
MySQLServerInfo.setServerVersion(databaseServerInfo.getDatabaseVersion());
}
}
-
- /**
- * Get backend MySQL datasource.
- *
- * @return datasource
- */
- private Optional<DataSource> getBackendMySQLDatasource() {
- List<String> schemaNames = ProxyContext.getInstance().getAllSchemaNames();
- if (schemaNames.isEmpty()) {
- return Optional.empty();
- }
- for (String schemaName : schemaNames) {
- ShardingSphereResource shardingSphereResource =
- ProxyContext.getInstance().getMetaData(schemaName).getResource();
- DatabaseType databaseType = shardingSphereResource.getDatabaseType();
- if ("MySQL".equals(databaseType.getName())) {
- return shardingSphereResource.getDataSources().values().stream().findFirst();
- }
- }
- return Optional.empty();
- }
protected Optional<ServerConfiguration> getScalingConfiguration(final YamlProxyConfiguration yamlConfig) {
if (null != yamlConfig.getServerConfiguration().getScaling()) {
diff --git a/shardingsphere-scaling/shardingsphere-scaling-dialect/shardingsphere-scaling-mysql/src/test/java/org/apache/shardingsphere/scaling/mysql/client/netty/MySQLNegotiateHandlerTest.java b/shardingsphere-scaling/shardingsphere-scaling-dialect/shardingsphere-scaling-mysql/src/test/java/org/apache/shardingsphere/scaling/mysql/client/netty/MySQLNegotiateHandlerTest.java
index 5b8ff45..32ad0da 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-dialect/shardingsphere-scaling-mysql/src/test/java/org/apache/shardingsphere/scaling/mysql/client/netty/MySQLNegotiateHandlerTest.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-dialect/shardingsphere-scaling-mysql/src/test/java/org/apache/shardingsphere/scaling/mysql/client/netty/MySQLNegotiateHandlerTest.java
@@ -79,9 +79,9 @@ public final class MySQLNegotiateHandlerTest {
verify(channel).writeAndFlush(ArgumentMatchers.any(MySQLHandshakeResponse41Packet.class));
ServerInfo serverInfo = ReflectionUtil.getFieldValue(mysqlNegotiateHandler, "serverInfo", ServerInfo.class);
assertNotNull(serverInfo);
- assertThat(serverInfo.getServerVersion().getMajor(), is(5));
- assertThat(serverInfo.getServerVersion().getMinor(), is(7));
- assertThat(serverInfo.getServerVersion().getSeries(), is(22));
+ assertThat(serverInfo.getServerVersion().getMajor(), is(8));
+ assertThat(serverInfo.getServerVersion().getMinor(), is(0));
+ assertThat(serverInfo.getServerVersion().getSeries(), is(20));
}
@Test