Search in sources :

Example 1 with ShardRequest

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

the class OverseerCollectionConfigSetProcessorTest method verifySubmitCaptures.

protected void verifySubmitCaptures(Integer numberOfSlices, Integer numberOfReplica, Collection<String> createNodes, boolean dontShuffleCreateNodeSet) {
    List<String> coreNames = new ArrayList<>();
    Map<String, Map<String, Integer>> sliceToNodeUrlsWithoutProtocolPartToNumberOfShardsRunningMapMap = new HashMap<>();
    List<String> nodeUrlWithoutProtocolPartForLiveNodes = new ArrayList<>(createNodes.size());
    for (String nodeName : createNodes) {
        String nodeUrlWithoutProtocolPart = nodeName.replaceAll("_", "/");
        if (nodeUrlWithoutProtocolPart.startsWith("http://"))
            nodeUrlWithoutProtocolPart = nodeUrlWithoutProtocolPart.substring(7);
        nodeUrlWithoutProtocolPartForLiveNodes.add(nodeUrlWithoutProtocolPart);
    }
    final Map<String, String> coreName_TO_nodeUrlWithoutProtocolPartForLiveNodes_map = new HashMap<>();
    ArgumentCaptor<ShardRequest> shardRequestCaptor = ArgumentCaptor.forClass(ShardRequest.class);
    ArgumentCaptor<String> nodeUrlsWithoutProtocolPartCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<ModifiableSolrParams> paramsCaptor = ArgumentCaptor.forClass(ModifiableSolrParams.class);
    verify(shardHandlerMock, times(numberOfReplica * numberOfSlices)).submit(shardRequestCaptor.capture(), nodeUrlsWithoutProtocolPartCaptor.capture(), paramsCaptor.capture());
    log.info("Datcmzz " + shardRequestCaptor.getAllValues().size());
    for (int i = 0; i < shardRequestCaptor.getAllValues().size(); i++) {
        ShardRequest shardRequest = shardRequestCaptor.getAllValues().get(i);
        String nodeUrlsWithoutProtocolPartCapture = nodeUrlsWithoutProtocolPartCaptor.getAllValues().get(i);
        ModifiableSolrParams params = paramsCaptor.getAllValues().get(i);
        assertEquals(CoreAdminAction.CREATE.toString(), shardRequest.params.get(CoreAdminParams.ACTION));
        // assertEquals(shardRequest.params, submitCapture.params);
        String coreName = shardRequest.params.get(CoreAdminParams.NAME);
        assertFalse("Core with name " + coreName + " created twice", coreNames.contains(coreName));
        coreNames.add(coreName);
        assertEquals(CONFIG_NAME, shardRequest.params.get("collection.configName"));
        assertEquals(COLLECTION_NAME, shardRequest.params.get(CoreAdminParams.COLLECTION));
        assertEquals(numberOfSlices.toString(), shardRequest.params.get(ZkStateReader.NUM_SHARDS_PROP));
        assertEquals(ADMIN_PATH, shardRequest.params.get("qt"));
        assertEquals(1, shardRequest.purpose);
        assertEquals(1, shardRequest.shards.length);
        assertEquals(nodeUrlsWithoutProtocolPartCapture, shardRequest.shards[0]);
        assertTrue("Shard " + coreName + " created on wrong node " + shardRequest.shards[0], nodeUrlWithoutProtocolPartForLiveNodes.contains(shardRequest.shards[0]));
        coreName_TO_nodeUrlWithoutProtocolPartForLiveNodes_map.put(coreName, shardRequest.shards[0]);
        assertEquals(shardRequest.shards, shardRequest.actualShards);
        String sliceName = shardRequest.params.get(CoreAdminParams.SHARD);
        if (!sliceToNodeUrlsWithoutProtocolPartToNumberOfShardsRunningMapMap.containsKey(sliceName)) {
            sliceToNodeUrlsWithoutProtocolPartToNumberOfShardsRunningMapMap.put(sliceName, new HashMap<String, Integer>());
        }
        Map<String, Integer> nodeUrlsWithoutProtocolPartToNumberOfShardsRunningMap = sliceToNodeUrlsWithoutProtocolPartToNumberOfShardsRunningMapMap.get(sliceName);
        Integer existingCount;
        nodeUrlsWithoutProtocolPartToNumberOfShardsRunningMap.put(shardRequest.shards[0], ((existingCount = nodeUrlsWithoutProtocolPartToNumberOfShardsRunningMap.get(shardRequest.shards[0])) == null) ? 1 : (existingCount + 1));
    }
    assertEquals(numberOfSlices * numberOfReplica, coreNames.size());
    for (int i = 1; i <= numberOfSlices; i++) {
        for (int j = 1; j <= numberOfReplica; j++) {
            String coreName = Assign.buildCoreName(COLLECTION_NAME, "shard" + i, Replica.Type.NRT, j);
            assertTrue("Shard " + coreName + " was not created", coreNames.contains(coreName));
            if (dontShuffleCreateNodeSet) {
                final String expectedNodeName = nodeUrlWithoutProtocolPartForLiveNodes.get((numberOfReplica * (i - 1) + (j - 1)) % nodeUrlWithoutProtocolPartForLiveNodes.size());
                assertFalse("expectedNodeName is null for coreName=" + coreName, null == expectedNodeName);
                final String actualNodeName = coreName_TO_nodeUrlWithoutProtocolPartForLiveNodes_map.get(coreName);
                assertFalse("actualNodeName is null for coreName=" + coreName, null == actualNodeName);
                assertTrue("node name mismatch for coreName=" + coreName + " ( actual=" + actualNodeName + " versus expected=" + expectedNodeName + " )", actualNodeName.equals(expectedNodeName));
            }
        }
    }
    assertEquals(numberOfSlices.intValue(), sliceToNodeUrlsWithoutProtocolPartToNumberOfShardsRunningMapMap.size());
    for (int i = 1; i <= numberOfSlices; i++) {
        sliceToNodeUrlsWithoutProtocolPartToNumberOfShardsRunningMapMap.keySet().contains("shard" + i);
    }
    int minShardsPerSlicePerNode = numberOfReplica / createNodes.size();
    int numberOfNodesSupposedToRunMaxShards = numberOfReplica % createNodes.size();
    int numberOfNodesSupposedToRunMinShards = createNodes.size() - numberOfNodesSupposedToRunMaxShards;
    int maxShardsPerSlicePerNode = (minShardsPerSlicePerNode + 1);
    if (numberOfNodesSupposedToRunMaxShards == 0) {
        numberOfNodesSupposedToRunMaxShards = numberOfNodesSupposedToRunMinShards;
        maxShardsPerSlicePerNode = minShardsPerSlicePerNode;
    }
    boolean diffBetweenMinAndMaxShardsPerSlicePerNode = (maxShardsPerSlicePerNode != minShardsPerSlicePerNode);
    for (Entry<String, Map<String, Integer>> sliceToNodeUrlsWithoutProtocolPartToNumberOfShardsRunningMapMapEntry : sliceToNodeUrlsWithoutProtocolPartToNumberOfShardsRunningMapMap.entrySet()) {
        int numberOfShardsRunning = 0;
        int numberOfNodesRunningMinShards = 0;
        int numberOfNodesRunningMaxShards = 0;
        int numberOfNodesRunningAtLeastOneShard = 0;
        for (String nodeUrlsWithoutProtocolPart : sliceToNodeUrlsWithoutProtocolPartToNumberOfShardsRunningMapMapEntry.getValue().keySet()) {
            int numberOfShardsRunningOnThisNode = sliceToNodeUrlsWithoutProtocolPartToNumberOfShardsRunningMapMapEntry.getValue().get(nodeUrlsWithoutProtocolPart);
            numberOfShardsRunning += numberOfShardsRunningOnThisNode;
            numberOfNodesRunningAtLeastOneShard++;
            assertTrue("Node " + nodeUrlsWithoutProtocolPart + " is running wrong number of shards. Supposed to run " + minShardsPerSlicePerNode + (diffBetweenMinAndMaxShardsPerSlicePerNode ? (" or " + maxShardsPerSlicePerNode) : ""), (numberOfShardsRunningOnThisNode == minShardsPerSlicePerNode) || (numberOfShardsRunningOnThisNode == maxShardsPerSlicePerNode));
            if (numberOfShardsRunningOnThisNode == minShardsPerSlicePerNode)
                numberOfNodesRunningMinShards++;
            if (numberOfShardsRunningOnThisNode == maxShardsPerSlicePerNode)
                numberOfNodesRunningMaxShards++;
        }
        if (minShardsPerSlicePerNode == 0)
            numberOfNodesRunningMinShards = (createNodes.size() - numberOfNodesRunningAtLeastOneShard);
        assertEquals("Too many shards are running under slice " + sliceToNodeUrlsWithoutProtocolPartToNumberOfShardsRunningMapMapEntry.getKey(), numberOfReplica.intValue(), numberOfShardsRunning);
        assertEquals(numberOfNodesSupposedToRunMinShards, numberOfNodesRunningMinShards);
        assertEquals(numberOfNodesSupposedToRunMaxShards, numberOfNodesRunningMaxShards);
    }
}
Also used : ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) ShardRequest(org.apache.solr.handler.component.ShardRequest)

