You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by zh...@apache.org on 2020/09/20 03:35:39 UTC
[hbase] branch branch-2.2 updated: HBASE-25066 Use
FutureUtils.rethrow in AsyncTableResultScanner to better catch the stack
trace (#2420)
This is an automated email from the ASF dual-hosted git repository.
zhangduo pushed a commit to branch branch-2.2
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-2.2 by this push:
new edf28f1 HBASE-25066 Use FutureUtils.rethrow in AsyncTableResultScanner to better catch the stack trace (#2420)
edf28f1 is described below
commit edf28f172d7501480f9924f4039e3e80d84443b6
Author: Duo Zhang <zh...@apache.org>
AuthorDate: Sun Sep 20 11:25:22 2020 +0800
HBASE-25066 Use FutureUtils.rethrow in AsyncTableResultScanner to better catch the stack trace (#2420)
Signed-off-by: Guanghao Zhang <zg...@apache.org>
---
.../hbase/client/AsyncTableResultScanner.java | 9 +++----
.../org/apache/hadoop/hbase/util/FutureUtils.java | 30 ++++++++++++----------
.../apache/hadoop/hbase/util/TestFutureUtils.java | 2 +-
3 files changed, 22 insertions(+), 19 deletions(-)
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncTableResultScanner.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncTableResultScanner.java
index 9b97e93..21ff4b7 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncTableResultScanner.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncTableResultScanner.java
@@ -23,13 +23,13 @@ import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.ArrayDeque;
import java.util.Queue;
-
+import org.apache.hadoop.hbase.client.metrics.ScanMetrics;
+import org.apache.hadoop.hbase.util.FutureUtils;
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.hadoop.hbase.client.metrics.ScanMetrics;
+
import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting;
-import org.apache.hbase.thirdparty.com.google.common.base.Throwables;
/**
* The {@link ResultScanner} implementation for {@link AsyncTable}. It will fetch data automatically
@@ -140,8 +140,7 @@ class AsyncTableResultScanner implements ResultScanner, AdvancedScanResultConsum
return null;
}
if (error != null) {
- Throwables.propagateIfPossible(error, IOException.class);
- throw new IOException(error);
+ FutureUtils.rethrow(error);
}
try {
wait();
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/FutureUtils.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/FutureUtils.java
index 8aadb2d..1a39759 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/FutureUtils.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/FutureUtils.java
@@ -136,19 +136,23 @@ public final class FutureUtils {
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;
+ /**
+ * If we could propagate the given {@code error} directly, we will fill the stack trace with the
+ * current thread's stack trace so it is easier to trace where is the exception thrown. If not, we
+ * will just create a new IOException and then throw it.
+ */
+ public static IOException rethrow(Throwable error) throws IOException {
+ if (error instanceof IOException) {
+ setStackTrace(error);
+ throw (IOException) error;
+ } else if (error instanceof RuntimeException) {
+ setStackTrace(error);
+ throw (RuntimeException) error;
+ } else if (error instanceof Error) {
+ setStackTrace(error);
+ throw (Error) error;
} else {
- throw new IOException(cause);
+ throw new IOException(error);
}
}
@@ -162,7 +166,7 @@ public final class FutureUtils {
} catch (InterruptedException e) {
throw (IOException) new InterruptedIOException().initCause(e);
} catch (ExecutionException e) {
- throw rethrow(e);
+ throw rethrow(e.getCause());
}
}
diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestFutureUtils.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestFutureUtils.java
index d560b24..cae48ed 100644
--- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestFutureUtils.java
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestFutureUtils.java
@@ -18,8 +18,8 @@
package org.apache.hadoop.hbase.util;
import static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;