Java Code Examples for org.apache.solr.common.cloud.Slice#getReplicasCopy()
The following examples show how to use
org.apache.solr.common.cloud.Slice#getReplicasCopy() .
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: SliceMutator.java From lucene-solr with Apache License 2.0 | 5 votes |
public ZkWriteCommand updateShardState(ClusterState clusterState, ZkNodeProps message) { String collectionName = message.getStr(ZkStateReader.COLLECTION_PROP); if (!checkCollectionKeyExistence(message)) return ZkStateWriter.NO_OP; log.info("Update shard state invoked for collection: {} with message: {}", collectionName, message); DocCollection collection = clusterState.getCollection(collectionName); Map<String, Slice> slicesCopy = new LinkedHashMap<>(collection.getSlicesMap()); for (String key : message.keySet()) { if (ZkStateReader.COLLECTION_PROP.equals(key)) continue; if (Overseer.QUEUE_OPERATION.equals(key)) continue; Slice slice = collection.getSlice(key); if (slice == null) { throw new RuntimeException("Overseer.updateShardState unknown collection: " + collectionName + " slice: " + key); } if (log.isInfoEnabled()) { log.info("Update shard state {} to {}", key, message.getStr(key)); } Map<String, Object> props = slice.shallowCopy(); if (Slice.State.getState(message.getStr(key)) == Slice.State.ACTIVE) { props.remove(Slice.PARENT); props.remove("shard_parent_node"); props.remove("shard_parent_zk_session"); } props.put(ZkStateReader.STATE_PROP, message.getStr(key)); // we need to use epoch time so that it's comparable across Overseer restarts props.put(ZkStateReader.STATE_TIMESTAMP_PROP, String.valueOf(cloudManager.getTimeSource().getEpochTimeNs())); Slice newSlice = new Slice(slice.getName(), slice.getReplicasCopy(), props,collectionName); slicesCopy.put(slice.getName(), newSlice); } return new ZkWriteCommand(collectionName, collection.copyWithSlices(slicesCopy)); }
Example 2
Source File: SliceMutator.java From lucene-solr with Apache License 2.0 | 5 votes |
public ZkWriteCommand removeRoutingRule(final ClusterState clusterState, ZkNodeProps message) { String collectionName = message.getStr(ZkStateReader.COLLECTION_PROP); if (!checkCollectionKeyExistence(message)) return ZkStateWriter.NO_OP; String shard = message.getStr(ZkStateReader.SHARD_ID_PROP); String routeKeyStr = message.getStr("routeKey"); log.info("Overseer.removeRoutingRule invoked for collection: {} shard: {} routeKey: {}" , collectionName, shard, routeKeyStr); DocCollection collection = clusterState.getCollection(collectionName); Slice slice = collection.getSlice(shard); if (slice == null) { log.warn("Unknown collection: {} shard: {}", collectionName, shard); return ZkStateWriter.NO_OP; } Map<String, RoutingRule> routingRules = slice.getRoutingRules(); if (routingRules != null) { routingRules.remove(routeKeyStr); // no rules left Map<String, Object> props = slice.shallowCopy(); props.put("routingRules", routingRules); Slice newSlice = new Slice(slice.getName(), slice.getReplicasCopy(), props,collectionName); return new ZkWriteCommand(collectionName, CollectionMutator.updateSlice(collectionName, collection, newSlice)); } return ZkStateWriter.NO_OP; }
Example 3
Source File: SliceMutator.java From lucene-solr with Apache License 2.0 | 5 votes |
public static DocCollection updateReplica(DocCollection collection, final Slice slice, String coreNodeName, final Replica replica) { Map<String, Replica> replicasCopy = slice.getReplicasCopy(); if (replica == null) { replicasCopy.remove(coreNodeName); } else { replicasCopy.put(replica.getName(), replica); } Slice newSlice = new Slice(slice.getName(), replicasCopy, slice.getProperties(), collection.getName()); log.debug("Old Slice: {}", slice); log.debug("New Slice: {}", newSlice); return CollectionMutator.updateSlice(collection.getName(), collection, newSlice); }
Example 4
Source File: NodeMutator.java From lucene-solr with Apache License 2.0 | 4 votes |
public List<ZkWriteCommand> downNode(ClusterState clusterState, ZkNodeProps message) { List<ZkWriteCommand> zkWriteCommands = new ArrayList<>(); String nodeName = message.getStr(ZkStateReader.NODE_NAME_PROP); log.debug("DownNode state invoked for node: {}", nodeName); Map<String, DocCollection> collections = clusterState.getCollectionsMap(); for (Map.Entry<String, DocCollection> entry : collections.entrySet()) { String collection = entry.getKey(); DocCollection docCollection = entry.getValue(); Map<String,Slice> slicesCopy = new LinkedHashMap<>(docCollection.getSlicesMap()); boolean needToUpdateCollection = false; for (Entry<String, Slice> sliceEntry : slicesCopy.entrySet()) { Slice slice = sliceEntry.getValue(); Map<String, Replica> newReplicas = slice.getReplicasCopy(); Collection<Replica> replicas = slice.getReplicas(); for (Replica replica : replicas) { String rNodeName = replica.getNodeName(); if (rNodeName == null) { throw new RuntimeException("Replica without node name! " + replica); } if (rNodeName.equals(nodeName)) { log.debug("Update replica state for {} to {}", replica, Replica.State.DOWN); Map<String, Object> props = replica.shallowCopy(); props.put(ZkStateReader.STATE_PROP, Replica.State.DOWN.toString()); Replica newReplica = new Replica(replica.getName(), props, collection, slice.getName()); newReplicas.put(replica.getName(), newReplica); needToUpdateCollection = true; } } Slice newSlice = new Slice(slice.getName(), newReplicas, slice.shallowCopy(),collection); slicesCopy.put(slice.getName(), newSlice); } if (needToUpdateCollection) { zkWriteCommands.add(new ZkWriteCommand(collection, docCollection.copyWithSlices(slicesCopy))); } } return zkWriteCommands; }