Example 2 with ShardRequest

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

the class MergeStrategyTest method test.

@Test
@ShardsFixed(num = 3)
public void test() throws Exception {
    del("*:*");
    index_specific(0, "id", "1", "sort_i", "5");
    index_specific(0, "id", "2", "sort_i", "50");
    index_specific(1, "id", "5", "sort_i", "4");
    index_specific(1, "id", "6", "sort_i", "10");
    index_specific(0, "id", "7", "sort_i", "1");
    index_specific(1, "id", "8", "sort_i", "2");
    index_specific(2, "id", "9", "sort_i", "1000");
    index_specific(2, "id", "10", "sort_i", "1500");
    index_specific(2, "id", "11", "sort_i", "1300");
    index_specific(1, "id", "12", "sort_i", "15");
    index_specific(1, "id", "13", "sort_i", "16");
    commit();
    handle.put("explain", SKIPVAL);
    handle.put("timestamp", SKIPVAL);
    handle.put("score", SKIPVAL);
    handle.put("wt", SKIP);
    handle.put("distrib", SKIP);
    handle.put("shards.qt", SKIP);
    handle.put("shards", SKIP);
    handle.put("q", SKIP);
    handle.put("maxScore", SKIPVAL);
    handle.put("_version_", SKIP);
    //Test mergeStrategy that uses score
    query("rq", "{!rank}", "q", "*:*", "rows", "12", "sort", "sort_i asc", "fl", "*,score");
    //Test without mergeStrategy
    query("q", "*:*", "rows", "12", "sort", "sort_i asc");
    //Test mergeStrategy1 that uses a sort field.
    query("rq", "{!rank mergeStrategy=1}", "q", "*:*", "rows", "12", "sort", "sort_i asc");
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("rows", "12");
    params.add("rq", "{!rank}");
    params.add("sort", "sort_i asc");
    params.add("fl", "*,score");
    setDistributedParams(params);
    QueryResponse rsp = queryServer(params);
    assertOrder(rsp, "10", "11", "9", "2", "13", "12", "6", "1", "5", "8", "7");
    params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("rows", "12");
    params.add("sort", "sort_i asc");
    params.add("fl", "*,score");
    setDistributedParams(params);
    rsp = queryServer(params);
    assertOrder(rsp, "7", "8", "5", "1", "6", "12", "13", "2", "9", "11", "10");
    MergeStrategy m1 = new MergeStrategy() {

        @Override
        public void merge(ResponseBuilder rb, ShardRequest sreq) {
        }

        public boolean mergesIds() {
            return true;
        }

        public boolean handlesMergeFields() {
            return false;
        }

        public void handleMergeFields(ResponseBuilder rb, SolrIndexSearcher searcher) {
        }

        @Override
        public int getCost() {
            return 1;
        }
    };
    MergeStrategy m2 = new MergeStrategy() {

        @Override
        public void merge(ResponseBuilder rb, ShardRequest sreq) {
        }

        public boolean mergesIds() {
            return true;
        }

        public boolean handlesMergeFields() {
            return false;
        }

        public void handleMergeFields(ResponseBuilder rb, SolrIndexSearcher searcher) {
        }

        @Override
        public int getCost() {
            return 100;
        }
    };
    MergeStrategy m3 = new MergeStrategy() {

        @Override
        public void merge(ResponseBuilder rb, ShardRequest sreq) {
        }

        public boolean mergesIds() {
            return false;
        }

        public boolean handlesMergeFields() {
            return false;
        }

        public void handleMergeFields(ResponseBuilder rb, SolrIndexSearcher searcher) {
        }

        @Override
        public int getCost() {
            return 50;
        }
    };
    MergeStrategy[] merges = { m1, m2, m3 };
    Arrays.sort(merges, MergeStrategy.MERGE_COMP);
    assert (merges[0].getCost() == 1);
    assert (merges[1].getCost() == 50);
    assert (merges[2].getCost() == 100);
}
Also used : MergeStrategy(org.apache.solr.handler.component.MergeStrategy) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) ShardRequest(org.apache.solr.handler.component.ShardRequest) ResponseBuilder(org.apache.solr.handler.component.ResponseBuilder) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) Test(org.junit.Test)

