1
votes

I have setup Solr 7.4 cluster with 3 nodes and 3 replicas and one collection with 5 shards

I added a collection called ‍‍posts (with 5 shards and 3 replicas), and by default, the leader of all its shards is 196.209.182.40

enter image description here

Is it appropriate that each shard has a different node as a leader?

for example :

enter image description here

Why Solr chooses all the leaders alike?

1

1 Answers

2
votes

Since shards can be located on completely different servers (and usually are), instead of as shown in your example where all shards are located on the same set of three nodes, yes, there can be different leaders for all shards.

The election process is described in Shards and indexing in SolrCloud.

In SolrCloud there are no masters or slaves. Instead, every shard consists of at least one physical replica, exactly one of which is a leader. Leaders are automatically elected, initially on a first-come-first-served basis, and then based on the ZooKeeper process described at https://zookeeper.apache.org/doc/r3.1.2/recipes.html#sc_leaderElection.

Referenced from the URL above:

A simple way of doing leader election with ZooKeeper is to use the SEQUENCE|EPHEMERAL flags when creating znodes that represent "proposals" of clients. The idea is to have a znode, say "/election", such that each znode creates a child znode "/election/n_" with both flags SEQUENCE|EPHEMERAL. With the sequence flag, ZooKeeper automatically appends a sequence number that is greater that any one previously appended to a child of "/election". The process that created the znode with the smallest appended sequence number is the leader.

In your case the same node was the first to respond in all cases (and possibly the one you submitted the create request to), and thus, was elected the original leader.