Skip to content

Commit

Permalink
Pipe: make exception message more friendly when creating data sync pi…
Browse files Browse the repository at this point in the history
…pe failed (#14208)

Co-authored-by: Steve Yurong Su <[email protected]>
  • Loading branch information
XNX02 and SteveYurongSu authored Nov 26, 2024
1 parent bb99334 commit 0160b65
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public abstract class IoTDBSyncClientManager extends IoTDBClientManager implemen

protected final Map<TEndPoint, Pair<IoTDBSyncClient, Boolean>> endPoint2ClientAndStatus =
new ConcurrentHashMap<>();
private final Map<TEndPoint, String> endPoint2HandshakeErrorMessage = new ConcurrentHashMap<>();

private final LoadBalancer loadBalancer;

Expand Down Expand Up @@ -124,12 +125,27 @@ public void checkClientStatusAndTryReconstructIfNecessary() {
return;
}
}
throw new PipeConnectionException(
String.format(
"All target servers %s are not available.", endPoint2ClientAndStatus.keySet()));
final StringBuilder errorMessage =
new StringBuilder(
String.format(
"All target servers %s are not available.", endPoint2ClientAndStatus.keySet()));
for (final Map.Entry<TEndPoint, String> entry : endPoint2HandshakeErrorMessage.entrySet()) {
errorMessage
.append(" (")
.append(" host: ")
.append(entry.getKey().getIp())
.append(", port: ")
.append(entry.getKey().getPort())
.append(", because: ")
.append(entry.getValue())
.append(")");
}
throw new PipeConnectionException(errorMessage.toString());
}

protected void reconstructClient(TEndPoint endPoint) {
endPoint2HandshakeErrorMessage.remove(endPoint);

final Pair<IoTDBSyncClient, Boolean> clientAndStatus = endPoint2ClientAndStatus.get(endPoint);

if (clientAndStatus.getLeft() != null) {
Expand Down Expand Up @@ -164,6 +180,7 @@ private void initClientAndStatus(
trustStorePath,
trustStorePwd));
} catch (Exception e) {
endPoint2HandshakeErrorMessage.put(endPoint, e.getMessage());
throw new PipeConnectionException(
String.format(
PipeConnectionException.CONNECTION_ERROR_FORMATTER,
Expand Down Expand Up @@ -210,6 +227,7 @@ public void sendHandshakeReq(final Pair<IoTDBSyncClient, Boolean> clientAndStatu
client.getIpAddress(),
client.getPort(),
resp.getStatus());
endPoint2HandshakeErrorMessage.put(client.getEndPoint(), resp.getStatus().getMessage());
} else {
clientAndStatus.setRight(true);
client.setTimeout(CONNECTION_TIMEOUT_MS.get());
Expand All @@ -225,6 +243,7 @@ public void sendHandshakeReq(final Pair<IoTDBSyncClient, Boolean> clientAndStatu
client.getPort(),
e.getMessage(),
e);
endPoint2HandshakeErrorMessage.put(client.getEndPoint(), e.getMessage());
}
}

Expand Down

0 comments on commit 0160b65

Please sign in to comment.