Skip to content

Commit b365b95

Browse files
author
mpv1989
committed
Fix reconnecting after ArangoDB restarts (issue #186)
1 parent b510107 commit b365b95

File tree

8 files changed

+28
-2
lines changed

8 files changed

+28
-2
lines changed

ChangeLog

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
v4.3.8 (2018-xx-xx)
22
---------------------------
33

4-
* Changed dependency com.arangodb:velocypack to 1.0.15
4+
* changed dependency com.arangodb:velocypack to 1.0.15
55
* fixed DateUtil does incorrect conversion of UTC time
6+
* fixed reconnecting after ArangoDB restarts (issue #186)
67

78
v4.3.7 (2018-04-17)
89
---------------------------

src/main/java/com/arangodb/internal/http/HttpConnection.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ public Response execute(final Request request) throws ArangoDBException, IOExcep
191191
host = hostHandler.get();
192192
while (true) {
193193
if (host == null) {
194+
hostHandler.reset();
194195
throw new ArangoDBException("Was not able to connect to any host");
195196
}
196197
try {

src/main/java/com/arangodb/internal/net/DelHostHandler.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,10 @@ public void fail() {
5858
}
5959
}
6060

61+
@Override
62+
public void reset() {
63+
host = null;
64+
hostHandler.reset();
65+
}
66+
6167
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,9 @@ public void fail() {
6262
}
6363
}
6464

65+
@Override
66+
public void reset() {
67+
iterations = 0;
68+
}
69+
6570
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,6 @@ public interface HostHandler {
3434

3535
void fail();
3636

37+
void reset();
38+
3739
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,9 @@ private Host getRandomHost(final boolean initial, final boolean closeConnections
6868
return hosts.get(0);
6969
}
7070

71+
@Override
72+
public void reset() {
73+
fallback.reset();
74+
}
75+
7176
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,9 @@ public void fail() {
6262
fails++;
6363
}
6464

65+
@Override
66+
public void reset() {
67+
fails = 0;
68+
}
69+
6570
}

src/main/java/com/arangodb/internal/velocystream/internal/VstConnection.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public synchronized void open() throws IOException {
103103
host = hostHandler.get();
104104
while (true) {
105105
if (host == null) {
106+
hostHandler.reset();
106107
throw new ArangoDBException("Was not able to connect to any host");
107108
}
108109
if (LOGGER.isDebugEnabled()) {
@@ -160,7 +161,7 @@ public Void call() throws Exception {
160161
while (true) {
161162
if (ttlTime != null && new Date().getTime() > ttlTime && messageStore.isEmpty()) {
162163
close();
163-
hostHandler.fail();
164+
hostHandler.reset();
164165
break;
165166
}
166167
if (!isOpen()) {

0 commit comments

Comments
 (0)