You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/01/21 07:00:48 UTC

[GitHub] [shardingsphere] darkaquarius opened a new issue #14976: We have two datasources, but choose the wrong one

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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] terrymanu commented on issue #14976: We have two datasources, but choose the wrong one

Posted by GitBox <gi...@apache.org>.
terrymanu commented on issue #14976:
URL: https://github.com/apache/shardingsphere/issues/14976#issuecomment-1042900687


   Closed because of no response for long time.


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] strongduanmu commented on issue #14976: We have two datasources, but choose the wrong one

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on issue #14976:
URL: https://github.com/apache/shardingsphere/issues/14976#issuecomment-1020692381


   @darkaquarius Can you provide a demo to help reproduce this problem?


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] strongduanmu commented on issue #14976: We have two datasources, but choose the wrong one

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on issue #14976:
URL: https://github.com/apache/shardingsphere/issues/14976#issuecomment-1020692381


   @darkaquarius Can you provide a demo to help reproduce this problem?


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] darkaquarius commented on issue #14976: We have two datasources, but choose the wrong one

Posted by GitBox <gi...@apache.org>.
darkaquarius commented on issue #14976:
URL: https://github.com/apache/shardingsphere/issues/14976#issuecomment-1020069309


   Although DynamicDataSource is used, we have gotten the correct shardingsphereDataSource  every time, so this problem has nothing to do with DynamicDataSource, it is a problem that occurs when entering shardingsphereDataSource.
   
   ![image](https://user-images.githubusercontent.com/16524112/150781949-5c575360-e35c-4e11-8034-371e14dd9283.png)
   
   ![image](https://user-images.githubusercontent.com/16524112/150786245-acf8b4ab-2ae8-40dd-825c-f47ee9651068.png)
   
   ![image](https://user-images.githubusercontent.com/16524112/150786363-276f50f1-33aa-49ff-b679-016aa137dc7f.png)
   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] terrymanu closed issue #14976: We have two datasources, but choose the wrong one

Posted by GitBox <gi...@apache.org>.
terrymanu closed issue #14976:
URL: https://github.com/apache/shardingsphere/issues/14976


   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] strongduanmu commented on issue #14976: We have two datasources, but choose the wrong one

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on issue #14976:
URL: https://github.com/apache/shardingsphere/issues/14976#issuecomment-1019628578


   Hi @darkaquarius, thank you for your feedback. I see that you are using `DynamicDataSource` to manage multiple `ShardingDataSource`, which is beyond the scope of ShardingSphere's management, so I can't provide help, you need to investigate DynamicDataSource by yourself.


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org