Search in sources :

Example 36 with TimeOut

use of org.apache.solr.util.TimeOut in project lucene-solr by apache.

the class DeleteAliasCmd method checkForAliasAbsence.

private void checkForAliasAbsence(String name) {
    TimeOut timeout = new TimeOut(30, TimeUnit.SECONDS);
    boolean success = false;
    Aliases aliases = null;
    while (!timeout.hasTimedOut()) {
        aliases = ocmh.zkStateReader.getAliases();
        String collections = aliases.getCollectionAlias(name);
        if (collections == null) {
            success = true;
            break;
        }
    }
    if (!success) {
        log.warn("Timeout waiting to be notified of Alias change...");
    }
}
Also used : TimeOut(org.apache.solr.util.TimeOut) Aliases(org.apache.solr.common.cloud.Aliases)

Example 37 with TimeOut

use of org.apache.solr.util.TimeOut in project lucene-solr by apache.

the class OverseerCollectionMessageHandler method migrateStateFormat.

//TODO should we not remove in the next release ?
private void migrateStateFormat(ClusterState state, ZkNodeProps message, NamedList results) throws KeeperException, InterruptedException {
    final String collectionName = message.getStr(COLLECTION_PROP);
    boolean firstLoop = true;
    // wait for a while until the state format changes
    TimeOut timeout = new TimeOut(30, TimeUnit.SECONDS);
    while (!timeout.hasTimedOut()) {
        DocCollection collection = zkStateReader.getClusterState().getCollection(collectionName);
        if (collection == null) {
            throw new SolrException(ErrorCode.BAD_REQUEST, "Collection: " + collectionName + " not found");
        }
        if (collection.getStateFormat() == 2) {
            // Done.
            results.add("success", new SimpleOrderedMap<>());
            return;
        }
        if (firstLoop) {
            // Actually queue the migration command.
            firstLoop = false;
            ZkNodeProps m = new ZkNodeProps(Overseer.QUEUE_OPERATION, MIGRATESTATEFORMAT.toLower(), COLLECTION_PROP, collectionName);
            Overseer.getStateUpdateQueue(zkStateReader.getZkClient()).offer(Utils.toJSON(m));
        }
        Thread.sleep(100);
    }
    throw new SolrException(ErrorCode.SERVER_ERROR, "Could not migrate state format for collection: " + collectionName);
}
Also used : TimeOut(org.apache.solr.util.TimeOut) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) DocCollection(org.apache.solr.common.cloud.DocCollection) RemoteSolrException(org.apache.solr.client.solrj.impl.HttpSolrClient.RemoteSolrException) SolrException(org.apache.solr.common.SolrException)

Example 38 with TimeOut

use of org.apache.solr.util.TimeOut in project lucene-solr by apache.

the class OverseerCollectionMessageHandler method modifyCollection.

private void modifyCollection(ClusterState clusterState, ZkNodeProps message, NamedList results) throws KeeperException, InterruptedException {
    final String collectionName = message.getStr(ZkStateReader.COLLECTION_PROP);
    //the rest of the processing is based on writing cluster state properties
    //remove the property here to avoid any errors down the pipeline due to this property appearing
    String configName = (String) message.getProperties().remove(COLL_CONF);
    if (configName != null) {
        validateConfigOrThrowSolrException(configName);
        boolean isLegacyCloud = Overseer.isLegacy(zkStateReader);
        createConfNode(configName, collectionName, isLegacyCloud);
        reloadCollection(null, new ZkNodeProps(NAME, collectionName), results);
    }
    overseer.getStateUpdateQueue(zkStateReader.getZkClient()).offer(Utils.toJSON(message));
    TimeOut timeout = new TimeOut(30, TimeUnit.SECONDS);
    boolean areChangesVisible = true;
    while (!timeout.hasTimedOut()) {
        DocCollection collection = zkStateReader.getClusterState().getCollection(collectionName);
        areChangesVisible = true;
        for (Map.Entry<String, Object> updateEntry : message.getProperties().entrySet()) {
            String updateKey = updateEntry.getKey();
            if (!updateKey.equals(ZkStateReader.COLLECTION_PROP) && !updateKey.equals(Overseer.QUEUE_OPERATION) && !collection.get(updateKey).equals(updateEntry.getValue())) {
                areChangesVisible = false;
                break;
            }
        }
        if (areChangesVisible)
            break;
        Thread.sleep(100);
    }
    if (!areChangesVisible)
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Could not modify collection " + message);
}
Also used : TimeOut(org.apache.solr.util.TimeOut) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) DocCollection(org.apache.solr.common.cloud.DocCollection) Map(java.util.Map) Utils.makeMap(org.apache.solr.common.util.Utils.makeMap) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) RemoteSolrException(org.apache.solr.client.solrj.impl.HttpSolrClient.RemoteSolrException) SolrException(org.apache.solr.common.SolrException)

Example 39 with TimeOut

use of org.apache.solr.util.TimeOut in project lucene-solr by apache.

the class OverseerCollectionMessageHandler method waitForCoreNodeGone.

