we using spring cassandra , datastax driver make requests cassandra using cachedpreparedstatementcreator/preparedstatement. @ startup, these warn messages showing in log files (there others, example of one)
:warn lg:com.datastax.driver.core.cluster - re-preparing prepared query insert active (id) values(?) using ttl ?. please note preparing same query more once anti-pattern , affect performance. consider preparing statement once.
the prepared statements created using cachedpreparedstatementcreator class. looking @ source code, appears there ‘race condition’ , implementation not threadsafe.
map<string, preparedstatement> sessionmap = psmap.get(session); if (sessionmap == null) { sessionmap = new concurrenthashmap<string, preparedstatement>(); psmap.put(session, sessionmap); } preparedstatement pstmt = sessionmap.get(keyspacecqlkey.tostring()); if (pstmt == null) { log.debug("no cached preparedstatement found...creating , caching"); pstmt = session.prepare(this.cql); sessionmap.put(keyspacecqlkey.tostring(), pstmt); } else { log.debug("found cached preparedstatement"); }
what intention class? intended threadsafe? , have information performance of cache?
there race condition between checking statements existence , creating new prepared statement. pursue solution similar 1 in reentrantreadwritelock docs.
note after write lock achieved there verification value still not present. solve condition you're seeing here.
consider filing ticket in spring data cassandra jira or submitting pr on github.
Comments
Post a Comment