tolbertam commented on code in PR #3917:
URL: https://github.com/apache/cassandra/pull/3917#discussion_r2080793274
##########
src/java/org/apache/cassandra/db/SystemKeyspace.java:
##########
@@ -1862,17 +1865,61 @@ public static void resetPreparedStatements()
preparedStatements.truncateBlockingWithoutSnapshot();
}
- public static int loadPreparedStatements(TriFunction<MD5Digest, String,
String, Boolean> onLoaded)
+ public static int loadPreparedStatements(TriFunction<MD5Digest, String,
String, Prepared> onLoaded)
+ {
+ return loadPreparedStatements(onLoaded,
QueryProcessor.PRELOAD_PREPARED_STATEMENTS_FETCH_SIZE);
+ }
+
+ public static int loadPreparedStatements(TriFunction<MD5Digest, String,
String, Prepared> onLoaded, int pageSize)
{
String query = String.format("SELECT prepared_id, logged_keyspace,
query_string FROM %s.%s", SchemaConstants.SYSTEM_KEYSPACE_NAME,
PREPARED_STATEMENTS);
- UntypedResultSet resultSet = executeOnceInternal(query);
+ UntypedResultSet resultSet = executeOnceInternalWithPaging(query,
pageSize);
int counter = 0;
+ boolean possibleLeakDetected = false;
+ // accumulate the number of bytes loaded into the prepared cache, if
it exceeds the cache size, assume we've
+ // encountered a leak and stop loading prepared statements.
+ long preparedBytesLoaded = 0L;
+ long cacheCapacity =
QueryProcessor.getPreparedStatementsCacheMaximumCapacity();
for (UntypedResultSet.Row row : resultSet)
{
- if
(onLoaded.accept(MD5Digest.wrap(row.getByteArray("prepared_id")),
- row.getString("query_string"),
- row.has("logged_keyspace") ?
row.getString("logged_keyspace") : null))
+ Prepared prepared =
onLoaded.accept(MD5Digest.wrap(row.getByteArray("prepared_id")),
+ row.getString("query_string"),
+ row.has("logged_keyspace") ?
row.getString("logged_keyspace") : null);
+ if (prepared != null)
+ {
counter++;
+ preparedBytesLoaded += Math.max(0, prepared.pstmntSize);
+ }
+
+ if (counter % pageSize == 0)
+ {
+ if (possibleLeakDetected)
+ {
+ logger.warn("Detected prepared statement cache filling up
during preload after preparing {} " +
Review Comment:
new variant:
> WARN [main] 2025-05-08 21:31:54,578 SystemKeyspace.java:1904 - Detected
prepared statement cache filling up during preload after preparing 463
statements (loaded 1.1 MiB with prepared_statements_cache_size being 1 MiB).
This could be an indication that prepared statements leaked prior to
CASSANDRA-19703 being fixed. Returning early to prevent indefinite startup.
Consider truncating system.prepared_statements to clear out leaked prepared
statements.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]