Skip to content

Conversation

@yifan-c
Copy link
Contributor

@yifan-c yifan-c commented Sep 5, 2025

Patch by Yifan Cai, James Berragan; Reviewed by TBD for CASSANALYTICS-87

Patch by Yifan Cai, James Berragan; Reviewed by TBD for CASSANALYTICS-87
Comment on lines +111 to +132
.removalListener(notification -> {
// The function is to eliminate the LEAK DETECTED errors.
// How it happens:
// 1. AutoCloseable objects (e.g. IndexSummary and BloomFilter) are evicted from cache
// 2. JVM GC and the close method is not called explicitly to reduce the reference count
// 3. Reference-Reaper thread release the object and print the LEAK DETECTED error
// The function fixes it by closing the object when evicting.
Object val = notification.getValue();
if (val instanceof AutoCloseable)
{
String typeLiteral = val.getClass().getName();
try
{
LOGGER.debug("Evicting auto-closable of type: {}", typeLiteral);
((AutoCloseable) val).close();
}
catch (Exception e)
{
LOGGER.error("Exception closing cached instance of {}", typeLiteral, e);
}
}
})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If commenting it out, the new test fails with "LEAK DETECTED" errors

@Override // The method is expected to be called when evicting the object from sstable cache; do not call it explicitly.
public void close() throws Exception
{
indexSummary.close();
Copy link
Contributor

Choose a reason for hiding this comment

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

Be careful with this, I remember trying this once before but it resulted in seg. faults (SIGSEGV).

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is ref. counted in the org.apache.cassandra.io.util.Memory class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack. I will double check. Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should be fixed in 61add5b

assertThat(SSTableCache.INSTANCE.containsSummary(sstable)).isFalse();
// trigger GC and wait a bit before asserting LEAK DETECTED is not logged.
System.gc();
Thread.sleep(1000);
Copy link
Member

Choose a reason for hiding this comment

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

NIT: We could use Awaitility, if we consider more places that need waiting for asynchronous condition. Kafka developers do not pull the dependency (even though only for test), but implemented a simple function to do the same here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to Uninterruptibles. I was under the impression that we removed guava from the repo. But looks like we still have them as test dependency.


public class IndexSummaryComponent implements AutoCloseable
{
private final IndexSummary indexSummary;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Extracted the IndexSummaryComponent out from SummaryDbUtils, since IndexSummary is version specific.

* @throws IOException io exception
*/
@Nullable
static IndexSummaryComponent readSummary(InputStream summaryStream,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The read method implementation is version specific too.

*/
public IndexSummary summarySharedCopy()
{
return indexSummary.sharedCopy();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

get a shared copy, so that if IndexSummaryComponent is closed, the underlying indexSummary is still not freed (since reference count > 0)

@yifan-c
Copy link
Contributor Author

yifan-c commented Sep 10, 2025

slf4j-test is too slow. So I have to remove the test in 4190d40

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