Skip to content

Commit 84a571e

Browse files
committed
removed DirtyReadHostHandler (DE-811)
1 parent 4d6420c commit 84a571e

File tree

10 files changed

+34
-171
lines changed

10 files changed

+34
-171
lines changed

core/src/main/java/com/arangodb/ArangoDB.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,7 @@ protected HostHandler createHostHandler(@UnstableApi final HostResolver hostReso
766766
}
767767

768768
LOG.debug("HostHandler is {}", hostHandler.getClass().getSimpleName());
769-
770-
return new DirtyReadHostHandler(hostHandler, new RoundRobinHostHandler(hostResolver));
769+
return hostHandler;
771770
}
772771

773772
@UnstableApi

core/src/main/java/com/arangodb/internal/net/AccessType.java

Lines changed: 0 additions & 30 deletions
This file was deleted.

core/src/main/java/com/arangodb/internal/net/Communication.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import com.arangodb.internal.config.ArangoConfig;
1010
import com.arangodb.internal.serde.InternalSerde;
1111
import com.arangodb.internal.util.HostUtils;
12-
import com.arangodb.internal.util.RequestUtils;
1312
import com.arangodb.internal.util.ResponseUtils;
1413
import org.slf4j.Logger;
1514
import org.slf4j.LoggerFactory;
@@ -45,7 +44,7 @@ public void close() throws IOException {
4544
}
4645

4746
public CompletableFuture<InternalResponse> executeAsync(final InternalRequest request, final HostHandle hostHandle) {
48-
return executeAsync(request, hostHandle, hostHandler.get(hostHandle, RequestUtils.determineAccessType(request)), 0);
47+
return executeAsync(request, hostHandle, hostHandler.get(hostHandle), 0);
4948
}
5049

