public Map<String, Slice> getSlicesMap(String collection) { DocCollection coll = getCollectionOrNull(collection); if (coll == null) return null; return coll.getSlicesMap(); }
private Replica getReplica(DocCollection coll, String replicaName) { if (coll == null) return null; for (Slice slice : coll.getSlices()) { Replica replica = slice.getReplica(replicaName); if (replica != null) return replica; } return null; }
@Override public Collection<Slice> getSearchSlicesSingle(String shardKey, SolrParams params, DocCollection collection) { if (shardKey == null) { return collection.getActiveSlices(); } // assume the shardKey is just a slice name Slice slice = collection.getSlice(shardKey); if (slice == null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "implicit router can't find shard " + shardKey + " in collection " + collection.getName()); } return Collections.singleton(slice); }
/**Use this to make an exact copy of DocCollection with a new set of Slices and every other property as is * @param slices the new set of Slices * @return the resulting DocCollection */ public DocCollection copyWithSlices(Map<String, Slice> slices){ return new DocCollection(getName(), slices, propMap, router, znodeVersion,znode); }
/** * 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); }
throw new IllegalArgumentException("docCollection must not be null"); if (docCollection.getSlicesMap().size() != shards) { throw new IllegalArgumentException("Incompatible shards: + " + shards + " for docCollection: " + docCollection); List<Slice> slices = new ZooKeeperInspector().getSortedSlices(docCollection.getSlices()); if (slices.size() != shards) { throw new IllegalStateException("Incompatible sorted shards: + " + shards + " for docCollection: " + docCollection); DocRouter docRouter = docCollection.getRouter(); if (docRouter == null) { throw new IllegalArgumentException("docRouter must not be null");
protected static void assertAllActive(String collection, ZkStateReader zkStateReader) throws KeeperException, InterruptedException { zkStateReader.forceUpdateCollection(collection); ClusterState clusterState = zkStateReader.getClusterState(); final DocCollection docCollection = clusterState.getCollectionOrNull(collection); if (docCollection == null || docCollection.getSlices() == null) { throw new IllegalArgumentException("Cannot find collection:" + collection); } Map<String,Slice> slices = docCollection.getSlicesMap(); for (Map.Entry<String,Slice> entry : slices.entrySet()) { Slice slice = entry.getValue(); if (slice.getState() != Slice.State.ACTIVE) { fail("Not all shards are ACTIVE - found a shard " + slice.getName() + " that is: " + slice.getState()); } Map<String,Replica> shards = slice.getReplicasMap(); for (Map.Entry<String,Replica> shard : shards.entrySet()) { Replica replica = shard.getValue(); if (replica.getState() != Replica.State.ACTIVE) { fail("Not all replicas are ACTIVE - found a replica " + replica.getName() + " that is: " + replica.getState()); } } } }
@Override public Collection<Slice> getSearchSlicesSingle(String shardKey, SolrParams params, DocCollection collection) { if (shardKey == null) { // search across whole collection // TODO: this may need modification in the future when shard splitting could cause an overlap return collection.getActiveSlices(); } // use the shardKey as an id for plain hashing Slice slice = getTargetSlice(shardKey, null, null, params, collection); return slice == null ? Collections.<Slice>emptyList() : Collections.singletonList(slice); } }
public Replica getLeader(String sliceName) { Slice slice = getSlice(sliceName); if (slice == null) return null; return slice.getLeader(); }
Collection<Slice> slices = cs.getCollection(testCollectionName).getActiveSlices(); assertTrue(slices.size() == shards); boolean allReplicasUp = false; final DocCollection docCollection = cs.getCollectionOrNull(testCollectionName); assertNotNull("No collection found for " + testCollectionName, docCollection); Slice shard = docCollection.getSlice(shardId); assertNotNull("No Slice for "+shardId, shard); allReplicasUp = true; // assume true
@Override public int getPartition(Text key, SolrInputDocumentWritable value, int numPartitions) { DocRouter docRouter = docCollection.getRouter(); SolrInputDocument doc = value.getSolrInputDocument(); String keyStr = key.toString();
@Override public Collection<Slice> getSearchSlicesSingle(String shardKey, SolrParams params, DocCollection collection) { if (shardKey == null) { // search across whole collection // TODO: this may need modification in the future when shard splitting could cause an overlap return collection.getActiveSlices(); } String id = shardKey; if (shardKey.indexOf(SEPARATOR) < 0) { // shardKey is a simple id, so don't do a range return Collections.singletonList(hashToSlice(Hash.murmurhash3_x86_32(id, 0, id.length(), 0), collection)); } Range completeRange = new KeyParser(id).getRange(); List<Slice> targetSlices = new ArrayList<>(1); for (Slice slice : collection.getActiveSlicesArr()) { Range range = slice.getRange(); if (range != null && range.overlaps(completeRange)) { targetSlices.add(slice); } } return targetSlices; }
@Override public String toString() { if (coll != null) { return coll.toString(); } else { return "null DocCollection ref"; } }
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); }
protected String getRouteField(DocCollection coll) { if (coll == null) return null; Map m = (Map) coll.get(DOC_ROUTER); if (m == null) return null; return (String) m.get("field"); }
private static DocCollection collectionFromObjects(String name, Map<String, Object> objs, Integer version, String znode) { Map<String,Object> props; Map<String,Slice> slices; Map<String,Object> sliceObjs = (Map<String,Object>)objs.get(DocCollection.SHARDS); if (sliceObjs == null) { // legacy format from 4.0... there was no separate "shards" level to contain the collection shards. slices = Slice.loadAllFromMap(objs); props = Collections.emptyMap(); } else { slices = Slice.loadAllFromMap(sliceObjs); props = new HashMap<>(objs); objs.remove(DocCollection.SHARDS); } Object routerObj = props.get(DocCollection.DOC_ROUTER); DocRouter router; if (routerObj == null) { router = DocRouter.DEFAULT; } else if (routerObj instanceof String) { // back compat with Solr4.4 router = DocRouter.getDocRouter((String)routerObj); } else { Map routerProps = (Map)routerObj; router = DocRouter.getDocRouter((String) routerProps.get("name")); } return new DocCollection(name, slices, props, router, version, znode); }
throw new IllegalArgumentException("docCollection must not be null"); if (docCollection.getSlicesMap().size() != shards) { throw new IllegalArgumentException("Incompatible shards: + " + shards + " for docCollection: " + docCollection); List<Slice> slices = new ZooKeeperInspector().getSortedSlices(docCollection.getSlices()); if (slices.size() != shards) { throw new IllegalStateException("Incompatible sorted shards: + " + shards + " for docCollection: " + docCollection); DocRouter docRouter = docCollection.getRouter(); if (docRouter == null) { throw new IllegalArgumentException("docRouter must not be null");
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); }
@Override public int getPartition(Text key, SolrInputDocumentWritable value, int numPartitions) { DocRouter docRouter = docCollection.getRouter(); SolrInputDocument doc = value.getSolrInputDocument(); String keyStr = key.toString();