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 e28f494c47a refactor auditStrategy config (#18884)
e28f494c47a is described below

commit e28f494c47a50a3f2717f2cf8baeb9584691a11d
Author: natehuang <[email protected]>
AuthorDate: Wed Jul 6 14:04:48 2022 +0800

    refactor auditStrategy config (#18884)
---
 .../api/config/ShardingRuleConfiguration.java      |  4 ++--
 .../rule/ShardingAutoTableRuleConfiguration.java   |  3 +++
 .../rule/ShardingTableRuleConfiguration.java       |  3 +++
 ...AlgorithmProvidedShardingRuleConfiguration.java |  4 ++--
 .../checker/audit/ShardingAuditChecker.java        | 20 ++++++++++------
 .../shardingsphere/sharding/rule/ShardingRule.java | 20 +++++++++++-----
 .../shardingsphere/sharding/rule/TableRule.java    |  6 +++++
 .../sharding/rule/builder/ShardingRuleBuilder.java | 17 ++++++++++---
 .../yaml/config/YamlShardingRuleConfiguration.java |  2 +-
 .../config/rule/YamlTableRuleConfiguration.java    |  3 +++
 ...eAlgorithmProviderConfigurationYamlSwapper.java |  8 +++----
 .../ShardingRuleConfigurationYamlSwapper.java      |  8 +++----
 .../ShardingTableRuleConfigurationYamlSwapper.java |  9 +++++++
 .../sharding/checker/ShardingAuditCheckerTest.java | 28 ++++++++++++----------
 .../sharding/rule/ShardingRuleTest.java            |  2 +-
 .../ShardingRuleConfigurationYamlSwapperTest.java  | 19 +++++----------
 .../TableRuleConfigurationYamlSwapperTest.java     |  7 ++++++
 .../src/test/resources/yaml/sharding-rule.yaml     | 10 +++++++-
 .../src/main/resources/conf/config-sharding.yaml   | 16 +++++++++----
 19 files changed, 129 insertions(+), 60 deletions(-)

diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/ShardingRuleConfiguration.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/ShardingRuleConfiguration.java
index 3be3c6f297b..0ee7b72269a 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/ShardingRuleConfiguration.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/ShardingRuleConfiguration.java
@@ -55,9 +55,9 @@ public final class ShardingRuleConfiguration implements 
DatabaseRuleConfiguratio
     
     private KeyGenerateStrategyConfiguration defaultKeyGenerateStrategy;
     
-    private String defaultShardingColumn;
+    private ShardingAuditStrategyConfiguration defaultAuditStrategy;
     
-    private ShardingAuditStrategyConfiguration auditStrategy;
+    private String defaultShardingColumn;
     
     private Map<String, ShardingSphereAlgorithmConfiguration> 
shardingAlgorithms = new LinkedHashMap<>();
     
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/rule/ShardingAutoTableRuleConfiguration.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/rule/ShardingAutoTableRuleConfiguration.java
index 70bcf9ed72f..5aaebb5cfbb 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/rule/ShardingAutoTableRuleConfiguration.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/rule/ShardingAutoTableRuleConfiguration.java
@@ -21,6 +21,7 @@ import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
 import lombok.Getter;
 import lombok.Setter;
+import 
org.apache.shardingsphere.sharding.api.config.strategy.audit.ShardingAuditStrategyConfiguration;
 import 
org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerateStrategyConfiguration;
 import 
org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration;
 
@@ -41,6 +42,8 @@ public final class ShardingAutoTableRuleConfiguration {
     
     private KeyGenerateStrategyConfiguration keyGenerateStrategy;
     
+    private ShardingAuditStrategyConfiguration auditStrategy;
+    
     // TODO prevent user to config this.
     private String actualDataNodes;
     
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/rule/ShardingTableRuleConfiguration.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/rule/ShardingTableRuleConfiguration.java
index 690e8fdda4d..3cfea064df6 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/rule/ShardingTableRuleConfiguration.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/rule/ShardingTableRuleConfiguration.java
@@ -21,6 +21,7 @@ import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
 import lombok.Getter;
 import lombok.Setter;
+import 
org.apache.shardingsphere.sharding.api.config.strategy.audit.ShardingAuditStrategyConfiguration;
 import 
org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerateStrategyConfiguration;
 import 
org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration;
 
@@ -43,6 +44,8 @@ public final class ShardingTableRuleConfiguration {
     
     private KeyGenerateStrategyConfiguration keyGenerateStrategy;
     
+    private ShardingAuditStrategyConfiguration auditStrategy;
+    
     public ShardingTableRuleConfiguration(final String logicTable) {
         this(logicTable, null);
     }
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/config/AlgorithmProvidedShardingRuleConfiguration.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/config/AlgorithmProvidedShardingRuleConfiguration.java
index 7eff474cf05..fd3a3dfc610 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/config/AlgorithmProvidedShardingRuleConfiguration.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/config/AlgorithmProvidedShardingRuleConfiguration.java
@@ -56,9 +56,9 @@ public final class AlgorithmProvidedShardingRuleConfiguration 
implements Databas
     
     private KeyGenerateStrategyConfiguration defaultKeyGenerateStrategy;
     
-    private String defaultShardingColumn;
+    private ShardingAuditStrategyConfiguration defaultAuditStrategy;
     
-    private ShardingAuditStrategyConfiguration auditStrategy;
+    private String defaultShardingColumn;
     
     private Map<String, ShardingAlgorithm> shardingAlgorithms = new 
LinkedHashMap<>();
     
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/checker/audit/ShardingAuditChecker.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/checker/audit/ShardingAuditChecker.java
index 3916d523d90..f04c71076b3 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/checker/audit/ShardingAuditChecker.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/checker/audit/ShardingAuditChecker.java
@@ -23,6 +23,7 @@ import org.apache.shardingsphere.infra.check.SQLCheckResult;
 import org.apache.shardingsphere.infra.executor.check.SQLChecker;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.infra.metadata.user.Grantee;
+import 
org.apache.shardingsphere.sharding.api.config.strategy.audit.ShardingAuditStrategyConfiguration;
 import org.apache.shardingsphere.sharding.constant.ShardingOrder;
 import org.apache.shardingsphere.sharding.rule.ShardingRule;
 
@@ -31,6 +32,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.function.BiPredicate;
+import java.util.stream.Collectors;
 
 /**
  * Sharding audit checker.
@@ -48,13 +50,17 @@ public final class ShardingAuditChecker implements 
SQLChecker<ShardingRule> {
         Collection<String> disableAuditNames = sqlStatementContext instanceof 
CommonSQLStatementContext
                 ? ((CommonSQLStatementContext<?>) 
sqlStatementContext).getSqlHintExtractor().findDisableAuditNames()
                 : Collections.emptyList();
-        for (String each : rule.getAuditStrategyConfig().getAuditorNames()) {
-            if (rule.getAuditStrategyConfig().isAllowHintDisable() && 
disableAuditNames.contains(each.toLowerCase())) {
-                continue;
-            }
-            SQLCheckResult result = 
rule.getAuditors().get(each).check(sqlStatementContext, parameters, grantee, 
databases.get(currentDatabase));
-            if (!result.isPassed()) {
-                return result;
+        Collection<ShardingAuditStrategyConfiguration> auditStrategies = 
sqlStatementContext.getTablesContext().getTableNames().stream().filter(rule::isShardingTable)
+                .map(each -> 
rule.getAuditStrategyConfiguration(rule.getTableRule(each))).collect(Collectors.toList());
+        for (ShardingAuditStrategyConfiguration auditStrategy : 
auditStrategies) {
+            for (String auditorName : auditStrategy.getAuditorNames()) {
+                if (auditStrategy.isAllowHintDisable() && 
disableAuditNames.contains(auditorName.toLowerCase())) {
+                    continue;
+                }
+                SQLCheckResult result = 
rule.getAuditors().get(auditorName).check(sqlStatementContext, parameters, 
grantee, databases.get(currentDatabase));
+                if (!result.isPassed()) {
+                    return result;
+                }
             }
         }
         return new SQLCheckResult(true, "");
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
index 15c45dc785d..a3e6bdb26f1 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
@@ -106,14 +106,14 @@ public final class ShardingRule implements DatabaseRule, 
DataNodeContainedRule,
     
     private final ShardingStrategyConfiguration 
defaultTableShardingStrategyConfig;
     
+    private final ShardingAuditStrategyConfiguration defaultAuditStrategy;
+    
     private final KeyGenerateAlgorithm defaultKeyGenerateAlgorithm;
     
     private final String defaultShardingColumn;
     
     private final Map<String, Collection<DataNode>> shardingTableDataNodes;
     
-    private final ShardingAuditStrategyConfiguration auditStrategyConfig;
-    
     public ShardingRule(final ShardingRuleConfiguration config, final 
Collection<String> dataSourceNames, final InstanceContext instanceContext) {
         configuration = config;
         this.dataSourceNames = getDataSourceNames(config.getTables(), 
config.getAutoTables(), dataSourceNames);
@@ -126,6 +126,7 @@ public final class ShardingRule implements DatabaseRule, 
DataNodeContainedRule,
         
bindingTableRules.putAll(createBindingTableRules(config.getBindingTableGroups()));
         defaultDatabaseShardingStrategyConfig = null == 
config.getDefaultDatabaseShardingStrategy() ? new 
NoneShardingStrategyConfiguration() : 
config.getDefaultDatabaseShardingStrategy();
         defaultTableShardingStrategyConfig = null == 
config.getDefaultTableShardingStrategy() ? new 
NoneShardingStrategyConfiguration() : config.getDefaultTableShardingStrategy();
+        defaultAuditStrategy = null == config.getDefaultAuditStrategy() ? new 
ShardingAuditStrategyConfiguration(Collections.emptyList(), true) : 
config.getDefaultAuditStrategy();
         defaultKeyGenerateAlgorithm = null == 
config.getDefaultKeyGenerateStrategy()
                 ? KeyGenerateAlgorithmFactory.newInstance()
                 : 
keyGenerators.get(config.getDefaultKeyGenerateStrategy().getKeyGeneratorName());
@@ -134,8 +135,6 @@ public final class ShardingRule implements DatabaseRule, 
DataNodeContainedRule,
         
Preconditions.checkArgument(isValidBindingTableConfiguration(tableRules, new 
BindingTableCheckedConfiguration(this.dataSourceNames, shardingAlgorithms, 
config.getBindingTableGroups(),
                 broadcastTables, defaultDatabaseShardingStrategyConfig, 
defaultTableShardingStrategyConfig, defaultShardingColumn)),
                 "Invalid binding table configuration in 
ShardingRuleConfiguration.");
-        auditStrategyConfig = null == config.getAuditStrategy() ? new 
ShardingAuditStrategyConfiguration(Collections.emptyList(), true) : 
config.getAuditStrategy();
-        
Preconditions.checkArgument(auditStrategyConfig.getAuditorNames().stream().allMatch(auditors::containsKey),
 "Cannot find sharding audit algorithm");
         keyGenerators.values().stream().filter(each -> each instanceof 
InstanceAwareAlgorithm).forEach(each -> ((InstanceAwareAlgorithm) 
each).setInstanceContext(instanceContext));
         if (defaultKeyGenerateAlgorithm instanceof InstanceAwareAlgorithm) {
             ((InstanceAwareAlgorithm) 
defaultKeyGenerateAlgorithm).setInstanceContext(instanceContext);
@@ -154,6 +153,7 @@ public final class ShardingRule implements DatabaseRule, 
DataNodeContainedRule,
         
bindingTableRules.putAll(createBindingTableRules(config.getBindingTableGroups()));
         defaultDatabaseShardingStrategyConfig = null == 
config.getDefaultDatabaseShardingStrategy() ? new 
NoneShardingStrategyConfiguration() : 
config.getDefaultDatabaseShardingStrategy();
         defaultTableShardingStrategyConfig = null == 
config.getDefaultTableShardingStrategy() ? new 
NoneShardingStrategyConfiguration() : config.getDefaultTableShardingStrategy();
+        defaultAuditStrategy = null == config.getDefaultAuditStrategy() ? new 
ShardingAuditStrategyConfiguration(Collections.emptyList(), true) : 
config.getDefaultAuditStrategy();
         defaultKeyGenerateAlgorithm = null == 
config.getDefaultKeyGenerateStrategy()
                 ? KeyGenerateAlgorithmFactory.newInstance()
                 : 
keyGenerators.get(config.getDefaultKeyGenerateStrategy().getKeyGeneratorName());
@@ -162,8 +162,6 @@ public final class ShardingRule implements DatabaseRule, 
DataNodeContainedRule,
         
Preconditions.checkArgument(isValidBindingTableConfiguration(tableRules, new 
BindingTableCheckedConfiguration(this.dataSourceNames, shardingAlgorithms, 
config.getBindingTableGroups(),
                 broadcastTables, defaultDatabaseShardingStrategyConfig, 
defaultTableShardingStrategyConfig, defaultShardingColumn)),
                 "Invalid binding table configuration in 
ShardingRuleConfiguration.");
-        auditStrategyConfig = null == config.getAuditStrategy() ? new 
ShardingAuditStrategyConfiguration(Collections.emptyList(), true) : 
config.getAuditStrategy();
-        
Preconditions.checkArgument(auditStrategyConfig.getAuditorNames().stream().allMatch(auditors::containsKey),
 "Cannot find sharding audit algorithm");
         keyGenerators.values().stream().filter(each -> each instanceof 
InstanceAwareAlgorithm).forEach(each -> ((InstanceAwareAlgorithm) 
each).setInstanceContext(instanceContext));
         if (defaultKeyGenerateAlgorithm instanceof InstanceAwareAlgorithm) {
             ((InstanceAwareAlgorithm) 
defaultKeyGenerateAlgorithm).setInstanceContext(instanceContext);
@@ -341,6 +339,16 @@ public final class ShardingRule implements DatabaseRule, 
DataNodeContainedRule,
         return null == tableRule.getTableShardingStrategyConfig() ? 
defaultTableShardingStrategyConfig : tableRule.getTableShardingStrategyConfig();
     }
     
+    /**
+     * Get audit strategy configuration.
+     *
+     * @param tableRule table rule
+     * @return audit strategy configuration
+     */
+    public ShardingAuditStrategyConfiguration 
getAuditStrategyConfiguration(final TableRule tableRule) {
+        return null == tableRule.getAuditStrategyConfig() ? 
defaultAuditStrategy : tableRule.getAuditStrategyConfig();
+    }
+    
     /**
      * Find table rule.
      *
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/TableRule.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/TableRule.java
index b0fa07e8c21..ae81f3bcfa9 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/TableRule.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/TableRule.java
@@ -29,6 +29,7 @@ import 
org.apache.shardingsphere.infra.exception.ShardingSphereException;
 import org.apache.shardingsphere.infra.expr.InlineExpressionParser;
 import 
org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
 import 
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
+import 
org.apache.shardingsphere.sharding.api.config.strategy.audit.ShardingAuditStrategyConfiguration;
 import 
org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerateStrategyConfiguration;
 import 
org.apache.shardingsphere.sharding.api.config.strategy.sharding.NoneShardingStrategyConfiguration;
 import 
org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration;
@@ -75,6 +76,8 @@ public final class TableRule {
     
     private final ShardingStrategyConfiguration tableShardingStrategyConfig;
     
+    private final ShardingAuditStrategyConfiguration auditStrategyConfig;
+    
     @Getter(AccessLevel.NONE)
     private final String generateKeyColumn;
     
@@ -96,6 +99,7 @@ public final class TableRule {
         actualTables = getActualTables();
         databaseShardingStrategyConfig = null;
         tableShardingStrategyConfig = null;
+        auditStrategyConfig = null;
         generateKeyColumn = null;
         keyGeneratorName = null;
         dataSourceDataNode = actualDataNodes.isEmpty() ? null : 
createDataSourceDataNode(actualDataNodes);
@@ -112,6 +116,7 @@ public final class TableRule {
         actualTables = getActualTables();
         databaseShardingStrategyConfig = 
tableRuleConfig.getDatabaseShardingStrategy();
         tableShardingStrategyConfig = 
tableRuleConfig.getTableShardingStrategy();
+        auditStrategyConfig = tableRuleConfig.getAuditStrategy();
         KeyGenerateStrategyConfiguration keyGeneratorConfig = 
tableRuleConfig.getKeyGenerateStrategy();
         generateKeyColumn = null != keyGeneratorConfig && 
!Strings.isNullOrEmpty(keyGeneratorConfig.getColumn()) ? 
keyGeneratorConfig.getColumn() : defaultGenerateKeyColumn;
         keyGeneratorName = null == keyGeneratorConfig ? null : 
keyGeneratorConfig.getKeyGeneratorName();
@@ -125,6 +130,7 @@ public final class TableRule {
         logicTable = tableRuleConfig.getLogicTable();
         databaseShardingStrategyConfig = new 
NoneShardingStrategyConfiguration();
         tableShardingStrategyConfig = tableRuleConfig.getShardingStrategy();
+        auditStrategyConfig = tableRuleConfig.getAuditStrategy();
         List<String> dataNodes = getDataNodes(tableRuleConfig, 
shardingAutoTableAlgorithm, dataSourceNames);
         dataNodeIndexMap = new HashMap<>(dataNodes.size(), 1);
         actualTablePrefix = tableRuleConfig.getActualTablePrefix();
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/builder/ShardingRuleBuilder.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/builder/ShardingRuleBuilder.java
index fccefda9c17..484a5075d97 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/builder/ShardingRuleBuilder.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/builder/ShardingRuleBuilder.java
@@ -25,6 +25,7 @@ import 
org.apache.shardingsphere.infra.rule.builder.database.DatabaseRuleBuilder
 import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
 import 
org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
 import 
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
+import 
org.apache.shardingsphere.sharding.api.config.strategy.audit.ShardingAuditStrategyConfiguration;
 import 
org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerateStrategyConfiguration;
 import 
org.apache.shardingsphere.sharding.api.config.strategy.sharding.NoneShardingStrategyConfiguration;
 import 
org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration;
@@ -50,20 +51,23 @@ public final class ShardingRuleBuilder implements 
DatabaseRuleBuilder<ShardingRu
     
     private boolean isValidRuleConfiguration(final ShardingRuleConfiguration 
config) {
         Map<String, ShardingSphereAlgorithmConfiguration> keyGenerators = 
config.getKeyGenerators();
+        Map<String, ShardingSphereAlgorithmConfiguration> auditors = 
config.getAuditors();
         Map<String, ShardingSphereAlgorithmConfiguration> shardingAlgorithms = 
config.getShardingAlgorithms();
         if 
(isInvalidKeyGenerateStrategy(config.getDefaultKeyGenerateStrategy(), 
keyGenerators)
+                || isInvalidAuditStrategy(config.getDefaultAuditStrategy(), 
auditors)
                 || 
isInvalidShardingStrategy(config.getDefaultDatabaseShardingStrategy(), 
shardingAlgorithms)
                 || 
isInvalidShardingStrategy(config.getDefaultTableShardingStrategy(), 
shardingAlgorithms)) {
             return false;
         }
         for (ShardingTableRuleConfiguration each : config.getTables()) {
-            if (isInvalidKeyGenerateStrategy(each.getKeyGenerateStrategy(), 
keyGenerators) || isInvalidShardingStrategy(each.getDatabaseShardingStrategy(), 
shardingAlgorithms)
-                    || 
isInvalidShardingStrategy(each.getTableShardingStrategy(), shardingAlgorithms)) 
{
+            if (isInvalidKeyGenerateStrategy(each.getKeyGenerateStrategy(), 
keyGenerators) || isInvalidAuditStrategy(each.getAuditStrategy(), auditors)
+                    || 
isInvalidShardingStrategy(each.getDatabaseShardingStrategy(), 
shardingAlgorithms) || 
isInvalidShardingStrategy(each.getTableShardingStrategy(), shardingAlgorithms)) 
{
                 return false;
             }
         }
         for (ShardingAutoTableRuleConfiguration each : config.getAutoTables()) 
{
-            if (isInvalidKeyGenerateStrategy(each.getKeyGenerateStrategy(), 
keyGenerators) || isInvalidShardingStrategy(each.getShardingStrategy(), 
shardingAlgorithms)) {
+            if (isInvalidKeyGenerateStrategy(each.getKeyGenerateStrategy(), 
keyGenerators) || isInvalidAuditStrategy(each.getAuditStrategy(), auditors)
+                    || isInvalidShardingStrategy(each.getShardingStrategy(), 
shardingAlgorithms)) {
                 return false;
             }
         }
@@ -84,6 +88,13 @@ public final class ShardingRuleBuilder implements 
DatabaseRuleBuilder<ShardingRu
         return 
!shardingAlgorithms.containsKey(shardingStrategy.getShardingAlgorithmName());
     }
     
+    private boolean isInvalidAuditStrategy(final 
ShardingAuditStrategyConfiguration auditStrategy, final Map<String, 
ShardingSphereAlgorithmConfiguration> auditors) {
+        if (null == auditStrategy) {
+            return false;
+        }
+        return !auditors.keySet().containsAll(auditStrategy.getAuditorNames());
+    }
+    
     @Override
     public int getOrder() {
         return ShardingOrder.ORDER;
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/yaml/config/YamlShardingRuleConfiguration.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/yaml/config/YamlShardingRuleConfiguration.java
index 0abd72f98c9..2f152500137 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/yaml/config/YamlShardingRuleConfiguration.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/yaml/config/YamlShardingRuleConfiguration.java
@@ -55,7 +55,7 @@ public final class YamlShardingRuleConfiguration implements 
YamlRuleConfiguratio
     
     private YamlKeyGenerateStrategyConfiguration defaultKeyGenerateStrategy;
     
-    private YamlShardingAuditStrategyConfiguration auditStrategy;
+    private YamlShardingAuditStrategyConfiguration defaultAuditStrategy;
     
     private Map<String, YamlShardingSphereAlgorithmConfiguration> 
shardingAlgorithms = new LinkedHashMap<>();
     
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/yaml/config/rule/YamlTableRuleConfiguration.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/yaml/config/rule/YamlTableRuleConfiguration.java
index abeb4ac9a6d..71f32df22b5 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/yaml/config/rule/YamlTableRuleConfiguration.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/yaml/config/rule/YamlTableRuleConfiguration.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.sharding.yaml.config.rule;
 import lombok.Getter;
 import lombok.Setter;
 import org.apache.shardingsphere.infra.yaml.config.pojo.YamlConfiguration;
+import 
org.apache.shardingsphere.sharding.yaml.config.strategy.audit.YamlShardingAuditStrategyConfiguration;
 import 
org.apache.shardingsphere.sharding.yaml.config.strategy.keygen.YamlKeyGenerateStrategyConfiguration;
 import 
org.apache.shardingsphere.sharding.yaml.config.strategy.sharding.YamlShardingStrategyConfiguration;
 
@@ -41,4 +42,6 @@ public final class YamlTableRuleConfiguration implements 
YamlConfiguration {
     private YamlShardingStrategyConfiguration tableStrategy;
     
     private YamlKeyGenerateStrategyConfiguration keyGenerateStrategy;
+    
+    private YamlShardingAuditStrategyConfiguration auditStrategy;
 }
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleAlgorithmProviderConfigurationYamlSwapper.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleAlgorithmProviderConfigurationYamlSwapper.java
index 687a5b0bb65..37634dccd25 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleAlgorithmProviderConfigurationYamlSwapper.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleAlgorithmProviderConfigurationYamlSwapper.java
@@ -69,8 +69,8 @@ public final class 
ShardingRuleAlgorithmProviderConfigurationYamlSwapper impleme
         if (null != data.getDefaultKeyGenerateStrategy()) {
             
yamlConfig.setDefaultKeyGenerateStrategy(keyGenerateStrategyYamlSwapper.swapToYamlConfiguration(data.getDefaultKeyGenerateStrategy()));
         }
-        if (null != data.getAuditStrategy()) {
-            
yamlConfig.setAuditStrategy(auditStrategyYamlSwapper.swapToYamlConfiguration(data.getAuditStrategy()));
+        if (null != data.getDefaultAuditStrategy()) {
+            
yamlConfig.setDefaultAuditStrategy(auditStrategyYamlSwapper.swapToYamlConfiguration(data.getDefaultAuditStrategy()));
         }
     }
     
@@ -116,8 +116,8 @@ public final class 
ShardingRuleAlgorithmProviderConfigurationYamlSwapper impleme
         if (null != yamlConfig.getDefaultKeyGenerateStrategy()) {
             
ruleConfig.setDefaultKeyGenerateStrategy(keyGenerateStrategyYamlSwapper.swapToObject(yamlConfig.getDefaultKeyGenerateStrategy()));
         }
-        if (null != yamlConfig.getAuditStrategy()) {
-            
ruleConfig.setAuditStrategy(auditStrategyYamlSwapper.swapToObject(yamlConfig.getAuditStrategy()));
+        if (null != yamlConfig.getDefaultAuditStrategy()) {
+            
ruleConfig.setDefaultAuditStrategy(auditStrategyYamlSwapper.swapToObject(yamlConfig.getDefaultAuditStrategy()));
         }
     }
     
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleConfigurationYamlSwapper.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleConfigurationYamlSwapper.java
index 49d046a6de9..501adb9abb1 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleConfigurationYamlSwapper.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleConfigurationYamlSwapper.java
@@ -76,8 +76,8 @@ public final class ShardingRuleConfigurationYamlSwapper 
implements YamlRuleConfi
         if (null != data.getDefaultKeyGenerateStrategy()) {
             
yamlConfig.setDefaultKeyGenerateStrategy(keyGenerateStrategyYamlSwapper.swapToYamlConfiguration(data.getDefaultKeyGenerateStrategy()));
         }
-        if (null != data.getAuditStrategy()) {
-            
yamlConfig.setAuditStrategy(auditStrategyYamlSwapper.swapToYamlConfiguration(data.getAuditStrategy()));
+        if (null != data.getDefaultAuditStrategy()) {
+            
yamlConfig.setDefaultAuditStrategy(auditStrategyYamlSwapper.swapToYamlConfiguration(data.getDefaultAuditStrategy()));
         }
     }
     
@@ -128,8 +128,8 @@ public final class ShardingRuleConfigurationYamlSwapper 
implements YamlRuleConfi
         if (null != yamlConfig.getDefaultKeyGenerateStrategy()) {
             
ruleConfig.setDefaultKeyGenerateStrategy(keyGenerateStrategyYamlSwapper.swapToObject(yamlConfig.getDefaultKeyGenerateStrategy()));
         }
-        if (null != yamlConfig.getAuditStrategy()) {
-            
ruleConfig.setAuditStrategy(auditStrategyYamlSwapper.swapToObject(yamlConfig.getAuditStrategy()));
+        if (null != yamlConfig.getDefaultAuditStrategy()) {
+            
ruleConfig.setDefaultAuditStrategy(auditStrategyYamlSwapper.swapToObject(yamlConfig.getDefaultAuditStrategy()));
         }
     }
     
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/rule/ShardingTableRuleConfigurationYamlSwapper.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/rule/ShardingTableRuleConfigurationYamlSwapper.java
index bbc7731888e..1a22ca8a5ea 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/rule/ShardingTableRuleConfigurationYamlSwapper.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/rule/ShardingTableRuleConfigurationYamlSwapper.java
@@ -22,6 +22,7 @@ import 
org.apache.shardingsphere.infra.yaml.config.swapper.YamlConfigurationSwap
 import 
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
 import 
org.apache.shardingsphere.sharding.yaml.config.rule.YamlTableRuleConfiguration;
 import 
org.apache.shardingsphere.sharding.yaml.swapper.strategy.KeyGenerateStrategyConfigurationYamlSwapper;
+import 
org.apache.shardingsphere.sharding.yaml.swapper.strategy.ShardingAuditStrategyConfigurationYamlSwapper;
 import 
org.apache.shardingsphere.sharding.yaml.swapper.strategy.ShardingStrategyConfigurationYamlSwapper;
 
 /**
@@ -33,6 +34,8 @@ public final class ShardingTableRuleConfigurationYamlSwapper 
implements YamlConf
     
     private final KeyGenerateStrategyConfigurationYamlSwapper 
keyGenerateStrategyYamlSwapper = new 
KeyGenerateStrategyConfigurationYamlSwapper();
     
+    private final ShardingAuditStrategyConfigurationYamlSwapper 
auditStrategyYamlSwapper = new ShardingAuditStrategyConfigurationYamlSwapper();
+    
     @Override
     public YamlTableRuleConfiguration swapToYamlConfiguration(final 
ShardingTableRuleConfiguration data) {
         YamlTableRuleConfiguration result = new YamlTableRuleConfiguration();
@@ -48,6 +51,9 @@ public final class ShardingTableRuleConfigurationYamlSwapper 
implements YamlConf
         if (null != data.getKeyGenerateStrategy()) {
             
result.setKeyGenerateStrategy(keyGenerateStrategyYamlSwapper.swapToYamlConfiguration(data.getKeyGenerateStrategy()));
         }
+        if (null != data.getAuditStrategy()) {
+            
result.setAuditStrategy(auditStrategyYamlSwapper.swapToYamlConfiguration(data.getAuditStrategy()));
+        }
         return result;
     }
     
@@ -65,6 +71,9 @@ public final class ShardingTableRuleConfigurationYamlSwapper 
implements YamlConf
         if (null != yamlConfig.getKeyGenerateStrategy()) {
             
result.setKeyGenerateStrategy(keyGenerateStrategyYamlSwapper.swapToObject(yamlConfig.getKeyGenerateStrategy()));
         }
+        if (null != yamlConfig.getAuditStrategy()) {
+            
result.setAuditStrategy(auditStrategyYamlSwapper.swapToObject(yamlConfig.getAuditStrategy()));
+        }
         return result;
     }
 }
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/checker/ShardingAuditCheckerTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/checker/ShardingAuditCheckerTest.java
index c681bd39323..298015f86ff 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/checker/ShardingAuditCheckerTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/checker/ShardingAuditCheckerTest.java
@@ -21,6 +21,7 @@ import 
org.apache.shardingsphere.infra.binder.statement.CommonSQLStatementContex
 import org.apache.shardingsphere.infra.check.SQLCheckResult;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.infra.metadata.user.Grantee;
+import 
org.apache.shardingsphere.sharding.api.config.strategy.audit.ShardingAuditStrategyConfiguration;
 import org.apache.shardingsphere.sharding.checker.audit.ShardingAuditChecker;
 import org.apache.shardingsphere.sharding.rule.ShardingRule;
 import org.junit.Before;
@@ -55,6 +56,9 @@ public final class ShardingAuditCheckerTest {
     @Mock
     private Grantee grantee;
     
+    @Mock
+    private ShardingAuditStrategyConfiguration auditStrategy;
+    
     private final ShardingAuditChecker checker = new ShardingAuditChecker();
     
     private final Map<String, ShardingSphereDatabase> databases = new 
LinkedHashMap<>();
@@ -63,35 +67,35 @@ public final class ShardingAuditCheckerTest {
     
     @Before
     public void setUp() {
-        
when(sqlStatementContext.getSqlHintExtractor().findDisableAuditNames()).thenReturn(new
 HashSet<>(Collections.singletonList("audit_algorithm")));
-        
when(rule.getAuditStrategyConfig().getAuditorNames()).thenReturn(Collections.singleton("audit_algorithm"));
+        
when(sqlStatementContext.getSqlHintExtractor().findDisableAuditNames()).thenReturn(new
 HashSet<>(Collections.singletonList("auditor_1")));
+        
when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.singletonList("foo_table"));
+        when(rule.isShardingTable("foo_table")).thenReturn(true);
+        
when(rule.getAuditStrategyConfiguration(rule.getTableRule("foo_table"))).thenReturn(auditStrategy);
+        
when(auditStrategy.getAuditorNames()).thenReturn(Collections.singleton("auditor_1"));
         databases.put("foo_db", mock(ShardingSphereDatabase.class));
     }
     
     @Test
     public void assertCheckSQLStatementPass() {
-        
when(rule.getAuditors().get("audit_algorithm").check(sqlStatementContext, 
parameters, grantee, databases.get("foo_db")))
-                .thenReturn(new SQLCheckResult(true, ""));
+        when(rule.getAuditors().get("auditor_1").check(sqlStatementContext, 
parameters, grantee, databases.get("foo_db"))).thenReturn(new 
SQLCheckResult(true, ""));
         asserCheckResult(checker.check(sqlStatementContext, 
Collections.emptyList(), grantee, "foo_db", databases, rule), true, "");
-        verify(rule.getAuditors().get("audit_algorithm"), 
times(1)).check(sqlStatementContext, parameters, grantee, 
databases.get("foo_db"));
+        verify(rule.getAuditors().get("auditor_1"), 
times(1)).check(sqlStatementContext, parameters, grantee, 
databases.get("foo_db"));
     }
     
     @Test
     public void assertSQCheckPassByDisableAuditNames() {
-        
when(rule.getAuditors().get("audit_algorithm").check(sqlStatementContext, 
parameters, grantee, databases.get("foo_db")))
-                .thenReturn(new SQLCheckResult(false, ""));
-        
when(rule.getAuditStrategyConfig().isAllowHintDisable()).thenReturn(true);
+        when(rule.getAuditors().get("auditor_1").check(sqlStatementContext, 
parameters, grantee, databases.get("foo_db"))).thenReturn(new 
SQLCheckResult(false, ""));
+        when(auditStrategy.isAllowHintDisable()).thenReturn(true);
         asserCheckResult(checker.check(sqlStatementContext, 
Collections.emptyList(), grantee, "foo_db", databases, rule), true, "");
-        
-        verify(rule.getAuditors().get("audit_algorithm"), 
times(0)).check(sqlStatementContext, parameters, grantee, 
databases.get("foo_db"));
+        verify(rule.getAuditors().get("auditor_1"), 
times(0)).check(sqlStatementContext, parameters, grantee, 
databases.get("foo_db"));
     }
     
     @Test
     public void assertSQLCheckNotPass() {
-        
when(rule.getAuditors().get("audit_algorithm").check(sqlStatementContext, 
parameters, grantee, databases.get("foo_db")))
+        when(rule.getAuditors().get("auditor_1").check(sqlStatementContext, 
parameters, grantee, databases.get("foo_db")))
                 .thenReturn(new SQLCheckResult(false, "Not allow DML operation 
without sharding conditions"));
         asserCheckResult(checker.check(sqlStatementContext, 
Collections.emptyList(), grantee, "foo_db", databases, rule), false, "Not allow 
DML operation without sharding conditions");
-        verify(rule.getAuditors().get("audit_algorithm"), 
times(1)).check(sqlStatementContext, parameters, grantee, 
databases.get("foo_db"));
+        verify(rule.getAuditors().get("auditor_1"), 
times(1)).check(sqlStatementContext, parameters, grantee, 
databases.get("foo_db"));
     }
     
     private void asserCheckResult(final SQLCheckResult checkResult, final 
boolean isPassed, final String errorMessage) {
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
index f5148efecd6..8590ebacbf8 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
@@ -472,7 +472,7 @@ public final class ShardingRuleTest {
         shardingRuleConfig.setDefaultTableShardingStrategy(new 
StandardShardingStrategyConfiguration("table_id", "standard"));
         shardingRuleConfig.setDefaultShardingColumn("table_id");
         shardingRuleConfig.setDefaultKeyGenerateStrategy(new 
KeyGenerateStrategyConfiguration("id", "default"));
-        shardingRuleConfig.setAuditStrategy(new 
ShardingAuditStrategyConfiguration(Collections.singletonList("audit_algorithm"),
 false));
+        shardingRuleConfig.setDefaultAuditStrategy(new 
ShardingAuditStrategyConfiguration(Collections.singletonList("audit_algorithm"),
 false));
         
shardingRuleConfig.getShardingAlgorithms().put("core_standard_fixture", new 
ShardingSphereAlgorithmConfiguration("CORE.STANDARD.FIXTURE", new 
Properties()));
         shardingRuleConfig.getKeyGenerators().put("uuid", new 
ShardingSphereAlgorithmConfiguration("UUID", new Properties()));
         shardingRuleConfig.getKeyGenerators().put("default", new 
ShardingSphereAlgorithmConfiguration("UUID", new Properties()));
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/swapper/ShardingRuleConfigurationYamlSwapperTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/swapper/ShardingRuleConfigurationYamlSwapperTest.java
index f3d3e56674e..3048a1c4d44 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/swapper/ShardingRuleConfigurationYamlSwapperTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/swapper/ShardingRuleConfigurationYamlSwapperTest.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.sharding.swapper;
 
-import 
org.apache.shardingsphere.infra.yaml.config.pojo.algorithm.YamlShardingSphereAlgorithmConfiguration;
 import 
org.apache.shardingsphere.infra.yaml.config.swapper.YamlConfigurationSwapper;
 import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
 import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
@@ -106,7 +105,7 @@ public final class ShardingRuleConfigurationYamlSwapperTest 
{
         assertNull(actual.getDefaultTableStrategy());
         assertNull(actual.getDefaultKeyGenerateStrategy());
         assertNull(actual.getDefaultShardingColumn());
-        assertNull(actual.getAuditStrategy());
+        assertNull(actual.getDefaultShardingColumn());
         assertNull(actual.getScalingName());
         assertTrue(actual.getScaling().isEmpty());
     }
@@ -121,7 +120,7 @@ public final class ShardingRuleConfigurationYamlSwapperTest 
{
         
shardingRuleConfig.setDefaultTableShardingStrategy(mock(ShardingStrategyConfiguration.class));
         
shardingRuleConfig.setDefaultTableShardingStrategy(mock(ShardingStrategyConfiguration.class));
         
shardingRuleConfig.setDefaultKeyGenerateStrategy(mock(KeyGenerateStrategyConfiguration.class));
-        
shardingRuleConfig.setAuditStrategy(mock(ShardingAuditStrategyConfiguration.class));
+        
shardingRuleConfig.setDefaultAuditStrategy(mock(ShardingAuditStrategyConfiguration.class));
         shardingRuleConfig.setDefaultShardingColumn("user_id");
         YamlShardingRuleConfiguration actual = 
shardingRuleConfigurationYamlSwapper.swapToYamlConfiguration(shardingRuleConfig);
         assertThat(actual.getTables().size(), is(1));
@@ -132,7 +131,7 @@ public final class ShardingRuleConfigurationYamlSwapperTest 
{
         assertNotNull(actual.getDefaultDatabaseStrategy());
         assertNotNull(actual.getDefaultTableStrategy());
         assertNotNull(actual.getDefaultKeyGenerateStrategy());
-        assertNotNull(actual.getAuditStrategy());
+        assertNotNull(actual.getDefaultAuditStrategy());
         assertThat(actual.getDefaultShardingColumn(), is("user_id"));
     }
     
@@ -147,7 +146,7 @@ public final class ShardingRuleConfigurationYamlSwapperTest 
{
         assertNull(actual.getDefaultDatabaseShardingStrategy());
         assertNull(actual.getDefaultTableShardingStrategy());
         assertNull(actual.getDefaultKeyGenerateStrategy());
-        assertNull(actual.getAuditStrategy());
+        assertNull(actual.getDefaultAuditStrategy());
         assertNull(actual.getDefaultShardingColumn());
     }
     
@@ -160,11 +159,8 @@ public final class 
ShardingRuleConfigurationYamlSwapperTest {
         
yamlConfig.setDefaultDatabaseStrategy(mock(YamlShardingStrategyConfiguration.class));
         
yamlConfig.setDefaultTableStrategy(mock(YamlShardingStrategyConfiguration.class));
         
yamlConfig.setDefaultKeyGenerateStrategy(mock(YamlKeyGenerateStrategyConfiguration.class));
-        
yamlConfig.setAuditStrategy(mock(YamlShardingAuditStrategyConfiguration.class));
+        
yamlConfig.setDefaultAuditStrategy(mock(YamlShardingAuditStrategyConfiguration.class));
         yamlConfig.setDefaultShardingColumn("user_id");
-        YamlShardingSphereAlgorithmConfiguration auditAlgorithmConfiguration = 
new YamlShardingSphereAlgorithmConfiguration();
-        auditAlgorithmConfiguration.setType("DML_SHARDING_CONDITIONS");
-        yamlConfig.getAuditors().put("sharding_key_required_auditor", 
auditAlgorithmConfiguration);
         ShardingRuleConfiguration actual = 
shardingRuleConfigurationYamlSwapper.swapToObject(yamlConfig);
         assertThat(actual.getTables().size(), is(1));
         assertThat(actual.getBindingTableGroups().size(), is(1));
@@ -174,10 +170,7 @@ public final class 
ShardingRuleConfigurationYamlSwapperTest {
         assertNotNull(actual.getDefaultDatabaseShardingStrategy());
         assertNotNull(actual.getDefaultTableShardingStrategy());
         assertNotNull(actual.getDefaultKeyGenerateStrategy());
-        assertNotNull(actual.getAuditStrategy());
-        assertThat(actual.getAuditors().size(), is(1));
-        
assertTrue(actual.getAuditors().containsKey("sharding_key_required_auditor"));
-        
assertThat(actual.getAuditors().get("sharding_key_required_auditor").getType(), 
is("DML_SHARDING_CONDITIONS"));
+        assertNotNull(actual.getDefaultAuditStrategy());
         assertThat(actual.getDefaultShardingColumn(), is("user_id"));
     }
     
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/swapper/rule/TableRuleConfigurationYamlSwapperTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/swapper/rule/TableRuleConfigurationYamlSwapperTest.java
index cefb3c6342d..4491c61ee9b 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/swapper/rule/TableRuleConfigurationYamlSwapperTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/swapper/rule/TableRuleConfigurationYamlSwapperTest.java
@@ -19,10 +19,12 @@ package org.apache.shardingsphere.sharding.swapper.rule;
 
 import 
org.apache.shardingsphere.infra.yaml.config.swapper.YamlConfigurationSwapper;
 import 
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
+import 
org.apache.shardingsphere.sharding.api.config.strategy.audit.ShardingAuditStrategyConfiguration;
 import 
org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerateStrategyConfiguration;
 import 
org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration;
 import 
org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
 import 
org.apache.shardingsphere.sharding.yaml.config.rule.YamlTableRuleConfiguration;
+import 
org.apache.shardingsphere.sharding.yaml.config.strategy.audit.YamlShardingAuditStrategyConfiguration;
 import 
org.apache.shardingsphere.sharding.yaml.config.strategy.keygen.YamlKeyGenerateStrategyConfiguration;
 import 
org.apache.shardingsphere.sharding.yaml.config.strategy.sharding.YamlShardingStrategyConfiguration;
 import 
org.apache.shardingsphere.sharding.yaml.swapper.rule.ShardingTableRuleConfigurationYamlSwapper;
@@ -79,6 +81,7 @@ public final class TableRuleConfigurationYamlSwapperTest {
         assertNull(actual.getDatabaseStrategy());
         assertNull(actual.getTableStrategy());
         assertNull(actual.getKeyGenerateStrategy());
+        assertNull(actual.getAuditStrategy());
     }
     
     @Test
@@ -87,12 +90,14 @@ public final class TableRuleConfigurationYamlSwapperTest {
         
shardingTableRuleConfig.setDatabaseShardingStrategy(mock(StandardShardingStrategyConfiguration.class));
         
shardingTableRuleConfig.setTableShardingStrategy(mock(StandardShardingStrategyConfiguration.class));
         
shardingTableRuleConfig.setKeyGenerateStrategy(mock(KeyGenerateStrategyConfiguration.class));
+        
shardingTableRuleConfig.setAuditStrategy(mock(ShardingAuditStrategyConfiguration.class));
         YamlTableRuleConfiguration actual = 
tableYamlSwapper.swapToYamlConfiguration(shardingTableRuleConfig);
         assertThat(actual.getLogicTable(), is("tbl"));
         assertThat(actual.getActualDataNodes(), 
is("ds_$->{0..1}.tbl_$->{0..1}"));
         assertNotNull(actual.getDatabaseStrategy());
         assertNotNull(actual.getTableStrategy());
         assertNotNull(actual.getKeyGenerateStrategy());
+        assertNotNull(actual.getAuditStrategy());
     }
     
     @Test(expected = NullPointerException.class)
@@ -121,11 +126,13 @@ public final class TableRuleConfigurationYamlSwapperTest {
         
yamlConfig.setDatabaseStrategy(mock(YamlShardingStrategyConfiguration.class));
         
yamlConfig.setTableStrategy(mock(YamlShardingStrategyConfiguration.class));
         
yamlConfig.setKeyGenerateStrategy(mock(YamlKeyGenerateStrategyConfiguration.class));
+        
yamlConfig.setAuditStrategy(mock(YamlShardingAuditStrategyConfiguration.class));
         ShardingTableRuleConfiguration actual = 
tableYamlSwapper.swapToObject(yamlConfig);
         assertThat(actual.getLogicTable(), is("tbl"));
         assertThat(actual.getActualDataNodes(), 
is("ds_$->{0..1}.tbl_$->{0..1}"));
         assertNotNull(actual.getDatabaseShardingStrategy());
         assertNotNull(actual.getTableShardingStrategy());
         assertNotNull(actual.getKeyGenerateStrategy());
+        assertNotNull(actual.getAuditStrategy());
     }
 }
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/resources/yaml/sharding-rule.yaml
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/resources/yaml/sharding-rule.yaml
index c35a52214e9..dd3267e1415 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/resources/yaml/sharding-rule.yaml
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/resources/yaml/sharding-rule.yaml
@@ -70,7 +70,11 @@ rules:
   defaultTableStrategy: 
     none:
   defaultShardingColumn: order_id
-  
+  defaultAuditStrategy:
+    auditorNames:
+      - sharding_key_required_auditor
+    allowHintDisable: true
+
   shardingAlgorithms:
     core_standard_fixture:
       type: CORE.STANDARD.FIXTURE
@@ -90,6 +94,10 @@ rules:
   keyGenerators:
     snowflake:
       type: SNOWFLAKE
+
+  auditors:
+    sharding_key_required_auditor:
+      type: DML_SHARDING_CONDITIONS
   
   scalingName: default_scaling
   scaling:
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/config-sharding.yaml
 
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/config-sharding.yaml
index f2f953e3029..47a2c45f4fa 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/config-sharding.yaml
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/config-sharding.yaml
@@ -54,8 +54,12 @@
 #          shardingColumn: order_id
 #          shardingAlgorithmName: t_order_inline
 #      keyGenerateStrategy:
-#          column: order_id
-#          keyGeneratorName: snowflake
+#        column: order_id
+#        keyGeneratorName: snowflake
+#      auditStrategy:
+#        auditorNames:
+#          - sharding_key_required_auditor
+#        allowHintDisable: true
 #    t_order_item:
 #      actualDataNodes: ds_${0..1}.t_order_item_${0..1}
 #      tableStrategy:
@@ -73,7 +77,7 @@
 #      shardingAlgorithmName: database_inline
 #  defaultTableStrategy:
 #    none:
-#  auditStrategy:
+#  defaultAuditStrategy:
 #    auditorNames:
 #      - sharding_key_required_auditor
 #    allowHintDisable: true
@@ -162,6 +166,10 @@
 #      keyGenerateStrategy:
 #        column: order_id
 #        keyGeneratorName: snowflake
+#      auditStrategy:
+#        auditorNames:
+#          - sharding_key_required_auditor
+#        allowHintDisable: true
 #    t_order_item:
 #      actualDataNodes: ds_${0..1}.t_order_item_${0..1}
 #      tableStrategy:
@@ -179,7 +187,7 @@
 #      shardingAlgorithmName: database_inline
 #  defaultTableStrategy:
 #    none:
-#  auditStrategy:
+#  defaultAuditStrategy:
 #    auditorNames:
 #      - sharding_key_required_auditor
 #    allowHintDisable: true

Reply via email to