Make delicious recipes!

Setting up Solr cloud


Solr ships with Zookeeper to provide for an easy cloud setup. Zookeeper can be run as a single node or it can be run as a cloud to avoid a single point of failure. Both options are discussed below.



Setting up Solr Cloud with one ZooKeeper(ZK)


#Start first server on default port 8983 (with embedded Zookeeper):
  java -DzkRun -DnumShards=2 -Dbootstrap_confdir=./solr/collection1/conf \
  -Dcollection.configName=myconf -jar start.jar

#Start second server on port 7574:
  java -Djetty.port=7574 -DzkHost=localhost:9983 -jar start.jar

#Start third server on port 7500:
  java -Djetty.port=7500 -DzkHost=localhost:9983 -jar start.jar

First server has some interesting options:
  1. -DzkRun: Instructs Solr to start Zookeeper along with regular Solr server.
  2. -DnumShards=2: Instructs Zookeeper/Solr combination to divide the data into two shards only.
    If more nodes are added to cloud, they will become replicas of the system.


See the cloud building
Execute each of the above commands one by one and refresh the page at http://localhost:8983/solr/#/~cloud after every execution.
This page will show you how the cloud is being formed.


Availability in a shard

When a replica gets a request, following happens:
  1. Replica (in this case the server on port 7500) gets the request.
  2. Replica forwards request to its leader (in this case the server on port 8983).
  3. The leader processes the request, and makes sure that all of its replicas process the request as well

If a leader goes down in a shard, a new leader is auto-elected but every shard must have at least one server running to provide full availability. If all nodes in a shard are dead, data from that shard will not be available to outside world.



Creating a ZK ensemble


In the above setup, there is only one Zookeeper node.
If the server with ZooKeeper (ZK) goes down, SolrCloud will still function but remaining servers will not get updates about future node failures or comebacks. This is fixed by keeping ZK external to Solr and adding multiple ZK instances to create a ZK ensemble. Since Solr comes with Zookeeper embedded, one can run few Solr servers along with built-in Zookeeper. This will create a Zookeeper ensemble among few nodes of the Solr Cloud and provide better availability.

Assuming ZK-ensemble is planned to be run on ports 9983,8574 and 9900,
#Start first solr server with ZK as:
#(Note that the order of parameters cannot be changed)
java -DzkRun -DnumShards=2 -Dbootstrap_confdir=./solr/collection1/conf \
   -Dcollection.configName=myconf -DzkHost=localhost:9983,localhost:8574,localhost:9900 \
   -jar start.jar

#Next server is started as: (Note the port numbers)
java -Djetty.port=7574 -DzkRun -DnumShards=2 \
    -DzkHost=localhost:9983,localhost:8574,localhost:9900 -jar start.jar

#Last server with ZK is started as:
java -Djetty.port=8900 -DzkRun -DnumShards=2 \
    -DzkHost=localhost:9983,localhost:8574,localhost:9900 -jar start.jar

#Finally, last server without ZK is started as:
java -Djetty.port=7500 -DzkHost=localhost:9983,localhost:8574,localhost:9900 \
    -jar start.jar

Notes:
  1. First three servers are running Zookeeper (so they have the params: -DzkRun -DnumShards=2)

  2. Last server is not running Zookeeper. It is only connecting to the cloud.

  3. Ports given to the option -Djetty.port are 7574, 8900, 7500 and the default 8983.
    Yet, the ports in -DzkHost=localhost:9983,localhost:8574,localhost:9900 are 9983, 8574 and 9900.
    This is so because by default Solr runs Zookeeper at: 1000 + Solr-Port


Node failures

If a node fails for sometime and then rejoins the cluster, it syncs itself with the leader. If very few changes have been committed (hard-coded to 100 in initial releases of Solr), then the node just pulls those changes from the leader's update log. This is called Peer Sync. If too many changes have been committed, then it replicates the entire snapshot from the leader. This is called Snapshot Replication

The ZK ensemble runs as long as half of its servers are running.










Like us on Facebook to remain in touch
with the latest in technology and tutorials!


Got a thought to share or found a
bug in the code?
We'd love to hear from you:

Name:
Email: (Your email is not shared with anybody)
Comment:

Facebook comments:

Site Owner: Sachin Goyal