Search in sources :

Example 11 with ShardRequest

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

the class PeerSync method handleResponse.

private boolean handleResponse(ShardResponse srsp) {
    ShardRequest sreq = srsp.getShardRequest();
    if (srsp.getException() != null) {
        // redundantly asking other replicas for them).
        if (cantReachIsSuccess && sreq.purpose == 1 && srsp.getException() instanceof SolrServerException) {
            Throwable solrException = ((SolrServerException) srsp.getException()).getRootCause();
            boolean connectTimeoutExceptionInChain = connectTimeoutExceptionInChain(srsp.getException());
            if (connectTimeoutExceptionInChain || solrException instanceof ConnectException || solrException instanceof ConnectTimeoutException || solrException instanceof NoHttpResponseException || solrException instanceof SocketException) {
                log.warn(msg() + " couldn't connect to " + srsp.getShardAddress() + ", counting as success", srsp.getException());
                return true;
            }
        }
        if (cantReachIsSuccess && sreq.purpose == 1 && srsp.getException() instanceof SolrException && ((SolrException) srsp.getException()).code() == 503) {
            log.warn(msg() + " got a 503 from " + srsp.getShardAddress() + ", counting as success", srsp.getException());
            return true;
        }
        if (cantReachIsSuccess && sreq.purpose == 1 && srsp.getException() instanceof SolrException && ((SolrException) srsp.getException()).code() == 404) {
            log.warn(msg() + " got a 404 from " + srsp.getShardAddress() + ", counting as success. " + "Perhaps /get is not registered?", srsp.getException());
            return true;
        }
        // TODO: we should return the above information so that when we can request a recovery through zookeeper, we do
        // that for these nodes
        // TODO: at least log???
        // srsp.getException().printStackTrace(System.out);
        log.warn(msg() + " exception talking to " + srsp.getShardAddress() + ", failed", srsp.getException());
        return false;
    }
    if (sreq.purpose == 1) {
        return handleVersions(srsp);
    } else {
        return handleUpdates(srsp);
    }
}
Also used : NoHttpResponseException(org.apache.http.NoHttpResponseException) SocketException(java.net.SocketException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ShardRequest(org.apache.solr.handler.component.ShardRequest) SolrException(org.apache.solr.common.SolrException) ConnectException(java.net.ConnectException) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException)

Example 12 with ShardRequest

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

the class PeerSync method requestUpdates.

private boolean requestUpdates(ShardResponse srsp, String versionsAndRanges, long totalUpdates) {
    String replica = srsp.getShardRequest().shards[0];
    log.info(msg() + "Requesting updates from " + replica + "n=" + totalUpdates + " versions=" + versionsAndRanges);
    // reuse our original request object
    ShardRequest sreq = srsp.getShardRequest();
    sreq.purpose = 0;
    sreq.params = new ModifiableSolrParams();
    sreq.params.set("qt", "/get");
    sreq.params.set(DISTRIB, false);
    sreq.params.set("getUpdates", versionsAndRanges);
    sreq.params.set("onlyIfActive", onlyIfActive);
    // fingerprint should really be requested only for the maxversion  we are requesting updates for
    // In case updates are coming in while node is coming up after restart, node would have already
    // buffered some of the updates. fingerprint we requested with versions would reflect versions
    // in our buffer as well and will definitely cause a mismatch
    sreq.params.set("fingerprint", doFingerprint);
    // needs to be zeroed for correct correlation to occur
    sreq.responses.clear();
    shardHandler.submit(sreq, sreq.shards[0], sreq.params);
    return true;
}
Also used : ShardRequest(org.apache.solr.handler.component.ShardRequest) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 13 with ShardRequest

use of org.apache.solr.handler.component.ShardRequest 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)

Example 14 with ShardRequest

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

the class SearchGroupsRequestFactory method constructRequest.

/**
   * {@inheritDoc}
   */
