terrymanu commented on issue #34771:
URL: 
https://github.com/apache/shardingsphere/issues/34771#issuecomment-3506426715

   After detailed analysis, this issue is not a bug in ShardingSphere, but is 
caused by incorrect configuration.
   
     Root Cause Analysis
   
     The fundamental problem is that the read-write splitting rule names do not 
match the data source names after sharding routing:
   
     1. Your Initial Configuration:
     ReadwriteSplittingDataSourceRuleConfiguration readWriteSource0 = new 
ReadwriteSplittingDataSourceRuleConfiguration(
         "write_read_split0", "master0", Collections.singletonList("save0"),
         TransactionalReadQueryStrategy.PRIMARY, "roundRobin");
   
     2. Routing Execution Flow:
       - Sharding routing executes first, routing queries to actual data 
sources (e.g., master1)
       - Read-write splitting routing executes second, needing to find 
corresponding read-write splitting rules based on data source names
       - Your sharding routing results in data source names: master0, master1, 
master2
       - But your read-write splitting rule names are: write_read_split0, 
write_read_split1, write_read_split2
     3. Matching Failure:
     // This matching logic fails because "master1" != "write_read_split1"
     if (dataSourceRule.isPresent() &&
         
((ReadwriteSplittingDataSourceRule)dataSourceRule.get()).getName().equalsIgnoreCase(each.getDataSourceMapper().getActualName()))
 {
         // This branch is not entered
     }
   
     Correct Configuration
   
     Your solution is correct. The read-write splitting rule names must match 
the data source names after sharding routing:
   
     ReadwriteSplittingDataSourceRuleConfiguration readWriteSource0 = new 
ReadwriteSplittingDataSourceRuleConfiguration(
         "master0", "master0", Collections.singletonList("save0"),
         TransactionalReadQueryStrategy.PRIMARY, "roundRobin");
     ReadwriteSplittingDataSourceRuleConfiguration readWriteSource1 = new 
ReadwriteSplittingDataSourceRuleConfiguration(
         "master1", "master1", Collections.singletonList("save1"),
         TransactionalReadQueryStrategy.PRIMARY, "roundRobin");
     ReadwriteSplittingDataSourceRuleConfiguration readWriteSource2 = new 
ReadwriteSplittingDataSourceRuleConfiguration(
         "master2", "master2", Collections.singletonList("save2"),
         TransactionalReadQueryStrategy.PRIMARY, "roundRobin");
   
     Parameter Description
   
     - First Parameter: Read-write splitting rule name, must match the actual 
data source name after sharding routing
     - Second Parameter: Write data source name
     - Third Parameter: Read data source list
     - Fourth Parameter: Read strategy within transactions
     - Fifth Parameter: Load balancing algorithm
   
     Conclusion
   
     This issue aligns with ShardingSphere's design principles. When using both 
sharding and read-write splitting features simultaneously, the read-write 
splitting rules need to recognize the results of sharding routing,
     therefore the rule names must match.
   
     Your final solution is completely correct. It is recommended to continue 
using this configuration approach.
   


-- 
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]

Reply via email to