1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.exceptions;
21
22 import java.io.EOFException;
23 import java.io.IOException;
24 import java.io.SyncFailedException;
25 import java.lang.reflect.UndeclaredThrowableException;
26 import java.net.ConnectException;
27 import java.net.SocketTimeoutException;
28 import java.nio.channels.ClosedChannelException;
29 import java.util.concurrent.TimeoutException;
30
31 import org.apache.hadoop.hbase.CallDroppedException;
32 import org.apache.hadoop.hbase.CallQueueTooBigException;
33 import org.apache.hadoop.hbase.DoNotRetryIOException;
34 import org.apache.hadoop.hbase.MultiActionResultTooLarge;
35 import org.apache.hadoop.hbase.NotServingRegionException;
36 import org.apache.hadoop.hbase.RegionTooBusyException;
37 import org.apache.hadoop.hbase.RetryImmediatelyException;
38 import org.apache.hadoop.hbase.classification.InterfaceAudience;
39 import org.apache.hadoop.hbase.classification.InterfaceStability;
40 import org.apache.hadoop.hbase.ipc.CallTimeoutException;
41 import org.apache.hadoop.hbase.ipc.FailedServerException;
42 import org.apache.hadoop.hbase.quotas.ThrottlingException;
43 import org.apache.hadoop.ipc.RemoteException;
44
45 @InterfaceAudience.Private
46 @InterfaceStability.Evolving
47 public final class ClientExceptionsUtil {
48
49 private ClientExceptionsUtil() {}
50
51 public static boolean isMetaClearingException(Throwable cur) {
52 cur = findException(cur);
53
54 if (cur == null) {
55 return true;
56 }
57 return !isSpecialException(cur) || (cur instanceof RegionMovedException)
58 || cur instanceof NotServingRegionException;
59 }
60
61 public static boolean isSpecialException(Throwable cur) {
62 return (cur instanceof RegionMovedException || cur instanceof RegionOpeningException
63 || cur instanceof RegionTooBusyException || cur instanceof ThrottlingException
64 || cur instanceof MultiActionResultTooLarge || cur instanceof RetryImmediatelyException
65 || cur instanceof CallQueueTooBigException || cur instanceof CallDroppedException
66 || cur instanceof NotServingRegionException || cur instanceof RequestTooBigException);
67 }
68
69
70
71
72
73
74
75
76
77
78
79 public static Throwable findException(Object exception) {
80 if (exception == null || !(exception instanceof Throwable)) {
81 return null;
82 }
83 Throwable cur = (Throwable) exception;
84 while (cur != null) {
85 if (isSpecialException(cur)) {
86 return cur;
87 }
88 if (cur instanceof RemoteException) {
89 RemoteException re = (RemoteException) cur;
90 cur = re.unwrapRemoteException();
91
92
93
94
95 if (cur == re) {
96 return cur;
97 }
98
99
100
101
102 } else if (cur.getCause() != null && !(cur.getCause() instanceof RemoteException)) {
103 cur = cur.getCause();
104 } else {
105 return cur;
106 }
107 }
108
109 return null;
110 }
111
112
113
114
115
116
117
118 public static boolean isCallQueueTooBigException(Throwable t) {
119 t = findException(t);
120 return (t instanceof CallQueueTooBigException);
121 }
122
123
124
125
126
127
128
129 public static boolean isCallDroppedException(Throwable t) {
130 t = findException(t);
131 return (t instanceof CallDroppedException);
132 }
133
134
135
136
137
138
139
140
141 public static boolean isConnectionException(Throwable e) {
142 if (e == null) {
143 return false;
144 }
145
146
147
148 return (e instanceof SocketTimeoutException || e instanceof ConnectException
149 || e instanceof ClosedChannelException || e instanceof SyncFailedException
150 || e instanceof EOFException || e instanceof TimeoutException
151 || e instanceof CallTimeoutException || e instanceof ConnectionClosingException
152 || e instanceof FailedServerException);
153 }
154
155
156
157
158
159
160
161 public static Throwable translatePFFE(Throwable t) throws IOException {
162 if (t instanceof NoSuchMethodError) {
163
164 throw (NoSuchMethodError) t;
165 }
166
167 if (t instanceof NullPointerException) {
168
169 throw (NullPointerException) t;
170 }
171
172 if (t instanceof UndeclaredThrowableException) {
173 t = t.getCause();
174 }
175 if (t instanceof RemoteException) {
176 t = ((RemoteException) t).unwrapRemoteException();
177 }
178 if (t instanceof DoNotRetryIOException) {
179 throw (DoNotRetryIOException) t;
180 }
181 if (t instanceof Error) {
182 throw (Error) t;
183 }
184 return t;
185 }
186 }