本文整理汇总了Java中org.apache.solr.common.cloud.ClusterState.getActiveSlices方法的典型用法代码示例。如果您正苦于以下问题:Java ClusterState.getActiveSlices方法的具体用法?Java ClusterState.getActiveSlices怎么用?Java ClusterState.getActiveSlices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.solr.common.cloud.ClusterState
的用法示例。
在下文中一共展示了ClusterState.getActiveSlices方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getActiveOrRecoveringReplicas
import org.apache.solr.common.cloud.ClusterState; //导入方法依赖的package包/类
protected List<Replica> getActiveOrRecoveringReplicas(String testCollectionName, String shardId) throws Exception {
Map<String,Replica> activeReplicas = new HashMap<String,Replica>();
ZkStateReader zkr = cloudClient.getZkStateReader();
ClusterState cs = zkr.getClusterState();
assertNotNull(cs);
for (Slice shard : cs.getActiveSlices(testCollectionName)) {
if (shard.getName().equals(shardId)) {
for (Replica replica : shard.getReplicas()) {
String replicaState = replica.getStr(ZkStateReader.STATE_PROP);
if (ZkStateReader.ACTIVE.equals(replicaState) || ZkStateReader.RECOVERING.equals(replicaState)) {
activeReplicas.put(replica.getName(), replica);
}
}
}
}
List<Replica> replicas = new ArrayList<Replica>();
replicas.addAll(activeReplicas.values());
return replicas;
}
示例2: getRemotCoreUrl
import org.apache.solr.common.cloud.ClusterState; //导入方法依赖的package包/类
private String getRemotCoreUrl(CoreContainer cores, String collectionName, String origCorename) {
ClusterState clusterState = cores.getZkController().getClusterState();
Collection<Slice> slices = clusterState.getActiveSlices(collectionName);
boolean byCoreName = false;
if (slices == null) {
slices = new ArrayList<>();
// look by core name
byCoreName = true;
slices = getSlicesForCollections(clusterState, slices, true);
if (slices == null || slices.size() == 0) {
slices = getSlicesForCollections(clusterState, slices, false);
}
}
if (slices == null || slices.size() == 0) {
return null;
}
String coreUrl = getCoreUrl(cores, collectionName, origCorename, clusterState,
slices, byCoreName, true);
if (coreUrl == null) {
coreUrl = getCoreUrl(cores, collectionName, origCorename, clusterState,
slices, byCoreName, false);
}
return coreUrl;
}
示例3: getRemotCoreUrl
import org.apache.solr.common.cloud.ClusterState; //导入方法依赖的package包/类
private String getRemotCoreUrl(CoreContainer cores, String collectionName, String origCorename) {
ClusterState clusterState = cores.getZkController().getClusterState();
Collection<Slice> slices = clusterState.getActiveSlices(collectionName);
boolean byCoreName = false;
if (slices == null) {
slices = new ArrayList<Slice>();
// look by core name
byCoreName = true;
slices = getSlicesForCollections(clusterState, slices, true);
if (slices == null || slices.size() == 0) {
slices = getSlicesForCollections(clusterState, slices, false);
}
}
if (slices == null || slices.size() == 0) {
return null;
}
String coreUrl = getCoreUrl(cores, collectionName, origCorename, clusterState,
slices, byCoreName, true);
if (coreUrl == null) {
coreUrl = getCoreUrl(cores, collectionName, origCorename, clusterState,
slices, byCoreName, false);
}
return coreUrl;
}
示例4: ensureAllReplicasAreActive
import org.apache.solr.common.cloud.ClusterState; //导入方法依赖的package包/类
protected static void ensureAllReplicasAreActive(String testCollectionName, int shards, int rf, int maxWaitSecs)
throws Exception {
long startMs = System.currentTimeMillis();
ZkStateReader zkr = cloudSolrClient.getZkStateReader();
zkr.updateClusterState(); // force the state to be fresh
ClusterState cs = zkr.getClusterState();
Collection<Slice> slices = cs.getActiveSlices(testCollectionName);
assertTrue(slices.size() == shards);
boolean allReplicasUp = false;
long waitMs = 0L;
long maxWaitMs = maxWaitSecs * 1000L;
Replica leader = null;
while (waitMs < maxWaitMs && !allReplicasUp) {
// refresh state every 2 secs
if (waitMs % 2000 == 0) {
log.info("Updating ClusterState");
cloudSolrClient.getZkStateReader().updateClusterState();
}
cs = cloudSolrClient.getZkStateReader().getClusterState();
assertNotNull(cs);
allReplicasUp = true; // assume true
for (Slice shard : cs.getActiveSlices(testCollectionName)) {
String shardId = shard.getName();
assertNotNull("No Slice for " + shardId, shard);
Collection<Replica> replicas = shard.getReplicas();
assertTrue(replicas.size() == rf);
leader = shard.getLeader();
assertNotNull(leader);
log.info("Found " + replicas.size() + " replicas and leader on " +
leader.getNodeName() + " for " + shardId + " in " + testCollectionName);
// ensure all replicas are "active"
for (Replica replica : replicas) {
String replicaState = replica.getStr(ZkStateReader.STATE_PROP);
if (!"active".equals(replicaState)) {
log.info("Replica " + replica.getName() + " for shard " + shardId + " is currently " + replicaState);
allReplicasUp = false;
}
}
}
if (!allReplicasUp) {
try {
Thread.sleep(500L);
} catch (Exception ignoreMe) {
}
waitMs += 500L;
}
} // end while
if (!allReplicasUp)
fail("Didn't see all replicas for " + testCollectionName +
" come up within " + maxWaitMs + " ms! ClusterState: " + printClusterStateInfo(testCollectionName));
long diffMs = (System.currentTimeMillis() - startMs);
log.info("Took " + diffMs + " ms to see all replicas become active for " + testCollectionName);
}
示例5: getShardReplicationFactor
import org.apache.solr.common.cloud.ClusterState; //导入方法依赖的package包/类
/**
* Walks the NamedList response after performing an update request looking for
* the replication factor that was achieved in each shard involved in the request.
* For single doc updates, there will be only one shard in the return value.
*/
@SuppressWarnings("rawtypes")
public Map<String,Integer> getShardReplicationFactor(String collection, NamedList resp) {
connect();
Map<String,Integer> results = new HashMap<String,Integer>();
if (resp instanceof CloudSolrServer.RouteResponse) {
NamedList routes = ((CloudSolrServer.RouteResponse)resp).getRouteResponses();
ClusterState clusterState = zkStateReader.getClusterState();
Map<String,String> leaders = new HashMap<String,String>();
for (Slice slice : clusterState.getActiveSlices(collection)) {
Replica leader = slice.getLeader();
if (leader != null) {
ZkCoreNodeProps zkProps = new ZkCoreNodeProps(leader);
String leaderUrl = zkProps.getBaseUrl() + "/" + zkProps.getCoreName();
leaders.put(leaderUrl, slice.getName());
String altLeaderUrl = zkProps.getBaseUrl() + "/" + collection;
leaders.put(altLeaderUrl, slice.getName());
}
}
Iterator<Map.Entry<String,Object>> routeIter = routes.iterator();
while (routeIter.hasNext()) {
Map.Entry<String,Object> next = routeIter.next();
String host = next.getKey();
NamedList hostResp = (NamedList)next.getValue();
Integer rf = (Integer)((NamedList)hostResp.get("responseHeader")).get(UpdateRequest.REPFACT);
if (rf != null) {
String shard = leaders.get(host);
if (shard == null) {
if (host.endsWith("/"))
shard = leaders.get(host.substring(0,host.length()-1));
if (shard == null) {
shard = host;
}
}
results.put(shard, rf);
}
}
}
return results;
}
示例6: waitToSeeReplicasActive
import org.apache.solr.common.cloud.ClusterState; //导入方法依赖的package包/类
protected void waitToSeeReplicasActive(String testCollectionName, String shardId, Set<String> replicasToCheck, int maxWaitSecs) throws Exception {
long startMs = System.currentTimeMillis();
ZkStateReader zkr = cloudClient.getZkStateReader();
zkr.updateClusterState(true); // force the state to be fresh
ClusterState cs = zkr.getClusterState();
Collection<Slice> slices = cs.getActiveSlices(testCollectionName);
boolean allReplicasUp = false;
long waitMs = 0L;
long maxWaitMs = maxWaitSecs * 1000L;
while (waitMs < maxWaitMs && !allReplicasUp) {
// refresh state every 2 secs
if (waitMs % 2000 == 0)
cloudClient.getZkStateReader().updateClusterState(true);
cs = cloudClient.getZkStateReader().getClusterState();
assertNotNull(cs);
Slice shard = cs.getSlice(testCollectionName, shardId);
assertNotNull("No Slice for "+shardId, shard);
allReplicasUp = true; // assume true
// wait to see all replicas are "active"
for (Replica replica : shard.getReplicas()) {
if (!replicasToCheck.contains(replica.getName()))
continue;
String replicaState = replica.getStr(ZkStateReader.STATE_PROP);
if (!ZkStateReader.ACTIVE.equals(replicaState)) {
log.info("Replica " + replica.getName() + " is currently " + replicaState);
allReplicasUp = false;
}
}
if (!allReplicasUp) {
try {
Thread.sleep(1000L);
} catch (Exception ignoreMe) {}
waitMs += 1000L;
}
} // end while
if (!allReplicasUp)
fail("Didn't see replicas "+ replicasToCheck +
" come up within " + maxWaitMs + " ms! ClusterState: " + printClusterStateInfo(testCollectionName));
long diffMs = (System.currentTimeMillis() - startMs);
log.info("Took " + diffMs + " ms to see replicas ["+replicasToCheck+"] become active.");
}