Java Code Examples for org.apache.solr.common.cloud.DocCollection#getActiveSlices()
The following examples show how to use
org.apache.solr.common.cloud.DocCollection#getActiveSlices() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SolrConfigHandler.java From lucene-solr with Apache License 2.0 | 6 votes |
public static List<String> getActiveReplicaCoreUrls(ZkController zkController, String collection) { List<String> activeReplicaCoreUrls = new ArrayList<>(); ClusterState clusterState = zkController.getZkStateReader().getClusterState(); Set<String> liveNodes = clusterState.getLiveNodes(); final DocCollection docCollection = clusterState.getCollectionOrNull(collection); if (docCollection != null && docCollection.getActiveSlices() != null && docCollection.getActiveSlices().size() > 0) { final Collection<Slice> activeSlices = docCollection.getActiveSlices(); for (Slice next : activeSlices) { Map<String, Replica> replicasMap = next.getReplicasMap(); if (replicasMap != null) { for (Map.Entry<String, Replica> entry : replicasMap.entrySet()) { Replica replica = entry.getValue(); if (replica.getState() == Replica.State.ACTIVE && liveNodes.contains(replica.getNodeName())) { activeReplicaCoreUrls.add(replica.getCoreUrl()); } } } } } return activeReplicaCoreUrls; }
Example 2
Source File: BasicDistributedZkTest.java From lucene-solr with Apache License 2.0 | 6 votes |
private long checkSlicesSameCounts(DocCollection dColl) throws SolrServerException, IOException { long docTotal = 0; // total number of documents found counting only one replica per slice. for (Slice slice : dColl.getActiveSlices()) { long sliceDocCount = -1; for (Replica rep : slice.getReplicas()) { try (HttpSolrClient one = getHttpSolrClient(rep.getCoreUrl())) { SolrQuery query = new SolrQuery("*:*"); query.setDistrib(false); QueryResponse resp = one.query(query); long hits = resp.getResults().getNumFound(); if (sliceDocCount == -1) { sliceDocCount = hits; docTotal += hits; } else { if (hits != sliceDocCount) { return -1; } } } } } return docTotal; }
Example 3
Source File: SolrCloudTestCase.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Get a (reproducibly) random shard from a {@link DocCollection} */ protected static Slice getRandomShard(DocCollection collection) { List<Slice> shards = new ArrayList<>(collection.getActiveSlices()); if (shards.size() == 0) fail("Couldn't get random shard for collection as it has no shards!\n" + collection.toString()); Collections.shuffle(shards, random()); return shards.get(0); }
Example 4
Source File: BlobRepository.java From lucene-solr with Apache License 2.0 | 5 votes |
private Replica getSystemCollReplica() { ZkStateReader zkStateReader = this.coreContainer.getZkController().getZkStateReader(); ClusterState cs = zkStateReader.getClusterState(); DocCollection coll = cs.getCollectionOrNull(CollectionAdminParams.SYSTEM_COLL); if (coll == null) throw new SolrException(SERVICE_UNAVAILABLE, CollectionAdminParams.SYSTEM_COLL + " collection not available"); ArrayList<Slice> slices = new ArrayList<>(coll.getActiveSlices()); if (slices.isEmpty()) throw new SolrException(SERVICE_UNAVAILABLE, "No active slices for " + CollectionAdminParams.SYSTEM_COLL + " collection"); Collections.shuffle(slices, RANDOM); //do load balancing Replica replica = null; for (Slice slice : slices) { List<Replica> replicas = new ArrayList<>(slice.getReplicasMap().values()); Collections.shuffle(replicas, RANDOM); for (Replica r : replicas) { if (r.getState() == Replica.State.ACTIVE) { if (zkStateReader.getClusterState().getLiveNodes().contains(r.get(ZkStateReader.NODE_NAME_PROP))) { replica = r; break; } else { if (log.isInfoEnabled()) { log.info("replica {} says it is active but not a member of live nodes", r.get(ZkStateReader.NODE_NAME_PROP)); } } } } } if (replica == null) { throw new SolrException(SERVICE_UNAVAILABLE, "No active replica available for " + CollectionAdminParams.SYSTEM_COLL + " collection"); } return replica; }
Example 5
Source File: AbstractCloudBackupRestoreTestCase.java From lucene-solr with Apache License 2.0 | 5 votes |
private Map<String, Integer> getShardToDocCountMap(CloudSolrClient client, DocCollection docCollection) throws SolrServerException, IOException { Map<String,Integer> shardToDocCount = new TreeMap<>(); for (Slice slice : docCollection.getActiveSlices()) { String shardName = slice.getName(); try (HttpSolrClient leaderClient = new HttpSolrClient.Builder(slice.getLeader().getCoreUrl()).withHttpClient(client.getHttpClient()).build()) { long docsInShard = leaderClient.query(new SolrQuery("*:*").setParam("distrib", "false")) .getResults().getNumFound(); shardToDocCount.put(shardName, (int) docsInShard); } } return shardToDocCount; }
Example 6
Source File: SolrCloudExampleTest.java From lucene-solr with Apache License 2.0 | 5 votes |
private Map<String, Long> getSoftAutocommitInterval(String collection) throws Exception { Map<String, Long> ret = new HashMap<>(); DocCollection coll = cloudClient.getZkStateReader().getClusterState().getCollection(collection); for (Slice slice : coll.getActiveSlices()) { for (Replica replica : slice.getReplicas()) { String uri = "" + replica.get(ZkStateReader.BASE_URL_PROP) + "/" + replica.get(ZkStateReader.CORE_NAME_PROP) + "/config"; @SuppressWarnings({"rawtypes"}) Map respMap = getAsMap(cloudClient, uri); Long maxTime = (Long) (getObjectByPath(respMap, true, asList("config", "updateHandler", "autoSoftCommit", "maxTime"))); ret.put(replica.getCoreName(), maxTime); } } return ret; }
Example 7
Source File: SimSolrCloudTestCase.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Get a (reproducibly) random shard from a {@link DocCollection} */ protected static Slice getRandomShard(DocCollection collection) { List<Slice> shards = new ArrayList<>(collection.getActiveSlices()); if (shards.size() == 0) fail("Couldn't get random shard for collection as it has no shards!\n" + collection.toString()); Collections.shuffle(shards, random()); return shards.get(0); }