Invalidate the Prepared statement cache only if either of the prepare…#4542
Invalidate the Prepared statement cache only if either of the prepare…#4542jaydeepkumar1984 wants to merge 1 commit intoapache:cassandra-4.0from
Conversation
| } | ||
| } | ||
| else | ||
| else if (cachedWithoutKeyspace != null || cachedWithKeyspace != null) |
There was a problem hiding this comment.
I think we need something like else if ((cachedWithoutKeyspace != null) != (cachedWithKeyspace != null)), to make sure at least one of them is in cache.
There was a problem hiding this comment.
Let me elaborate.
boolean safeToReturnCached = cachedWithoutKeyspace != null && cachedWithKeyspace != null;
We are in the else block because safeToReturnCached is false. If safeToReturnCached is false, that means either cachedWithoutKeyspace is null or cachedWithKeyspace is null or both of them.
So, at this place, if (cachedWithoutKeyspace != null || cachedWithKeyspace != null) is sufficient.
Could you please double-check?
There was a problem hiding this comment.
@jaydeepkumar1984 thanks for elaborating, I think you're right.
Just as a nitpick, and if you get a chance, could you add a short comment saying "only evict if we know one of the statements is cached".
There was a problem hiding this comment.
Incorporated
| } | ||
| } | ||
| else | ||
| else if (cachedWithoutKeyspace != null || cachedWithKeyspace != null) |
There was a problem hiding this comment.
@jaydeepkumar1984 thanks for elaborating, I think you're right.
Just as a nitpick, and if you get a chance, could you add a short comment saying "only evict if we know one of the statements is cached".
…d caches is empty, but not both
d61f28d to
6f2529e
Compare
|
Pushed as 077b7eb |
https://issues.apache.org/jira/browse/CASSANDRA-17248 added prepared statement eviction logic because there was a change in prepared statements' behavior between 4.0.1 -> 4.0.2. However, the eviction logic introduces a race condition depicted in https://issues.apache.org/jira/browse/CASSANDRA-17401
As per this discussion, we should keep the eviction logic in the 4.0 branch, but invoke only in a real corner case scenario.
This PR will evict the statements only during the corner case scenario in which either of the prepared statement caches is empty, but not both.
The Cassandra Jira