terrymanu commented on issue #31448:
URL:
https://github.com/apache/shardingsphere/issues/31448#issuecomment-3508194664
Thank you for reporting this issue! Your analysis is very accurate, and this
is indeed an important defect in ShardingSphere's Shadow functionality.
Issue Confirmation
After our analysis, the Shadow functionality currently has the following
problems in batch insert scenarios:
1. "All or Nothing" Logic Defect: The current implementation requires ALL
records in a batch to match Shadow conditions before routing to the shadow
database
2. Expected Behavior Mismatch: The correct implementation should be
record-level routing, where matching records go to the shadow database and
non-matching records go to the production database
3. Lack of XA Transaction Support: Distributed transactions are needed to
ensure atomicity of cross-datasource operations
Root Cause
The core issue lies in the logic of the
ColumnShadowAlgorithmDeterminer.isShadow() method:
for (PreciseColumnShadowValue<Comparable<?>> each :
createColumnShadowValues(shadowCondition)) {
if (!shadowAlgorithm.isShadow(each)) {
return false; // One mismatched record makes entire batch not
shadow
}
}
return true;
Current Status
Shadow functionality is a relatively niche feature in ShardingSphere with
limited usage scenarios, so it is currently not a high priority for mainline
optimization.
Community Contribution Invitation
We would like to enthusiastically invite you to contribute this fix to the
community! This involves the following major work:
1. Routing Engine Overhaul: Support record-level datasource routing
decisions
2. SQL Splitting Logic: Split batch SQL into multiple sub-SQL statements
based on conditions
3. XA Transaction Integration: Ensure transaction consistency for
cross-datasource operations
4. Comprehensive Testing: Including functional tests, performance tests,
and compatibility tests
If you are interested in submitting a PR to fix this issue, we would be
happy to:
- Provide architectural-level technical guidance
- Assist with related code reviews
- Help ensure the quality and compatibility of the fix
Thank you again for your attention to and contribution to ShardingSphere!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]