I'm having a single shard and 1 leader & 1 replica architecture. When using "CloudSolrClient", queries are being distributed to both leader and replica. But is there a way to point it only to leader(using zookeeper) other than finding the leader manually and building the query?
Asked
Active
Viewed 445 times
0
-
What is the need for such use case when deployed in cloud mode. ? Why don't you deploy single standalone solr server. – Shivakumar ss Dec 07 '16 at 13:05
-
Another option is in solrj create instance of httpsolrclient pointing to your leader. This will by pass your zookeeper. – Shivakumar ss Dec 07 '16 at 13:07
-
@ShivaKumarSS We are facing some issue during "merge"(merging old document with new document). So during indexing, we want the queries to point leader directly when finding old document (for merge). – Riya Dec 07 '16 at 13:11
-
Check my #2 comment – Shivakumar ss Dec 07 '16 at 13:12
-
@ShivaKumarSS But in case of leader going down(for some reason), and the replica taking place as a leader, we have to change the httpsolr URL manually. so is there is way to use zookeeper for this?so that it automatically take cares? – Riya Dec 07 '16 at 13:15
1 Answers
0
It's possible to get the Shards leader in SolrJ and there are several scenarios where this is useful, like for instance when you need to perform a backup programmatically (see example in Solr in Action book). Here is the relevant code I use:
private final String COLLECTION_NAME = "myCollection";
private final String ZOOKEPER_CLIENT_TIMEOUT_MS = "1000000"
private Map<String, String> getShardLeaders(CloudSolrServer cloudSolrServer) throws InterruptedException, KeeperException {
Map<String, String> shardleaders = new TreeMap<String, String>();
ZkStateReader zkStateReader = cloudSolrServer.getZkStateReader();
for (Slice slice : zkStateReader.getClusterState().getSlices(COLLECTION_NAME)) {
shardleaders.put(slice.getName(), zkStateReader.getLeaderUrl(COLLECTION_NAME, slice.getName(), ZOOKEPER_CLIENT_TIMEOUT_MS));
}
return shardleaders;
}

AR1
- 4,507
- 4
- 26
- 42