Skip to content

Version 8.0 #606

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

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
removed DirtyReadHostHandler (DE-811)
  • Loading branch information
rashtao committed Jun 6, 2025
commit bccc900c1500b4e11f8054e76ee17bf89a544a73
3 changes: 1 addition & 2 deletions core/src/main/java/com/arangodb/ArangoDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -766,8 +766,7 @@ protected HostHandler createHostHandler(@UnstableApi final HostResolver hostReso
}

LOG.debug("HostHandler is {}", hostHandler.getClass().getSimpleName());

return new DirtyReadHostHandler(hostHandler, new RoundRobinHostHandler(hostResolver));
return hostHandler;
}

@UnstableApi
Expand Down
30 changes: 0 additions & 30 deletions core/src/main/java/com/arangodb/internal/net/AccessType.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.arangodb.internal.config.ArangoConfig;
import com.arangodb.internal.serde.InternalSerde;
import com.arangodb.internal.util.HostUtils;
import com.arangodb.internal.util.RequestUtils;
import com.arangodb.internal.util.ResponseUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -45,7 +44,7 @@ public void close() throws IOException {
}

public CompletableFuture<InternalResponse> executeAsync(final InternalRequest request, final HostHandle hostHandle) {
return executeAsync(request, hostHandle, hostHandler.get(hostHandle, RequestUtils.determineAccessType(request)), 0);
return executeAsync(request, hostHandle, hostHandler.get(hostHandle), 0);
}

