darkaquarius opened a new issue #14976:
URL: https://github.com/apache/shardingsphere/issues/14976


   there are two datasources used in our project.
   
   old datasource's configuration is, only shards tables, do NOT shards 
database:
   
![image](https://user-images.githubusercontent.com/16524112/150477329-5cea3dcc-606e-4531-80e5-7dc3675cec21.png)
   
   new datasource's configuration is, we shards both databases and tables:
   
![image](https://user-images.githubusercontent.com/16524112/150477759-bfb55045-e762-4dd0-b351-c98f0f1d3ba3.png)
   
   The datasources are:
   
![image](https://user-images.githubusercontent.com/16524112/150478900-6dd46323-7c7e-4274-90bd-b92c5b70344b.png)
   
   We use the two datasources by extending spring AbstractRoutingDataSource
   ```
   public class DynamicDataSource extends AbstractRoutingDataSource {
   
       @Override
       protected Object determineCurrentLookupKey() {
           return DynamicDataSourceHolder.getDataSource();
       }
   
   }
   ```
   DynamicDataSourceHolder uses ThreadLocal to choose either old datasource or 
new datasource.
   
   We read the new datasource first and then write into new datasource by 
multithreading, as the following:
   
![image](https://user-images.githubusercontent.com/16524112/150478627-16260174-b750-4b04-843a-d49f39938cc0.png)
   
   But sometimes, we find that it wrote to the old dataSource! 
   
   For convenience, we added some logs in InlineShardingAlgorithm:
   
![7D6C4DE4-F7F9-4F25-BF03-0A192EA90D07](https://user-images.githubusercontent.com/16524112/150479548-8c5dd9a0-5110-4765-b451-1bcc4b0aceb7.png)
   
   The logs are:
   
![6923C463-9A1E-4841-A721-E2ECA58BF970](https://user-images.githubusercontent.com/16524112/150480144-b245ab8c-384d-4ec3-a145-766298a7ffdf.png)
   
   First, we found the new datasource's sharding rules, but then, when we 
wrote, we unexpectedly found the old datasource sharding rules, so we failed to 
write data!
   
   And then, we execute the code again, the we succeed!
   
![7A15A09A-BAC8-480B-BAE9-63EFEAF03F2B](https://user-images.githubusercontent.com/16524112/150480790-c655f5a4-89a5-4310-bf53-d90941698c35.png)
   
   We counted it, about 100,000 executions will report an error once, Does 
anyone know why?


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