Skip to content

CASSANDRA-21474: NoSpamLogger uses unbounded cache that could lead to memory exhaustion - #4993

Open
viktoriiakotovets wants to merge 2 commits into
apache:trunkfrom
viktoriiakotovets:CASSANDRA-21474/trunk
Open

CASSANDRA-21474: NoSpamLogger uses unbounded cache that could lead to memory exhaustion#4993
viktoriiakotovets wants to merge 2 commits into
apache:trunkfrom
viktoriiakotovets:CASSANDRA-21474/trunk

Conversation

@viktoriiakotovets

@viktoriiakotovets viktoriiakotovets commented Aug 4, 2026

Copy link
Copy Markdown

https://issues.apache.org/jira/browse/CASSANDRA-21474): NoSpamLogger uses unbounded cache that could lead to memory exhaustion

Terminating due to class java.lang.OutOfMemoryError/Java heap space
     java.lang.OutOfMemoryError: Java heap space
     	at org.cliffc.high_scale_lib.NonBlockingHashMap$CHM.resize(NonBlockingHashMap.java:863)
     	at org.cliffc.high_scale_lib.NonBlockingHashMap$CHM.access$200(NonBlockingHashMap.java:713)
     	at org.cliffc.high_scale_lib.NonBlockingHashMap.putIfMatch(NonBlockingHashMap.java:649)
     	at org.cliffc.high_scale_lib.NonBlockingHashMap.putIfMatch(NonBlockingHashMap.java:354)
     	at org.cliffc.high_scale_lib.NonBlockingHashMap.putIfAbsent(NonBlockingHashMap.java:321)
     	at org.apache.cassandra.utils.NoSpamLogger.getStatement(NoSpamLogger.java:275)
     	at org.apache.cassandra.utils.NoSpamLogger.getStatement(NoSpamLogger.java:266)
     	at org.apache.cassandra.utils.NoSpamLogger.log(NoSpamLogger.java:246)
     	at org.apache.cassandra.utils.NoSpamLogger.warn(NoSpamLogger.java:226)
     	at org.apache.cassandra.utils.NoSpamLogger.warn(NoSpamLogger.java:231) 

What is the issue

NoSpamLogger uses unbounded cache that could lead to memory exhaustion

What does this PR fix and why was it fixed

This PR replaces the previous NonBlockingHashMap based caching implementation in NoSpamLogger with Caffeine cache to prevent unbounded memory growth and improve cache management

kathirsvn and others added 2 commits August 3, 2026 22:54
…port from CNDB-17505)

### What is the issue
NoSpamLogger uses unbounded cache that could lead to memory exhaustion

### What does this PR fix and why was it fixed
This PR replaces the previous `NonBlockingHashMap` based caching
implementation in `NoSpamLogger` with Caffeine cache to prevent
unbounded memory growth and improve cache management
Comment on lines +274 to +295
.expireAfter(new Expiry<String, NoSpamLogStatement>()
{
@Override
public long expireAfterCreate(String key, NoSpamLogStatement value, long currentTime)
{
return value.expiry();
}

@Override
public long expireAfterUpdate(String key, NoSpamLogStatement value,
long currentTime, long currentDuration)
{
return value.expiry();
}

@Override
public long expireAfterRead(String key, NoSpamLogStatement value,
long currentTime, long currentDuration)
{
return currentDuration;
}
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw, you might prefer

expireAfter(Expiry.writing((String key, NoSpamLogStatement value) -> Duration.ofNanos(value.expiry()))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, but that might need upgrade to 3.2.2 first

@viktoriiakotovets
viktoriiakotovets marked this pull request as ready for review August 5, 2026 21:44
@viktoriiakotovets
viktoriiakotovets marked this pull request as draft August 7, 2026 15:01
@viktoriiakotovets
viktoriiakotovets marked this pull request as ready for review August 7, 2026 15:01
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.

3 participants