Skip to content

Commit 2acc420

Browse files
committed
Avoid iterating all prepared statements when getting PreparedStatementsCacheSize metric
Patch by marcuse; reviewed by Dmitry Konstantinov for CASSANDRA-21038
1 parent a0f97a9 commit 2acc420

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
5.1
2+
* Avoid iterating all prepared statements when getting PreparedStatementsCacheSize metric (CASSANDRA-21038)
23
* Reduce performance impact of TableMetadataRef.get and KeyspaceMetadataRef.get (CASSANDRA-20465)
34
* Improve CMS initialization (CASSANDRA-21036)
45
* Introducing comments and security labels for schema elements (CASSANDRA-20943)

src/java/org/apache/cassandra/cql3/QueryProcessor.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,9 @@ public static int preparedStatementsCount()
181181

182182
public static long preparedStatementsCacheMemoryUsedBytes()
183183
{
184-
long preparedStatementsCacheMemoryUsedBytes = 0;
185-
for (Map.Entry<MD5Digest, Prepared> entry : preparedStatements.asMap().entrySet())
186-
{
187-
preparedStatementsCacheMemoryUsedBytes += getSizeOfPreparedStatementForCache(entry.getKey(), entry.getValue());
188-
}
189-
return preparedStatementsCacheMemoryUsedBytes;
184+
return preparedStatements.policy().eviction()
185+
.map(p -> p.weightedSize().orElse(0L))
186+
.orElse(0L);
190187
}
191188

192189
// Work around initialization dependency

0 commit comments

Comments
 (0)