Skip to content

fix leaky segment reference on segment drop#18782

Merged
gianm merged 3 commits intoapache:masterfrom
clintropolis:fix-leaky-segment-reference-on-drop
Nov 29, 2025
Merged

fix leaky segment reference on segment drop#18782
gianm merged 3 commits intoapache:masterfrom
clintropolis:fix-leaky-segment-reference-on-drop

Conversation

@clintropolis
Copy link
Copy Markdown
Member

@clintropolis clintropolis commented Nov 26, 2025

Description

Fixes an unfortunate bug where we leak segment references on dropping segments, preventing them from actually being dropped - the files are deleted on disk, but the buffer is not unmapped since it is tied to reference counter, so the fd is held open until the process restarts. Affects version 35, so probably need to do a patch release.

try (final Closer closer = Closer.create()) {
final Optional<Segment> oldSegment = cacheManager.acquireCachedSegment(oldSegmentRef);
long numberOfRows = oldSegment.map(segment -> {
closer.register(segment);
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.

minor nit: the oldSegment.map here seems a bit unnecessary, could be more readable if use simple if oldSegment.isPresent()

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.

To me the structure seems reasonable, since for regular segments it is doing return countInspector.getNumRows() and the return val numberOfRows ends up going to the dataSourceState.removeSegment call.

Comment on lines +131 to +134
public int getNumRows()
{
return 1234;
}
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.

This seems unused?

@gianm gianm added this to the 35.0.1 milestone Nov 29, 2025
@gianm gianm merged commit 22990f2 into apache:master Nov 29, 2025
57 checks passed
@clintropolis clintropolis deleted the fix-leaky-segment-reference-on-drop branch December 4, 2025 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants