From 8744f332682b1bb735e9f65c9904ef86f57568d3 Mon Sep 17 00:00:00 2001 From: zhangduo Date: Mon, 9 Apr 2018 14:47:50 +0800 Subject: [PATCH] HBASE-20182 Throw IOException instead of NoServerForRegionException because it is a DoNotRetryRegionException --- .../hbase/client/AsyncNonMetaRegionLocator.java | 23 +++++++++++----------- .../hbase/client/ConnectionImplementation.java | 4 ++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.java index c30de9a..7634b10 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.java @@ -269,12 +269,7 @@ class AsyncNonMetaRegionLocator { } // return whether we should stop the scan - private boolean onScanNext(TableName tableName, LocateRequest req, Result result, - Throwable error) { - if (error != null) { - complete(tableName, req, null, error); - return true; - } + private boolean onScanNext(TableName tableName, LocateRequest req, Result result) { RegionLocations locs = MetaTableAccessor.getRegionLocations(result); LOG.debug("The fetched location of '{}', row='{}', locateType={} is {}", tableName, Bytes.toStringBinary(req.row), req.locateType, locs); @@ -298,7 +293,7 @@ class AsyncNonMetaRegionLocator { } if (loc.getServerName() == null) { complete(tableName, req, null, - new NoServerForRegionException( + new IOException( String.format("No server address listed for region '%s', row='%s', locateType=%s", info.getRegionNameAsString(), Bytes.toStringBinary(req.row), req.locateType))); return true; @@ -370,22 +365,28 @@ class AsyncNonMetaRegionLocator { private boolean completeNormally = false; + private boolean tableNotFound = true; + @Override public void onError(Throwable error) { - onScanNext(tableName, req, null, error); + complete(tableName, req, null, error); } @Override public void onComplete() { - if (!completeNormally) { - onScanNext(tableName, req, null, new TableNotFoundException(tableName)); + if (tableNotFound) { + complete(tableName, req, null, new TableNotFoundException(tableName)); + } else if (!completeNormally) { + complete(tableName, req, null, new IOException( + "Unable to find region for " + Bytes.toStringBinary(req.row) + " in " + tableName)); } } @Override public void onNext(Result[] results, ScanController controller) { for (Result result : results) { - if (onScanNext(tableName, req, result, null)) { + tableNotFound = false; + if (onScanNext(tableName, req, result)) { completeNormally = true; controller.terminate(); return; diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java index a272ffb..53e4b7f 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java @@ -836,7 +836,7 @@ class ConnectionImplementation implements ClusterConnection, Closeable { if (tableNotFound) { throw new TableNotFoundException(tableName); } else { - throw new NoServerForRegionException( + throw new IOException( "Unable to find region for " + Bytes.toStringBinary(row) + " in " + tableName); } } @@ -864,7 +864,7 @@ class ConnectionImplementation implements ClusterConnection, Closeable { // the parent in the above condition, so we may have already reached a region which does // not contains us. if (!regionInfo.containsRow(row)) { - throw new NoServerForRegionException( + throw new IOException( "Unable to find region for " + Bytes.toStringBinary(row) + " in " + tableName); } ServerName serverName = locations.getRegionLocation(replicaId).getServerName(); -- 2.7.4