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

Fix some resource leak in tests #12794

Merged
merged 1 commit into from
Apr 8, 2024

Conversation

Jackie-Jiang
Copy link
Contributor

Under topic #12793

  • Fix the warning message of resource leak in DirectMemory
  • Make resource leak warning more clear
  • Fix resource leak in some tests (not all)

@codecov-commenter
Copy link

codecov-commenter commented Apr 4, 2024

Codecov Report

Attention: Patch coverage is 83.33333% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 61.98%. Comparing base (59551e4) to head (cce90f8).
Report is 207 commits behind head on master.

Files Patch % Lines
...he/pinot/segment/spi/memory/unsafe/MmapMemory.java 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #12794      +/-   ##
============================================
+ Coverage     61.75%   61.98%   +0.23%     
+ Complexity      207      198       -9     
============================================
  Files          2436     2461      +25     
  Lines        133233   134772    +1539     
  Branches      20636    20822     +186     
============================================
+ Hits          82274    83542    +1268     
- Misses        44911    45063     +152     
- Partials       6048     6167     +119     
Flag Coverage Δ
custom-integration1 <0.01% <0.00%> (-0.01%) ⬇️
integration <0.01% <0.00%> (-0.01%) ⬇️
integration1 <0.01% <0.00%> (-0.01%) ⬇️
integration2 0.00% <0.00%> (ø)
java-11 61.95% <83.33%> (+0.24%) ⬆️
java-21 61.85% <83.33%> (+0.23%) ⬆️
skip-bytebuffers-false 61.97% <83.33%> (+0.22%) ⬆️
skip-bytebuffers-true 27.99% <0.00%> (+0.26%) ⬆️
temurin 61.98% <83.33%> (+0.23%) ⬆️
unittests 61.98% <83.33%> (+0.23%) ⬆️
unittests1 46.69% <83.33%> (-0.20%) ⬇️
unittests2 28.00% <0.00%> (+0.27%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Jackie-Jiang Jackie-Jiang merged commit 32a02bc into apache:master Apr 8, 2024
19 checks passed
@Jackie-Jiang Jackie-Jiang deleted the fix_test_resource_leak branch April 8, 2024 01:21
@@ -480,6 +480,8 @@ public void testBigDecimalTooBig() {
Assert.assertThrows(IllegalArgumentException.class, () -> {
mutableSegmentImpl.index(row, defaultMetadata);
});

mutableSegmentImpl.destroy();
Copy link
Contributor

Choose a reason for hiding this comment

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

This won't destroy the segment if the test fails

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently we don't take care of resource leak during test failures. That can be addressed separately

_closed = true;
}
}
Unsafer.UNSAFE.freeMemory(_address);
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 we have to recover the synchronization here. Otherwise a race condition may try to free an address that was already cleaned. That could end up producing a SIGSEV which would kill the server.

We can improve the code using double check

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 whole method is changed to synchronized. I don't remember where I read it, but for modern JVM double checking synchronization is not necessary, especially when we almost always only call it once.

Copy link
Contributor

Choose a reason for hiding this comment

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

You are right, I didn't see that. Anyway, in the other PR I've changed that so we don't need to synchronize in case one thread close this after another.

What newer jvms does for a fact is to make synchronized by default is specially expensive. This is due to:

  • Virtual threads being pinned with synchronize. This is secondary given we don't use them and it should be something that eventually will be improved in (even) more modern JVMs
  • +UseBiasedLocking has been disabled since Java 15 and the plan is to remove it. See https://openjdk.org/jeps/374, this and this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why would multiple threads trying to close the same buffer? If that happens, that means the buffer ownership is messed up. In regular case, this method should only be invoked exactly once.
I think double-checked locking might have performance gain when used in a singleton, but not here

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, lets close the other PR then.

Copy link
Contributor

@gortiz gortiz left a comment

Choose a reason for hiding this comment

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

I've created #12808 to apply the changes I proposed in the comments I've added here.

BTW, Foreign Memory API has been marked as production ready in recently released Java 22. It would be great to have a third alternative where that API is used (only if runtime is >= 22) and probably we should start thinking on removing LArray.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants