/** * Checks if the collection has already been created in Solr. */ private static boolean checkIfCollectionExists(CloudSolrClient server, String collection) throws KeeperException, InterruptedException { ZkStateReader zkStateReader = server.getZkStateReader(); zkStateReader.updateClusterState(true); ClusterState clusterState = zkStateReader.getClusterState(); return clusterState.getCollectionOrNull(collection) != null; }
/** * Returns true if the specified collection name exists, false otherwise. * * Implementation note: This method resolves the collection reference by calling * {@link CollectionRef#get()} which can make a call to ZooKeeper. This is necessary * because the semantics of how collection list is loaded have changed in SOLR-6629. * Please see javadocs in {@link ZkStateReader#refreshCollectionList(Watcher)} */ public boolean hasCollection(String collectionName) { return getCollectionOrNull(collectionName) != null; }
/** * Returns the corresponding {@link DocCollection} object for the given collection name * if such a collection exists. Returns null otherwise. Equivalent to getCollectionOrNull(collectionName, false) */ public DocCollection getCollectionOrNull(String collectionName) { return getCollectionOrNull(collectionName, false); }
@Override public DocCollection getCollection(String name) throws IOException { ClusterState cs = getClusterState(); return cs == null ? null : cs.getCollectionOrNull(name); }
/** * Get the named DocCollection object, or throw an exception if it doesn't exist. */ public DocCollection getCollection(String collection) { DocCollection coll = getCollectionOrNull(collection); if (coll == null) throw new SolrException(ErrorCode.BAD_REQUEST, "Could not find collection : " + collection); return coll; }
public Map<String, Slice> getSlicesMap(String collection) { DocCollection coll = getCollectionOrNull(collection); if (coll == null) return null; return coll.getSlicesMap(); }
public Collection<Slice> getActiveSlices(String collection) { DocCollection coll = getCollectionOrNull(collection); if (coll == null) return null; return coll.getActiveSlices(); }
/** * Get the named Slice for collection, or null if not found. */ public Slice getSlice(String collection, String sliceName) { DocCollection coll = getCollectionOrNull(collection); if (coll == null) return null; return coll.getSlice(sliceName); }
public Map<String, Slice> getActiveSlicesMap(String collection) { DocCollection coll = getCollectionOrNull(collection); if (coll == null) return null; return coll.getActiveSlicesMap(); }
/** * Get the named DocCollection object, or throw an exception if it doesn't exist. */ public DocCollection getCollection(String collection) { DocCollection coll = getCollectionOrNull(collection); if (coll == null) throw new SolrException(ErrorCode.BAD_REQUEST, "Could not find collection : " + collection); return coll; }
/** * Gets the replica by the core name (assuming the slice is unknown) or null if replica is not found. * If the slice is known, do not use this method. * coreNodeName is the same as replicaName */ public Replica getReplica(final String collection, final String coreNodeName) { return getReplica(getCollectionOrNull(collection), coreNodeName); }
public Collection<Slice> getSlices(String collection) { DocCollection coll = getCollectionOrNull(collection); if (coll == null) return null; return coll.getSlices(); }
public static boolean isAutoAddReplicas(ZkStateReader reader, String collection) { ClusterState clusterState = reader.getClusterState(); if (clusterState != null) { DocCollection docCollection = clusterState.getCollectionOrNull(collection); if (docCollection != null) { return docCollection.getAutoAddReplicas(); } } return false; }
/** * Get the lead replica for specific collection, or null if one currently doesn't exist. */ public Replica getLeader(String collection, String sliceName) { DocCollection coll = getCollectionOrNull(collection); if (coll == null) return null; Slice slice = coll.getSlice(sliceName); if (slice == null) return null; return slice.getLeader(); } private Replica getReplica(DocCollection coll, String replicaName) {
protected int getTotalReplicas(String collection) { ZkStateReader zkStateReader = cloudClient.getZkStateReader(); DocCollection coll = zkStateReader.getClusterState().getCollectionOrNull(collection); if (coll == null) return 0; // support for when collection hasn't been created yet int cnt = 0; for (Slice slices : coll.getSlices()) { cnt += slices.getReplicas().size(); } return cnt; }
/** * Checks if the collection has already been created in Solr. */ private static boolean checkIfCollectionExists(CloudSolrClient server, String collection) throws KeeperException, InterruptedException { final ZkStateReader zkStateReader = server.getZkStateReader(); zkStateReader.forceUpdateCollection(collection); final ClusterState clusterState = zkStateReader.getClusterState(); return clusterState.getCollectionOrNull(collection) != null; }
/** * Checks if the collection has already been created in Solr. */ private static boolean checkIfCollectionExists(CloudSolrClient server, String collection) throws KeeperException, InterruptedException { ZkStateReader zkStateReader = server.getZkStateReader(); zkStateReader.updateClusterState(); ClusterState clusterState = zkStateReader.getClusterState(); return clusterState.getCollectionOrNull(collection) != null; }
/** * Checks if the collection has already been created in Solr. */ private static boolean checkIfCollectionExists(CloudSolrClient server, String collection) throws KeeperException, InterruptedException { ZkStateReader zkStateReader = server.getZkStateReader(); zkStateReader.updateClusterState(); ClusterState clusterState = zkStateReader.getClusterState(); return clusterState.getCollectionOrNull(collection) != null; }
public Replica getLeader(String collection, String shard) { if (clusterState != null) { DocCollection docCollection = clusterState.getCollectionOrNull(collection); Replica replica = docCollection != null ? docCollection.getLeader(shard) : null; if (replica != null && getClusterState().liveNodesContain(replica.getNodeName())) { return replica; } } return null; }
protected ZkCoreNodeProps getLeaderUrlFromZk(String collection, String slice) { ClusterState clusterState = getCommonCloudSolrClient().getZkStateReader().getClusterState(); final DocCollection docCollection = clusterState.getCollectionOrNull(collection); if (docCollection != null && docCollection.getLeader(slice) != null) { return new ZkCoreNodeProps(docCollection.getLeader(slice)); } throw new RuntimeException("Could not find leader:" + collection + " " + slice); }