-
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?
Changes from 2 commits
c76a46e
dfe0076
3645d2b
9266487
2209337
e2426c0
e8d1432
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
import org.apache.helix.common.DedupEventProcessor; | ||
import org.apache.helix.controller.stages.AttributeName; | ||
import org.apache.helix.controller.stages.ClusterEvent; | ||
import org.apache.helix.util.ExecutorTaskUtil; | ||
|
||
public class AbstractBaseStage implements Stage { | ||
protected String _eventId; | ||
|
@@ -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 commentThe 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 commentThe 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 commentThe 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 commentThe 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. |
||
if (service != null) { | ||
return service.submit(task); | ||
return service.submit(ExecutorTaskUtil.wrap(task)); | ||
} | ||
return null; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package org.apache.helix.util; | ||
|
||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import java.util.concurrent.Callable; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class ExecutorTaskUtil { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(ExecutorTaskUtil.class); | ||
|
||
/** | ||
* Wrap a callable so that any raised exception is logged | ||
* (can be interesting in case the callable is used as a completely asynchronous task | ||
* fed to an {@link java.util.concurrent.ExecutorService}), for which we are never | ||
* calling any of the {@link java.util.concurrent.Future#get()} or {@link java.util.concurrent.Future#get(long, java.util.concurrent.TimeUnit)} | ||
* methods. | ||
*/ | ||
public static <T> Callable<T> wrap(Callable<T> callable) { | ||
return () -> { | ||
try { | ||
return callable.call(); | ||
} catch (Throwable t) { | ||
LOG.error("Callable run on thread {} raised an exception and exited", Thread.currentThread().getName(), t); | ||
throw t; | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* Wrap a runnable so that any raised exception is logged | ||
* (can be interesting in case the callable is used as a completely asynchronous task | ||
* fed to an {@link java.util.concurrent.ExecutorService}), for which we are never | ||
* calling any of the {@link java.util.concurrent.Future#get()} or {@link java.util.concurrent.Future#get(long, java.util.concurrent.TimeUnit)} | ||
* methods. | ||
*/ | ||
public static Runnable wrap(Runnable runnable) { | ||
return () -> { | ||
try { | ||
runnable.run(); | ||
} catch (Throwable t) { | ||
LOG.error("Runnable run on thread {} raised an exception and exited", Thread.currentThread().getName(), t); | ||
throw t; | ||
} | ||
}; | ||
} | ||
} |
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.