Apache9 commented on a change in pull request #264: HBASE-22316 Record the
stack trace for current thread in FutureUtils.get
URL: https://github.com/apache/hbase/pull/264#discussion_r288607514
##########
File path:
hbase-common/src/main/java/org/apache/hadoop/hbase/util/FutureUtils.java
##########
@@ -122,6 +120,41 @@ public static Throwable
unwrapCompletionException(Throwable error) {
return error;
}
+ // This method is used to record the stack trace that calling the
FutureUtils.get method. As in
+ // async client, the retry will be done in the retry timer thread, so the
exception we get from
+ // the CompletableFuture will have a stack trace starting from the root of
the retry timer. If we
+ // just throw this exception out when calling future.get(by unwrapping the
ExecutionException),
+ // the upper layer even can not know where is the exception thrown...
+ // See HBASE-22316.
+ private static void setStackTrace(Throwable error) {
+ StackTraceElement[] localStackTrace =
Thread.currentThread().getStackTrace();
+ StackTraceElement[] originalStackTrace = error.getStackTrace();
+ StackTraceElement[] newStackTrace =
+ new StackTraceElement[localStackTrace.length + originalStackTrace.length
+ 1];
+ System.arraycopy(localStackTrace, 0, newStackTrace, 0,
localStackTrace.length);
+ newStackTrace[localStackTrace.length] =
+ new StackTraceElement("--------Future", "get--------", null, -1);
+ System.arraycopy(originalStackTrace, 0, newStackTrace,
localStackTrace.length + 1,
+ originalStackTrace.length);
+ error.setStackTrace(newStackTrace);
+ }
+
+ private static IOException rethrow(ExecutionException error) throws
IOException {
+ Throwable cause = error.getCause();
+ if (cause instanceof IOException) {
+ setStackTrace(cause);
+ throw (IOException) cause;
+ } else if (cause instanceof RuntimeException) {
+ setStackTrace(cause);
+ throw (RuntimeException) cause;
+ } else if (cause instanceof Error) {
+ setStackTrace(cause);
+ throw (Error) cause;
+ } else {
Review comment:
We just create a new IOException, it will record the stack trace when
creating the new IOException. When you call printStackTrace, you will see a
'Caused by:'
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services