-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-26942 cache region locations when getAllRegionLocations #4335
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c73a751
HBASE-26942 cache region locations when getAllRegionLocations
329ef8b
replace future.whenComplete with FutureUtils.addListener
5c53f68
fix a re-complete future problem
3e1530e
add a test case for getting region locations exceptionally
9ccecce
fix the unrelated test case
98d106d
catch the exception and complete future exceptionnal while adding reg…
4f334a0
add a test case for getting region locations exceptionally
7da42da
fix a re-complete future mistake
c5798cd
remove the extra future
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 need to handle the case where error != null here. In that case I believe locs will be null, and you'll get an NPE below. Can you add a test for this?
Also, I think the convention in the async client is to use FutureUtils.addListener. The benefit there is it will also handle catching any errors thrown by your own callback.
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 your great suggestions.
From my understanding, if the error is not null, the get method on this future will get an ExecutionException, the region location caching code will not run, therefore there is no NPR problem here (Correct me if I am wrong). Based on this consideration I didn't handle the case error != null. But I agree that it's better to use FutureUtils.addListener. Thanks for reminding me about this. I'll address it as soon as possible.
Also, Congratulations on being HBase committer. @bbeaudreault
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 congrats!
Here's the javadoc for whenComplete:
My understanding of that is, if there were an error the callback would get called with
locs == nullanderror != null. And then, your callback should not throw an exception. But since you're callback is called with locs == null, your callback is-was would throw an NPE. Then basd on the last 2 sentences, it would be the same result for the end-user, but they'd see an NPE instead of the originating error.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.
In terms of your recent change, I don't think it's necessary to re-complete the future within the addListener callback. I've been looking through other usages of the method and the only time they seem to do that is in cases where you're chaining together multiple async calls with one high level future. I could definitely be wrong about that though, and I'm not sure there's a harm in re-completing.
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 your patient reply. It helps me a lot.
After re-reading the doc and doing some tests, it turns out I was wrong before. Yes, there will indeed be NPE problem here. But based on the doc above and my tests, the user will still see the originating error. If the error is not null here, the future will completed exceptionally with this error no matter the supplied action throws an exception or not. Am I right?
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.
No problem, thank you for verifying in tests. I think now that you are using addListener, you are correct. This is part of the benefit of addListener, but still better to avoid the exception altogether. I believe in your original implementation with your own
withCompletecall it would have resulted in an NPE to the user (but I could be wrong, it's been a while).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.
Would you mind including a test case in TestAsyncNonMetaRegionLocator for the exceptional 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.
OK. I'll address it as soon as possible. Thanks.