Search in sources :

Example 11 with ShardHandler

use of org.apache.solr.handler.component.ShardHandler in project lucene-solr by apache.

the class OverseerNodePrioritizer method invokeOverseerOp.

private void invokeOverseerOp(String electionNode, String op) {
    ModifiableSolrParams params = new ModifiableSolrParams();
    ShardHandler shardHandler = shardHandlerFactory.getShardHandler();
    params.set(CoreAdminParams.ACTION, CoreAdminAction.OVERSEEROP.toString());
    params.set("op", op);
    params.set("qt", adminPath);
    params.set("electionNode", electionNode);
    ShardRequest sreq = new ShardRequest();
    sreq.purpose = 1;
    String replica = zkStateReader.getBaseUrlForNodeName(LeaderElector.getNodeName(electionNode));
    sreq.shards = new String[] { replica };
    sreq.actualShards = sreq.shards;
    sreq.params = params;
    shardHandler.submit(sreq, replica, sreq.params);
    shardHandler.takeCompletedOrError();
}
Also used : ShardRequest(org.apache.solr.handler.component.ShardRequest) ShardHandler(org.apache.solr.handler.component.ShardHandler) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 12 with ShardHandler

use of org.apache.solr.handler.component.ShardHandler in project lucene-solr by apache.

the class OverseerCollectionMessageHandler method waitForCoreAdminAsyncCallToComplete.

private NamedList waitForCoreAdminAsyncCallToComplete(String nodeName, String requestId) {
    ShardHandler shardHandler = shardHandlerFactory.getShardHandler();
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set(CoreAdminParams.ACTION, CoreAdminAction.REQUESTSTATUS.toString());
    params.set(CoreAdminParams.REQUESTID, requestId);
    int counter = 0;
    ShardRequest sreq;
    do {
        sreq = new ShardRequest();
        params.set("qt", adminPath);
        sreq.purpose = 1;
        String replica = zkStateReader.getBaseUrlForNodeName(nodeName);
        sreq.shards = new String[] { replica };
        sreq.actualShards = sreq.shards;
        sreq.params = params;
        shardHandler.submit(sreq, replica, sreq.params);
        ShardResponse srsp;
        do {
            srsp = shardHandler.takeCompletedOrError();
            if (srsp != null) {
                NamedList results = new NamedList();
                processResponse(results, srsp, Collections.emptySet());
                if (srsp.getSolrResponse().getResponse() == null) {
                    NamedList response = new NamedList();
                    response.add("STATUS", "failed");
                    return response;
                }
                String r = (String) srsp.getSolrResponse().getResponse().get("STATUS");
                if (r.equals("running")) {
                    log.debug("The task is still RUNNING, continuing to wait.");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        Thread.currentThread().interrupt();
                    }
                    continue;
                } else if (r.equals("completed")) {
                    log.debug("The task is COMPLETED, returning");
                    return srsp.getSolrResponse().getResponse();
                } else if (r.equals("failed")) {
                    // TODO: Improve this. Get more information.
                    log.debug("The task is FAILED, returning");
                    return srsp.getSolrResponse().getResponse();
                } else if (r.equals("notfound")) {
                    log.debug("The task is notfound, retry");
                    if (counter++ < 5) {
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                        }
                        break;
                    }
                    throw new SolrException(ErrorCode.BAD_REQUEST, "Invalid status request for requestId: " + requestId + "" + srsp.getSolrResponse().getResponse().get("STATUS") + "retried " + counter + "times");
                } else {
                    throw new SolrException(ErrorCode.BAD_REQUEST, "Invalid status request " + srsp.getSolrResponse().getResponse().get("STATUS"));
                }
            }
        } while (srsp != null);
    } while (true);
}
Also used : ShardResponse(org.apache.solr.handler.component.ShardResponse) NamedList(org.apache.solr.common.util.NamedList) ShardRequest(org.apache.solr.handler.component.ShardRequest) ShardHandler(org.apache.solr.handler.component.ShardHandler) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) RemoteSolrException(org.apache.solr.client.solrj.impl.HttpSolrClient.RemoteSolrException) SolrException(org.apache.solr.common.SolrException)

Example 13 with ShardHandler

use of org.apache.solr.handler.component.ShardHandler in project lucene-solr by apache.

the class OverseerCollectionMessageHandler method collectionCmd.

