Skip to content

Commit 462531e

Browse files
authored
throw the same type original Exception when login (#346)
1 parent 13b0f3f commit 462531e

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/main/java/com/alipay/oceanbase/rpc/location/model/TableRoute.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ public void initRoster(TableEntryKey rootServerKey, boolean initialized,
235235
BOOT.info("{} success to get replicaLocation {}", tableClient.getDatabase(),
236236
JSON.toJSON(replicaLocations));
237237

238+
List<Exception> obTableExceptions = new ArrayList<>();
238239
for (ReplicaLocation replicaLocation : replicaLocations) {
239240
ObServerInfo info = replicaLocation.getInfo();
240241
ObServerAddr addr = replicaLocation.getAddr();
@@ -266,11 +267,32 @@ public void initRoster(TableEntryKey rootServerKey, boolean initialized,
266267
addr.getIp(), addr.getSvrPort());
267268
RUNTIME.warn("initMetadata meet exception", e);
268269
e.printStackTrace();
270+
// collect exceptions when login
271+
obTableExceptions.add(e);
269272
}
270273
}
271274
if (servers.isEmpty()) {
272275
BOOT.error("{} failed to connect any replicaLocation server: {}",
273-
tableClient.getDatabase(), JSON.toJSON(replicaLocations));
276+
tableClient.getDatabase(), JSON.toJSON(replicaLocations));
277+
boolean isSameTypeException = true;
278+
int errCode = -1;
279+
// if collected exceptions are the same type, throw the original exception
280+
for (Exception e : obTableExceptions) {
281+
if (!(e instanceof ObTableException)) {
282+
isSameTypeException = false;
283+
break;
284+
}
285+
int curErrCord = ((ObTableException) e).getErrorCode();
286+
if (errCode == -1) {
287+
errCode = curErrCord;
288+
} else if (errCode != curErrCord) {
289+
isSameTypeException = false;
290+
break;
291+
}
292+
}
293+
if (isSameTypeException && !obTableExceptions.isEmpty()) {
294+
throw obTableExceptions.get(0);
295+
}
274296
throw new Exception("failed to connect any replicaLocation server");
275297
}
276298

0 commit comments

Comments
 (0)