private CompletableFuture<InternalResponse> executeAsync(final InternalRequest request, final HostHandle hostHandle, final Host host, final int attemptCount) {
Expand Down Expand Up @@ -96,7 +95,7 @@ private CompletableFuture<InternalResponse> doExecuteAsync(
final HostDescription redirectHost = HostUtils.createFromLocation(location);
hostHandler.failIfNotMatch(redirectHost, errorEntityEx);
mirror(
executeAsync(request, new HostHandle().setHost(redirectHost), hostHandler.get(hostHandle, RequestUtils.determineAccessType(request)), attemptCount + 1),
executeAsync(request, new HostHandle().setHost(redirectHost), hostHandler.get(hostHandle), attemptCount + 1),
rfuture
);
}
Expand All @@ -123,9 +122,9 @@ private void handleException(boolean isSafe, Throwable e, HostHandle hostHandle,
if (hostHandle != null && hostHandle.getHost() != null) {
hostHandle.setHost(null);
}
hostHandler.checkNext(hostHandle, RequestUtils.determineAccessType(request));
hostHandler.checkNext(hostHandle);
if (isSafe) {
Host nextHost = hostHandler.get(hostHandle, RequestUtils.determineAccessType(request));
Host nextHost = hostHandler.get(hostHandle);
LOGGER.warn("Could not connect to {} while executing request [id={}]",
host.getDescription(), reqId, ioEx);
LOGGER.debug("Try connecting to {}", nextHost.getDescription());
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ public FallbackHostHandler(final HostResolver resolver) {
}

@Override
public Host get(final HostHandle hostHandle, AccessType accessType) {
checkNext(hostHandle, accessType);
public Host get(final HostHandle hostHandle) {
checkNext(hostHandle);
if (current.isMarkforDeletion()) {
fail(new ArangoDBException("Host marked for deletion"));
}
return current;
}

@Override
public void checkNext(HostHandle hostHandle, AccessType accessType) {
public void checkNext(HostHandle hostHandle) {
if (current == lastSuccess && iterations >= 3) {
ArangoDBException e = ArangoDBException.of("Cannot contact any host!",
new ArangoDBMultipleException(new ArrayList<>(lastFailExceptions)));
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/com/arangodb/internal/net/HostHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
@UsedInApi
public interface HostHandler {

Host get(HostHandle hostHandle, AccessType accessType);
Host get(HostHandle hostHandle);

void checkNext(HostHandle hostHandle, AccessType accessType);
void checkNext(HostHandle hostHandle);

void success();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public RandomHostHandler(final HostResolver resolver, final HostHandler fallback
}

@Override
public Host get(final HostHandle hostHandle, AccessType accessType) {
public Host get(final HostHandle hostHandle) {
if (current == null || current.isMarkforDeletion()) {
hosts = resolver.getHosts();
current = getRandomHost();
Expand All @@ -53,7 +53,7 @@ public Host get(final HostHandle hostHandle, AccessType accessType) {
}

@Override
public void checkNext(HostHandle hostHandle, AccessType accessType) {
public void checkNext(HostHandle hostHandle) {
}

@Override
Expand All @@ -64,7 +64,7 @@ public void success() {
@Override
public void fail(Exception exception) {
fallback.fail(exception);
current = fallback.get(null, null);
current = fallback.get(null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public RoundRobinHostHandler(final HostResolver resolver) {
}

@Override
public Host get(final HostHandle hostHandle, AccessType accessType) {
checkNext(hostHandle, accessType);
public Host get(final HostHandle hostHandle) {
checkNext(hostHandle);
final int size = hosts.getHostsList().size();
final int index = (int) ((current++) % size);
Host host = hosts.getHostsList().get(index);
Expand All @@ -76,7 +76,7 @@ public Host get(final HostHandle hostHandle, AccessType accessType) {
}

@Override
public void checkNext(HostHandle hostHandle, AccessType accessType) {
public void checkNext(HostHandle hostHandle) {
hosts = resolver.getHosts();
final int size = hosts.getHostsList().size();

Expand Down
12 changes: 0 additions & 12 deletions core/src/main/java/com/arangodb/internal/util/RequestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@

package com.arangodb.internal.util;

import com.arangodb.internal.net.AccessType;
import com.arangodb.internal.InternalRequest;
import com.arangodb.internal.RequestType;

/**
* @author Mark Vollmary
Expand All @@ -39,14 +37,4 @@ public static InternalRequest allowDirtyRead(final InternalRequest request) {
return request.putHeaderParam(HEADER_ALLOW_DIRTY_READ, "true");
}

public static AccessType determineAccessType(final InternalRequest request) {
if (request.containsHeaderParam(HEADER_ALLOW_DIRTY_READ)) {
return AccessType.DIRTY_READ;
}
if (request.getRequestType() == RequestType.GET) {
return AccessType.READ;
}
return AccessType.WRITE;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,26 @@ public void close() {
@Test
void fallbackHostHandlerSingleHost() {
final HostHandler handler = new FallbackHostHandler(SINGLE_HOST);
assertThat(handler.get(null, null)).isEqualTo(HOST_0);
assertThat(handler.get(null)).isEqualTo(HOST_0);
handler.fail(new RuntimeException());
assertThat(handler.get(null, null)).isEqualTo(HOST_0);
assertThat(handler.get(null)).isEqualTo(HOST_0);
}

@Test
void fallbackHostHandlerMultipleHosts() {
final HostHandler handler = new FallbackHostHandler(MULTIPLE_HOSTS);
for (int i = 0; i < 3; i++) {
assertThat(handler.get(null, null)).isEqualTo(HOST_0);
assertThat(handler.get(null)).isEqualTo(HOST_0);
handler.fail(new RuntimeException("HOST_0 failed"));
assertThat(handler.get(null, null)).isEqualTo(HOST_1);
assertThat(handler.get(null)).isEqualTo(HOST_1);
handler.fail(new RuntimeException("HOST_1 failed"));
assertThat(handler.get(null, null)).isEqualTo(HOST_2);
assertThat(handler.get(null)).isEqualTo(HOST_2);
handler.fail(new RuntimeException("HOST_2 failed"));
if (i < 2) {
assertThat(handler.get(null, null)).isEqualTo(HOST_0);
assertThat(handler.get(null)).isEqualTo(HOST_0);
} else {
try {
handler.get(null, null);
handler.get(null);
fail();
} catch (ArangoDBException e) {
assertThat(e.getCause()).isNotNull();
Expand All @@ -123,24 +123,24 @@ void fallbackHostHandlerMultipleHosts() {
@Test
void randomHostHandlerSingleHost() {
final HostHandler handler = new RandomHostHandler(SINGLE_HOST, new FallbackHostHandler(SINGLE_HOST));
assertThat(handler.get(null, null)).isEqualTo(HOST_0);
assertThat(handler.get(null)).isEqualTo(HOST_0);
handler.fail(new RuntimeException());
assertThat(handler.get(null, null)).isEqualTo(HOST_0);
assertThat(handler.get(null)).isEqualTo(HOST_0);
}

@Test
void randomHostHandlerMultipleHosts() {
final HostHandler handler = new RandomHostHandler(MULTIPLE_HOSTS, new FallbackHostHandler(MULTIPLE_HOSTS));

final Host pick0 = handler.get(null, null);
final Host pick0 = handler.get(null);
assertThat(pick0).isIn(HOST_0, HOST_1, HOST_2);
handler.fail(new RuntimeException());

final Host pick1 = handler.get(null, null);
final Host pick1 = handler.get(null);
assertThat(pick1).isIn(HOST_0, HOST_1, HOST_2);
handler.success();

final Host pick3 = handler.get(null, null);
final Host pick3 = handler.get(null);
assertThat(pick3)
.isIn(HOST_0, HOST_1, HOST_2)
.isEqualTo(pick1);
Expand All @@ -149,25 +149,25 @@ void randomHostHandlerMultipleHosts() {
@Test
void roundRobinHostHandlerSingleHost() {
final HostHandler handler = new RoundRobinHostHandler(SINGLE_HOST);
assertThat(handler.get(null, null)).isEqualTo(HOST_0);
assertThat(handler.get(null)).isEqualTo(HOST_0);
handler.fail(new RuntimeException());
assertThat(handler.get(null, null)).isEqualTo(HOST_0);
assertThat(handler.get(null)).isEqualTo(HOST_0);
}

@Test
void roundRobinHostHandlerMultipleHosts() {
final HostHandler handler = new RoundRobinHostHandler(MULTIPLE_HOSTS);
final Host pick0 = handler.get(null, null);
final Host pick0 = handler.get(null);
assertThat(pick0).isIn(HOST_0, HOST_1, HOST_2);
final Host pick1 = handler.get(null, null);
final Host pick1 = handler.get(null);
assertThat(pick1)
.isIn(HOST_0, HOST_1, HOST_2)
.isNotEqualTo(pick0);
final Host pick2 = handler.get(null, null);
final Host pick2 = handler.get(null);
assertThat(pick2)
.isIn(HOST_0, HOST_1, HOST_2)
.isNotIn(pick0, pick1);
final Host pick4 = handler.get(null, null);
final Host pick4 = handler.get(null);
assertThat(pick4).isEqualTo(pick0);
}

Expand Down