From 00dbf3a246217e67a237b0b4e3596c0e4f5356f8 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Sun, 4 Feb 2024 23:05:13 +0800 Subject: [PATCH] Refactor DistSQLExecutorRequiredChecker (#29993) * Refactor DistSQLUpdateExecuteEngine * Refactor DistSQLExecutorRequiredChecker --- .../DropBroadcastTableRuleExecutor.java | 2 +- .../update/AlterEncryptRuleExecutor.java | 2 +- .../update/DropEncryptRuleExecutor.java | 2 +- .../handler/update/AlterMaskRuleExecutor.java | 2 +- .../handler/update/DropMaskRuleExecutor.java | 2 +- .../AlterReadwriteSplittingRuleExecutor.java | 2 +- .../DropReadwriteSplittingRuleExecutor.java | 2 +- .../AlterDefaultShadowAlgorithmExecutor.java | 2 +- .../update/AlterShadowRuleExecutor.java | 2 +- .../DropDefaultShadowAlgorithmExecutor.java | 2 +- .../update/DropShadowAlgorithmExecutor.java | 2 +- .../update/DropShadowRuleExecutor.java | 2 +- .../AlterDefaultShardingStrategyExecutor.java | 2 +- ...terShardingTableReferenceRuleExecutor.java | 2 +- .../AlterShardingTableRuleExecutor.java | 2 +- ...ateShardingTableReferenceRuleExecutor.java | 2 +- .../DropDefaultShardingStrategyExecutor.java | 2 +- .../update/DropShardingAlgorithmExecutor.java | 2 +- .../update/DropShardingAuditorExecutor.java | 2 +- .../DropShardingKeyGeneratorExecutor.java | 2 +- .../DropShardingTableReferenceExecutor.java | 2 +- .../update/DropShardingTableRuleExecutor.java | 2 +- .../DistSQLExecutorCurrentRuleRequired.java | 8 +++++--- .../DistSQLExecutorRequiredChecker.java | 20 +++++++++++++------ .../update/DistSQLUpdateExecuteEngine.java | 11 +++++----- .../DatabaseRuleDefinitionExecuteEngine.java | 6 +++--- ...cyDatabaseRuleDefinitionExecuteEngine.java | 6 +++--- .../update/UnloadSingleTableExecutor.java | 2 +- 28 files changed, 53 insertions(+), 44 deletions(-) diff --git a/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/update/DropBroadcastTableRuleExecutor.java b/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/update/DropBroadcastTableRuleExecutor.java index 7053231e977ec..74a690d3e7879 100644 --- a/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/update/DropBroadcastTableRuleExecutor.java +++ b/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/update/DropBroadcastTableRuleExecutor.java @@ -35,7 +35,7 @@ /** * Drop broadcast table rule executor. */ -@DistSQLExecutorCurrentRuleRequired("Broadcast") +@DistSQLExecutorCurrentRuleRequired(BroadcastRule.class) @Setter public final class DropBroadcastTableRuleExecutor implements DatabaseRuleDropExecutor { diff --git a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutor.java b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutor.java index 9cab21c32e2c8..8d1f2ca4f2f74 100644 --- a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutor.java +++ b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/AlterEncryptRuleExecutor.java @@ -49,7 +49,7 @@ /** * Alter encrypt rule executor. */ -@DistSQLExecutorCurrentRuleRequired("Encrypt") +@DistSQLExecutorCurrentRuleRequired(EncryptRule.class) @Setter public final class AlterEncryptRuleExecutor implements DatabaseRuleAlterExecutor { diff --git a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleExecutor.java b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleExecutor.java index 9b850607f9c47..dd92d227e7511 100644 --- a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleExecutor.java +++ b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/update/DropEncryptRuleExecutor.java @@ -40,7 +40,7 @@ /** * Drop encrypt rule executor. */ -@DistSQLExecutorCurrentRuleRequired("Encrypt") +@DistSQLExecutorCurrentRuleRequired(EncryptRule.class) @Setter public final class DropEncryptRuleExecutor implements DatabaseRuleDropExecutor { diff --git a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/AlterMaskRuleExecutor.java b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/AlterMaskRuleExecutor.java index 2014908805e71..d4ad38655c53b 100644 --- a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/AlterMaskRuleExecutor.java +++ b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/AlterMaskRuleExecutor.java @@ -41,7 +41,7 @@ /** * Alter mask rule executor. */ -@DistSQLExecutorCurrentRuleRequired("Mask") +@DistSQLExecutorCurrentRuleRequired(MaskRule.class) @Setter public final class AlterMaskRuleExecutor implements DatabaseRuleAlterExecutor { diff --git a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleExecutor.java b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleExecutor.java index f3b13e15a2986..e3fd674dad237 100644 --- a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleExecutor.java +++ b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/update/DropMaskRuleExecutor.java @@ -41,7 +41,7 @@ /** * Drop mask rule statement executor. */ -@DistSQLExecutorCurrentRuleRequired("Mask") +@DistSQLExecutorCurrentRuleRequired(MaskRule.class) @Setter public final class DropMaskRuleExecutor implements DatabaseRuleDropExecutor { diff --git a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleExecutor.java b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleExecutor.java index 4fa48aab0d8ea..7455ccf2d7838 100644 --- a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleExecutor.java +++ b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingRuleExecutor.java @@ -41,7 +41,7 @@ /** * Alter readwrite-splitting rule executor. */ -@DistSQLExecutorCurrentRuleRequired("Readwrite-splitting") +@DistSQLExecutorCurrentRuleRequired(ReadwriteSplittingRule.class) @Setter public final class AlterReadwriteSplittingRuleExecutor implements DatabaseRuleAlterExecutor { diff --git a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutor.java b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutor.java index 24aedde0f749a..660219b771212 100644 --- a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutor.java +++ b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutor.java @@ -47,7 +47,7 @@ /** * Drop readwrite-splitting rule executor. */ -@DistSQLExecutorCurrentRuleRequired("Readwrite-splitting") +@DistSQLExecutorCurrentRuleRequired(ReadwriteSplittingRule.class) @Setter public final class DropReadwriteSplittingRuleExecutor implements DatabaseRuleDropExecutor { diff --git a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterDefaultShadowAlgorithmExecutor.java b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterDefaultShadowAlgorithmExecutor.java index d110f796f954d..e61be9a79d51c 100644 --- a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterDefaultShadowAlgorithmExecutor.java +++ b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterDefaultShadowAlgorithmExecutor.java @@ -40,7 +40,7 @@ /** * Alter default shadow algorithm executor. */ -@DistSQLExecutorCurrentRuleRequired("Shadow") +@DistSQLExecutorCurrentRuleRequired(ShadowRule.class) @Setter public final class AlterDefaultShadowAlgorithmExecutor implements DatabaseRuleAlterExecutor { diff --git a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowRuleExecutor.java b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowRuleExecutor.java index 5124bf82645a2..be88c9b79c520 100644 --- a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowRuleExecutor.java +++ b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/AlterShadowRuleExecutor.java @@ -43,7 +43,7 @@ /** * Alter shadow rule executor. */ -@DistSQLExecutorCurrentRuleRequired("Shadow") +@DistSQLExecutorCurrentRuleRequired(ShadowRule.class) @Setter public final class AlterShadowRuleExecutor implements DatabaseRuleAlterExecutor { diff --git a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropDefaultShadowAlgorithmExecutor.java b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropDefaultShadowAlgorithmExecutor.java index fbeec4d54d524..6d6c58c193e76 100644 --- a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropDefaultShadowAlgorithmExecutor.java +++ b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropDefaultShadowAlgorithmExecutor.java @@ -32,7 +32,7 @@ /** * Drop default shadow algorithm executor. */ -@DistSQLExecutorCurrentRuleRequired("Shadow") +@DistSQLExecutorCurrentRuleRequired(ShadowRule.class) @Setter public final class DropDefaultShadowAlgorithmExecutor implements DatabaseRuleDropExecutor { diff --git a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowAlgorithmExecutor.java b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowAlgorithmExecutor.java index db9b644febd3f..5e6478207c418 100644 --- a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowAlgorithmExecutor.java +++ b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowAlgorithmExecutor.java @@ -42,7 +42,7 @@ /** * Drop shadow algorithm executor. */ -@DistSQLExecutorCurrentRuleRequired("Shadow") +@DistSQLExecutorCurrentRuleRequired(ShadowRule.class) @Setter public final class DropShadowAlgorithmExecutor implements DatabaseRuleDropExecutor { diff --git a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowRuleExecutor.java b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowRuleExecutor.java index 355b3b199af2f..cbe562de7f368 100644 --- a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowRuleExecutor.java +++ b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowRuleExecutor.java @@ -42,7 +42,7 @@ /** * Drop shadow rule executor. */ -@DistSQLExecutorCurrentRuleRequired("Shadow") +@DistSQLExecutorCurrentRuleRequired(ShadowRule.class) @Setter public final class DropShadowRuleExecutor implements DatabaseRuleDropExecutor { diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterDefaultShardingStrategyExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterDefaultShardingStrategyExecutor.java index 6451a5ec7aba3..c9d1fa8710193 100644 --- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterDefaultShardingStrategyExecutor.java +++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterDefaultShardingStrategyExecutor.java @@ -41,7 +41,7 @@ /** * Alter default sharding strategy executor. */ -@DistSQLExecutorCurrentRuleRequired("Sharding") +@DistSQLExecutorCurrentRuleRequired(ShardingRule.class) @Setter public final class AlterDefaultShardingStrategyExecutor implements DatabaseRuleAlterExecutor { diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableReferenceRuleExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableReferenceRuleExecutor.java index 59892135f45c7..123b836afb04e 100644 --- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableReferenceRuleExecutor.java +++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableReferenceRuleExecutor.java @@ -43,7 +43,7 @@ /** * Alter sharding table reference rule executor. */ -@DistSQLExecutorCurrentRuleRequired("Sharding") +@DistSQLExecutorCurrentRuleRequired(ShardingRule.class) @Setter public final class AlterShardingTableReferenceRuleExecutor implements DatabaseRuleAlterExecutor { diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableRuleExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableRuleExecutor.java index 45059e1bd4c88..c82de9f6c1c79 100644 --- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableRuleExecutor.java +++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/AlterShardingTableRuleExecutor.java @@ -35,7 +35,7 @@ /** * Alter sharding table rule executor. */ -@DistSQLExecutorCurrentRuleRequired("Sharding") +@DistSQLExecutorCurrentRuleRequired(ShardingRule.class) @Setter public final class AlterShardingTableRuleExecutor implements DatabaseRuleAlterExecutor { diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingTableReferenceRuleExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingTableReferenceRuleExecutor.java index 2759c4bdd75c4..3b661d01b42b9 100644 --- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingTableReferenceRuleExecutor.java +++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/CreateShardingTableReferenceRuleExecutor.java @@ -43,7 +43,7 @@ /** * Create sharding table reference rule executor. */ -@DistSQLExecutorCurrentRuleRequired("Sharding") +@DistSQLExecutorCurrentRuleRequired(ShardingRule.class) @Setter public final class CreateShardingTableReferenceRuleExecutor implements DatabaseRuleCreateExecutor { diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropDefaultShardingStrategyExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropDefaultShardingStrategyExecutor.java index dedaee5942ce0..85cebcd344eeb 100644 --- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropDefaultShardingStrategyExecutor.java +++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropDefaultShardingStrategyExecutor.java @@ -34,7 +34,7 @@ /** * Drop default sharding strategy executor. */ -@DistSQLExecutorCurrentRuleRequired("Sharding") +@DistSQLExecutorCurrentRuleRequired(ShardingRule.class) @Setter public final class DropDefaultShardingStrategyExecutor implements DatabaseRuleDropExecutor { diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAlgorithmExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAlgorithmExecutor.java index 6b73b782c22ef..d1b9c48c538aa 100644 --- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAlgorithmExecutor.java +++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAlgorithmExecutor.java @@ -37,7 +37,7 @@ /** * Drop sharding algorithm executor. */ -@DistSQLExecutorCurrentRuleRequired("Sharding") +@DistSQLExecutorCurrentRuleRequired(ShardingRule.class) @Setter public final class DropShardingAlgorithmExecutor implements DatabaseRuleDropExecutor { diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAuditorExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAuditorExecutor.java index 4106a0956f017..71333cf406a12 100644 --- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAuditorExecutor.java +++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingAuditorExecutor.java @@ -37,7 +37,7 @@ /** * Drop sharding auditor statement executor. */ -@DistSQLExecutorCurrentRuleRequired("Sharding auditor") +@DistSQLExecutorCurrentRuleRequired(ShardingRule.class) @Setter public final class DropShardingAuditorExecutor implements DatabaseRuleDropExecutor { diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingKeyGeneratorExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingKeyGeneratorExecutor.java index 9b1a22fac10e9..c473c38307111 100644 --- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingKeyGeneratorExecutor.java +++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingKeyGeneratorExecutor.java @@ -38,7 +38,7 @@ /** * Drop sharding key generator executor. */ -@DistSQLExecutorCurrentRuleRequired("Key generator") +@DistSQLExecutorCurrentRuleRequired(ShardingRule.class) @Setter public final class DropShardingKeyGeneratorExecutor implements DatabaseRuleDropExecutor { diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableReferenceExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableReferenceExecutor.java index 40f016f0d333a..5e038a4feca4a 100644 --- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableReferenceExecutor.java +++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableReferenceExecutor.java @@ -35,7 +35,7 @@ /** * Drop sharding table reference executor. */ -@DistSQLExecutorCurrentRuleRequired("Sharding") +@DistSQLExecutorCurrentRuleRequired(ShardingRule.class) @Setter public final class DropShardingTableReferenceExecutor implements DatabaseRuleDropExecutor { diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleExecutor.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleExecutor.java index b918d6d60dcee..c9185aebc2d10 100644 --- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleExecutor.java +++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/update/DropShardingTableRuleExecutor.java @@ -40,7 +40,7 @@ /** * Drop sharding table rule executor. */ -@DistSQLExecutorCurrentRuleRequired("Sharding") +@DistSQLExecutorCurrentRuleRequired(ShardingRule.class) @Setter public final class DropShardingTableRuleExecutor implements DatabaseRuleDropExecutor { diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/required/DistSQLExecutorCurrentRuleRequired.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/required/DistSQLExecutorCurrentRuleRequired.java index 240601308a2e8..34d739b348d7e 100644 --- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/required/DistSQLExecutorCurrentRuleRequired.java +++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/required/DistSQLExecutorCurrentRuleRequired.java @@ -17,6 +17,8 @@ package org.apache.shardingsphere.distsql.handler.required; +import org.apache.shardingsphere.infra.rule.ShardingSphereRule; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -30,9 +32,9 @@ public @interface DistSQLExecutorCurrentRuleRequired { /** - * Get rule type. + * Get rule class. * - * @return rule type + * @return rule class */ - String value(); + Class value(); } diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/required/DistSQLExecutorRequiredChecker.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/required/DistSQLExecutorRequiredChecker.java index 919bd91202910..6a3eed8cc5da0 100644 --- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/required/DistSQLExecutorRequiredChecker.java +++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/required/DistSQLExecutorRequiredChecker.java @@ -22,6 +22,7 @@ import org.apache.shardingsphere.distsql.statement.rdl.rule.type.DropRuleStatement; import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.exception.core.external.sql.type.generic.UnsupportedSQLOperationException; +import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; @@ -41,22 +42,29 @@ public final class DistSQLExecutorRequiredChecker { * * @param sqlStatement SQL statement * @param contextManager context manager - * @param databaseName database name - * @param rule rule + * @param database database */ - public void check(final SQLStatement sqlStatement, final ContextManager contextManager, final String databaseName, final ShardingSphereRule rule) { + public void check(final SQLStatement sqlStatement, final ContextManager contextManager, final ShardingSphereDatabase database) { Optional.ofNullable(executor.getClass().getAnnotation(DistSQLExecutorClusterModeRequired.class)).ifPresent(optional -> checkClusterMode(contextManager)); - Optional.ofNullable(executor.getClass().getAnnotation(DistSQLExecutorCurrentRuleRequired.class)).ifPresent(optional -> checkCurrentRule(sqlStatement, databaseName, rule, optional)); + Optional.ofNullable(executor.getClass().getAnnotation(DistSQLExecutorCurrentRuleRequired.class)).ifPresent(optional -> checkCurrentRule(sqlStatement, contextManager, database, optional)); } private void checkClusterMode(final ContextManager contextManager) { ShardingSpherePreconditions.checkState(contextManager.getInstanceContext().isCluster(), () -> new UnsupportedSQLOperationException("Mode must be `Cluster`.")); } - private void checkCurrentRule(final SQLStatement sqlStatement, final String databaseName, final ShardingSphereRule rule, final DistSQLExecutorCurrentRuleRequired currentRuleRequired) { + private void checkCurrentRule(final SQLStatement sqlStatement, final ContextManager contextManager, final ShardingSphereDatabase database, + final DistSQLExecutorCurrentRuleRequired currentRuleRequired) { if (sqlStatement instanceof DropRuleStatement && ((DropRuleStatement) sqlStatement).isIfExists()) { return; } - ShardingSpherePreconditions.checkNotNull(rule, () -> new MissingRequiredRuleException(currentRuleRequired.value(), databaseName)); + Optional rule = findRule(contextManager, database, currentRuleRequired.value()); + String ruleType = currentRuleRequired.value().getSimpleName().substring(0, currentRuleRequired.value().getSimpleName().indexOf("Rule")); + ShardingSpherePreconditions.checkState(rule.isPresent(), () -> null == database ? new MissingRequiredRuleException(ruleType) : new MissingRequiredRuleException(ruleType, database.getName())); + } + + private Optional findRule(final ContextManager contextManager, final ShardingSphereDatabase database, final Class ruleClass) { + Optional globalRule = contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().findSingleRule(ruleClass); + return null == database || globalRule.isPresent() ? globalRule : database.getRuleMetaData().findSingleRule(ruleClass); } } diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/update/DistSQLUpdateExecuteEngine.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/update/DistSQLUpdateExecuteEngine.java index dfb880975793d..e90517404fe3b 100644 --- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/update/DistSQLUpdateExecuteEngine.java +++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/update/DistSQLUpdateExecuteEngine.java @@ -78,12 +78,10 @@ private void executeRuleDefinitionUpdate() { @SuppressWarnings("rawtypes") private void executeDatabaseRuleDefinitionUpdate(final DatabaseRuleDefinitionExecutor databaseExecutor) { if (isNormalRuleUpdater()) { - new DatabaseRuleDefinitionExecuteEngine( - (RuleDefinitionStatement) sqlStatement, contextManager, getDatabase(databaseName), databaseExecutor).executeUpdate(); + new DatabaseRuleDefinitionExecuteEngine((RuleDefinitionStatement) sqlStatement, contextManager, getDatabase(databaseName), databaseExecutor).executeUpdate(); } else { // TODO Remove when metadata structure adjustment completed. #25485 - new LegacyDatabaseRuleDefinitionExecuteEngine( - (RuleDefinitionStatement) sqlStatement, contextManager, getDatabase(databaseName), databaseExecutor).executeUpdate(); + new LegacyDatabaseRuleDefinitionExecuteEngine((RuleDefinitionStatement) sqlStatement, contextManager, getDatabase(databaseName), databaseExecutor).executeUpdate(); } } @@ -106,8 +104,9 @@ private boolean isNormalRuleUpdater() { @SuppressWarnings({"rawtypes", "unchecked"}) private void executeNormalUpdate() throws SQLException { DistSQLUpdateExecutor executor = TypedSPILoader.getService(DistSQLUpdateExecutor.class, sqlStatement.getClass()); - new DistSQLExecutorAwareSetter(executor).set(contextManager, null == databaseName ? null : getDatabase(databaseName), null); - new DistSQLExecutorRequiredChecker(executor).check(sqlStatement, contextManager, databaseName, null); + ShardingSphereDatabase database = null == databaseName ? null : getDatabase(databaseName); + new DistSQLExecutorAwareSetter(executor).set(contextManager, database, null); + new DistSQLExecutorRequiredChecker(executor).check(sqlStatement, contextManager, database); executor.executeUpdate(sqlStatement, contextManager); } diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/update/rdl/rule/engine/database/DatabaseRuleDefinitionExecuteEngine.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/update/rdl/rule/engine/database/DatabaseRuleDefinitionExecuteEngine.java index e6d497bda62a5..6d168fc1662ea 100644 --- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/update/rdl/rule/engine/database/DatabaseRuleDefinitionExecuteEngine.java +++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/update/rdl/rule/engine/database/DatabaseRuleDefinitionExecuteEngine.java @@ -52,7 +52,7 @@ public void executeUpdate() { executor.setDatabase(database); Optional rule = database.getRuleMetaData().findSingleRule(executor.getRuleClass()); executor.setRule(rule.orElse(null)); - checkBeforeUpdate(rule.orElse(null)); + checkBeforeUpdate(); RuleConfiguration currentRuleConfig = rule.map(ShardingSphereRule::getConfiguration).orElse(null); if (getRefreshStatus()) { contextManager.getMetaDataContexts().getPersistService().getMetaDataVersionPersistService() @@ -61,8 +61,8 @@ public void executeUpdate() { } @SuppressWarnings("unchecked") - private void checkBeforeUpdate(final ShardingSphereRule rule) { - new DistSQLExecutorRequiredChecker(executor).check(sqlStatement, contextManager, database.getName(), rule); + private void checkBeforeUpdate() { + new DistSQLExecutorRequiredChecker(executor).check(sqlStatement, contextManager, database); executor.checkBeforeUpdate(sqlStatement); } diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/update/rdl/rule/engine/legacy/LegacyDatabaseRuleDefinitionExecuteEngine.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/update/rdl/rule/engine/legacy/LegacyDatabaseRuleDefinitionExecuteEngine.java index 86a3303f27bf0..c90d5704f63d0 100644 --- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/update/rdl/rule/engine/legacy/LegacyDatabaseRuleDefinitionExecuteEngine.java +++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/type/update/rdl/rule/engine/legacy/LegacyDatabaseRuleDefinitionExecuteEngine.java @@ -64,7 +64,7 @@ public void executeUpdate() { executor.setDatabase(database); Optional rule = database.getRuleMetaData().findSingleRule(executor.getRuleClass()); executor.setRule(rule.orElse(null)); - checkBeforeUpdate(rule.orElse(null)); + checkBeforeUpdate(); RuleConfiguration currentRuleConfig = rule.map(ShardingSphereRule::getConfiguration).orElse(null); if (getRefreshStatus(sqlStatement, executor)) { contextManager.getInstanceContext().getModeContextManager().alterRuleConfiguration(database.getName(), processSQLStatement(database, sqlStatement, executor, currentRuleConfig)); @@ -72,8 +72,8 @@ public void executeUpdate() { } @SuppressWarnings("unchecked") - private void checkBeforeUpdate(final ShardingSphereRule rule) { - new DistSQLExecutorRequiredChecker(executor).check(sqlStatement, contextManager, database.getName(), rule); + private void checkBeforeUpdate() { + new DistSQLExecutorRequiredChecker(executor).check(sqlStatement, contextManager, database); executor.checkBeforeUpdate(sqlStatement); } diff --git a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/UnloadSingleTableExecutor.java b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/UnloadSingleTableExecutor.java index 0bea460ee1620..4599d63380c3a 100644 --- a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/UnloadSingleTableExecutor.java +++ b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/UnloadSingleTableExecutor.java @@ -41,7 +41,7 @@ /** * Unload single table statement executor. */ -@DistSQLExecutorCurrentRuleRequired("Single") +@DistSQLExecutorCurrentRuleRequired(SingleRule.class) @Setter public final class UnloadSingleTableExecutor implements DatabaseRuleAlterExecutor {