-
Notifications
You must be signed in to change notification settings - Fork 25.8k
split brain condition after second network disconnect - even with minimum_master_nodes set #2117
Description
Summary:
Split brain can occur on the second network disconnect of a node, when the minimum_master_nodes is configured correctly(n/2+1). The split brain occurs if the nodeId(UUID) of the disconnected node is such that the disconnected node picks itself as the next logical master while pinging the other nodes(NodeFaultDetection). The split brain only occurs on the second time that the node is disconnected/isolated.
Detail:
Using ZenDiscovery, Node Id's are randomly generated(A UUID): ZenDiscovery:169.
When the node is disconnected/isolated it the ElectMasterService uses an ordered list of the Nodes (Ordered by nodeId) to determine a new potential master. It picks the first of the ordered list: ElectMasterService:95
Because the nodeId's are random, it's possible for the disconnected/isolated node to be first in the ordered list, electing itself as a possible master.
The first time network is disconnected, the minimum_master_nodes property is honored and the disconnected/isolated node goes into a "ping" mode, where it simply tries to ping for other nodes. Once the network is re-connected, the node re-joins the cluster successfully.
The Second time the network is disconnected, the minimum_master_nodes intent is not honored. The disconnected/isolated node fails to realise that it's not connected to the remaining node in the 3 node cluster and elects itself as master, still thinking it's connected.
It feels like there is a failure in the transition between MasterFaultDetection and NodeFaultDetection, because it works the first time!
The fault only occurs if the nodeId is ordered such that the disconnected node picks itself as the master while isolated. If the nodeId's are ordered such that it picks one of the other 2 nodes to be potential master then the isolated node honors the minimum_master_nodes intent every time.
Because the nodeId's are randomly(UUID) generated, the probability of this occuring drops as the number of nodes in the cluster goes up. For our 3 node cluster it's ~50% (with one node detected as gone, it's up to the ordering of the remaining two nodeId's)
Note, While we were trying track this down we found that the cluster.service TRACE level logging (which outputs the cluster state) does not list the nodes in election order. IE, the first node in that printed list is not necessarily going to elected as master by the isolated node.
Detail Steps to reproduce:
Because the ordering of the nodeId's is random(UUID) we were having trouble getting a consitantly reproducable test case. To fix the ordering, we made a patch to ZenDiscovery to allow us to optionally configure a nodeId. This allowed us to set the nodeId of the disconnected/isolated node to guarantee it's ordering, allowing us to consistently reproduce.
We've tested this scenario on the 0.19.4, 0.19.7, 0.19.8 distributions and see the error when the nodeId's were ordered just right.
We also tested this scenario on the current git master with the supplied patch.
In this scenario, node3 will the be the node we disconnect/isolate. So we start the nodes up in numerical order to ensure node3 doesn't start as master.
- Configure nodes with attached configs (one is provided for each node)
- Start up nodes 1 and 2. After they are attached and one is master, start node 3
- Create a blank index with default shard/replica(5/1) settings
- Pull network cable from node 3
- Node 3 detects master has gone (MasterFaultDetection)
- Node 3 elects itself as master (Because the nodeId's are ordered just right)
- Node 3 detects the remaining node has gone, enters ZenDiscovery minimum_master_nodes mode, prints a message indicating not enough nodes
- Node 3 goes into a ping state looking for nodes
- At this point, node 1 and node 2 report a valid cluster, they know about each other but not about node 3.
- Reconnect network to node 3
- Node 3 rejoins the cluster correctly, seeing that there is already a master in the cluster.
At this point, everything is working as expected.
- Pull network cable from node 3 again
- Node 3 detects master has gone (MasterFaultDetection)
- Node 3 elects as itself as master (Because the nodeId's are ordered just right)
- Node 3 now fails to detect that the remaining node in the cluster is not accessible. It starts throwing a number of Netty NoRouteToHostExceptions about the remaining node.
- According to node 3, cluster health is yellow and cluster state shows 2 data nodes
- Reconnect network to node 3
- Node 3 appears to connect to the node that it thinks it's still connected to. (can see that via the cluster state api). The other nodes log nothing and do not show the disconnected node as connected in any way.
- Node 3 at this point accepts indexing and search requests, a classic split brain.
Here's a gist with the patch to ZenDiscovery and the 3 node configs.