Skip to content

HDDS-16654. Replace usage of deprecated finalize() in OM - #11376

Open
anuragp010 wants to merge 2 commits into
apache:masterfrom
anuragp010:HDDS-16654
Open

anuragp010 wants to merge 2 commits into
apache:masterfrom
anuragp010:HDDS-16654

Conversation

@anuragp010

@anuragp010 anuragp010 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

OmSnapshot overrode Object.finalize() to warn if its DBStore wasn't closed before GC. But finalize() is deprecated for removal (JEP 421). This PR replaces it with LeakDetector, a ReferenceQueue-based leak tracker, used in the same way by ManagedRocksObjectUtils. A static LEAK_DETECTOR tracks each OmSnapshot instance via LEAK_DETECTOR.track(this, reporter). If the instance is dropped unclosed, the detector's background thread reports the same warning the old finalize() did, once the object is actually collected.

Generated with Claude Code.

What is the link to the Apache JIRA

HDDS-16654

How was this patch tested?

  1. Newly added Unit Tests

@github-actions github-actions Bot added the om label Oct 1, 2026

@chihsuan chihsuan left a comment

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.

Thanks for working on this! @anuragp010 Looks good overall, just two small notes. 👍

* opened; this exercises the constructor's LeakDetector registration and the GC-triggered report.
*/
@Test
void leakDetectedForUnclosedSnapshot() throws Exception {

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.

Should we also add a test for the closed case? Right now the tests still pass even without leakTracker.close().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @chihsuan ! Yes that's a good point. I have added it.

// Close DB
omMetadataManager.getStore().close();
// Closed properly: stop tracking so the leak reporter does not fire at GC.
leakTracker.close();

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.

nit: Could we use try/finally here, like OzoneClient#close? That way the tracker is still released if the store close throws.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Makes sense - have added it.

@adoroszlai adoroszlai left a comment

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.

Thanks @anuragp010 for the patch.

Comment on lines +365 to +370
return () -> {
if (!store.isClosed()) {
// Print hash code for debugging
LOG.warn("{} is not closed properly. snapshotName: {}", store, snapshotName);
}
};

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.

I don't think we should keep a strong reference to store in the leak reporter.

  • I think checking store.isClosed() is unnecessary. LeakTracker discards properly closed instances and will not call the reporter.
  • For "print hash code for debugging", we should get that eagerly and keep reference only to the string to be included in the message.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @adoroszlai ! Right, makes sense. I have addressed this.

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