Skip to content

set max 3 retries for active failover redirects #412

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

Merged
merged 1 commit into from
Nov 11, 2021
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 @@ -56,6 +56,11 @@ private VstCommunicationAsync(final HostHandler hostHandler, final Integer timeo

@Override
protected CompletableFuture<Response> execute(final Request request, final VstConnectionAsync connection) {
return execute(request, connection, 0);
}

@Override
protected CompletableFuture<Response> execute(final Request request, final VstConnectionAsync connection, final int attemptCount) {
final CompletableFuture<Response> rfuture = new CompletableFuture<>();
try {
final Message message = createMessage(request);
Expand All @@ -73,11 +78,15 @@ protected CompletableFuture<Response> execute(final Request request, final VstCo
try {
checkError(response);
} catch (final ArangoDBRedirectException e) {
if (attemptCount >= 3) {
rfuture.completeExceptionally(e);
return;
}
final String location = e.getLocation();
final HostDescription redirectHost = HostUtils.createFromLocation(location);
hostHandler.closeCurrentOnError();
hostHandler.fail();
execute(request, new HostHandle().setHost(redirectHost))
execute(request, new HostHandle().setHost(redirectHost), attemptCount + 1)
.whenComplete((v, err) -> {
if (v != null) {
rfuture.complete(v);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public void close() throws IOException {
}

public Response execute(final Request request, final HostHandle hostHandle) throws ArangoDBException, IOException {
return execute(request, hostHandle, 0);
}

private Response execute(final Request request, final HostHandle hostHandle, final int attemptCount) throws ArangoDBException, IOException {
final AccessType accessType = RequestUtils.determineAccessType(request);
Host host = hostHandler.get(hostHandle, accessType);
try {
Expand Down Expand Up @@ -99,12 +103,12 @@ public Response execute(final Request request, final HostHandle hostHandle) thro
}
}
} catch (final ArangoDBException e) {
if (e instanceof ArangoDBRedirectException) {
if (e instanceof ArangoDBRedirectException && attemptCount < 3) {
final String location = ((ArangoDBRedirectException) e).getLocation();
final HostDescription redirectHost = HostUtils.createFromLocation(location);
hostHandler.closeCurrentOnError();
hostHandler.fail();
return execute(request, new HostHandle().setHost(redirectHost));
return execute(request, new HostHandle().setHost(redirectHost), attemptCount + 1);
} else {
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,18 @@ public void close() throws IOException {
}

public R execute(final Request request, final HostHandle hostHandle) throws ArangoDBException {
return execute(request, hostHandle, 0);
}

protected R execute(final Request request, final HostHandle hostHandle, final int attemptCount) throws ArangoDBException {
final C connection = connect(hostHandle, RequestUtils.determineAccessType(request));
return execute(request, connection);
return execute(request, connection, attemptCount);
}

protected abstract R execute(final Request request, C connection) throws ArangoDBException;

protected abstract R execute(final Request request, C connection, final int attemptCount) throws ArangoDBException;

protected void checkError(final Response response) throws ArangoDBException {
ResponseUtils.checkError(util, response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ protected VstCommunicationSync(final HostHandler hostHandler, final Integer time

@Override
protected Response execute(final Request request, final VstConnectionSync connection) throws ArangoDBException {
return execute(request, connection, 0);
}

@Override
protected Response execute(final Request request, final VstConnectionSync connection, final int attemptCount) throws ArangoDBException {
try {
final Message requestMessage = createMessage(request);
final Message responseMessage = send(requestMessage, connection);
Expand All @@ -132,11 +137,14 @@ protected Response execute(final Request request, final VstConnectionSync connec
} catch (final VPackParserException e) {
throw new ArangoDBException(e);
} catch (final ArangoDBRedirectException e) {
if (attemptCount >= 3) {
throw e;
}
final String location = e.getLocation();
final HostDescription redirectHost = HostUtils.createFromLocation(location);
hostHandler.closeCurrentOnError();
hostHandler.fail();
return execute(request, new HostHandle().setHost(redirectHost));
return execute(request, new HostHandle().setHost(redirectHost), attemptCount + 1);
}
}

Expand Down