This is an automated email from the ASF dual-hosted git repository. sunnianjun 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 f84d21dfa35 Add DistSQLConnectionContext (#29878) f84d21dfa35 is described below commit f84d21dfa35f2ad18e897ed1e3d2ff729ae32c1b Author: Liang Zhang <zhangli...@apache.org> AuthorDate: Sat Jan 27 23:21:21 2024 +0800 Add DistSQLConnectionContext (#29878) * Add DistSQLConnectionContext * Add DistSQLConnectionContext * Add DistSQLConnectionContext * Add DistSQLConnectionContext --- .../DistSQLExecutorConnectionContextAware.java | 24 +++--------------- .../DistSQLConnectionContext.java} | 29 +++++++++++++++------- .../type/ral/query/QueryableRALExecuteEngine.java | 9 ++++--- .../distsql/handler/type/rul/RULExecuteEngine.java | 16 +++--------- .../distsql/ral/QueryableRALBackendHandler.java | 6 +++-- .../ral/queryable/ShowDistVariableExecutor.java | 9 ++++--- .../ral/queryable/ShowDistVariablesExecutor.java | 9 ++++--- .../handler/distsql/rul/RULBackendHandler.java | 21 +++------------- .../handler/distsql/rul/type/PreviewExecutor.java | 22 ++++++---------- .../queryable/ShowComputeNodesExecutorTest.java | 18 -------------- .../queryable/ShowDistVariableExecutorTest.java | 6 ++++- .../queryable/ShowDistVariablesExecutorTest.java | 16 +++++------- 12 files changed, 67 insertions(+), 118 deletions(-) diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/aware/DistSQLExecutorConnectionContextAware.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/aware/DistSQLExecutorConnectionContextAware.java index d50f5c4624d..a1c4e9dd086 100644 --- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/aware/DistSQLExecutorConnectionContextAware.java +++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/aware/DistSQLExecutorConnectionContextAware.java @@ -17,9 +17,7 @@ package org.apache.shardingsphere.distsql.handler.aware; -import org.apache.shardingsphere.infra.executor.sql.prepare.driver.DatabaseConnectionManager; -import org.apache.shardingsphere.infra.executor.sql.prepare.driver.ExecutorStatementManager; -import org.apache.shardingsphere.infra.session.connection.ConnectionContext; +import org.apache.shardingsphere.distsql.handler.type.DistSQLConnectionContext; /** * DistSQL executor connection context aware. @@ -27,25 +25,9 @@ import org.apache.shardingsphere.infra.session.connection.ConnectionContext; public interface DistSQLExecutorConnectionContextAware { /** - * Set connection context. + * Set DistSQL connection context. * * @param connectionContext connection context */ - void setConnectionContext(ConnectionContext connectionContext); - - /** - * Set database connection manager. - * - * @param databaseConnectionManager database connection manager - */ - @SuppressWarnings("rawtypes") - void setDatabaseConnectionManager(DatabaseConnectionManager databaseConnectionManager); - - /** - * Set executor statement manager. - * - * @param executorStatementManager executor statement manager - */ - @SuppressWarnings("rawtypes") - void setStatementManager(ExecutorStatementManager executorStatementManager); + void setConnectionContext(DistSQLConnectionContext connectionContext); } diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/aware/DistSQLExecutorConnectionSizeAware.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/DistSQLConnectionContext.java similarity index 50% rename from infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/aware/DistSQLExecutorConnectionSizeAware.java rename to infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/DistSQLConnectionContext.java index 92d065d32af..b3f4d9853c9 100644 --- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/aware/DistSQLExecutorConnectionSizeAware.java +++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/DistSQLConnectionContext.java @@ -15,17 +15,28 @@ * limitations under the License. */ -package org.apache.shardingsphere.distsql.handler.aware; +package org.apache.shardingsphere.distsql.handler.type; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.apache.shardingsphere.infra.executor.sql.prepare.driver.DatabaseConnectionManager; +import org.apache.shardingsphere.infra.executor.sql.prepare.driver.ExecutorStatementManager; +import org.apache.shardingsphere.infra.session.connection.ConnectionContext; /** - * DistSQL executor connection size aware. + * DistSQL connection context. */ -public interface DistSQLExecutorConnectionSizeAware { +@RequiredArgsConstructor +@Getter +public final class DistSQLConnectionContext { + + private final ConnectionContext connectionContext; + + private final int connectionSize; + + @SuppressWarnings("rawtypes") + private final DatabaseConnectionManager databaseConnectionManager; - /** - * Set connection size. - * - * @param connectionSize connection size - */ - void setConnectionSize(int connectionSize); + @SuppressWarnings("rawtypes") + private final ExecutorStatementManager executorStatementManager; } diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/ral/query/QueryableRALExecuteEngine.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/ral/query/QueryableRALExecuteEngine.java index 6590b26f566..91843be0f23 100644 --- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/ral/query/QueryableRALExecuteEngine.java +++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/ral/query/QueryableRALExecuteEngine.java @@ -19,8 +19,9 @@ package org.apache.shardingsphere.distsql.handler.type.ral.query; import lombok.Getter; import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorConnectionSizeAware; +import org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorConnectionContextAware; import org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorDatabaseAware; +import org.apache.shardingsphere.distsql.handler.type.DistSQLConnectionContext; import org.apache.shardingsphere.distsql.handler.type.DistSQLQueryExecutor; import org.apache.shardingsphere.distsql.handler.util.DatabaseNameUtils; import org.apache.shardingsphere.distsql.statement.DistSQLStatement; @@ -67,13 +68,13 @@ public abstract class QueryableRALExecuteEngine { if (executor instanceof DistSQLExecutorDatabaseAware) { ((DistSQLExecutorDatabaseAware) executor).setDatabase(getDatabase(DatabaseNameUtils.getDatabaseName(sqlStatement, currentDatabaseName))); } - if (executor instanceof DistSQLExecutorConnectionSizeAware) { - ((DistSQLExecutorConnectionSizeAware) executor).setConnectionSize(getConnectionSize()); + if (executor instanceof DistSQLExecutorConnectionContextAware) { + ((DistSQLExecutorConnectionContextAware) executor).setConnectionContext(getDistSQLConnectionContext()); } return executor.getRows(sqlStatement, contextManager); } protected abstract ShardingSphereDatabase getDatabase(String databaseName); - protected abstract int getConnectionSize(); + protected abstract DistSQLConnectionContext getDistSQLConnectionContext(); } diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rul/RULExecuteEngine.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rul/RULExecuteEngine.java index b98e2ab9fa0..9a40e340799 100644 --- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rul/RULExecuteEngine.java +++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/rul/RULExecuteEngine.java @@ -22,15 +22,13 @@ import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorConnectionContextAware; import org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorDatabaseAware; import org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorDatabaseProtocolTypeAware; +import org.apache.shardingsphere.distsql.handler.type.DistSQLConnectionContext; import org.apache.shardingsphere.distsql.handler.type.DistSQLQueryExecutor; import org.apache.shardingsphere.distsql.handler.util.DatabaseNameUtils; import org.apache.shardingsphere.distsql.statement.DistSQLStatement; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; -import org.apache.shardingsphere.infra.executor.sql.prepare.driver.DatabaseConnectionManager; -import org.apache.shardingsphere.infra.executor.sql.prepare.driver.ExecutorStatementManager; import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.session.connection.ConnectionContext; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -71,9 +69,7 @@ public abstract class RULExecuteEngine { ((DistSQLExecutorDatabaseProtocolTypeAware) executor).setDatabaseProtocolType(getDatabaseProtocolType()); } if (executor instanceof DistSQLExecutorConnectionContextAware) { - ((DistSQLExecutorConnectionContextAware) executor).setConnectionContext(getConnectionContext()); - ((DistSQLExecutorConnectionContextAware) executor).setDatabaseConnectionManager(getDatabaseConnectionManager()); - ((DistSQLExecutorConnectionContextAware) executor).setStatementManager(getStatementManager()); + ((DistSQLExecutorConnectionContextAware) executor).setConnectionContext(getDistSQLConnectionContext()); } rows = executor.getRows(sqlStatement, contextManager); } @@ -82,11 +78,5 @@ public abstract class RULExecuteEngine { protected abstract DatabaseType getDatabaseProtocolType(); - protected abstract ConnectionContext getConnectionContext(); - - @SuppressWarnings("rawtypes") - protected abstract DatabaseConnectionManager getDatabaseConnectionManager(); - - @SuppressWarnings("rawtypes") - protected abstract ExecutorStatementManager getStatementManager(); + protected abstract DistSQLConnectionContext getDistSQLConnectionContext(); } diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandler.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandler.java index 2b8eb7e75a2..3aca63d245a 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandler.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/QueryableRALBackendHandler.java @@ -17,6 +17,7 @@ package org.apache.shardingsphere.proxy.backend.handler.distsql.ral; +import org.apache.shardingsphere.distsql.handler.type.DistSQLConnectionContext; import org.apache.shardingsphere.distsql.handler.type.ral.query.QueryableRALExecuteEngine; import org.apache.shardingsphere.distsql.statement.ral.queryable.QueryableRALStatement; import org.apache.shardingsphere.infra.merge.result.MergedResult; @@ -86,7 +87,8 @@ public final class QueryableRALBackendHandler extends QueryableRALExecuteEngine } @Override - protected int getConnectionSize() { - return connectionSession.getDatabaseConnectionManager().getConnectionSize(); + protected DistSQLConnectionContext getDistSQLConnectionContext() { + return new DistSQLConnectionContext(connectionSession.getConnectionContext(), + connectionSession.getDatabaseConnectionManager().getConnectionSize(), connectionSession.getDatabaseConnectionManager(), connectionSession.getStatementManager()); } } diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutor.java index 2eb8ca1cf65..96b81bd2304 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutor.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutor.java @@ -18,7 +18,8 @@ package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable; import lombok.Setter; -import org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorConnectionSizeAware; +import org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorConnectionContextAware; +import org.apache.shardingsphere.distsql.handler.type.DistSQLConnectionContext; import org.apache.shardingsphere.distsql.handler.type.DistSQLQueryExecutor; import org.apache.shardingsphere.distsql.statement.ral.queryable.show.ShowDistVariableStatement; import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey; @@ -44,9 +45,9 @@ import java.util.Properties; * Show dist variable executor. */ @Setter -public final class ShowDistVariableExecutor implements DistSQLQueryExecutor<ShowDistVariableStatement>, DistSQLExecutorConnectionSizeAware { +public final class ShowDistVariableExecutor implements DistSQLQueryExecutor<ShowDistVariableStatement>, DistSQLExecutorConnectionContextAware { - private int connectionSize; + private DistSQLConnectionContext connectionContext; @Override public Collection<String> getColumnNames() { @@ -103,7 +104,7 @@ public final class ShowDistVariableExecutor implements DistSQLQueryExecutor<Show private String getConnectionSize(final String variableName) { ShardingSpherePreconditions.checkState(DistSQLVariable.CACHED_CONNECTIONS == DistSQLVariable.getValueOf(variableName), () -> new UnsupportedVariableException(variableName)); - return String.valueOf(connectionSize); + return String.valueOf(connectionContext.getConnectionSize()); } private String getStringResult(final Object value) { diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutor.java index a07e1e05347..8c4ce5c632b 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutor.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutor.java @@ -18,7 +18,8 @@ package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable; import lombok.Setter; -import org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorConnectionSizeAware; +import org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorConnectionContextAware; +import org.apache.shardingsphere.distsql.handler.type.DistSQLConnectionContext; import org.apache.shardingsphere.distsql.handler.type.DistSQLQueryExecutor; import org.apache.shardingsphere.distsql.statement.ral.queryable.show.ShowDistVariablesStatement; import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey; @@ -45,9 +46,9 @@ import java.util.stream.Collectors; * Show dist variables executor. */ @Setter -public final class ShowDistVariablesExecutor implements DistSQLQueryExecutor<ShowDistVariablesStatement>, DistSQLExecutorConnectionSizeAware { +public final class ShowDistVariablesExecutor implements DistSQLQueryExecutor<ShowDistVariablesStatement>, DistSQLExecutorConnectionContextAware { - private int connectionSize; + private DistSQLConnectionContext connectionContext; @Override public Collection<String> getColumnNames() { @@ -63,7 +64,7 @@ public final class ShowDistVariablesExecutor implements DistSQLQueryExecutor<Sho result.addAll(TemporaryConfigurationPropertyKey.getKeyNames().stream() .map(each -> new LocalDataQueryResultRow(each.toLowerCase(), getStringResult(metaData.getTemporaryProps().getValue(TemporaryConfigurationPropertyKey.valueOf(each))))) .collect(Collectors.toList())); - result.add(new LocalDataQueryResultRow(DistSQLVariable.CACHED_CONNECTIONS.name().toLowerCase(), connectionSize)); + result.add(new LocalDataQueryResultRow(DistSQLVariable.CACHED_CONNECTIONS.name().toLowerCase(), connectionContext.getConnectionSize())); addLoggingPropsRows(metaData, result); if (sqlStatement.getLikePattern().isPresent()) { String pattern = SQLUtils.convertLikePatternToRegex(sqlStatement.getLikePattern().get()); diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/RULBackendHandler.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/RULBackendHandler.java index ca2886ebd10..e43dda5f401 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/RULBackendHandler.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/RULBackendHandler.java @@ -17,16 +17,14 @@ package org.apache.shardingsphere.proxy.backend.handler.distsql.rul; +import org.apache.shardingsphere.distsql.handler.type.DistSQLConnectionContext; import org.apache.shardingsphere.distsql.handler.type.rul.RULExecuteEngine; import org.apache.shardingsphere.distsql.statement.rul.RULStatement; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; -import org.apache.shardingsphere.infra.executor.sql.prepare.driver.DatabaseConnectionManager; -import org.apache.shardingsphere.infra.executor.sql.prepare.driver.ExecutorStatementManager; import org.apache.shardingsphere.infra.merge.result.MergedResult; import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult; import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.session.connection.ConnectionContext; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.handler.distsql.DistSQLBackendHandler; import org.apache.shardingsphere.proxy.backend.response.data.QueryResponseCell; @@ -100,19 +98,8 @@ public final class RULBackendHandler extends RULExecuteEngine implements DistSQL } @Override - protected ConnectionContext getConnectionContext() { - return connectionSession.getConnectionContext(); - } - - @SuppressWarnings("rawtypes") - @Override - protected DatabaseConnectionManager getDatabaseConnectionManager() { - return connectionSession.getDatabaseConnectionManager(); - } - - @SuppressWarnings("rawtypes") - @Override - protected ExecutorStatementManager getStatementManager() { - return connectionSession.getStatementManager(); + protected DistSQLConnectionContext getDistSQLConnectionContext() { + return new DistSQLConnectionContext(connectionSession.getConnectionContext(), + connectionSession.getDatabaseConnectionManager().getConnectionSize(), connectionSession.getDatabaseConnectionManager(), connectionSession.getStatementManager()); } } diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/type/PreviewExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/type/PreviewExecutor.java index 04be10d3513..0e6fa738061 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/type/PreviewExecutor.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/type/PreviewExecutor.java @@ -21,6 +21,7 @@ import com.google.common.base.Preconditions; import lombok.Setter; import org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorConnectionContextAware; import org.apache.shardingsphere.distsql.handler.aware.DistSQLExecutorDatabaseAware; +import org.apache.shardingsphere.distsql.handler.type.DistSQLConnectionContext; import org.apache.shardingsphere.distsql.handler.type.DistSQLQueryExecutor; import org.apache.shardingsphere.distsql.statement.rul.sql.PreviewStatement; import org.apache.shardingsphere.infra.binder.context.aware.CursorDefinitionAware; @@ -42,9 +43,7 @@ import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.J import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutorCallback; import org.apache.shardingsphere.infra.executor.sql.execute.result.ExecuteResult; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.type.stream.JDBCStreamQueryResult; -import org.apache.shardingsphere.infra.executor.sql.prepare.driver.DatabaseConnectionManager; import org.apache.shardingsphere.infra.executor.sql.prepare.driver.DriverExecutionPrepareEngine; -import org.apache.shardingsphere.infra.executor.sql.prepare.driver.ExecutorStatementManager; import org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.JDBCDriverType; import org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.StatementOption; import org.apache.shardingsphere.infra.hint.HintValueContext; @@ -52,7 +51,6 @@ import org.apache.shardingsphere.infra.hint.SQLHintUtils; import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.session.connection.ConnectionContext; import org.apache.shardingsphere.infra.session.query.QueryContext; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.parser.rule.SQLParserRule; @@ -80,13 +78,7 @@ public final class PreviewExecutor implements DistSQLQueryExecutor<PreviewStatem private ShardingSphereDatabase database; - private ConnectionContext connectionContext; - - @SuppressWarnings("rawtypes") - private DatabaseConnectionManager databaseConnectionManager; - - @SuppressWarnings("rawtypes") - private ExecutorStatementManager statementManager; + private DistSQLConnectionContext connectionContext; @Override public Collection<String> getColumnNames() { @@ -108,11 +100,11 @@ public final class PreviewExecutor implements DistSQLQueryExecutor<PreviewStatem String schemaName = queryContext.getSqlStatementContext().getTablesContext().getSchemaName() .orElseGet(() -> new DatabaseTypeRegistry(database.getProtocolType()).getDefaultSchemaName(database.getName())); SQLFederationEngine federationEngine = new SQLFederationEngine(database.getName(), schemaName, metaData, contextManager.getMetaDataContexts().getStatistics(), - new JDBCExecutor(BackendExecutorContext.getInstance().getExecutorEngine(), connectionContext)); + new JDBCExecutor(BackendExecutorContext.getInstance().getExecutorEngine(), connectionContext.getConnectionContext())); Collection<ExecutionUnit> executionUnits = federationEngine.decide(queryContext.getSqlStatementContext(), queryContext.getParameters(), database, metaData.getGlobalRuleMetaData()) ? getFederationExecutionUnits(queryContext, metaData, federationEngine) : new KernelProcessor().generateExecutionContext( - queryContext, database, metaData.getGlobalRuleMetaData(), metaData.getProps(), connectionContext).getExecutionUnits(); + queryContext, database, metaData.getGlobalRuleMetaData(), metaData.getProps(), connectionContext.getConnectionContext()).getExecutionUnits(); return executionUnits.stream().map(each -> new LocalDataQueryResultRow(each.getDataSourceName(), each.getSqlUnit().getSql())).collect(Collectors.toList()); } @@ -121,7 +113,7 @@ public final class PreviewExecutor implements DistSQLQueryExecutor<PreviewStatem return; } String cursorName = ((CursorAvailable) toBePreviewedStatementContext).getCursorName().get().getIdentifier().getValue().toLowerCase(); - CursorStatementContext cursorStatementContext = (CursorStatementContext) connectionContext.getCursorContext().getCursorDefinitions().get(cursorName); + CursorStatementContext cursorStatementContext = (CursorStatementContext) connectionContext.getConnectionContext().getCursorContext().getCursorDefinitions().get(cursorName); Preconditions.checkNotNull(cursorStatementContext, "Cursor %s does not exist.", cursorName); ((CursorDefinitionAware) toBePreviewedStatementContext).setUpCursorDefinition(cursorStatementContext); } @@ -154,8 +146,8 @@ public final class PreviewExecutor implements DistSQLQueryExecutor<PreviewStatem @SuppressWarnings({"unchecked", "rawtypes"}) private DriverExecutionPrepareEngine<JDBCExecutionUnit, Connection> createDriverExecutionPrepareEngine(final boolean isReturnGeneratedKeys, final ConfigurationProperties props) { int maxConnectionsSizePerQuery = props.<Integer>getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY); - return new DriverExecutionPrepareEngine<>(JDBCDriverType.STATEMENT, maxConnectionsSizePerQuery, databaseConnectionManager, statementManager, - new StatementOption(isReturnGeneratedKeys), database.getRuleMetaData().getRules(), database.getResourceMetaData().getStorageUnits()); + return new DriverExecutionPrepareEngine<>(JDBCDriverType.STATEMENT, maxConnectionsSizePerQuery, connectionContext.getDatabaseConnectionManager(), + connectionContext.getExecutorStatementManager(), new StatementOption(isReturnGeneratedKeys), database.getRuleMetaData().getRules(), database.getResourceMetaData().getStorageUnits()); } @Override diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodesExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodesExecutorTest.java index 985eb559364..ecce75e0da7 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodesExecutorTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodesExecutorTest.java @@ -31,7 +31,6 @@ import org.junit.jupiter.api.Test; import java.util.Collection; import java.util.Collections; -import java.util.Iterator; import java.util.Properties; import static org.hamcrest.CoreMatchers.is; @@ -42,23 +41,6 @@ import static org.mockito.Mockito.when; class ShowComputeNodesExecutorTest { - @Test - void assertGetColumns() { - ShowComputeNodesExecutor executor = new ShowComputeNodesExecutor(); - Collection<String> columns = executor.getColumnNames(); - assertThat(columns.size(), is(9)); - Iterator<String> iterator = columns.iterator(); - assertThat(iterator.next(), is("instance_id")); - assertThat(iterator.next(), is("instance_type")); - assertThat(iterator.next(), is("host")); - assertThat(iterator.next(), is("port")); - assertThat(iterator.next(), is("status")); - assertThat(iterator.next(), is("mode_type")); - assertThat(iterator.next(), is("worker_id")); - assertThat(iterator.next(), is("labels")); - assertThat(iterator.next(), is("version")); - } - @Test void assertExecuteWithStandaloneMode() { ShowComputeNodesExecutor executor = new ShowComputeNodesExecutor(); diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutorTest.java index 5408ca0828f..54b5701a9ca 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutorTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariableExecutorTest.java @@ -17,10 +17,14 @@ package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable; +import org.apache.shardingsphere.distsql.handler.type.DistSQLConnectionContext; import org.apache.shardingsphere.distsql.statement.ral.queryable.show.ShowDistVariableStatement; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.config.props.temporary.TemporaryConfigurationProperties; +import org.apache.shardingsphere.infra.executor.sql.prepare.driver.DatabaseConnectionManager; +import org.apache.shardingsphere.infra.executor.sql.prepare.driver.ExecutorStatementManager; import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; +import org.apache.shardingsphere.infra.session.connection.ConnectionContext; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.proxy.backend.exception.UnsupportedVariableException; import org.apache.shardingsphere.test.util.PropertiesBuilder; @@ -54,7 +58,7 @@ class ShowDistVariableExecutorTest { @Test void assertShowCachedConnections() { ShowDistVariableExecutor executor = new ShowDistVariableExecutor(); - executor.setConnectionSize(1); + executor.setConnectionContext(new DistSQLConnectionContext(mock(ConnectionContext.class), 1, mock(DatabaseConnectionManager.class), mock(ExecutorStatementManager.class))); Collection<LocalDataQueryResultRow> actual = executor.getRows(new ShowDistVariableStatement("CACHED_CONNECTIONS"), contextManager); assertThat(actual.size(), is(1)); LocalDataQueryResultRow row = actual.iterator().next(); diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutorTest.java index 39689988c11..6ca20eaeed2 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutorTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowDistVariablesExecutorTest.java @@ -17,11 +17,15 @@ package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable; +import org.apache.shardingsphere.distsql.handler.type.DistSQLConnectionContext; import org.apache.shardingsphere.distsql.statement.ral.queryable.show.ShowDistVariablesStatement; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.config.props.temporary.TemporaryConfigurationProperties; +import org.apache.shardingsphere.infra.executor.sql.prepare.driver.DatabaseConnectionManager; +import org.apache.shardingsphere.infra.executor.sql.prepare.driver.ExecutorStatementManager; import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; +import org.apache.shardingsphere.infra.session.connection.ConnectionContext; import org.apache.shardingsphere.logging.rule.LoggingRule; import org.apache.shardingsphere.logging.rule.builder.DefaultLoggingRuleConfigurationBuilder; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -43,22 +47,13 @@ class ShowDistVariablesExecutorTest { private final ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); - @Test - void assertGetColumns() { - ShowDistVariablesExecutor executor = new ShowDistVariablesExecutor(); - Collection<String> columns = executor.getColumnNames(); - assertThat(columns.size(), is(2)); - Iterator<String> iterator = columns.iterator(); - assertThat(iterator.next(), is("variable_name")); - assertThat(iterator.next(), is("variable_value")); - } - @Test void assertExecute() { when(contextManager.getMetaDataContexts().getMetaData().getProps()).thenReturn(new ConfigurationProperties(PropertiesBuilder.build(new Property("system-log-level", "INFO")))); when(contextManager.getMetaDataContexts().getMetaData().getTemporaryProps()) .thenReturn(new TemporaryConfigurationProperties(PropertiesBuilder.build(new Property("proxy-meta-data-collector-enabled", Boolean.FALSE.toString())))); ShowDistVariablesExecutor executor = new ShowDistVariablesExecutor(); + executor.setConnectionContext(new DistSQLConnectionContext(mock(ConnectionContext.class), 1, mock(DatabaseConnectionManager.class), mock(ExecutorStatementManager.class))); Collection<LocalDataQueryResultRow> actual = executor.getRows(mock(ShowDistVariablesStatement.class), contextManager); assertThat(actual.size(), is(21)); LocalDataQueryResultRow row = actual.iterator().next(); @@ -74,6 +69,7 @@ class ShowDistVariablesExecutorTest { when(contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()) .thenReturn(new RuleMetaData(Collections.singleton(new LoggingRule(new DefaultLoggingRuleConfigurationBuilder().build())))); ShowDistVariablesExecutor executor = new ShowDistVariablesExecutor(); + executor.setConnectionContext(new DistSQLConnectionContext(mock(ConnectionContext.class), 1, mock(DatabaseConnectionManager.class), mock(ExecutorStatementManager.class))); Collection<LocalDataQueryResultRow> actual = executor.getRows(new ShowDistVariablesStatement("sql_%"), contextManager); assertThat(actual.size(), is(2)); Iterator<LocalDataQueryResultRow> iterator = actual.iterator();