Solr API,用于获取分片的领导者/副本状态 [英] Solr API for getting shard's leader/replica status
问题描述
Solr有一个Admin UI,我们可以在其中检查部署到Solr Cloud的每个集合.例如,我可以看到集合中是否存在切片/碎片,如下面的URL所述.
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 as mentioned in the below URL.
出于安全原因,我们的生产环境无法提供对此Admin UI的访问权限.我需要提供一个API,以获取每个集合及其碎片和每个碎片副本的状态.我正在使用Solr API来做到这一点
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());
}
上面的代码始终仅将shard的状态返回为Active,即使其副本显示在UI中.我假设这仅返回分片的状态,而不返回分片的领导者或副本的状态.
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.
如何通过Solr API获取副本状态?是否有为此的任何API? Solr Admin UI正在使用什么API获取分片的副本/领导者状态?
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?
谢谢
推荐答案
代码未查看副本状态.这是一个打印出副本状态的文件:
The code is not looking at replica status. Here is one that prints out replica status:
CloudSolrServer server = new CloudSolrServer(zknodesurlstring);
server.setDefaultCollection("mycollection");
server.connect();
ZkStateReader reader = server.getZkStateReader();
Collection<Slice> slices = reader.getClusterState().getSlices("mycollection");
Iterator<Slice> iter = slices.iterator();
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());
}
}
这篇关于Solr API,用于获取分片的领导者/副本状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!