-
Notifications
You must be signed in to change notification settings - Fork 228
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
#2963 Fix NPE when rebalancing #2977
base: master
Are you sure you want to change the base?
#2963 Fix NPE when rebalancing #2977
Conversation
In case _helixManager in one of the known controllers is _null_, finding the "leader controller" can lead to a NPE. When run as an asynchronous task, the NPE may not even be logged, and the task finishes without any trace, hence the addition of ExecutorTaskUtil class to wrap callables/runnables in such a manner that such an exception at least gets logged.
return controllers.stream() | ||
.filter(controller -> controller._helixManager != null) | ||
.filter(controller -> controller._helixManager.isLeader()) | ||
.findAny().orElse(null); |
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.
Are you sure using Helix format???
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.
Sorry, not sure I understand what you mean with "helix format". Is the formatting of the lines somehow faulty? From what I see the ".filter(...)" lines are indented the same way as the ".findAny()" line was before, so I don't get what is wrong, sorry.
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 now understood what you meant. I applied the format to all the files I touched. I don't necessarily find it more readable, but then I guess this is also a question of taste. Hopefully this is ok now.
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.
Please make sure you load the Helix intellij / eclipse auto code formatter.
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. reverted global reformatting and only applied it on the lines I had changed initially.
@@ -64,9 +65,9 @@ public String getStageName() { | |||
return className; | |||
} | |||
|
|||
public static <T> Future asyncExecute(ExecutorService service, Callable<T> task) { | |||
public static <T> Future<T> asyncExecute(ExecutorService service, Callable<T> task) { |
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.
Why to change 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.
Following the boy-scout rule, every time I see something which could be easily improved, I try to do so.
Here for type-safety, it is useful for the caller of this method to know/remember that the "get" method on the future they just got would supply an object of type T instead of an object of any forgotten type.
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 minimize the this kind of change. The reason is that Helix release not only support java 11 but backward compatible with 8.
Any this kind of "improvement" for working code may break backward build.
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.
This "improvement" would have been compatible with Java 1.5, for all I know, but OK, your choice. Rolled back.
Issues
Fixes #2963
Description
In case _helixManager in one of the known controllers is null, finding the "leader controller" can lead to a NPE.
I added a check for _helixManager member's nullity in the helix controller before using it to determine if a controller is leader or not.
When run as an asynchronous task, the NPE may not even be logged, and the task abruptly finishes without any trace, hence the addition of ExecutorTaskUtil class to wrap callables/runnables in such a manner that such an exception at least gets logged.
Tests
No added tests.
Commits
Code Quality
(helix-style-intellij.xml if IntelliJ IDE is used)