/** * @param name The name of the collection * @param slices The logical shards of the collection. This is used directly and a copy is not made. * @param props The properties of the slice. This is used directly and a copy is not made. */ public DocCollection(String name, Map<String, Slice> slices, Map<String, Object> props, DocRouter router, int zkVersion, String znode) { super(props==null ? props = new HashMap<String,Object>() : props); this.znodeVersion = zkVersion; this.name = name; this.slices = slices; this.activeSlices = new HashMap<>(); this.replicationFactor = (Integer) verifyProp(props, REPLICATION_FACTOR); this.maxShardsPerNode = (Integer) verifyProp(props, MAX_SHARDS_PER_NODE); Boolean autoAddReplicas = (Boolean) verifyProp(props, AUTO_ADD_REPLICAS); this.autoAddReplicas = autoAddReplicas == null ? false : autoAddReplicas; verifyProp(props, RULE); verifyProp(props, SNITCH); Iterator<Map.Entry<String, Slice>> iter = slices.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<String, Slice> slice = iter.next(); if (slice.getValue().getState() == Slice.State.ACTIVE) this.activeSlices.put(slice.getKey(), slice.getValue()); } this.router = router; this.znode = znode == null? ZkStateReader.CLUSTER_STATE : znode; assert name != null && slices != null; }
if (slice.getValue().getState() == Slice.State.ACTIVE) { this.activeSlices.put(slice.getKey(), slice.getValue());
for (Slice slice : slices) { if (slice.getState() == Slice.State.ACTIVE) { Collection<Replica> replicas = slice.getReplicas(); for (Replica replica : replicas) {
for (Slice slice : slices) { if (slice.getState() == Slice.State.ACTIVE) { Collection<Replica> replicas = slice.getReplicas(); for (Replica replica : replicas) {
for (Slice slice : slices) { if (slice.getState() == Slice.State.ACTIVE) { Collection<Replica> replicas = slice.getReplicas(); for (Replica replica : replicas) {
for (Map.Entry<String,Slice> entry : slices.entrySet()) { Slice slice = entry.getValue(); if (slice.getState() == Slice.State.CONSTRUCTION) { // similar to replica recovering; pretend its the same thing if (verbose) System.out.println("Found a slice in construction state; will wait."); sawLiveRecovering = true;
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()); } } } }
for (Slice slice : slices) { if (slice.getState() == Slice.State.ACTIVE) { Collection<Replica> replicas = slice.getReplicas(); for (Replica replica : replicas) {
for (Slice slice : slices) { if (slice.getState() == Slice.State.ACTIVE) { Collection<Replica> replicas = slice.getReplicas(); for (Replica replica : replicas) {
for (Map.Entry<String,Slice> entry : slices.entrySet()) { Slice slice = entry.getValue(); if (slice.getState() == Slice.State.CONSTRUCTION) { // similar to replica recovering; pretend its the same thing if (verbose) System.out.println("Found a slice in construction state; will wait."); sawLiveRecovering = true;
for (Slice slice : slices) { if (slice.getState() == Slice.State.ACTIVE) { Collection<Replica> replicas = slice.getReplicas(); for (Replica replica : replicas) {
ClusterState clusterState = zkController.getClusterState(); Slice slice = clusterState.getSlice(collectionName, shardName); replicaState = (slice != null) ? slice.getState() : "gone"; } else { replicaState = "not connected to Zookeeper";