void collectionCmd(ZkNodeProps message, ModifiableSolrParams params, NamedList results, Replica.State stateMatcher, String asyncId, Map<String, String> requestMap, Set<String> okayExceptions) {
    log.info("Executing Collection Cmd : " + params);
    String collectionName = message.getStr(NAME);
    ShardHandler shardHandler = shardHandlerFactory.getShardHandler();
    ClusterState clusterState = zkStateReader.getClusterState();
    DocCollection coll = clusterState.getCollection(collectionName);
    for (Slice slice : coll.getSlices()) {
        sliceCmd(clusterState, params, stateMatcher, slice, shardHandler, asyncId, requestMap);
    }
    processResponses(results, shardHandler, false, null, asyncId, requestMap, okayExceptions);
}
Also used : ClusterState(org.apache.solr.common.cloud.ClusterState) Slice(org.apache.solr.common.cloud.Slice) ShardHandler(org.apache.solr.handler.component.ShardHandler) DocCollection(org.apache.solr.common.cloud.DocCollection)

Example 14 with ShardHandler

use of org.apache.solr.handler.component.ShardHandler in project lucene-solr by apache.

the class PeerSync method canHandleVersionRanges.

private boolean canHandleVersionRanges(String replica) {
    SyncShardRequest sreq = new SyncShardRequest();
    requests.add(sreq);
    // determine if leader can handle version ranges
    sreq.shards = new String[] { replica };
    sreq.actualShards = sreq.shards;
    sreq.params = new ModifiableSolrParams();
    sreq.params.set("qt", "/get");
    sreq.params.set(DISTRIB, false);
    sreq.params.set("checkCanHandleVersionRanges", false);
    ShardHandler sh = shardHandlerFactory.getShardHandler(client);
    sh.submit(sreq, replica, sreq.params);
    ShardResponse srsp = sh.takeCompletedIncludingErrors();
    Boolean canHandleVersionRanges = srsp.getSolrResponse().getResponse().getBooleanArg("canHandleVersionRanges");
    if (canHandleVersionRanges == null || canHandleVersionRanges.booleanValue() == false) {
        return false;
    }
    return true;
}
Also used : ShardResponse(org.apache.solr.handler.component.ShardResponse) ShardHandler(org.apache.solr.handler.component.ShardHandler) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 15 with ShardHandler

use of org.apache.solr.handler.component.ShardHandler in project lucene-solr by apache.

the class PeerSync method sync.

/** Requests and applies recent updates from peers */
public static void sync(SolrCore core, List<String> replicas, int nUpdates) {
    ShardHandlerFactory shardHandlerFactory = core.getCoreContainer().getShardHandlerFactory();
    ShardHandler shardHandler = shardHandlerFactory.getShardHandler();
    for (String replica : replicas) {
        ShardRequest sreq = new ShardRequest();
        sreq.shards = new String[] { replica };
        sreq.params = new ModifiableSolrParams();
        sreq.params.set("qt", "/get");
        sreq.params.set(DISTRIB, false);
        sreq.params.set("getVersions", nUpdates);
        shardHandler.submit(sreq, replica, sreq.params);
    }
    for (String replica : replicas) {
        ShardResponse srsp = shardHandler.takeCompletedOrError();
    }
}
Also used : ShardResponse(org.apache.solr.handler.component.ShardResponse) HttpShardHandlerFactory(org.apache.solr.handler.component.HttpShardHandlerFactory) ShardHandlerFactory(org.apache.solr.handler.component.ShardHandlerFactory) ShardRequest(org.apache.solr.handler.component.ShardRequest) ShardHandler(org.apache.solr.handler.component.ShardHandler) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Aggregations

ShardHandler (org.apache.solr.handler.component.ShardHandler)17 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)16 SolrException (org.apache.solr.common.SolrException)12 Replica (org.apache.solr.common.cloud.Replica)11 HashMap (java.util.HashMap)9 Slice (org.apache.solr.common.cloud.Slice)9 DocCollection (org.apache.solr.common.cloud.DocCollection)7 ArrayList (java.util.ArrayList)6 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)6 NamedList (org.apache.solr.common.util.NamedList)6 Map (java.util.Map)5 ZkNodeProps (org.apache.solr.common.cloud.ZkNodeProps)5 ShardRequest (org.apache.solr.handler.component.ShardRequest)5 ClusterState (org.apache.solr.common.cloud.ClusterState)3 SolrZkClient (org.apache.solr.common.cloud.SolrZkClient)3 CollectionSnapshotMetaData (org.apache.solr.core.snapshots.CollectionSnapshotMetaData)3 ShardResponse (org.apache.solr.handler.component.ShardResponse)3 TimeOut (org.apache.solr.util.TimeOut)3 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2