Example 3 with ShardRequest

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

the class CreateCollectionCmd method call.

@Override
public void call(ClusterState clusterState, ZkNodeProps message, NamedList results) throws Exception {
    final String collectionName = message.getStr(NAME);
    log.info("Create collection {}", collectionName);
    if (clusterState.hasCollection(collectionName)) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "collection already exists: " + collectionName);
    }
    String configName = getConfigName(collectionName, message);
    if (configName == null) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No config set found to associate with the collection.");
    }
    ocmh.validateConfigOrThrowSolrException(configName);
    try {
        // look at the replication factor and see if it matches reality
        // if it does not, find best nodes to create more cores
        int numTlogReplicas = message.getInt(TLOG_REPLICAS, 0);
        int numNrtReplicas = message.getInt(NRT_REPLICAS, message.getInt(REPLICATION_FACTOR, numTlogReplicas > 0 ? 0 : 1));
        int numPullReplicas = message.getInt(PULL_REPLICAS, 0);
        ShardHandler shardHandler = ocmh.shardHandlerFactory.getShardHandler();
        final String async = message.getStr(ASYNC);
        Integer numSlices = message.getInt(NUM_SLICES, null);
        String router = message.getStr("router.name", DocRouter.DEFAULT_NAME);
        List<String> shardNames = new ArrayList<>();
        if (ImplicitDocRouter.NAME.equals(router)) {
            ClusterStateMutator.getShardNames(shardNames, message.getStr("shards", null));
            numSlices = shardNames.size();
        } else {
            if (numSlices == null) {
                throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, NUM_SLICES + " is a required param (when using CompositeId router).");
            }
            ClusterStateMutator.getShardNames(numSlices, shardNames);
        }
        int maxShardsPerNode = message.getInt(MAX_SHARDS_PER_NODE, 1);
        if (numNrtReplicas + numTlogReplicas <= 0) {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, NRT_REPLICAS + " + " + TLOG_REPLICAS + " must be greater than 0");
        }
        if (numSlices <= 0) {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, NUM_SLICES + " must be > 0");
        }
        // we need to look at every node and see how many cores it serves
        // add our new cores to existing nodes serving the least number of cores
        // but (for now) require that each core goes on a distinct node.
        final List<String> nodeList = OverseerCollectionMessageHandler.getLiveOrLiveAndCreateNodeSetList(clusterState.getLiveNodes(), message, RANDOM);
        Map<ReplicaAssigner.Position, String> positionVsNodes;
        if (nodeList.isEmpty()) {
            log.warn("It is unusual to create a collection (" + collectionName + ") without cores.");
            positionVsNodes = new HashMap<>();
        } else {
            int totalNumReplicas = numNrtReplicas + numTlogReplicas + numPullReplicas;
            if (totalNumReplicas > nodeList.size()) {
                log.warn("Specified number of replicas of " + totalNumReplicas + " on collection " + collectionName + " is higher than the number of Solr instances currently live or live and part of your " + CREATE_NODE_SET + "(" + nodeList.size() + "). It's unusual to run two replica of the same slice on the same Solr-instance.");
            }
            int maxShardsAllowedToCreate = maxShardsPerNode * nodeList.size();
            int requestedShardsToCreate = numSlices * totalNumReplicas;
            if (maxShardsAllowedToCreate < requestedShardsToCreate) {
                throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Cannot create collection " + collectionName + ". Value of " + MAX_SHARDS_PER_NODE + " is " + maxShardsPerNode + ", and the number of nodes currently live or live and part of your " + CREATE_NODE_SET + " is " + nodeList.size() + ". This allows a maximum of " + maxShardsAllowedToCreate + " to be created. Value of " + NUM_SLICES + " is " + numSlices + ", value of " + NRT_REPLICAS + " is " + numNrtReplicas + ", value of " + TLOG_REPLICAS + " is " + numTlogReplicas + " and value of " + PULL_REPLICAS + " is " + numPullReplicas + ". This requires " + requestedShardsToCreate + " shards to be created (higher than the allowed number)");
            }
            positionVsNodes = ocmh.identifyNodes(clusterState, nodeList, message, shardNames, numNrtReplicas, numTlogReplicas, numPullReplicas);
        }
        ZkStateReader zkStateReader = ocmh.zkStateReader;
        boolean isLegacyCloud = Overseer.isLegacy(zkStateReader);
        ocmh.createConfNode(configName, collectionName, isLegacyCloud);
        Map<String, String> collectionParams = new HashMap<>();
        Map<String, Object> collectionProps = message.getProperties();
        for (String propName : collectionProps.keySet()) {
            if (propName.startsWith(ZkController.COLLECTION_PARAM_PREFIX)) {
                collectionParams.put(propName.substring(ZkController.COLLECTION_PARAM_PREFIX.length()), (String) collectionProps.get(propName));
            }
        }
        createCollectionZkNode(zkClient, collectionName, collectionParams);
        Overseer.getStateUpdateQueue(zkStateReader.getZkClient()).offer(Utils.toJSON(message));
        // wait for a while until we don't see the collection
        TimeOut waitUntil = new TimeOut(30, TimeUnit.SECONDS);
        boolean created = false;
        while (!waitUntil.hasTimedOut()) {
            Thread.sleep(100);
            created = zkStateReader.getClusterState().hasCollection(collectionName);
            if (created)
                break;
        }
        if (!created)
            throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Could not fully create collection: " + collectionName);
        if (nodeList.isEmpty()) {
            log.debug("Finished create command for collection: {}", collectionName);
            return;
        }
        // For tracking async calls.
        Map<String, String> requestMap = new HashMap<>();
        log.debug(formatString("Creating SolrCores for new collection {0}, shardNames {1} , nrtReplicas : {2}, tlogReplicas: {3}, pullReplicas: {4}", collectionName, shardNames, numNrtReplicas, numTlogReplicas, numPullReplicas));
        Map<String, ShardRequest> coresToCreate = new LinkedHashMap<>();
        for (Map.Entry<ReplicaAssigner.Position, String> e : positionVsNodes.entrySet()) {
            ReplicaAssigner.Position position = e.getKey();
            String nodeName = e.getValue();
            String coreName = Assign.buildCoreName(collectionName, position.shard, position.type, position.index + 1);
            log.debug(formatString("Creating core {0} as part of shard {1} of collection {2} on {3}", coreName, position.shard, collectionName, nodeName));
            String baseUrl = zkStateReader.getBaseUrlForNodeName(nodeName);
            // Otherwise the core creation fails
            if (!isLegacyCloud) {
                ZkNodeProps props = new ZkNodeProps(Overseer.QUEUE_OPERATION, ADDREPLICA.toString(), ZkStateReader.COLLECTION_PROP, collectionName, ZkStateReader.SHARD_ID_PROP, position.shard, ZkStateReader.CORE_NAME_PROP, coreName, ZkStateReader.STATE_PROP, Replica.State.DOWN.toString(), ZkStateReader.BASE_URL_PROP, baseUrl, ZkStateReader.REPLICA_TYPE, position.type.name());
                Overseer.getStateUpdateQueue(zkStateReader.getZkClient()).offer(Utils.toJSON(props));
            }
            // Need to create new params for each request
            ModifiableSolrParams params = new ModifiableSolrParams();
            params.set(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.CREATE.toString());
            params.set(CoreAdminParams.NAME, coreName);
            params.set(COLL_CONF, configName);
            params.set(CoreAdminParams.COLLECTION, collectionName);
            params.set(CoreAdminParams.SHARD, position.shard);
            params.set(ZkStateReader.NUM_SHARDS_PROP, numSlices);
            params.set(CoreAdminParams.NEW_COLLECTION, "true");
            params.set(CoreAdminParams.REPLICA_TYPE, position.type.name());
            if (async != null) {
                String coreAdminAsyncId = async + Math.abs(System.nanoTime());
                params.add(ASYNC, coreAdminAsyncId);
                requestMap.put(nodeName, coreAdminAsyncId);
            }
            ocmh.addPropertyParams(message, params);
            ShardRequest sreq = new ShardRequest();
            sreq.nodeName = nodeName;
            params.set("qt", ocmh.adminPath);
            sreq.purpose = 1;
            sreq.shards = new String[] { baseUrl };
            sreq.actualShards = sreq.shards;
            sreq.params = params;
            if (isLegacyCloud) {
                shardHandler.submit(sreq, sreq.shards[0], sreq.params);
            } else {
                coresToCreate.put(coreName, sreq);
            }
        }
        if (!isLegacyCloud) {
            // wait for all replica entries to be created
            Map<String, Replica> replicas = ocmh.waitToSeeReplicasInState(collectionName, coresToCreate.keySet());
            for (Map.Entry<String, ShardRequest> e : coresToCreate.entrySet()) {
                ShardRequest sreq = e.getValue();
                sreq.params.set(CoreAdminParams.CORE_NODE_NAME, replicas.get(e.getKey()).getName());
                shardHandler.submit(sreq, sreq.shards[0], sreq.params);
            }
        }
        ocmh.processResponses(results, shardHandler, false, null, async, requestMap, Collections.emptySet());
        if (results.get("failure") != null && ((SimpleOrderedMap) results.get("failure")).size() > 0) {
            // Let's cleanup as we hit an exception
            // We shouldn't be passing 'results' here for the cleanup as the response would then contain 'success'
            // element, which may be interpreted by the user as a positive ack
            ocmh.cleanupCollection(collectionName, new NamedList());
            log.info("Cleaned up artifacts for failed create collection for [{}]", collectionName);
        } else {
            log.debug("Finished create command on all shards for collection: {}", collectionName);
        }
    } catch (SolrException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, null, ex);
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TimeOut(org.apache.solr.util.TimeOut) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) ArrayList(java.util.ArrayList) StrUtils.formatString(org.apache.solr.common.util.StrUtils.formatString) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) LinkedHashMap(java.util.LinkedHashMap) ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) SolrException(org.apache.solr.common.SolrException) NamedList(org.apache.solr.common.util.NamedList) ReplicaAssigner(org.apache.solr.cloud.rule.ReplicaAssigner) ShardHandler(org.apache.solr.handler.component.ShardHandler) Replica(org.apache.solr.common.cloud.Replica) SolrException(org.apache.solr.common.SolrException) KeeperException(org.apache.zookeeper.KeeperException) ZooKeeperException(org.apache.solr.common.cloud.ZooKeeperException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) ShardRequest(org.apache.solr.handler.component.ShardRequest) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 4 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 5 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)

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