shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

sharding-jdbc can't work in multi thread concurrent

Open mfeng-ya opened this issue 7 years ago • 10 comments

Bug Report

For English only, other languages will not accept.

Before report a bug, make sure you have:

Please pay attention on issues you submitted, because we maybe need more details. If no response more than 7 days and we cannot reproduce it on current information, we will close it.

Please answer these questions before submitting your issue. Thanks!

Which version of ShardingSphere did you use?

4.0.0.M1

Which project did you use? Sharding-JDBC or Sharding-Proxy?

Sharding-JDBC

Expected behavior

Actual behavior

multi thread concurrent can't work

Reason analyze (If you can)

InsertStatement(other Statement no validation) is not thread safe, PreparedStatementRoutingEngine#route fetch Statement used cache image

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

image

Example codes for reproduce this issue (such as a github link).

mfeng-ya avatar Mar 07 '19 08:03 mfeng-ya

Which version is stable and usable now?

mfeng-ya avatar Mar 07 '19 09:03 mfeng-ya

new question ShardingRule i think is singleton image image org.apache.commons.collections4.map.ReferenceMap is not thread-safe, cache used with it no problem in multi thread concurrent? image

mfeng-ya avatar Mar 07 '19 09:03 mfeng-ya

Could change field 'parsingResultCache' to #ThreadLocal in #ShardingRule?

mfeng-ya avatar Mar 07 '19 10:03 mfeng-ya

@mfeng-ya it caused by shared SQLStatement, ParsingResultCache is global cache, it cloud not change to ThreadLocal

codefairy08 avatar Mar 08 '19 03:03 codefairy08

@codefairy08 ParsingResultCache may be could refer to the ConcurrentReferenceHashMap in hibernate-validator's util package image

mfeng-ya avatar Mar 09 '19 07:03 mfeng-ya

@mfeng-ya It does not work, It is not caused by ParsingResultCache , the instance in ParsingResultCache should not be changed.

codefairy08 avatar Mar 10 '19 09:03 codefairy08

@codefairy08 I see, however it's a new question

mfeng-ya avatar Mar 11 '19 02:03 mfeng-ya

I have met a problem while using sharing-jdbc version 3.1.0. Thread hang in with high CPU load. Thread call stack show thread hang in HashMap.getEntry(). So how can i fix this problem beacuse of HashMap is not thread save in ParsingResultCache.

ToukitsuLin avatar Apr 02 '19 08:04 ToukitsuLin

This should be a VERY BASIC issue which should not happen since everybody know that HashMap is NOT THREAD-SAFE.

yanglifan avatar Apr 03 '19 04:04 yanglifan

mark ParsingResultCache

Ah39 avatar Aug 16 '19 03:08 Ah39