You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by manohar211 <ma...@gmail.com> on 2014/09/04 13:37:20 UTC
Solr API for getting shard's leader/replica status
Solr has a Admin UI where we can check each and every Collections that were
deployed to Solr Cloud. For example, I can see a Slice/Shard in a collection
up or not in the mentioned diagram.
<http://lucene.472066.n3.nabble.com/file/n4156902/cloud-graph.png>
Our production environment doesn't provide access to this Admin UI due to
security reasons. I need to provide an API to get the status of each and
every collection, and its shards and each shard's replica. I am using Solr
APIs to do that
http://lucene.apache.org/solr/4_7_2/solr-solrj/index.html
/CloudSolrServer server = new CloudSolrServer(<zk quorum>);
ZkStateReader reader = server.getZkStateReader();
Collection<Slice> slices = reader.getClusterState().getSlices(collection);
Iterator<Slice> iter = slices.iterator();
while (iter.hasNext()) {
Slice slice = iter.next();
System.out.println(slice.getName());
System.out.println(slice.getState());
}/
The above piece of code is always returning Active only as the state of
shard, even its replica is showing down in the UI. I assume this returns
only the state of a shard, not the state of shard's leader or replica.
How can I get the replicas status through Solr APIs? is there any API for
this? And what is the API being using by Solr Admin UI for getting shard's
replicas/leader status?
Thanks
--
View this message in context: http://lucene.472066.n3.nabble.com/Solr-API-for-getting-shard-s-leader-replica-status-tp4156902.html
Sent from the Solr - User mailing list archive at Nabble.com.
Re: Solr API for getting shard's leader/replica status
Posted by Jeff Wartes <jw...@whitepages.com>.
I had a similar need. The resulting tool is in scala, but it still might
be useful to look at. I had to work through some of those same issues:
https://github.com/whitepages/solrcloud_manager
>From a clusterstate perspective, I mostly cared about active vs
non-active, so hereĀ¹s a sample output of printing the cluster state:
sbt "run -z zookeeper.example.com:2181/qa"
[info] Running com.whitepages.CLI -z zookeeper.example.com:2181/qa
Aliases:
collection1-current -> collection1
Nodes:
101.16.0.101:8980/solr (up/used)
101.16.0.103:8980/solr (up/used)
Collection Slice ReplicaName Host ActiveSlice ActiveReplica CoreName
collection1 shard1* core_node2 101.16.0.103:8980/solr true true collection1
_shard1_replica1
collection1 shard1 core_node3 101.16.0.101:8980/solr true true collection1_
shard1_replica2
collection1 shard2* core_node1 101.16.0.103:8980/solr true true collection1
_shard2_replica1
collection1 shard2 core_node4 101.16.0.101:8980/solr true true collection1_
shard2_replica2
On 9/5/14, 2:21 AM, "manohar211" <ma...@gmail.com> wrote:
>Thanks for the comments!!
>I found out the solution on how I can get the replica's state. Here's the
>piece of code.
>
>while (iter.hasNext()) {
> Slice slice = iter.next();
> for(Replica replica:slice.getReplicas()) {
>
> System.out.println("replica state for " +
>replica.getStr("core")
>+ " : "+ replica.getStr( "state" ));
>
> System.out.println(slice.getName());
> System.out.println(slice.getState());
> }
> }
>
>
>
>--
>View this message in context:
>http://lucene.472066.n3.nabble.com/Solr-API-for-getting-shard-s-leader-rep
>lica-status-tp4156902p4157108.html
>Sent from the Solr - User mailing list archive at Nabble.com.
Re: Solr API for getting shard's leader/replica status
Posted by manohar211 <ma...@gmail.com>.
Thanks for the comments!!
I found out the solution on how I can get the replica's state. Here's the
piece of code.
while (iter.hasNext()) {
Slice slice = iter.next();
for(Replica replica:slice.getReplicas()) {
System.out.println("replica state for " + replica.getStr("core")
+ " : "+ replica.getStr( "state" ));
System.out.println(slice.getName());
System.out.println(slice.getState());
}
}
--
View this message in context: http://lucene.472066.n3.nabble.com/Solr-API-for-getting-shard-s-leader-replica-status-tp4156902p4157108.html
Sent from the Solr - User mailing list archive at Nabble.com.
Re: Solr API for getting shard's leader/replica status
Posted by Timothy Potter <th...@gmail.com>.
https://issues.apache.org/jira/browse/SOLR-6481
On Thu, Sep 4, 2014 at 12:32 PM, Timothy Potter <th...@gmail.com> wrote:
> You need to also verify the node hosting the replica is a live node
> (/live_nodes). From SolrJ, you can call:
> clusterState.getLiveNodes().contains(node).
>
> As for API, there is CLUSTERSTATE provided by the Collection API, but
> it's not consulting /live_nodes (which is a bug) - I'll open a ticket.
>
> On Thu, Sep 4, 2014 at 4:37 AM, manohar211 <ma...@gmail.com> wrote:
>> Solr has a Admin UI where we can check each and every Collections that were
>> deployed to Solr Cloud. For example, I can see a Slice/Shard in a collection
>> up or not in the mentioned diagram.
>> <http://lucene.472066.n3.nabble.com/file/n4156902/cloud-graph.png>
>>
>> Our production environment doesn't provide access to this Admin UI due to
>> security reasons. I need to provide an API to get the status of each and
>> every collection, and its shards and each shard's replica. I am using Solr
>> APIs to do that
>>
>> http://lucene.apache.org/solr/4_7_2/solr-solrj/index.html
>>
>> /CloudSolrServer server = new CloudSolrServer(<zk quorum>);
>> ZkStateReader reader = server.getZkStateReader();
>> Collection<Slice> slices = reader.getClusterState().getSlices(collection);
>> Iterator<Slice> iter = slices.iterator();
>> while (iter.hasNext()) {
>> Slice slice = iter.next();
>> System.out.println(slice.getName());
>> System.out.println(slice.getState());
>> }/
>>
>> The above piece of code is always returning Active only as the state of
>> shard, even its replica is showing down in the UI. I assume this returns
>> only the state of a shard, not the state of shard's leader or replica.
>>
>> How can I get the replicas status through Solr APIs? is there any API for
>> this? And what is the API being using by Solr Admin UI for getting shard's
>> replicas/leader status?
>>
>> Thanks
>>
>>
>>
>> --
>> View this message in context: http://lucene.472066.n3.nabble.com/Solr-API-for-getting-shard-s-leader-replica-status-tp4156902.html
>> Sent from the Solr - User mailing list archive at Nabble.com.
Re: Solr API for getting shard's leader/replica status
Posted by Timothy Potter <th...@gmail.com>.
You need to also verify the node hosting the replica is a live node
(/live_nodes). From SolrJ, you can call:
clusterState.getLiveNodes().contains(node).
As for API, there is CLUSTERSTATE provided by the Collection API, but
it's not consulting /live_nodes (which is a bug) - I'll open a ticket.
On Thu, Sep 4, 2014 at 4:37 AM, manohar211 <ma...@gmail.com> wrote:
> Solr has a Admin UI where we can check each and every Collections that were
> deployed to Solr Cloud. For example, I can see a Slice/Shard in a collection
> up or not in the mentioned diagram.
> <http://lucene.472066.n3.nabble.com/file/n4156902/cloud-graph.png>
>
> Our production environment doesn't provide access to this Admin UI due to
> security reasons. I need to provide an API to get the status of each and
> every collection, and its shards and each shard's replica. I am using Solr
> APIs to do that
>
> http://lucene.apache.org/solr/4_7_2/solr-solrj/index.html
>
> /CloudSolrServer server = new CloudSolrServer(<zk quorum>);
> ZkStateReader reader = server.getZkStateReader();
> Collection<Slice> slices = reader.getClusterState().getSlices(collection);
> Iterator<Slice> iter = slices.iterator();
> while (iter.hasNext()) {
> Slice slice = iter.next();
> System.out.println(slice.getName());
> System.out.println(slice.getState());
> }/
>
> The above piece of code is always returning Active only as the state of
> shard, even its replica is showing down in the UI. I assume this returns
> only the state of a shard, not the state of shard's leader or replica.
>
> How can I get the replicas status through Solr APIs? is there any API for
> this? And what is the API being using by Solr Admin UI for getting shard's
> replicas/leader status?
>
> Thanks
>
>
>
> --
> View this message in context: http://lucene.472066.n3.nabble.com/Solr-API-for-getting-shard-s-leader-replica-status-tp4156902.html
> Sent from the Solr - User mailing list archive at Nabble.com.