Skip to content

Commit b1d4878

Browse files
ArthurSXL8saintstack
authored andcommitted
HBASE-22700 refactor isMetaClearingException (apache#578)
1 parent d9184c3 commit b1d4878

File tree

5 files changed

+37
-17
lines changed

5 files changed

+37
-17
lines changed

hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncRegionLocatorHelper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import static org.apache.hadoop.hbase.exceptions.ClientExceptionsUtil.findException;
2121
import static org.apache.hadoop.hbase.exceptions.ClientExceptionsUtil.isMetaClearingException;
22+
import static org.apache.hadoop.hbase.exceptions.ClientExceptionsUtil.isRegionServerOverloadedException;
2223

2324
import java.util.Arrays;
2425
import java.util.Optional;
@@ -67,7 +68,8 @@ static void updateCachedLocationOnError(HRegionLocation loc, Throwable exception
6768
LOG.debug("The actual exception when updating {} is {}", loc,
6869
cause != null ? cause.toString() : "none");
6970
}
70-
if (cause == null || !isMetaClearingException(cause)) {
71+
if (cause == null || !isMetaClearingException(cause)
72+
|| isRegionServerOverloadedException(cause)) {
7173
LOG.debug("Will not update {} because the exception is null or not the one we care about",
7274
loc);
7375
return;

hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncRequestFutureImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,8 @@ private void receiveGlobalFailure(
711711
// Do not use the exception for updating cache because it might be coming from
712712
// any of the regions in the MultiAction.
713713
updateCachedLocations(server, regionName, row,
714-
ClientExceptionsUtil.isMetaClearingException(t) ? null : t);
714+
ClientExceptionsUtil.isMetaClearingException(t) &&
715+
!ClientExceptionsUtil.isRegionServerOverloadedException(t) ? null : t);
715716
for (Action action : e.getValue()) {
716717
Retry retry = manageError(
717718
action.getOriginalIndex(), action.getAction(), canRetry, t, server);
@@ -913,7 +914,8 @@ private void invokeCallBack(byte[] regionName, byte[] row, CResult result) {
913914
}
914915

915916
private void cleanServerCache(ServerName server, Throwable regionException) {
916-
if (ClientExceptionsUtil.isMetaClearingException(regionException)) {
917+
if (ClientExceptionsUtil.isMetaClearingException(regionException)
918+
&& !ClientExceptionsUtil.isRegionServerOverloadedException(regionException)) {
917919
// We want to make sure to clear the cache in case there were location-related exceptions.
918920
// We don't to clear the cache for every possible exception that comes through, however.
919921
asyncProcess.connection.clearCaches(server);

hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1911,7 +1911,8 @@ public void updateCachedLocations(final TableName tableName, byte[] regionName,
19111911
RegionInfo regionInfo = oldLocation.getRegion();
19121912
Throwable cause = ClientExceptionsUtil.findException(exception);
19131913
if (cause != null) {
1914-
if (!ClientExceptionsUtil.isMetaClearingException(cause)) {
1914+
if (!ClientExceptionsUtil.isMetaClearingException(cause)
1915+
|| ClientExceptionsUtil.isRegionServerOverloadedException(cause)) {
19151916
// We know that the region is still on this region server
19161917
return;
19171918
}

hbase-client/src/main/java/org/apache/hadoop/hbase/exceptions/ClientExceptionsUtil.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.apache.hadoop.hbase.CallDroppedException;
3333
import org.apache.hadoop.hbase.CallQueueTooBigException;
3434
import org.apache.hadoop.hbase.DoNotRetryIOException;
35-
import org.apache.hadoop.hbase.MultiActionResultTooLarge;
3635
import org.apache.hadoop.hbase.NotServingRegionException;
3736
import org.apache.hadoop.hbase.RegionTooBusyException;
3837
import org.apache.hadoop.hbase.RetryImmediatelyException;
@@ -59,18 +58,28 @@ public static boolean isMetaClearingException(Throwable cur) {
5958
if (cur == null) {
6059
return true;
6160
}
62-
return !isSpecialException(cur) || (cur instanceof RegionMovedException)
63-
|| cur instanceof NotServingRegionException;
61+
return !isMetaCachePreservingException(cur);
6462
}
6563

66-
public static boolean isSpecialException(Throwable cur) {
67-
return (cur instanceof RegionMovedException || cur instanceof RegionOpeningException
68-
|| cur instanceof RegionTooBusyException || cur instanceof RpcThrottlingException
69-
|| cur instanceof MultiActionResultTooLarge || cur instanceof RetryImmediatelyException
70-
|| cur instanceof CallQueueTooBigException || cur instanceof CallDroppedException
71-
|| cur instanceof NotServingRegionException || cur instanceof RequestTooBigException);
64+
public static boolean isRegionServerOverloadedException(Throwable t) {
65+
t = findException(t);
66+
return isInstanceOfRegionServerOverloadedException(t);
67+
}
68+
69+
private static boolean isInstanceOfRegionServerOverloadedException(Throwable t) {
70+
return t instanceof CallQueueTooBigException || t instanceof CallDroppedException;
7271
}
7372

73+
private static boolean isMetaCachePreservingException(Throwable t) {
74+
return t instanceof RegionOpeningException || t instanceof RegionTooBusyException
75+
|| t instanceof RpcThrottlingException || t instanceof RetryImmediatelyException
76+
|| t instanceof RequestTooBigException;
77+
}
78+
79+
private static boolean isExceptionWeCare(Throwable t) {
80+
return isMetaCachePreservingException(t) || isInstanceOfRegionServerOverloadedException(t)
81+
|| t instanceof NotServingRegionException;
82+
}
7483

7584
/**
7685
* Look for an exception we know in the remote exception:
@@ -87,15 +96,15 @@ public static Throwable findException(Object exception) {
8796
}
8897
Throwable cur = (Throwable) exception;
8998
while (cur != null) {
90-
if (isSpecialException(cur)) {
99+
if (isExceptionWeCare(cur)) {
91100
return cur;
92101
}
93102
if (cur instanceof RemoteException) {
94103
RemoteException re = (RemoteException) cur;
95104
cur = re.unwrapRemoteException();
96105

97106
// unwrapRemoteException can return the exception given as a parameter when it cannot
98-
// unwrap it. In this case, there is no need to look further
107+
// unwrap it. In this case, there is no need to look further
99108
// noinspection ObjectEquality
100109
if (cur == re) {
101110
return cur;

hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMetaCache.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.ArrayList;
2828
import java.util.List;
2929
import org.apache.hadoop.conf.Configuration;
30+
import org.apache.hadoop.hbase.CallDroppedException;
3031
import org.apache.hadoop.hbase.CallQueueTooBigException;
3132
import org.apache.hadoop.hbase.HBaseClassTestRule;
3233
import org.apache.hadoop.hbase.HBaseTestingUtility;
@@ -40,6 +41,7 @@
4041
import org.apache.hadoop.hbase.TableName;
4142
import org.apache.hadoop.hbase.exceptions.ClientExceptionsUtil;
4243
import org.apache.hadoop.hbase.exceptions.RegionOpeningException;
44+
import org.apache.hadoop.hbase.exceptions.RequestTooBigException;
4345
import org.apache.hadoop.hbase.quotas.RpcThrottlingException;
4446
import org.apache.hadoop.hbase.regionserver.HRegionServer;
4547
import org.apache.hadoop.hbase.regionserver.RSRpcServices;
@@ -143,12 +145,14 @@ public void testPreserveMetaCacheOnException() throws Exception {
143145
table.mutateRow(mutations);
144146
} catch (IOException ex) {
145147
// Only keep track of the last exception that updated the meta cache
146-
if (ClientExceptionsUtil.isMetaClearingException(ex) || success) {
148+
if ((ClientExceptionsUtil.isMetaClearingException(ex)
149+
&& !ClientExceptionsUtil.isRegionServerOverloadedException(ex)) || success) {
147150
exp = ex;
148151
}
149152
}
150153
// Do not test if we did not touch the meta cache in this iteration.
151-
if (exp != null && ClientExceptionsUtil.isMetaClearingException(exp)) {
154+
if (exp != null && ClientExceptionsUtil.isMetaClearingException(exp)
155+
&& !ClientExceptionsUtil.isRegionServerOverloadedException(exp)) {
152156
assertNull(conn.getCachedLocation(TABLE_NAME, row));
153157
} else if (success) {
154158
assertNotNull(conn.getCachedLocation(TABLE_NAME, row));
@@ -207,7 +211,9 @@ public static List<Throwable> metaCachePreservingExceptions() {
207211
add(new RpcThrottlingException(" "));
208212
add(new MultiActionResultTooLarge(" "));
209213
add(new RetryImmediatelyException(" "));
214+
add(new RequestTooBigException());
210215
add(new CallQueueTooBigException());
216+
add(new CallDroppedException());
211217
}};
212218
}
213219

0 commit comments

Comments
 (0)