Search in sources :

Example 26 with Slice

use of org.apache.solr.common.cloud.Slice in project lucene-solr by apache.

the class RecoveryStrategy method sendPrepRecoveryCmd.

private final void sendPrepRecoveryCmd(String leaderBaseUrl, String leaderCoreName, Slice slice) throws SolrServerException, IOException, InterruptedException, ExecutionException {
    WaitForState prepCmd = new WaitForState();
    prepCmd.setCoreName(leaderCoreName);
    prepCmd.setNodeName(zkController.getNodeName());
    prepCmd.setCoreNodeName(coreZkNodeName);
    prepCmd.setState(Replica.State.RECOVERING);
    prepCmd.setCheckLive(true);
    prepCmd.setOnlyIfLeader(true);
    final Slice.State state = slice.getState();
    if (state != Slice.State.CONSTRUCTION && state != Slice.State.RECOVERY && state != Slice.State.RECOVERY_FAILED) {
        prepCmd.setOnlyIfLeaderActive(true);
    }
    final int maxTries = 30;
    for (int numTries = 0; numTries < maxTries; numTries++) {
        try {
            sendPrepRecoveryCmd(leaderBaseUrl, prepCmd);
            break;
        } catch (ExecutionException e) {
            if (e.getCause() instanceof SolrServerException) {
                SolrServerException solrException = (SolrServerException) e.getCause();
                if (solrException.getRootCause() instanceof SocketTimeoutException && numTries < maxTries) {
                    LOG.warn("Socket timeout on send prep recovery cmd, retrying.. ");
                    continue;
                }
            }
            throw e;
        }
    }
}
Also used : WaitForState(org.apache.solr.client.solrj.request.CoreAdminRequest.WaitForState) SocketTimeoutException(java.net.SocketTimeoutException) Slice(org.apache.solr.common.cloud.Slice) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ExecutionException(java.util.concurrent.ExecutionException)

Example 27 with Slice

use of org.apache.solr.common.cloud.Slice in project lucene-solr by apache.

the class ZkController method waitForCoreNodeName.

private void waitForCoreNodeName(CoreDescriptor descriptor) {
    int retryCount = 320;
    log.debug("look for our core node name");
    while (retryCount-- > 0) {
        Map<String, Slice> slicesMap = zkStateReader.getClusterState().getSlicesMap(descriptor.getCloudDescriptor().getCollectionName());
        if (slicesMap != null) {
            for (Slice slice : slicesMap.values()) {
                for (Replica replica : slice.getReplicas()) {
                    // TODO: for really large clusters, we could 'index' on this
                    String nodeName = replica.getStr(ZkStateReader.NODE_NAME_PROP);
                    String core = replica.getStr(ZkStateReader.CORE_NAME_PROP);
                    String msgNodeName = getNodeName();
                    String msgCore = descriptor.getName();
                    if (msgNodeName.equals(nodeName) && core.equals(msgCore)) {
                        descriptor.getCloudDescriptor().setCoreNodeName(replica.getName());
                        return;
                    }
                }
            }
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }
}
Also used : Slice(org.apache.solr.common.cloud.Slice) Replica(org.apache.solr.common.cloud.Replica)

Example 28 with Slice

use of org.apache.solr.common.cloud.Slice in project lucene-solr by apache.

the class NodeMutator method downNode.

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.equals(nodeName)) {
                    log.debug("Update replica state for " + replica + " to " + Replica.State.DOWN.toString());
                    Map<String, Object> props = replica.shallowCopy();
                    props.put(ZkStateReader.STATE_PROP, Replica.State.DOWN.toString());
                    Replica newReplica = new Replica(replica.getName(), props);
                    newReplicas.put(replica.getName(), newReplica);
                    needToUpdateCollection = true;
                }
            }
            Slice newSlice = new Slice(slice.getName(), newReplicas, slice.shallowCopy());
            slicesCopy.put(slice.getName(), newSlice);
        }
        if (needToUpdateCollection) {
            zkWriteCommands.add(new ZkWriteCommand(collection, docCollection.copyWithSlices(slicesCopy)));
        }
    }
    return zkWriteCommands;
}
Also used : ArrayList(java.util.ArrayList) Replica(org.apache.solr.common.cloud.Replica) LinkedHashMap(java.util.LinkedHashMap) Slice(org.apache.solr.common.cloud.Slice) DocCollection(org.apache.solr.common.cloud.DocCollection) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 29 with Slice

