Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isolate broken graphd server while client application is running #524

Merged
merged 1 commit into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class SessionPool implements Serializable {
private final int healthCheckTime;
private final int retryTimes;
private final int intervalTime;
private final boolean reconnect;
private final String spaceName;
private final String useSpace;

Expand All @@ -66,6 +67,7 @@ public SessionPool(SessionPoolConfig poolConfig) {
this.cleanTime = poolConfig.getCleanTime();
this.retryTimes = poolConfig.getRetryTimes();
this.intervalTime = poolConfig.getIntervalTime();
this.reconnect = poolConfig.isReconnect();
this.healthCheckTime = poolConfig.getHealthCheckTime();
this.spaceName = poolConfig.getSpaceName();
useSpace = "USE `" + spaceName + "`;";
Expand Down Expand Up @@ -146,7 +148,7 @@ public ResultSet execute(String stmt) throws IOErrorException,
NebulaSession nebulaSession = null;
ResultSet resultSet = null;
int tryTimes = 0;
while (tryTimes++ < retryTimes) {
while (tryTimes++ <= retryTimes) {
try {
nebulaSession = getSession();
resultSet = nebulaSession.execute(stmt);
Expand All @@ -160,6 +162,11 @@ public ResultSet execute(String stmt) throws IOErrorException,
resultSet.getErrorCode(), resultSet.getErrorMessage(), tryTimes));
nebulaSession.release();
sessionList.remove(nebulaSession);
try {
Thread.sleep(intervalTime);
} catch (InterruptedException interruptedException) {
// ignore
}
} catch (ClientServerIncompatibleException e) {
// will never get here.
} catch (AuthFailedException | BindSpaceFailedException e) {
Expand Down Expand Up @@ -330,11 +337,25 @@ private void updateSessionQueue() {
* @param state {@link SessionState}
* @return NebulaSession
*/
private synchronized NebulaSession createSessionObject(SessionState state)
private NebulaSession createSessionObject(SessionState state)
throws ClientServerIncompatibleException, AuthFailedException,
IOErrorException, BindSpaceFailedException {
SyncConnection connection = new SyncConnection();
connection.open(getAddress(), sessionPoolConfig.getTimeout());
int tryConnect = sessionPoolConfig.getGraphAddressList().size();
// reconnect with all available address
while (tryConnect-- > 0) {
try {
connection.open(getAddress(), sessionPoolConfig.getTimeout());
break;
} catch (Exception e) {
if (tryConnect == 0 || !reconnect) {
throw e;
} else {
log.warn("connect failed, " + e.getMessage());
}
}
}

AuthResult authResult;
try {
authResult = connection.authenticate(sessionPoolConfig.getUsername(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public class SessionPoolConfig implements Serializable {
// interval time for retry, unit ms
private int intervalTime = 0;

// whether reconnect when create session using a broken graphd server
private boolean reconnect = false;


public SessionPoolConfig(List<HostAddress> addresses,
String spaceName,
Expand Down Expand Up @@ -180,6 +183,14 @@ public SessionPoolConfig setIntervalTime(int intervalTime) {
return this;
}

public boolean isReconnect() {
return reconnect;
}

public SessionPoolConfig setReconnect(boolean reconnect) {
this.reconnect = reconnect;
return this;
}

@Override
public String toString() {
Expand All @@ -195,6 +206,7 @@ public String toString() {
+ ", waitTime=" + waitTime
+ ", retryTimes=" + retryTimes
+ ", intervalTIme=" + intervalTime
+ ", reconnect=" + reconnect
+ '}';
}
}
Loading