This is an automated email from the ASF dual-hosted git repository.

marcuse pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 2acc420e1c Avoid iterating all prepared statements when getting 
PreparedStatementsCacheSize metric
2acc420e1c is described below

commit 2acc420e1c511bc65af90b950504a8e1e8c70170
Author: Marcus Eriksson <[email protected]>
AuthorDate: Wed Oct 15 14:20:35 2025 +0200

    Avoid iterating all prepared statements when getting 
PreparedStatementsCacheSize metric
    
    Patch by marcuse; reviewed by Dmitry Konstantinov for CASSANDRA-21038
---
 CHANGES.txt                                            | 1 +
 src/java/org/apache/cassandra/cql3/QueryProcessor.java | 9 +++------
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/CHANGES.txt b/CHANGES.txt
index 77caf7cb25..5a5022e418 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 5.1
+ * Avoid iterating all prepared statements when getting 
PreparedStatementsCacheSize metric (CASSANDRA-21038)
  * Reduce performance impact of TableMetadataRef.get and 
KeyspaceMetadataRef.get (CASSANDRA-20465)
  * Improve CMS initialization (CASSANDRA-21036)
  * Introducing comments and security labels for schema elements 
(CASSANDRA-20943)
diff --git a/src/java/org/apache/cassandra/cql3/QueryProcessor.java 
b/src/java/org/apache/cassandra/cql3/QueryProcessor.java
index 8f22bda5c8..7cb1d668e0 100644
--- a/src/java/org/apache/cassandra/cql3/QueryProcessor.java
+++ b/src/java/org/apache/cassandra/cql3/QueryProcessor.java
@@ -181,12 +181,9 @@ public class QueryProcessor implements QueryHandler
 
     public static long preparedStatementsCacheMemoryUsedBytes()
     {
-        long preparedStatementsCacheMemoryUsedBytes = 0;
-        for (Map.Entry<MD5Digest, Prepared> entry : 
preparedStatements.asMap().entrySet())
-        {
-            preparedStatementsCacheMemoryUsedBytes += 
getSizeOfPreparedStatementForCache(entry.getKey(), entry.getValue());
-        }
-        return preparedStatementsCacheMemoryUsedBytes;
+        return preparedStatements.policy().eviction()
+                                 .map(p -> p.weightedSize().orElse(0L))
+                                 .orElse(0L);
     }
 
     // Work around initialization dependency


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to