Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CNDB-11092 main: Fix IndexInputLeakDetector #1310

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

adelapena
Copy link

Fix IndexInputLeakDetector, which has been mostly no-op for a long time. It detects opened index inputs that haven't been closed. It seemed originally designed to also detect attempts at closing index inputs that had already been closed, but the current usage seems to do that kind of duplicated closing, which is probably ok if the operation is idempotent.

@adelapena adelapena self-assigned this Sep 30, 2024
@pkolaczk pkolaczk self-requested a review October 2, 2024 10:09
Copy link

@pkolaczk pkolaczk left a comment

Choose a reason for hiding this comment

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

Overall looks good, but I have one concern about synchronization of the set.

Comment on lines 58 to 59
private static final IndexFileUtils instance = new IndexFileUtils(defaultWriterOption);
private static IndexFileUtils overrideInstance = null;
Copy link

Choose a reason for hiding this comment

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

It's a bit nitpicking, but is there any particular reason we use a combination of two variables instead of just marking the first one non-final and updating it in place? Then we wouldn't need to change all the stuff from .instance to .instance() (which is fine, but I'm worried it increases the conflict area in any merges we do e.g. wit apache). Is there any downside of using a single field?

Copy link
Author

Choose a reason for hiding this comment

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

Not sure why it was done this way, this comes from a previous set of changes in main-5.0. Agree on the single variable. Regarding having getters and setters, the only reason that occurs to me is perhaps having less visibility in the setter? In any case, I have changed it to the simplest approach.

By the way, regarding Apache we have CASSANDRA-19961 to update this there too, albeit in that case the problem is that some inputs are not being closed.


public class TrackingIndexFileUtils extends IndexFileUtils
{
private final Map<TrackingIndexInput, String> openInputs = Collections.synchronizedMap(new HashMap<>());
private final Set<TrackingIndexInput> closedInputs = new HashSet<>();
Copy link

Choose a reason for hiding this comment

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

bug: That should be synchronized set, as inputs can be closed by any threads. The synchronized on close does not cut it because it does not synchronize on this common utils object, but it synchronizes on the individual IndexInput. So two different index inputs closing at the same time would attempt to insert into this set concurrently.

Copy link
Author

Choose a reason for hiding this comment

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

Right, good catch, fixed.

@adelapena
Copy link
Author

Mmh, it seems the fixed detector has found some leaks. Looking into it.

@adelapena
Copy link
Author

The found leak was due to SortedTermsReader.Cursor not closing blockOffsets, which is done in main-5.0 but not here in main. Fixed.

@adelapena
Copy link
Author

It seems the issues reported by Sonar are due to the changes around IndexFileUtils discussed above.

Copy link

sonarcloud bot commented Oct 2, 2024

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