How does Cassandra choose node to send a request to?

Imagine that a Cassandra cluster should be accessible by a client application. In the Java api, we create a cluster instance and send a request to read or write through the session. If we use ONE read / write consistency, how api selects the actual node (node ​​coordinator) to forward the request. Is this a random choice? please help understand this.

+6
source share
1 answer

Cassandra drivers use the gossip protocol (and a process called node) to obtain information about the cluster. If a node becomes unavailable, the client driver automatically tries to use other nodes and re-connect time with the dead (s). In the section for DataStax documents :

Gossip is a peer-to-peer communication protocol in which nodes periodically exchange state information about themselves and other nodes that they know about. A gossip process runs every second and status messages are exchanged with three other nodes in the cluster. Nodes exchange information about themselves and other nodes with which they gossip, so all nodes quickly learn about all the other nodes in the cluster.

In fact, the list of nodes to which you connect your client are the initial contact points for obtaining information about the entire cluster. This is why your client can communicate with all nodes in the cluster (if necessary), even if you can provide only a small subset of nodes in your connection string.

Once your driver receives information about the gossip in the cluster, it can then make reasonable decisions about why the node should run the request. node selection is not a voting or random selection process. Based on the returned gossip information, the client driver applies its load balancing policy . While this takes into account several factors, it mainly tries to select the node with the lowest network distance from the client.

+7
source

Source: https://habr.com/ru/post/978542/


All Articles