Implementation:Apache Shardingsphere ShadowAlgorithm SPI
| Knowledge Sources | |
|---|---|
| Domains | Shadow_Testing, SPI |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
SPI marker interface for shadow algorithm implementations in the ShardingSphere shadow testing framework.
Description
ShadowAlgorithm is the root interface in the shadow algorithm SPI hierarchy. It extends ShardingSphereAlgorithm and serves as the base type that all shadow algorithm implementations must implement. Concrete sub-interfaces include ColumnShadowAlgorithm for column-value-based routing and HintShadowAlgorithm for SQL-hint-based routing.
Usage
Implement this interface (via its sub-interfaces) when creating custom shadow routing algorithms that determine whether SQL statements should be routed to shadow data sources during testing.
Code Reference
Source Location
- Repository: Apache_Shardingsphere
- File: features/shadow/api/src/main/java/org/apache/shardingsphere/shadow/spi/ShadowAlgorithm.java
- Lines: 1-26
Signature
public interface ShadowAlgorithm extends ShardingSphereAlgorithm {
}
Import
import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| (none) | — | — | Marker interface with no direct inputs |
Outputs
| Name | Type | Description |
|---|---|---|
| (none) | — | Marker interface; sub-interfaces define concrete contracts |
Usage Examples
// Custom shadow algorithm implementation via sub-interface
public final class MyShadowAlgorithm implements ColumnShadowAlgorithm<String> {
@Override
public boolean isShadow(final Collection<String> shadowTableNames, final PreciseColumnShadowValue<String> shadowValue) {
return "shadow".equals(shadowValue.getValue());
}
@Override
public String getShadowColumn() {
return "shadow_flag";
}
@Override
public ShadowOperationType getShadowOperationType() {
return ShadowOperationType.INSERT;
}
@Override
public String getType() {
return "MY_SHADOW";
}
}