5150
private CompletableFuture<InternalResponse> executeAsync(final InternalRequest request, final HostHandle hostHandle, final Host host, final int attemptCount) {
@@ -96,7 +95,7 @@ private CompletableFuture<InternalResponse> doExecuteAsync(
9695
final HostDescription redirectHost = HostUtils.createFromLocation(location);
9796
hostHandler.failIfNotMatch(redirectHost, errorEntityEx);
9897
mirror(
99-
executeAsync(request, new HostHandle().setHost(redirectHost), hostHandler.get(hostHandle, RequestUtils.determineAccessType(request)), attemptCount + 1),
98+
executeAsync(request, new HostHandle().setHost(redirectHost), hostHandler.get(hostHandle), attemptCount + 1),
10099
rfuture
101100
);
102101
}
@@ -123,9 +122,9 @@ private void handleException(boolean isSafe, Throwable e, HostHandle hostHandle,
123122
if (hostHandle != null && hostHandle.getHost() != null) {
124123
hostHandle.setHost(null);
125124
}
126-
hostHandler.checkNext(hostHandle, RequestUtils.determineAccessType(request));
125+
hostHandler.checkNext(hostHandle);
127126
if (isSafe) {
128-
Host nextHost = hostHandler.get(hostHandle, RequestUtils.determineAccessType(request));
127+
Host nextHost = hostHandler.get(hostHandle);
129128
LOGGER.warn("Could not connect to {} while executing request [id={}]",
130129
host.getDescription(), reqId, ioEx);
131130
LOGGER.debug("Try connecting to {}", nextHost.getDescription());

core/src/main/java/com/arangodb/internal/net/DirtyReadHostHandler.java

Lines changed: 0 additions & 93 deletions
This file was deleted.

core/src/main/java/com/arangodb/internal/net/FallbackHostHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ public FallbackHostHandler(final HostResolver resolver) {
4949
}
5050

5151
@Override
52-
public Host get(final HostHandle hostHandle, AccessType accessType) {
53-
checkNext(hostHandle, accessType);
52+
public Host get(final HostHandle hostHandle) {
53+
checkNext(hostHandle);
5454
if (current.isMarkforDeletion()) {
5555
fail(new ArangoDBException("Host marked for deletion"));
5656
}
5757
return current;
5858
}
5959

6060
@Override
61-
public void checkNext(HostHandle hostHandle, AccessType accessType) {
61+
public void checkNext(HostHandle hostHandle) {
6262
if (current == lastSuccess && iterations >= 3) {
6363
ArangoDBException e = ArangoDBException.of("Cannot contact any host!",
6464
new ArangoDBMultipleException(new ArrayList<>(lastFailExceptions)));

core/src/main/java/com/arangodb/internal/net/HostHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
@UsedInApi
3232
public interface HostHandler {
3333

34-
Host get(HostHandle hostHandle, AccessType accessType);
34+
Host get(HostHandle hostHandle);
3535

36-
void checkNext(HostHandle hostHandle, AccessType accessType);
36+
void checkNext(HostHandle hostHandle);
3737

3838
void success();
3939

core/src/main/java/com/arangodb/internal/net/RandomHostHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public RandomHostHandler(final HostResolver resolver, final HostHandler fallback
4444
}
4545

4646
@Override
47-
public Host get(final HostHandle hostHandle, AccessType accessType) {
47+
public Host get(final HostHandle hostHandle) {
4848
if (current == null || current.isMarkforDeletion()) {
4949
hosts = resolver.getHosts();
5050
current = getRandomHost();
@@ -53,7 +53,7 @@ public Host get(final HostHandle hostHandle, AccessType accessType) {
5353
}
5454

5555
@Override
56-
public void checkNext(HostHandle hostHandle, AccessType accessType) {
56+
public void checkNext(HostHandle hostHandle) {
5757
}
5858

5959
@Override
@@ -64,7 +64,7 @@ public void success() {
6464
@Override
6565
public void fail(Exception exception) {
6666
fallback.fail(exception);
67-
current = fallback.get(null, null);
67+
current = fallback.get(null);
6868
}
6969

7070
@Override

core/src/main/java/com/arangodb/internal/net/RoundRobinHostHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ public RoundRobinHostHandler(final HostResolver resolver) {
5353
}
5454

5555
@Override
56-
public Host get(final HostHandle hostHandle, AccessType accessType) {
57-
checkNext(hostHandle, accessType);
56+
public Host get(final HostHandle hostHandle) {
57+
checkNext(hostHandle);
5858
final int size = hosts.getHostsList().size();
5959
final int index = (int) ((current++) % size);
6060
Host host = hosts.getHostsList().get(index);
@@ -76,7 +76,7 @@ public Host get(final HostHandle hostHandle, AccessType accessType) {
7676
}
7777

7878
@Override
79-
public void checkNext(HostHandle hostHandle, AccessType accessType) {
79+
public void checkNext(HostHandle hostHandle) {
8080
hosts = resolver.getHosts();
8181
final int size = hosts.getHostsList().size();
8282

core/src/main/java/com/arangodb/internal/util/RequestUtils.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020

2121
package com.arangodb.internal.util;
2222

23-
import com.arangodb.internal.net.AccessType;
2423
import com.arangodb.internal.InternalRequest;
25-
import com.arangodb.internal.RequestType;
2624

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

42-
public static AccessType determineAccessType(final InternalRequest request) {
43-
if (request.containsHeaderParam(HEADER_ALLOW_DIRTY_READ)) {
44-
return AccessType.DIRTY_READ;
45-
}
46-
if (request.getRequestType() == RequestType.GET) {
47-
return AccessType.READ;
48-
}
49-
return AccessType.WRITE;
50-
}
51-
5240
}

test-functional/src/test/java/com/arangodb/internal/HostHandlerTest.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -84,26 +84,26 @@ public void close() {
8484
@Test
8585
void fallbackHostHandlerSingleHost() {
8686
final HostHandler handler = new FallbackHostHandler(SINGLE_HOST);
87-
assertThat(handler.get(null, null)).isEqualTo(HOST_0);
87+
assertThat(handler.get(null)).isEqualTo(HOST_0);
8888
handler.fail(new RuntimeException());
89-
assertThat(handler.get(null, null)).isEqualTo(HOST_0);
89+
assertThat(handler.get(null)).isEqualTo(HOST_0);
9090
}
9191

9292
@Test
9393
void fallbackHostHandlerMultipleHosts() {
9494
final HostHandler handler = new FallbackHostHandler(MULTIPLE_HOSTS);
9595
for (int i = 0; i < 3; i++) {
96-
assertThat(handler.get(null, null)).isEqualTo(HOST_0);
96+
assertThat(handler.get(null)).isEqualTo(HOST_0);
9797
handler.fail(new RuntimeException("HOST_0 failed"));
98-
assertThat(handler.get(null, null)).isEqualTo(HOST_1);
98+
assertThat(handler.get(null)).isEqualTo(HOST_1);
9999
handler.fail(new RuntimeException("HOST_1 failed"));
100-
assertThat(handler.get(null, null)).isEqualTo(HOST_2);
100+
assertThat(handler.get(null)).isEqualTo(HOST_2);
101101
handler.fail(new RuntimeException("HOST_2 failed"));
102102
if (i < 2) {
103-
assertThat(handler.get(null, null)).isEqualTo(HOST_0);
103+
assertThat(handler.get(null)).isEqualTo(HOST_0);
104104
} else {
105105
try {
106-
handler.get(null, null);
106+
handler.get(null);
107107
fail();
108108
} catch (ArangoDBException e) {
109109
assertThat(e.getCause()).isNotNull();
@@ -123,24 +123,24 @@ void fallbackHostHandlerMultipleHosts() {
123123
@Test
124124
void randomHostHandlerSingleHost() {
125125
final HostHandler handler = new RandomHostHandler(SINGLE_HOST, new FallbackHostHandler(SINGLE_HOST));
126-
assertThat(handler.get(null, null)).isEqualTo(HOST_0);
126+
assertThat(handler.get(null)).isEqualTo(HOST_0);
127127
handler.fail(new RuntimeException());
128-
assertThat(handler.get(null, null)).isEqualTo(HOST_0);
128+
assertThat(handler.get(null)).isEqualTo(HOST_0);
129129
}
130130

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

135-
final Host pick0 = handler.get(null, null);
135+
final Host pick0 = handler.get(null);
136136
assertThat(pick0).isIn(HOST_0, HOST_1, HOST_2);
137137
handler.fail(new RuntimeException());
138138

139-
final Host pick1 = handler.get(null, null);
139+
final Host pick1 = handler.get(null);
140140
assertThat(pick1).isIn(HOST_0, HOST_1, HOST_2);
141141
handler.success();
142142

143-
final Host pick3 = handler.get(null, null);
143+
final Host pick3 = handler.get(null);
144144
assertThat(pick3)
145145
.isIn(HOST_0, HOST_1, HOST_2)
146146
.isEqualTo(pick1);
@@ -149,25 +149,25 @@ void randomHostHandlerMultipleHosts() {
149149
@Test
150150
void roundRobinHostHandlerSingleHost() {
151151
final HostHandler handler = new RoundRobinHostHandler(SINGLE_HOST);
152-
assertThat(handler.get(null, null)).isEqualTo(HOST_0);
152+
assertThat(handler.get(null)).isEqualTo(HOST_0);
153153
handler.fail(new RuntimeException());
154-
assertThat(handler.get(null, null)).isEqualTo(HOST_0);
154+
assertThat(handler.get(null)).isEqualTo(HOST_0);
155155
}
156156

157157
@Test
158158
void roundRobinHostHandlerMultipleHosts() {
159159
final HostHandler handler = new RoundRobinHostHandler(MULTIPLE_HOSTS);
160-
final Host pick0 = handler.get(null, null);
160+
final Host pick0 = handler.get(null);
161161
assertThat(pick0).isIn(HOST_0, HOST_1, HOST_2);
162-
final Host pick1 = handler.get(null, null);
162+
final Host pick1 = handler.get(null);
163163
assertThat(pick1)
164164
.isIn(HOST_0, HOST_1, HOST_2)
165165
.isNotEqualTo(pick0);
166-
final Host pick2 = handler.get(null, null);
166+
final Host pick2 = handler.get(null);
167167
assertThat(pick2)
168168
.isIn(HOST_0, HOST_1, HOST_2)
169169
.isNotIn(pick0, pick1);
170-
final Host pick4 = handler.get(null, null);
170+
final Host pick4 = handler.get(null);
171171
assertThat(pick4).isEqualTo(pick0);
172172
}
173173

0 commit comments

Comments
 (0)