use of org.apache.solr.common.cloud.Slice in project lucene-solr by apache.

the class ReplicaMutator method addReplicaProperty.

public ZkWriteCommand addReplicaProperty(ClusterState clusterState, ZkNodeProps message) {
    if (checkKeyExistence(message, ZkStateReader.COLLECTION_PROP) == false || checkKeyExistence(message, ZkStateReader.SHARD_ID_PROP) == false || checkKeyExistence(message, ZkStateReader.REPLICA_PROP) == false || checkKeyExistence(message, ZkStateReader.PROPERTY_PROP) == false || checkKeyExistence(message, ZkStateReader.PROPERTY_VALUE_PROP) == false) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Overseer ADDREPLICAPROP requires " + ZkStateReader.COLLECTION_PROP + " and " + ZkStateReader.SHARD_ID_PROP + " and " + ZkStateReader.REPLICA_PROP + " and " + ZkStateReader.PROPERTY_PROP + " and " + ZkStateReader.PROPERTY_VALUE_PROP + " no action taken.");
    }
    String collectionName = message.getStr(ZkStateReader.COLLECTION_PROP);
    String sliceName = message.getStr(ZkStateReader.SHARD_ID_PROP);
    String replicaName = message.getStr(ZkStateReader.REPLICA_PROP);
    String property = message.getStr(ZkStateReader.PROPERTY_PROP).toLowerCase(Locale.ROOT);
    if (StringUtils.startsWith(property, COLL_PROP_PREFIX) == false) {
        property = OverseerCollectionMessageHandler.COLL_PROP_PREFIX + property;
    }
    property = property.toLowerCase(Locale.ROOT);
    String propVal = message.getStr(ZkStateReader.PROPERTY_VALUE_PROP);
    String shardUnique = message.getStr(OverseerCollectionMessageHandler.SHARD_UNIQUE);
    boolean isUnique = false;
    if (SliceMutator.SLICE_UNIQUE_BOOLEAN_PROPERTIES.contains(property)) {
        if (StringUtils.isNotBlank(shardUnique) && Boolean.parseBoolean(shardUnique) == false) {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Overseer ADDREPLICAPROP for " + property + " cannot have " + OverseerCollectionMessageHandler.SHARD_UNIQUE + " set to anything other than" + "'true'. No action taken");
        }
        isUnique = true;
    } else {
        isUnique = Boolean.parseBoolean(shardUnique);
    }
    DocCollection collection = clusterState.getCollection(collectionName);
    Replica replica = collection.getReplica(replicaName);
    if (replica == null) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Could not find collection/slice/replica " + collectionName + "/" + sliceName + "/" + replicaName + " no action taken.");
    }
    log.info("Setting property {} with value {} for collection {}", property, propVal, collectionName);
    log.debug("Full message: {}", message);
    // already the value we're going to set
    if (StringUtils.equalsIgnoreCase(replica.getStr(property), propVal))
        return ZkStateWriter.NO_OP;
    // OK, there's no way we won't change the cluster state now
    Map<String, Replica> replicas = collection.getSlice(sliceName).getReplicasCopy();
    if (isUnique == false) {
        replicas.get(replicaName).getProperties().put(property, propVal);
    } else {
        // Set prop for this replica, but remove it for all others.
        for (Replica rep : replicas.values()) {
            if (rep.getName().equalsIgnoreCase(replicaName)) {
                rep.getProperties().put(property, propVal);
            } else {
                rep.getProperties().remove(property);
            }
        }
    }
    Slice newSlice = new Slice(sliceName, replicas, collection.getSlice(sliceName).shallowCopy());
    DocCollection newCollection = CollectionMutator.updateSlice(collectionName, collection, newSlice);
    return new ZkWriteCommand(collectionName, newCollection);
}
Also used : Slice(org.apache.solr.common.cloud.Slice) DocCollection(org.apache.solr.common.cloud.DocCollection) Replica(org.apache.solr.common.cloud.Replica) SolrException(org.apache.solr.common.SolrException)

