This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 1c09a0609df Fix #26833, update single table judgment in
DropTableStatementSchemaRefresher (#26834)
1c09a0609df is described below
commit 1c09a0609df93fa84969a138f1ad85cf3a53caff
Author: Raigor <[email protected]>
AuthorDate: Sat Jul 8 16:56:10 2023 +0800
Fix #26833, update single table judgment in
DropTableStatementSchemaRefresher (#26834)
---
.../type/table/DropTableStatementSchemaRefresher.java | 7 +++----
.../connection/refresher/util/TableRefreshUtils.java | 18 ++++++++++++++++++
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git
a/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/table/DropTableStatementSchemaRefresher.java
b/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/table/DropTableStatementSchemaRefresher.java
index 38dd649b3d6..62ec9037dcb 100644
---
a/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/table/DropTableStatementSchemaRefresher.java
+++
b/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/table/DropTableStatementSchemaRefresher.java
@@ -40,12 +40,11 @@ public final class DropTableStatementSchemaRefresher
implements MetaDataRefreshe
final String schemaName, final DropTableStatement
sqlStatement, final ConfigurationProperties props) {
AlterSchemaMetaDataPOJO alterSchemaMetaDataPOJO = new
AlterSchemaMetaDataPOJO(database.getName(), schemaName);
sqlStatement.getTables().forEach(each ->
alterSchemaMetaDataPOJO.getDroppedTables().add(each.getTableName().getIdentifier().getValue()));
- modeContextManager.alterSchemaMetaData(alterSchemaMetaDataPOJO);
ShardingSphereRuleMetaData ruleMetaData = database.getRuleMetaData();
+ boolean isRuleRefreshRequired =
TableRefreshUtils.isRuleRefreshRequired(ruleMetaData, schemaName,
sqlStatement.getTables());
+ modeContextManager.alterSchemaMetaData(alterSchemaMetaDataPOJO);
for (SimpleTableSegment each : sqlStatement.getTables()) {
- String tableName = each.getTableName().getIdentifier().getValue();
- if (isSingleTable(tableName, ruleMetaData)
- && TableRefreshUtils.isRuleRefreshRequired(ruleMetaData,
schemaName, tableName)) {
+ if (isRuleRefreshRequired &&
isSingleTable(each.getTableName().getIdentifier().getValue(), ruleMetaData)) {
modeContextManager.alterRuleConfiguration(database.getName(),
ruleMetaData.getConfigurations());
break;
}
diff --git
a/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/util/TableRefreshUtils.java
b/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/util/TableRefreshUtils.java
index 86d33f8b85d..a936474658a 100644
---
a/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/util/TableRefreshUtils.java
+++
b/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/util/TableRefreshUtils.java
@@ -26,6 +26,7 @@ import
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRule
import
org.apache.shardingsphere.infra.rule.identifier.type.MutableDataNodeRule;
import org.apache.shardingsphere.single.api.config.SingleRuleConfiguration;
import org.apache.shardingsphere.single.api.constant.SingleTableConstants;
+import
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
import java.util.Collection;
import java.util.Optional;
@@ -36,6 +37,23 @@ import java.util.Optional;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class TableRefreshUtils {
+ /**
+ * Judge whether the rule need to be refreshed.
+ *
+ * @param ruleMetaData rule meta data
+ * @param schemaName schema name
+ * @param tableSegments table segments
+ * @return whether the rule need to be refreshed
+ */
+ public static boolean isRuleRefreshRequired(final
ShardingSphereRuleMetaData ruleMetaData, final String schemaName, final
Collection<SimpleTableSegment> tableSegments) {
+ for (SimpleTableSegment each : tableSegments) {
+ if (isRuleRefreshRequired(ruleMetaData, schemaName,
each.getTableName().getIdentifier().getValue())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
* Judge whether the rule need to be refreshed.
*