-
Couldn't load subscription status.
- Fork 3.9k
ARROW-2696: [JAVA] enhance AllocationListener with an onFailedAllocation() call #2133
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
Conversation
…o have a separate listener instance
Codecov Report
@@ Coverage Diff @@
## master #2133 +/- ##
==========================================
+ Coverage 86.39% 86.41% +0.02%
==========================================
Files 242 242
Lines 41475 41496 +21
==========================================
+ Hits 35832 35859 +27
+ Misses 5643 5637 -6
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good. Few minor comments.
| final ChildAllocator childAllocator = new ChildAllocator(this, name, initReservation, | ||
| maxAllocation); | ||
| final ChildAllocator childAllocator = new ChildAllocator(listener,this, name, initReservation, | ||
| maxAllocation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weird indenting here and elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Please note that this passed the check style
| // Allocation listener | ||
| // It counts the number of times it has been invoked, and how much memory allocation it has seen | ||
| // When set to 'expand on fail', it attempts to expand the associated allocator's limit | ||
| static class TestAllocationListener implements AllocationListener { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private final?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| } | ||
|
|
||
| int getNumCalls() { | ||
| return numCalls; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should be able to do this count number of calls monitoring using Jmockit's APIs rather than custom building something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, and in fact I had it like that initially. However, I found I was repeating code again and again in the mocks, and it was much easier to just build a custom listener.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack
| // Second try, in case the listener can do something about it | ||
| outcome = this.allocateBytes(actualRequestSize); | ||
| } | ||
| if (!outcome.isOk()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's avoid checking twice in the base case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| } | ||
|
|
||
| private BaseAllocator( | ||
| protected BaseAllocator( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we update the protected constructor/consolidate? Would rather not expose more constructors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how to update/consolidate, short of removing the previous two protected constructors -- which breaks the public interface, and thus probably not the best idea. I cannot use the existing constructors since I need to support listener instances that are not common to the entire hierarchy.
Suggestions are welcome.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is okay changing the constructor signature of BaseAllocator and consolidate overlap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @vancobuca! Generally I feel it's better to catch the OOM exception where it's appropriate because then you have the context of what is being attempted, and take that into account for any retries. But I guess this can be helpful too in some cases, so looks ok to me.
| assertOpen(); | ||
|
|
||
| final ChildAllocator childAllocator = new ChildAllocator(this, name, initReservation, | ||
| final ChildAllocator childAllocator = new ChildAllocator(listener,this, name, initReservation, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing a space between listener,this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, will merge by evening if no more comments
…ion() call (apache#2133) * Explicit listener added to newChildAllocator(), allowing each child to have a separate listener instance * AllocationListener.onFailedAlloc() method added, with default no-op implementation * Call to onFailedAlloc() implemented * Review comments * Review comment: missing space * Consolidated BaseAllocator constructors
On allocation failures, before throwing an out of memory exception, the base allocator makes a listener callback, giving the user code a change to correct its memory usage -- perhaps flush some state; perhaps clear out some caches; or perhaps trade-off some limits.
The AllocationListener has a new method added:
boolean onFailedAllocation(long size, Accountant.AllocationOutcome outcome)
with the semantics: return 'true' if the allocation can be retried (presumably after the code altered the state in some way), or 'false' if not.
If the listener asks for a retry, the allocator retries exactly once.