@Override
public ShardRequest[] constructRequest(ResponseBuilder rb) {
    ShardRequest sreq = new ShardRequest();
    GroupingSpecification groupingSpecification = rb.getGroupingSpec();
    if (groupingSpecification.getFields().length == 0) {
        return new ShardRequest[0];
    }
    sreq.purpose = ShardRequest.PURPOSE_GET_TOP_GROUPS;
    sreq.params = new ModifiableSolrParams(rb.req.getParams());
    // TODO: base on current params or original params?
    // don't pass through any shards param
    sreq.params.remove(ShardParams.SHARDS);
    // results from the start.
    if (rb.shards_start > -1) {
        // if the client set shards.start set this explicitly
        sreq.params.set(CommonParams.START, rb.shards_start);
    } else {
        sreq.params.set(CommonParams.START, "0");
    }
    // we could just specify that this is a shard request.
    if (rb.shards_rows > -1) {
        // if the client set shards.rows set this explicity
        sreq.params.set(CommonParams.ROWS, rb.shards_rows);
    } else {
        sreq.params.set(CommonParams.ROWS, rb.getSortSpec().getOffset() + rb.getSortSpec().getCount());
    }
    // in this first phase, request only the unique key field
    // and any fields needed for merging.
    sreq.params.set(GroupParams.GROUP_DISTRIBUTED_FIRST, "true");
    if ((rb.getFieldFlags() & SolrIndexSearcher.GET_SCORES) != 0 || rb.getSortSpec().includesScore()) {
        sreq.params.set(CommonParams.FL, rb.req.getSchema().getUniqueKeyField().getName() + ",score");
    } else {
        sreq.params.set(CommonParams.FL, rb.req.getSchema().getUniqueKeyField().getName());
    }
    return new ShardRequest[] { sreq };
}
Also used : ShardRequest(org.apache.solr.handler.component.ShardRequest) GroupingSpecification(org.apache.solr.search.grouping.GroupingSpecification) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 15 with ShardRequest

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

the class StoredFieldsShardRequestFactory method constructRequest.

@Override
public ShardRequest[] constructRequest(ResponseBuilder rb) {
    HashMap<String, Set<ShardDoc>> shardMap = new HashMap<>();
    for (TopGroups<BytesRef> topGroups : rb.mergedTopGroups.values()) {
        for (GroupDocs<BytesRef> group : topGroups.groups) {
            mapShardToDocs(shardMap, group.scoreDocs);
        }
    }
    for (QueryCommandResult queryCommandResult : rb.mergedQueryCommandResults.values()) {
        mapShardToDocs(shardMap, queryCommandResult.getTopDocs().scoreDocs);
    }
    ShardRequest[] shardRequests = new ShardRequest[shardMap.size()];
    SchemaField uniqueField = rb.req.getSchema().getUniqueKeyField();
    int i = 0;
    for (Collection<ShardDoc> shardDocs : shardMap.values()) {
        ShardRequest sreq = new ShardRequest();
        sreq.purpose = ShardRequest.PURPOSE_GET_FIELDS;
        sreq.shards = new String[] { shardDocs.iterator().next().shard };
        sreq.params = new ModifiableSolrParams();
        sreq.params.add(rb.req.getParams());
        sreq.params.remove(GroupParams.GROUP);
        sreq.params.remove(CommonParams.SORT);
        sreq.params.remove(ResponseBuilder.FIELD_SORT_VALUES);
        String fl = sreq.params.get(CommonParams.FL);
        if (fl != null) {
            fl = fl.trim();
            // don't add "id" if the fl is empty or "score" or it would change the meaning.
            if (fl.length() != 0 && !"score".equals(fl) && !"*".equals(fl)) {
                sreq.params.set(CommonParams.FL, fl + ',' + uniqueField.getName());
            }
        }
        List<String> ids = new ArrayList<>(shardDocs.size());
        for (ShardDoc shardDoc : shardDocs) {
            ids.add(shardDoc.id.toString());
        }
        sreq.params.add(ShardParams.IDS, StrUtils.join(ids, ','));
        shardRequests[i++] = sreq;
    }
    return shardRequests;
}
Also used : QueryCommandResult(org.apache.solr.search.grouping.distributed.command.QueryCommandResult) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SchemaField(org.apache.solr.schema.SchemaField) ShardRequest(org.apache.solr.handler.component.ShardRequest) BytesRef(org.apache.lucene.util.BytesRef) ShardDoc(org.apache.solr.handler.component.ShardDoc)

Aggregations

ShardRequest (org.apache.solr.handler.component.ShardRequest)16 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)13 ShardHandler (org.apache.solr.handler.component.ShardHandler)5 SolrException (org.apache.solr.common.SolrException)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 BytesRef (org.apache.lucene.util.BytesRef)2 NamedList (org.apache.solr.common.util.NamedList)2 ShardResponse (org.apache.solr.handler.component.ShardResponse)2 ConnectException (java.net.ConnectException)1 SocketException (java.net.SocketException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 NoHttpResponseException (org.apache.http.NoHttpResponseException)1 ConnectTimeoutException (org.apache.http.conn.ConnectTimeoutException)1 CharsRefBuilder (org.apache.lucene.util.CharsRefBuilder)1 SolrServerException (org.apache.solr.client.solrj.SolrServerException)1 RemoteSolrException (org.apache.solr.client.solrj.impl.HttpSolrClient.RemoteSolrException)1 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)1