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

#2963 Fix NPE when rebalancing #2977

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

jacob-netguardians
Copy link

Issues

  • My PR addresses the following Helix issues and references them in the PR description:

Fixes #2963

Description

  • Here are some details about my PR, including screenshots of any UI changes:

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

  • The following tests are written for this issue:

No added tests.

Commits

  • My commits all reference appropriate Apache Helix GitHub issues in their subject lines. In addition, my commits follow the guidelines from "How to write a good git commit message":
    1. Subject is separated from body by a blank line
    2. Subject is limited to 50 characters (not including Jira issue reference)
    3. Subject does not end with a period
    4. Subject uses the imperative mood ("add", not "adding")
    5. Body wraps at 72 characters
    6. Body explains "what" and "why", not "how"

Code Quality

  • My diff has been formatted using helix-style.xml
    (helix-style-intellij.xml if IntelliJ IDE is used)

jacob-netguardians and others added 2 commits November 19, 2024 10:43
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.
Comment on lines 238 to 241
return controllers.stream()
.filter(controller -> controller._helixManager != null)
.filter(controller -> controller._helixManager.isLeader())
.findAny().orElse(null);
Copy link
Contributor

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???

Copy link
Author

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.

Copy link
Author

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.

Copy link
Contributor

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.

Copy link
Author

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why to change this?

Copy link
Author

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.

Copy link
Contributor

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.

Copy link
Author

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.

Reformatted touched files according to "helix-format"
Reformatted changed file according to the "helix format"
Reformatted touched files according to "helix-format"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GenericHelixControler.getLeaderController does not check for potential conrtroller's _helixMapper's nullity
2 participants