From ec857e6e1f07f9ec949c23868bfd0ec0cd4781f9 Mon Sep 17 00:00:00 2001 From: JackShi148 Date: Fri, 13 Jun 2025 17:50:29 +0800 Subject: [PATCH] throw the same type original Exception when login --- .../rpc/location/model/TableRoute.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/alipay/oceanbase/rpc/location/model/TableRoute.java b/src/main/java/com/alipay/oceanbase/rpc/location/model/TableRoute.java index e55f69ea..fa222770 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/location/model/TableRoute.java +++ b/src/main/java/com/alipay/oceanbase/rpc/location/model/TableRoute.java @@ -235,6 +235,7 @@ public void initRoster(TableEntryKey rootServerKey, boolean initialized, BOOT.info("{} success to get replicaLocation {}", tableClient.getDatabase(), JSON.toJSON(replicaLocations)); + List obTableExceptions = new ArrayList<>(); for (ReplicaLocation replicaLocation : replicaLocations) { ObServerInfo info = replicaLocation.getInfo(); ObServerAddr addr = replicaLocation.getAddr(); @@ -266,11 +267,32 @@ public void initRoster(TableEntryKey rootServerKey, boolean initialized, addr.getIp(), addr.getSvrPort()); RUNTIME.warn("initMetadata meet exception", e); e.printStackTrace(); + // collect exceptions when login + obTableExceptions.add(e); } } if (servers.isEmpty()) { BOOT.error("{} failed to connect any replicaLocation server: {}", - tableClient.getDatabase(), JSON.toJSON(replicaLocations)); + tableClient.getDatabase(), JSON.toJSON(replicaLocations)); + boolean isSameTypeException = true; + int errCode = -1; + // if collected exceptions are the same type, throw the original exception + for (Exception e : obTableExceptions) { + if (!(e instanceof ObTableException)) { + isSameTypeException = false; + break; + } + int curErrCord = ((ObTableException) e).getErrorCode(); + if (errCode == -1) { + errCode = curErrCord; + } else if (errCode != curErrCord) { + isSameTypeException = false; + break; + } + } + if (isSameTypeException && !obTableExceptions.isEmpty()) { + throw obTableExceptions.get(0); + } throw new Exception("failed to connect any replicaLocation server"); }