Skip to content

Commit fcff8e6

Browse files
committed
JAVA-1565: Mark node down when it loses its last connection and was already reconnecting
1 parent 3e72da2 commit fcff8e6

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

changelog/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### 4.0.0-alpha2 (in progress)
66

7+
- [bug] JAVA-1565: Mark node down when it loses its last connection and was already reconnecting
78
- [bug] JAVA-1594: Don't create pool if node comes back up but is ignored
89
- [bug] JAVA-1593: Reconnect control connection if current node is removed, forced down or ignored
910
- [bug] JAVA-1595: Don't use system.local.rpc_address when refreshing node list

core/src/main/java/com/datastax/oss/driver/internal/core/metadata/NodeStateManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ private void onChannelEvent(ChannelEvent event) {
117117
break;
118118
case CLOSED:
119119
node.openConnections -= 1;
120+
if (node.openConnections == 0 && node.reconnections > 0) {
121+
setState(node, NodeState.DOWN, "it was reconnecting and lost its last connection");
122+
}
120123
break;
121124
case RECONNECTION_STARTED:
122125
node.reconnections += 1;

core/src/test/java/com/datastax/oss/driver/internal/core/metadata/NodeStateManagerTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,21 @@ public void should_mark_node_down_if_reconnection_starts_with_no_connections() {
482482
Mockito.verify(eventBus).fire(NodeStateEvent.changed(NodeState.UP, NodeState.DOWN, node1));
483483
}
484484

485+
@Test
486+
public void should_mark_node_down_if_no_connections_and_reconnection_already_started() {
487+
new NodeStateManager(context);
488+
489+
node1.state = NodeState.UP;
490+
node1.openConnections = 1;
491+
492+
eventBus.fire(ChannelEvent.reconnectionStarted(node1));
493+
eventBus.fire(ChannelEvent.channelClosed(node1));
494+
waitForPendingAdminTasks();
495+
496+
assertThat(node1.state).isEqualTo(NodeState.DOWN);
497+
Mockito.verify(eventBus).fire(NodeStateEvent.changed(NodeState.UP, NodeState.DOWN, node1));
498+
}
499+
485500
@Test
486501
public void should_keep_node_up_if_reconnection_starts_with_some_connections() {
487502
new NodeStateManager(context);

0 commit comments

Comments
 (0)