-
Notifications
You must be signed in to change notification settings - Fork 3.7k
4.1: CASSANDRA-19703: Ensure prepared_statement INSERT timestamp precedes eviction DELETE #3917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
1e639da
to
9c1c572
Compare
b4e9ee8
to
927960e
Compare
IIUC here we're fixing 3 things:
|
Aren't we missing a test we stop loading pstmnts once cache is full? Maybe you could use byteman to capture the call to the log warn method. That with a modified yaml to have a smaller pstmnts cache somehow should do the trick. I think it's one important feature we're not testing unless I am missing sthg. |
LGTM modulus the 2 minor issues I mentioned last. I would still heavily compact junits but that's just me. We need another C* committer to +1 this now right? |
Pushed some changes which hopefully addresses the remaining feedback, hopefully everything looks ok! I merged in recent changes from 4.1 and ran a full CI run. I'll find a second reviewer tomorrow. |
5f2194e
to
9c1bb60
Compare
went ahead and rebased and squashed the commits as I had updated from trunk previously which messed with the history a bit. Made no changes and ensured a clean diff before pushing. |
CHANGES.txt
Outdated
@@ -5,6 +5,7 @@ | |||
* Optionally skip exception logging on invalid legacy protocol magic exception (CASSANDRA-19483) | |||
* Fix SimpleClient ability to release acquired capacity (CASSANDRA-20202) | |||
* Fix WaitQueue.Signal.awaitUninterruptibly may block forever if invoking thread is interrupted (CASSANDRA-20084) | |||
* Ensure prepared_statement INSERT timestamp precedes eviction DELETE (CASSANDRA-19703) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think new entries go at the top
// should detect a possible leak and defer paging indefinitely by returning early in preloadPreparedStatements. | ||
int statementsLoadedWhenFull = -1; | ||
long accumulatedSize = 0; | ||
long cacheSize = new DataStorageSpec.LongBytesBound(DatabaseDescriptor.getPreparedStatementsCacheSizeMiB(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use QueryProcessor.PREPARED_STATEMENT_CACHE_SIZE_BYTES instead now that we have a constant for this. will fix.
LGTM, we need PRs and CI for the other branches now. |
thanks 👍 will go ahead and squash into a single commit, and kick off CI against 4.1/5.0/trunk branches. |
29bbb19
to
5e4f087
Compare
squashed with no changes. |
5e4f087
to
cf0e58e
Compare
I think we need 4.0 as well |
Technically the bug is not likely to be encountered on 4.0 as Caffeine is running an older version that behaves differently, but it wouldn't hurt to do so, will create a branch. |
Updates SystemKeyspace.writePreparedStatement to accept a timestamp associated with the Prepared creation time. Using this timestamp will ensure that an INSERT into system.prepared_statements will always precede the timestamp for the same Prepared in SystemKeyspace.removePreparedStatement. This is needed because Caffeine 2.9.2 may evict an entry as soon as it is inserted if the maximum weight of the cache is exceeded causing the DELETE to be executed before the INSERT. Additionally, any clusters currently experiencing a leaky system.prepared_statements table from this bug may struggle to bounce into a version with this fix as SystemKeyspace.loadPreparedPreparedStatements currently does not paginate the query to system.prepared_statements, causing heap OOMs. To fix this this patch adds pagination at 5000 rows and aborts loading once the cache size is loaded. This should allow nodes to come up and delete older prepared statements that may no longer be used as the cache fills up (which should happen immediately). This patch does not address the issue of Caffeine immediately evicting a prepared statement, however it will prevent the system.prepared_statements table from growing unbounded. For most users this should be adequate, as the cache should only be filled when there are erroneously many unique prepared statements. In such a case we can expect that clients will constantly prepare statements regardless of whether or not the cache is evicting statements. patch by Andy Tolbert; reviewed by Berenguer Blasi and Caleb Rackliffe for CASSANDRA-19703
3c80c2e
to
499847b
Compare
squashed with no changes. |
Updates SystemKeyspace.writePreparedStatement to accept a timestamp
associated with the Prepared creation time. Using this timestamp
will ensure that an INSERT into system.prepared_statements will
always precede the timestamp for the same Prepared in
SystemKeyspace.removePreparedStatement.
This is needed because Caffeine 2.9.2 may evict an entry as soon
as it is inserted if the maximum weight of the cache is exceeded
causing the DELETE to be executed before the INSERT.
Additionally, any clusters currently experiencing a leaky
system.prepared_statements table from this bug may struggle to
bounce into a version with this fix as
SystemKeyspace.loadPreparedPreparedStatements currently does
not paginate the query to system.prepared_statements, causing heap
OOMs. To fix this this patch adds pagination at 5000 rows and
aborts loading once the cache size is loaded. This should allow
nodes to come up and delete older prepared statements that may no
longer be used as the cache fills up (which should happen immediately).
This patch does not address the issue of Caffeine immediately evicting
a prepared statement, however it will prevent the
system.prepared_statements table from growing unbounded. For most users
this should be adequate, as the cache should only be filled when there
are erroneously many unique prepared statements. In such a case we can
expect that clients will constantly prepare statements regardless
of whether or not the cache is evicting statements.
patch by Andy Tolbert; reviewed by Berenguer Blasi and Caleb Rackliffe for CASSANDRA-19703