Search in sources :

Example 31 with DocCollection

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

the class OverseerCollectionMessageHandler method waitForNewShard.

void waitForNewShard(String collectionName, String sliceName) throws KeeperException, InterruptedException {
    log.debug("Waiting for slice {} of collection {} to be available", sliceName, collectionName);
    RTimer timer = new RTimer();
    int retryCount = 320;
    while (retryCount-- > 0) {
        DocCollection collection = zkStateReader.getClusterState().getCollection(collectionName);
        if (collection == null) {
            throw new SolrException(ErrorCode.SERVER_ERROR, "Unable to find collection: " + collectionName + " in clusterstate");
        }
        Slice slice = collection.getSlice(sliceName);
        if (slice != null) {
            log.debug("Waited for {}ms for slice {} of collection {} to be available", timer.getTime(), sliceName, collectionName);
            return;
        }
        Thread.sleep(1000);
    }
    throw new SolrException(ErrorCode.SERVER_ERROR, "Could not find new slice " + sliceName + " in collection " + collectionName + " even after waiting for " + timer.getTime() + "ms");
}
Also used : Slice(org.apache.solr.common.cloud.Slice) DocCollection(org.apache.solr.common.cloud.DocCollection) RTimer(org.apache.solr.util.RTimer) RemoteSolrException(org.apache.solr.client.solrj.impl.HttpSolrClient.RemoteSolrException) SolrException(org.apache.solr.common.SolrException)

Example 32 with DocCollection

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

the class OverseerConfigSetMessageHandler method deleteConfigSet.

private void deleteConfigSet(String configSetName, boolean force) throws IOException {
    ZkConfigManager configManager = new ZkConfigManager(zkStateReader.getZkClient());
    if (!configManager.configExists(configSetName)) {
        throw new SolrException(ErrorCode.BAD_REQUEST, "ConfigSet does not exist to delete: " + configSetName);
    }
    for (Map.Entry<String, DocCollection> entry : zkStateReader.getClusterState().getCollectionsMap().entrySet()) {
        if (configSetName.equals(zkStateReader.readConfigName(entry.getKey())))
            throw new SolrException(ErrorCode.BAD_REQUEST, "Can not delete ConfigSet as it is currently being used by collection [" + entry.getKey() + "]");
    }
    String propertyPath = ConfigSetProperties.DEFAULT_FILENAME;
    NamedList properties = getConfigSetProperties(getPropertyPath(configSetName, propertyPath));
    if (properties != null) {
        Object immutable = properties.get(ConfigSetProperties.IMMUTABLE_CONFIGSET_ARG);
        boolean isImmutableConfigSet = immutable != null ? Boolean.parseBoolean(immutable.toString()) : false;
        if (!force && isImmutableConfigSet) {
            throw new SolrException(ErrorCode.BAD_REQUEST, "Requested delete of immutable ConfigSet: " + configSetName);
        }
    }
    configManager.deleteConfigDir(configSetName);
}
Also used : ZkConfigManager(org.apache.solr.common.cloud.ZkConfigManager) NamedList(org.apache.solr.common.util.NamedList) DocCollection(org.apache.solr.common.cloud.DocCollection) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) HashMap(java.util.HashMap) Map(java.util.Map) SolrException(org.apache.solr.common.SolrException)

Example 33 with DocCollection

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

the class CollectionMutator method createShard.

