You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "zt9788 (via GitHub)" <gi...@apache.org> on 2023/06/06 03:16:07 UTC

[GitHub] [shardingsphere] zt9788 opened a new issue, #26064: Is doSharding's collection not thread safe?

zt9788 opened a new issue, #26064:
URL: https://github.com/apache/shardingsphere/issues/26064

   ## Bug Report
   
   ### Which version of ShardingSphere did you use?
   ShardingShpere 5.3.2 JDK17
   
   I make a custom ComplexKeysShardingAlgorithm 
   in `doSharding(Collection<String> collection,
                                            ComplexKeysShardingValue<String> complexKeysShardingValue)`
   
   I use the `collection.toArray()[0]` sometimes will throw ` Index X out of bounds for length X` when programe starting.
   
   ```
   at java.util.LinkedHashMap.keysToArray(LinkedHashMap.java:545)
   at java.util.HashSet.toArray(HashSet.java:368)
   at ...CustomhardingAlgorithm.doSharding(CustomhardingAlgorithm.java:64)
   ....
   ```
   
   There are very few abnormal situations that have occurred, and I have not been able to reproduce them local.
   
   


-- 
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.apache.org

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


[GitHub] [shardingsphere] zt9788 commented on issue #26064: Is doSharding's collection not thread safe?

Posted by "zt9788 (via GitHub)" <gi...@apache.org>.
zt9788 commented on issue #26064:
URL: https://github.com/apache/shardingsphere/issues/26064#issuecomment-1577943895

   Code is:
   
   I haven't do anything yet, just get index0  of them after toArray
   
   ```
   
       @Override
       public Collection<String> doSharding(Collection<String> collection,
                                            ComplexKeysShardingValue<String> complexKeysShardingValue) {
           if(App.getApplicationContext() == null) {
               return collection;
           }
           Set<String> shardingSuffix = new HashSet<>();
           var tablename =  collection.toArray()[0]; // here throw the Exception
   ...
   ```


-- 
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] zt9788 commented on issue #26064: Is doSharding's collection not thread safe?

Posted by "zt9788 (via GitHub)" <gi...@apache.org>.
zt9788 commented on issue #26064:
URL: https://github.com/apache/shardingsphere/issues/26064#issuecomment-1577863985

   @RaigorJiang 
   No, the Exception is ` Index 2 out of bounds for length  2` (index >0 )
   and I make sure the collection is not empty (when toArray hashset will make a array length = collection.size() but if the set changed that may throw the exception


-- 
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] RaigorJiang commented on issue #26064: Is doSharding's collection not thread safe?

Posted by "RaigorJiang (via GitHub)" <gi...@apache.org>.
RaigorJiang commented on issue #26064:
URL: https://github.com/apache/shardingsphere/issues/26064#issuecomment-1577879947

   Did you modify the input collection in the `CustomhardingAlgorithm#doSharding` method?


-- 
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] RaigorJiang commented on issue #26064: Is doSharding's collection not thread safe?

Posted by "RaigorJiang (via GitHub)" <gi...@apache.org>.
RaigorJiang commented on issue #26064:
URL: https://github.com/apache/shardingsphere/issues/26064#issuecomment-1577856675

   @zt9788 
   Is it possible that your collection is empty?


-- 
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] zt9788 closed issue #26064: Is doSharding's collection not thread safe?

Posted by "zt9788 (via GitHub)" <gi...@apache.org>.
zt9788 closed issue #26064: Is doSharding's collection not thread safe?
URL: https://github.com/apache/shardingsphere/issues/26064


-- 
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] zt9788 commented on issue #26064: Is doSharding's collection not thread safe?

Posted by "zt9788 (via GitHub)" <gi...@apache.org>.
zt9788 commented on issue #26064:
URL: https://github.com/apache/shardingsphere/issues/26064#issuecomment-1577990947

   @RaigorJiang 
   
   I carefully checked and found that in doSharding with multiple threads, I may indeed perform an add operation on the collection (normally only for the first time), which may be the problem
   
   Thank you very much. I will close the issue first and carefully investigate it. If it is confirmed to be a shardingshpere issue, I will open it 
   
   It is indeed a bit strange because even modifications are still add, and I don't know why there is an out of bounds exception
   
   Thank you again for your reply


-- 
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] RaigorJiang commented on issue #26064: Is doSharding's collection not thread safe?

Posted by "RaigorJiang (via GitHub)" <gi...@apache.org>.
RaigorJiang commented on issue #26064:
URL: https://github.com/apache/shardingsphere/issues/26064#issuecomment-1577986052

   That's really strange, there is no logic to modify this collection in ShardingSphere.
   Would it be convenient for you to add logging and an `isEmpty` check before collection.toArray() ? to analyze the 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