-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-24750 : All ExecutorService should use guava ThreadFactoryBuilder #2196
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
|
🎊 +1 overall
This message was automatically generated. |
| Threads.newDaemonThreadFactory("rs(" + name + ")-backup")); | ||
| executor = new ThreadPoolExecutor(1, threads, keepAlive, TimeUnit.SECONDS, | ||
| new LinkedBlockingQueue<>(), | ||
| new ThreadFactoryBuilder().setNameFormat("rs(" + name + ")-backup-pool-%d").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.
Should the thread names follow existing format (dropping '-pool') ?
People may have got used to the current format during debugging.
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.
The reason why I appended -pool is to actually adhere with current format only. We add -pool in Threads class internally.
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.
@tedyu could you please review?
Thanks
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.
The change is fine.
|
🎊 +1 overall
This message was automatically generated. |
|
🎊 +1 overall
This message was automatically generated. |
| return boundedCachedThreadPool; | ||
| } | ||
|
|
||
| public static ThreadPoolExecutor getBoundedCachedThreadPool(int maxCachedThread, long timeout, |
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 wonder if these getBoundedCachedThreadPool methods could be replace to calls to methods directly on java.util.concurrent.Executors. I think we'd need to evaluate on a case-by-case basis how the resulting pools are being used and if they're constructed to correctly match the use-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.
Agree, at least for now, let me make callers use getBoundedCachedThreadPool with ThreadFactoryBuilder input and only keep that version of getBoundedCachedThreadPool in Threads class.
hbase-server/src/test/java/org/apache/hadoop/hbase/procedure/SimpleRSProcedureManager.java
Outdated
Show resolved
Hide resolved
|
🎊 +1 overall
This message was automatically generated. |
|
🎊 +1 overall
This message was automatically generated. |
|
🎊 +1 overall
This message was automatically generated. |
ndimiduk
left a comment
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.
Nice cleanup here.
| Thread t = namedFactory.newThread(r); | ||
| if (handler != null) { | ||
| t.setUncaughtExceptionHandler(handler); | ||
| } else { |
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.
@virajjasani Sorry,I did not explain clear, I wonder if here may cause Inconsistent? In guava's builder class, if we do not assign UncaughtExceptionHandler, the UncaughtExceptionHandler will be null, not LOGGING_EXCEPTION_HANDLER
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.
compare with hbase-shaded-miscellaneous
private static ThreadFactory doBuild(ThreadFactoryBuilder builder) {
final String nameFormat = builder.nameFormat;
final Boolean daemon = builder.daemon;
final Integer priority = builder.priority;
final UncaughtExceptionHandler uncaughtExceptionHandler = builder.uncaughtExceptionHandler;
final ThreadFactory backingThreadFactory =
(builder.backingThreadFactory != null)
? builder.backingThreadFactory
: Executors.defaultThreadFactory();
final AtomicLong count = (nameFormat != null) ? new AtomicLong(0) : null;
return new ThreadFactory() {
@Override
public Thread newThread(Runnable runnable) {
Thread thread = backingThreadFactory.newThread(runnable);
if (nameFormat != null) {
thread.setName(format(nameFormat, count.getAndIncrement()));
}
if (daemon != null) {
thread.setDaemon(daemon);
}
if (priority != null) {
thread.setPriority(priority);
}
if (uncaughtExceptionHandler != null) {
thread.setUncaughtExceptionHandler(uncaughtExceptionHandler);
}
return thread;
}
};
}
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 see, you are correct. We should not see issue from end result viewpoint if we are just executing some tasks and some exception interrupts executor thread specifically when ThreadGroup takes care of it:
public void uncaughtException(Thread t, Throwable e) {
if (parent != null) {
parent.uncaughtException(t, e);
} else {
Thread.UncaughtExceptionHandler ueh =
Thread.getDefaultUncaughtExceptionHandler();
if (ueh != null) {
ueh.uncaughtException(t, e);
} else if (!(e instanceof ThreadDeath)) {
System.err.print("Exception in thread \""
+ t.getName() + "\" ");
e.printStackTrace(System.err);
}
}
}
However, if we want to maintain the same log present in LOGGING_EXCEPTION_HANDLER as default (which is what used to happen before this patch) behaviour, we should update the corresponding usages with uncaught exception handler as LOGGING_EXCEPTION_HANDLER in all places.
Let me raise a PR for 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.
thank you for explaining about it.
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 @nyl3532016 .
FYI #2231
…er (#2214) Closes #2196 Signed-off-by: Nick Dimiduk <[email protected]> Signed-off-by: Ted Yu <[email protected]> Signed-off-by: niuyulin <[email protected]>
…er (apache#2214) Closes apache#2196 Signed-off-by: Nick Dimiduk <[email protected]> Signed-off-by: Ted Yu <[email protected]> Signed-off-by: niuyulin <[email protected]>
Jira: https://issues.apache.org/jira/browse/HBASE-24750