From 28d09cedcfac5b9b6e07ea54fd352541cc9a6f14 Mon Sep 17 00:00:00 2001 From: zhangduo Date: Wed, 11 Apr 2018 14:37:56 +0800 Subject: [PATCH] HBASE-20182 Addendum throw IOException instead of NoServerForRegionException because it is a DoNotRetryRegionException --- .../org/apache/hadoop/hbase/HRegionInfo.java | 8 ++++--- .../client/AsyncNonMetaRegionLocator.java | 23 ++++++++++--------- .../client/ConnectionImplementation.java | 4 ++-- .../hbase/client/RegionInfoBuilder.java | 8 ++++--- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java index e2982bd2f51..fc039265c57 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java @@ -159,9 +159,11 @@ public class HRegionInfo implements RegionInfo, Comparable { } private byte [] endKey = HConstants.EMPTY_BYTE_ARRAY; - // This flag is in the parent of a split while the parent is still referenced - // by daughter regions. We USED to set this flag when we disabled a table - // but now table state is kept up in zookeeper as of 0.90.0 HBase. + // This flag is in the parent of a split while the parent is still referenced by daughter regions. + // We USED to set this flag when we disabled a table but now table state is kept up in zookeeper + // as of 0.90.0 HBase. And now in DisableTableProcedure, finally we will create bunch of + // UnassignProcedures and at the last of the procedure we will set the region state to CLOSED, and + // will not change the offLine flag. private boolean offLine = false; private long regionId = -1; private transient byte [] regionName = HConstants.EMPTY_BYTE_ARRAY; 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 c30de9a21e1..7634b10f929 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 a272ffbeafa..53e4b7fe1b8 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(); diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RegionInfoBuilder.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RegionInfoBuilder.java index fc35afbbf23..3de98606f39 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RegionInfoBuilder.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RegionInfoBuilder.java @@ -149,9 +149,11 @@ public class RegionInfoBuilder { * old region name format. */ - // This flag is in the parent of a split while the parent is still referenced - // by daughter regions. We USED to set this flag when we disabled a table - // but now table state is kept up in zookeeper as of 0.90.0 HBase. + // This flag is in the parent of a split while the parent is still referenced by daughter + // regions. We USED to set this flag when we disabled a table but now table state is kept up in + // zookeeper as of 0.90.0 HBase. And now in DisableTableProcedure, finally we will create bunch + // of UnassignProcedures and at the last of the procedure we will set the region state to + // CLOSED, and will not change the offLine flag. private boolean offLine = false; private boolean split = false; private final long regionId;