Example 30 with Slice

use of org.apache.solr.common.cloud.Slice in project lucene-solr by apache.

the class ReplicaMutator method deleteReplicaProperty.

public ZkWriteCommand deleteReplicaProperty(ClusterState clusterState, ZkNodeProps message) {
    if (checkKeyExistence(message, ZkStateReader.COLLECTION_PROP) == false || checkKeyExistence(message, ZkStateReader.SHARD_ID_PROP) == false || checkKeyExistence(message, ZkStateReader.REPLICA_PROP) == false || checkKeyExistence(message, ZkStateReader.PROPERTY_PROP) == false) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Overseer DELETEREPLICAPROP requires " + ZkStateReader.COLLECTION_PROP + " and " + ZkStateReader.SHARD_ID_PROP + " and " + ZkStateReader.REPLICA_PROP + " and " + ZkStateReader.PROPERTY_PROP + " no action taken.");
    }
    String collectionName = message.getStr(ZkStateReader.COLLECTION_PROP);
    String sliceName = message.getStr(ZkStateReader.SHARD_ID_PROP);
    String replicaName = message.getStr(ZkStateReader.REPLICA_PROP);
    String property = message.getStr(ZkStateReader.PROPERTY_PROP).toLowerCase(Locale.ROOT);
    if (StringUtils.startsWith(property, COLL_PROP_PREFIX) == false) {
        property = OverseerCollectionMessageHandler.COLL_PROP_PREFIX + property;
    }
    DocCollection collection = clusterState.getCollection(collectionName);
    Replica replica = collection.getReplica(replicaName);
    if (replica == null) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Could not find collection/slice/replica " + collectionName + "/" + sliceName + "/" + replicaName + " no action taken.");
    }
    log.info("Deleting property {} for collection: {} slice: {} replica: {}", property, collectionName, sliceName, replicaName);
    log.debug("Full message: {}", message);
    String curProp = replica.getStr(property);
    // not there anyway, nothing to do.
    if (curProp == null)
        return ZkStateWriter.NO_OP;
    Slice slice = collection.getSlice(sliceName);
    DocCollection newCollection = SliceMutator.updateReplica(collection, slice, replicaName, unsetProperty(replica, property));
    return new ZkWriteCommand(collectionName, newCollection);
}
Also used : Slice(org.apache.solr.common.cloud.Slice) DocCollection(org.apache.solr.common.cloud.DocCollection) Replica(org.apache.solr.common.cloud.Replica) SolrException(org.apache.solr.common.SolrException)

Aggregations

Slice (org.apache.solr.common.cloud.Slice)221 Replica (org.apache.solr.common.cloud.Replica)143 DocCollection (org.apache.solr.common.cloud.DocCollection)121 ClusterState (org.apache.solr.common.cloud.ClusterState)82 ArrayList (java.util.ArrayList)79 HashMap (java.util.HashMap)68 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)51 SolrException (org.apache.solr.common.SolrException)49 Map (java.util.Map)47 Test (org.junit.Test)37 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)28 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)25 HashSet (java.util.HashSet)24 SolrQuery (org.apache.solr.client.solrj.SolrQuery)24 IOException (java.io.IOException)23 NamedList (org.apache.solr.common.util.NamedList)23 List (java.util.List)22 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)22 DocRouter (org.apache.solr.common.cloud.DocRouter)20 ZkCoreNodeProps (org.apache.solr.common.cloud.ZkCoreNodeProps)20