boolean waitForCoreNodeGone(String collectionName, String shard, String replicaName, int timeoutms) throws InterruptedException {
    TimeOut timeout = new TimeOut(timeoutms, TimeUnit.MILLISECONDS);
    boolean deleted = false;
    while (!timeout.hasTimedOut()) {
        Thread.sleep(100);
        DocCollection docCollection = zkStateReader.getClusterState().getCollection(collectionName);
        if (docCollection != null) {
            Slice slice = docCollection.getSlice(shard);
            if (slice == null || slice.getReplica(replicaName) == null) {
                deleted = true;
            }
        }
        // Return true if either someone already deleted the collection/slice/replica.
        if (docCollection == null || deleted)
            break;
    }
    return deleted;
}
Also used : TimeOut(org.apache.solr.util.TimeOut) Slice(org.apache.solr.common.cloud.Slice) DocCollection(org.apache.solr.common.cloud.DocCollection)

Example 40 with TimeOut

use of org.apache.solr.util.TimeOut in project lucene-solr by apache.

the class SchemaManager method doOperations.

private List doOperations(List<CommandOperation> operations) throws InterruptedException, IOException, KeeperException {
    //The default timeout is 10 minutes when no BaseSolrResource.UPDATE_TIMEOUT_SECS is specified
    int timeout = req.getParams().getInt(BaseSolrResource.UPDATE_TIMEOUT_SECS, 600);
    //If BaseSolrResource.UPDATE_TIMEOUT_SECS=0 or -1 then end time then we'll try for 10 mins ( default timeout )
    if (timeout < 1) {
        timeout = 600;
    }
    TimeOut timeOut = new TimeOut(timeout, TimeUnit.SECONDS);
    SolrCore core = req.getCore();
    String errorMsg = "Unable to persist managed schema. ";
    List errors = Collections.emptyList();
    int latestVersion = -1;
    synchronized (req.getSchema().getSchemaUpdateLock()) {
        while (!timeOut.hasTimedOut()) {
            managedIndexSchema = getFreshManagedSchema(req.getCore());
            for (CommandOperation op : operations) {
                OpType opType = OpType.get(op.name);
                if (opType != null) {
                    opType.perform(op, this);
                } else {
                    op.addError("No such operation : " + op.name);
                }
            }
            errors = CommandOperation.captureErrors(operations);
            if (!errors.isEmpty())
                break;
            SolrResourceLoader loader = req.getCore().getResourceLoader();
            if (loader instanceof ZkSolrResourceLoader) {
                ZkSolrResourceLoader zkLoader = (ZkSolrResourceLoader) loader;
                StringWriter sw = new StringWriter();
                try {
                    managedIndexSchema.persist(sw);
                } catch (IOException e) {
                    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "unable to serialize schema");
                //unlikely
                }
                try {
                    latestVersion = ZkController.persistConfigResourceToZooKeeper(zkLoader, managedIndexSchema.getSchemaZkVersion(), managedIndexSchema.getResourceName(), sw.toString().getBytes(StandardCharsets.UTF_8), true);
                    req.getCore().getCoreContainer().reload(req.getCore().getName());
                    break;
                } catch (ZkController.ResourceModifiedInZkException e) {
                    log.info("Schema was modified by another node. Retrying..");
                }
            } else {
                try {
                    //only for non cloud stuff
                    managedIndexSchema.persistManagedSchema(false);
                    core.setLatestSchema(managedIndexSchema);
                } catch (SolrException e) {
                    log.warn(errorMsg);
                    errors = singletonList(errorMsg + e.getMessage());
                }
                break;
            }
        }
    }
    if (req.getCore().getResourceLoader() instanceof ZkSolrResourceLoader) {
        // Don't block further schema updates while waiting for a pending update to propagate to other replicas.
        // This reduces the likelihood of a (time-limited) distributed deadlock during concurrent schema updates.
        waitForOtherReplicasToUpdate(timeOut, latestVersion);
    }
    if (errors.isEmpty() && timeOut.hasTimedOut()) {
        log.warn(errorMsg + "Timed out.");
        errors = singletonList(errorMsg + "Timed out.");
    }
    return errors;
}
Also used : TimeOut(org.apache.solr.util.TimeOut) SolrCore(org.apache.solr.core.SolrCore) CommandOperation(org.apache.solr.common.util.CommandOperation) IOException(java.io.IOException) ZkSolrResourceLoader(org.apache.solr.cloud.ZkSolrResourceLoader) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) StringWriter(java.io.StringWriter) ZkController(org.apache.solr.cloud.ZkController) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ZkSolrResourceLoader(org.apache.solr.cloud.ZkSolrResourceLoader) SolrException(org.apache.solr.common.SolrException)

Aggregations

TimeOut (org.apache.solr.util.TimeOut)48 SolrException (org.apache.solr.common.SolrException)15 Slice (org.apache.solr.common.cloud.Slice)15 DocCollection (org.apache.solr.common.cloud.DocCollection)14 Replica (org.apache.solr.common.cloud.Replica)13 SolrQuery (org.apache.solr.client.solrj.SolrQuery)11 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)8 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)8 HashMap (java.util.HashMap)7 Test (org.junit.Test)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 SolrInputDocument (org.apache.solr.common.SolrInputDocument)6 ZkNodeProps (org.apache.solr.common.cloud.ZkNodeProps)6 NamedList (org.apache.solr.common.util.NamedList)6 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)5 Map (java.util.Map)4 SolrServerException (org.apache.solr.client.solrj.SolrServerException)4 Collections.singletonList (java.util.Collections.singletonList)3 HashSet (java.util.HashSet)3