Skip to content
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

CASSANDRA-19703: Ensure prepared_statement INSERT timestamp precedes eviction DELETE #3917

Open
wants to merge 1 commit into
base: cassandra-4.1
Choose a base branch
from

Conversation

tolbertam
Copy link
Contributor

@tolbertam tolbertam commented Feb 21, 2025

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.

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 pagingation at 5000 rows, which 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).

Adds #testAsyncPstmtInvalidation which almost always reproduces the issue without this fix.

Adds #testPreloadPreparedStatements to verify pagination behavior.

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.

CASSANDRA-19703

@tolbertam tolbertam changed the base branch from trunk to cassandra-4.1 February 21, 2025 00:03
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 pagingation at 5000 rows,
which 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).

Adds #testAsyncPstmtInvalidation which almost always reproduces the
issue without this fix.

Adds #testPreloadPreparedStatements to verify pagination behavior.

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.
@tolbertam tolbertam marked this pull request as ready for review February 21, 2025 05:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant