Implementation:Apache Shardingsphere YamlShadowRuleConfiguration Structure
| Knowledge Sources | |
|---|---|
| Domains | Configuration_Management, Shadow_Testing |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
Concrete YAML-bindable configuration class for defining shadow rule structure, provided by the ShardingSphere shadow module.
Description
YamlShadowRuleConfiguration is a final class that serves as the deserialization target for shadow rule YAML configuration documents. It implements the YamlRuleConfiguration interface, which itself extends YamlConfiguration, making it eligible for processing by YamlEngine.unmarshal().
The class declares four fields representing the main sections of a shadow rule configuration:
- dataSources: A
Map<String, YamlShadowDataSourceConfiguration>mapping logical data source names to their production/shadow data source pairs. Annotated with@RuleNodeTupleField(type = Type.DATA_SOURCE). - tables: A
Map<String, YamlShadowTableConfiguration>mapping table names to their shadow table configuration (data source names and algorithm names). Annotated with@RuleNodeTupleField(type = Type.TABLE). - shadowAlgorithms: A
Map<String, YamlAlgorithmConfiguration>mapping algorithm names to their type and properties. Annotated with@RuleNodeTupleField(type = Type.ALGORITHM). - defaultShadowAlgorithmName: A
Stringidentifying the default shadow algorithm. Annotated with@RuleNodeTupleField(type = Type.DEFAULT_ALGORITHM).
All map fields are initialized with new LinkedHashMap<>() to guarantee insertion-order preservation and non-null defaults. The class-level @RuleNodeTupleEntity("shadow") annotation registers this configuration under the "shadow" rule type for governance node path construction. Lombok @Getter and @Setter annotations generate the accessor methods used by the SnakeYAML deserialization engine.
The getRuleConfigurationType() method returns ShadowRuleConfiguration.class, linking this YAML class to its corresponding domain configuration type.
Usage
Use YamlShadowRuleConfiguration as the target class when deserializing shadow rule YAML content via YamlEngine.unmarshal(yamlContent, YamlShadowRuleConfiguration.class). After deserialization, pass the resulting object to YamlShadowRuleConfigurationSwapper.swapToObject() to obtain the domain-level ShadowRuleConfiguration.
Code Reference
Source Location
- Repository: Apache ShardingSphere
- File:
features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/yaml/config/YamlShadowRuleConfiguration.java - Lines: 40-58
Signature
@RuleNodeTupleEntity("shadow")
@Getter
@Setter
public final class YamlShadowRuleConfiguration implements YamlRuleConfiguration {
@RuleNodeTupleField(type = Type.DATA_SOURCE)
private Map<String, YamlShadowDataSourceConfiguration> dataSources = new LinkedHashMap<>();
@RuleNodeTupleField(type = Type.TABLE)
private Map<String, YamlShadowTableConfiguration> tables = new LinkedHashMap<>();
@RuleNodeTupleField(type = Type.ALGORITHM)
private Map<String, YamlAlgorithmConfiguration> shadowAlgorithms = new LinkedHashMap<>();
@RuleNodeTupleField(type = Type.DEFAULT_ALGORITHM)
private String defaultShadowAlgorithmName;
@Override
public Class<ShadowRuleConfiguration> getRuleConfigurationType() {
return ShadowRuleConfiguration.class;
}
}
Import
import org.apache.shardingsphere.shadow.yaml.config.YamlShadowRuleConfiguration;
I/O Contract
Inputs
This is a data class. Its fields are populated by the YAML deserialization engine from YAML key-value pairs.
| Name | Type | Required | Description |
|---|---|---|---|
| dataSources | Map<String, YamlShadowDataSourceConfiguration> | No | Map of logical data source names to production/shadow data source pairs |
| tables | Map<String, YamlShadowTableConfiguration> | No | Map of table names to their shadow table configurations |
| shadowAlgorithms | Map<String, YamlAlgorithmConfiguration> | No | Map of algorithm names to algorithm type and properties |
| defaultShadowAlgorithmName | String | No | Name of the default shadow algorithm (must be SQL_HINT type if specified) |
Outputs
| Name | Type | Description |
|---|---|---|
| getRuleConfigurationType() | Class<ShadowRuleConfiguration> | Returns the domain configuration class this YAML class corresponds to |
Usage Examples
// Example: Deserialize YAML content into YamlShadowRuleConfiguration
String yamlContent = "dataSources:\n"
+ " shadowDataSource:\n"
+ " productionDataSourceName: ds_prod\n"
+ " shadowDataSourceName: ds_shadow\n"
+ "tables:\n"
+ " t_order:\n"
+ " dataSourceNames:\n"
+ " - shadowDataSource\n"
+ " shadowAlgorithmNames:\n"
+ " - user-id-insert-match-algorithm\n"
+ "shadowAlgorithms:\n"
+ " user-id-insert-match-algorithm:\n"
+ " type: VALUE_MATCH\n"
+ " props:\n"
+ " operation: insert\n"
+ " column: user_id\n"
+ " value: 0\n";
YamlShadowRuleConfiguration yamlConfig = YamlEngine.unmarshal(yamlContent, YamlShadowRuleConfiguration.class);
// yamlConfig.getDataSources() contains the "shadowDataSource" entry
// yamlConfig.getTables() contains the "t_order" entry
// yamlConfig.getShadowAlgorithms() contains the "user-id-insert-match-algorithm" entry