public ZkWriteCommand createShard(final ClusterState clusterState, ZkNodeProps message) {
    String collectionName = message.getStr(ZkStateReader.COLLECTION_PROP);
    if (!checkCollectionKeyExistence(message))
        return ZkStateWriter.NO_OP;
    String shardId = message.getStr(ZkStateReader.SHARD_ID_PROP);
    DocCollection collection = clusterState.getCollection(collectionName);
    Slice slice = collection.getSlice(shardId);
    if (slice == null) {
        Map<String, Replica> replicas = Collections.EMPTY_MAP;
        Map<String, Object> sliceProps = new HashMap<>();
        String shardRange = message.getStr(ZkStateReader.SHARD_RANGE_PROP);
        String shardState = message.getStr(ZkStateReader.SHARD_STATE_PROP);
        String shardParent = message.getStr(ZkStateReader.SHARD_PARENT_PROP);
        String shardParentZkSession = message.getStr("shard_parent_zk_session");
        String shardParentNode = message.getStr("shard_parent_node");
        sliceProps.put(Slice.RANGE, shardRange);
        sliceProps.put(ZkStateReader.STATE_PROP, shardState);
        if (shardParent != null) {
            sliceProps.put(Slice.PARENT, shardParent);
        }
        if (shardParentZkSession != null) {
            sliceProps.put("shard_parent_zk_session", shardParentZkSession);
        }
        if (shardParentNode != null) {
            sliceProps.put("shard_parent_node", shardParentNode);
        }
        collection = updateSlice(collectionName, collection, new Slice(shardId, replicas, sliceProps));
        return new ZkWriteCommand(collectionName, collection);
    } else {
        log.error("Unable to create Shard: " + shardId + " because it already exists in collection: " + collectionName);
        return ZkStateWriter.NO_OP;
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Slice(org.apache.solr.common.cloud.Slice) DocCollection(org.apache.solr.common.cloud.DocCollection) Replica(org.apache.solr.common.cloud.Replica)

Example 34 with DocCollection

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

the class CollectionMutator method modifyCollection.

public ZkWriteCommand modifyCollection(final ClusterState clusterState, ZkNodeProps message) {
    if (!checkCollectionKeyExistence(message))
        return ZkStateWriter.NO_OP;
    DocCollection coll = clusterState.getCollection(message.getStr(COLLECTION_PROP));
    Map<String, Object> m = coll.shallowCopy();
    boolean hasAnyOps = false;
    for (String prop : CollectionsHandler.MODIFIABLE_COLL_PROPS) {
        if (message.get(prop) != null) {
            hasAnyOps = true;
            m.put(prop, message.get(prop));
        }
    }
    if (!hasAnyOps) {
        return ZkStateWriter.NO_OP;
    }
    return new ZkWriteCommand(coll.getName(), new DocCollection(coll.getName(), coll.getSlicesMap(), m, coll.getRouter(), coll.getZNodeVersion(), coll.getZNode()));
}
Also used : DocCollection(org.apache.solr.common.cloud.DocCollection)

Example 35 with DocCollection

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

the class CollectionMutator method updateSlice.

public static DocCollection updateSlice(String collectionName, DocCollection collection, Slice slice) {
    DocCollection newCollection = null;
    Map<String, Slice> slices;
    if (collection == null) {
        //  when updateSlice is called on a collection that doesn't exist, it's currently when a core is publishing itself
        // without explicitly creating a collection.  In this current case, we assume custom sharding with an "implicit" router.
        slices = new LinkedHashMap<>(1);
        slices.put(slice.getName(), slice);
        Map<String, Object> props = new HashMap<>(1);
        props.put(DocCollection.DOC_ROUTER, Utils.makeMap(NAME, ImplicitDocRouter.NAME));
        newCollection = new DocCollection(collectionName, slices, props, new ImplicitDocRouter());
    } else {
        // make a shallow copy
        slices = new LinkedHashMap<>(collection.getSlicesMap());
        slices.put(slice.getName(), slice);
        newCollection = collection.copyWithSlices(slices);
    }
    return newCollection;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ImplicitDocRouter(org.apache.solr.common.cloud.ImplicitDocRouter) Slice(org.apache.solr.common.cloud.Slice) DocCollection(org.apache.solr.common.cloud.DocCollection)

Aggregations

DocCollection (org.apache.solr.common.cloud.DocCollection)187 Slice (org.apache.solr.common.cloud.Slice)120 Replica (org.apache.solr.common.cloud.Replica)86 HashMap (java.util.HashMap)55 ClusterState (org.apache.solr.common.cloud.ClusterState)52 ArrayList (java.util.ArrayList)50 Map (java.util.Map)42 SolrException (org.apache.solr.common.SolrException)41 Test (org.junit.Test)39 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)32 List (java.util.List)23 NamedList (org.apache.solr.common.util.NamedList)23 HashSet (java.util.HashSet)21 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)19 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)19 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)19 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)17 SolrQuery (org.apache.solr.client.solrj.SolrQuery)16 SolrInputDocument (org.apache.solr.common.SolrInputDocument)16 ZkNodeProps (org.apache.solr.common.cloud.ZkNodeProps)15