From 51efe0ba94c8f729036c5f7474d5aaa35604d7a7 Mon Sep 17 00:00:00 2001 From: zhangliang Date: Thu, 23 Jan 2025 22:07:03 +0800 Subject: [PATCH 1/2] Remove MetaDataRefreshEngine.DDL_STATEMENT_CLASSES --- .../metadata/MetaDataRefreshEngine.java | 24 +------------------ 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/metadata/MetaDataRefreshEngine.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/metadata/MetaDataRefreshEngine.java index 30bde2fee732f..000284123a9e2 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/metadata/MetaDataRefreshEngine.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/metadata/MetaDataRefreshEngine.java @@ -29,23 +29,8 @@ import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.mode.metadata.refresher.metadata.federation.FederationMetaDataRefresher; import org.apache.shardingsphere.mode.persist.service.MetaDataManagerPersistService; -import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.AlterIndexStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.AlterSchemaStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.AlterTableStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.AlterViewStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateIndexStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateSchemaStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateTableStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateViewStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DDLStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropIndexStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropSchemaStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropTableStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropViewStatement; -import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.RenameTableStatement; import java.sql.SQLException; -import java.util.Arrays; import java.util.Collection; import java.util.Objects; import java.util.Optional; @@ -57,10 +42,6 @@ @RequiredArgsConstructor public final class MetaDataRefreshEngine { - private static final Collection> DDL_STATEMENT_CLASSES = Arrays.asList(CreateTableStatement.class, AlterTableStatement.class, DropTableStatement.class, - CreateViewStatement.class, AlterViewStatement.class, DropViewStatement.class, CreateIndexStatement.class, AlterIndexStatement.class, DropIndexStatement.class, CreateSchemaStatement.class, - AlterSchemaStatement.class, DropSchemaStatement.class, RenameTableStatement.class); - private final MetaDataManagerPersistService metaDataManagerPersistService; private final ShardingSphereDatabase database; @@ -75,7 +56,7 @@ public final class MetaDataRefreshEngine { */ public boolean isNeedRefreshMetaData(final SQLStatementContext sqlStatementContext) { Class sqlStatementClass = sqlStatementContext.getSqlStatement().getClass().getSuperclass(); - return DDL_STATEMENT_CLASSES.contains(sqlStatementClass); + return TypedSPILoader.findService(MetaDataRefresher.class, sqlStatementClass).isPresent(); } /** @@ -87,9 +68,6 @@ public boolean isNeedRefreshMetaData(final SQLStatementContext sqlStatementConte */ @SuppressWarnings({"unchecked", "rawtypes"}) public void refresh(final SQLStatementContext sqlStatementContext, final Collection routeUnits) throws SQLException { - if (!isNeedRefreshMetaData(sqlStatementContext)) { - return; - } Class sqlStatementClass = sqlStatementContext.getSqlStatement().getClass().getSuperclass(); Optional metaDataRefresher = TypedSPILoader.findService(MetaDataRefresher.class, sqlStatementClass); if (!metaDataRefresher.isPresent()) { From 2cb1e2bcac3c1a0ba38b7de51cd3cf0cfa521ec8 Mon Sep 17 00:00:00 2001 From: zhangliang Date: Thu, 23 Jan 2025 22:09:20 +0800 Subject: [PATCH 2/2] Remove MetaDataRefreshEngine.DDL_STATEMENT_CLASSES --- .../pushdown/jdbc/DriverJDBCPushDownExecuteUpdateExecutor.java | 2 +- .../mode/metadata/refresher/metadata/MetaDataRefreshEngine.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/pushdown/jdbc/DriverJDBCPushDownExecuteUpdateExecutor.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/pushdown/jdbc/DriverJDBCPushDownExecuteUpdateExecutor.java index db4d9671ed3e0..7a0eeb82eb303 100644 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/pushdown/jdbc/DriverJDBCPushDownExecuteUpdateExecutor.java +++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/pushdown/jdbc/DriverJDBCPushDownExecuteUpdateExecutor.java @@ -109,7 +109,7 @@ private int doExecuteUpdate(final ShardingSphereDatabase database, final Executi .newInstance(database, executionContext.getSqlStatementContext().getSqlStatement(), updateCallback); List updateCounts = jdbcExecutor.execute(executionGroupContext, callback); MetaDataRefreshEngine metaDataRefreshEngine = new MetaDataRefreshEngine(connection.getContextManager().getPersistServiceFacade().getMetaDataManagerPersistService(), database, props); - if (metaDataRefreshEngine.isNeedRefreshMetaData(executionContext.getSqlStatementContext())) { + if (metaDataRefreshEngine.isNeedRefresh(executionContext.getSqlStatementContext())) { if (isNeedImplicitCommit(executionContext.getSqlStatementContext())) { connection.commit(); } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/metadata/MetaDataRefreshEngine.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/metadata/MetaDataRefreshEngine.java index 000284123a9e2..c0f0eeb20640b 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/metadata/MetaDataRefreshEngine.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/metadata/MetaDataRefreshEngine.java @@ -54,7 +54,7 @@ public final class MetaDataRefreshEngine { * @param sqlStatementContext SQL statement context * @return is need refresh meta data or not */ - public boolean isNeedRefreshMetaData(final SQLStatementContext sqlStatementContext) { + public boolean isNeedRefresh(final SQLStatementContext sqlStatementContext) { Class sqlStatementClass = sqlStatementContext.getSqlStatement().getClass().getSuperclass(); return TypedSPILoader.findService(MetaDataRefresher.class, sqlStatementClass).isPresent(); }