Skip to content

Commit

Permalink
Session insert request won't fail while rolling upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
JackieTien97 authored Jan 28, 2024
1 parent e7b0ca5 commit 9831082
Show file tree
Hide file tree
Showing 12 changed files with 1,289 additions and 842 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,9 @@ public class SessionConfig {

public static final boolean DEFAULT_ENABLE_AUTO_FETCH = true;

public static final int MAX_RETRY_COUNT = 60;

public static final long RETRY_INTERVAL_IN_MS = 500;

private SessionConfig() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ public class Session implements ISession {
// default enable
protected boolean enableAutoFetch = true;

protected int maxRetryCount = SessionConfig.MAX_RETRY_COUNT;

protected long retryIntervalInMs = SessionConfig.RETRY_INTERVAL_IN_MS;

private static final String REDIRECT_TWICE = "redirect twice";

private static final String REDIRECT_TWICE_RETRY = "redirect twice, please try again.";
Expand Down Expand Up @@ -421,6 +425,8 @@ public Session(Builder builder) {
this.trustStore = builder.trustStore;
this.trustStorePwd = builder.trustStorePwd;
this.enableAutoFetch = builder.enableAutoFetch;
this.maxRetryCount = builder.maxRetryCount;
this.retryIntervalInMs = builder.retryIntervalInMs;
}

@Override
Expand Down Expand Up @@ -580,9 +586,11 @@ public synchronized void close() throws IoTDBConnectionException {
public SessionConnection constructSessionConnection(
Session session, TEndPoint endpoint, ZoneId zoneId) throws IoTDBConnectionException {
if (endpoint == null) {
return new SessionConnection(session, zoneId, availableNodes);
return new SessionConnection(
session, zoneId, availableNodes, maxRetryCount, retryIntervalInMs);
}
return new SessionConnection(session, endpoint, zoneId, availableNodes);
return new SessionConnection(
session, endpoint, zoneId, availableNodes, maxRetryCount, retryIntervalInMs);
}

@Override
Expand Down Expand Up @@ -1261,7 +1269,6 @@ private void handleRedirection(String deviceId, TEndPoint endpoint) {
});
if (connection == null) {
deviceIdToEndpoint.remove(deviceId);
logger.warn("Can not redirect to {}, because session can not connect to it.", endpoint);
}
}
}
Expand Down Expand Up @@ -3551,6 +3558,10 @@ public static class Builder {
private String trustStore;
private String trustStorePwd;

private int maxRetryCount = SessionConfig.MAX_RETRY_COUNT;

private long retryIntervalInMs = SessionConfig.RETRY_INTERVAL_IN_MS;

public Builder useSSL(boolean useSSL) {
this.useSSL = useSSL;
return this;
Expand Down Expand Up @@ -3633,6 +3644,16 @@ public Builder enableAutoFetch(boolean enableAutoFetch) {
return this;
}

public Builder maxRetryCount(int maxRetryCount) {
this.maxRetryCount = maxRetryCount;
return this;
}

public Builder retryIntervalInMs(long retryIntervalInMs) {
this.retryIntervalInMs = retryIntervalInMs;
return this;
}

public Session build() {
if (nodeUrls != null
&& (!SessionConfig.DEFAULT_HOST.equals(host) || rpcPort != SessionConfig.DEFAULT_PORT)) {
Expand Down
Loading

0 comments on commit 9831082

Please sign in to comment.