Search in sources :

Example 1 with Node

use of org.apache.solr.update.SolrCmdDistributor.Node in project lucene-solr by apache.

the class SolrCmdDistributorTest method testMaxRetries.

private void testMaxRetries() throws IOException {
    final MockStreamingSolrClients streamingClients = new MockStreamingSolrClients(updateShardHandler);
    SolrCmdDistributor cmdDistrib = new SolrCmdDistributor(streamingClients, 5, 0);
    streamingClients.setExp(Exp.CONNECT_EXCEPTION);
    ArrayList<Node> nodes = new ArrayList<>();
    final HttpSolrClient solrclient1 = (HttpSolrClient) clients.get(0);
    final AtomicInteger retries = new AtomicInteger();
    ZkNodeProps nodeProps = new ZkNodeProps(ZkStateReader.BASE_URL_PROP, solrclient1.getBaseURL(), ZkStateReader.CORE_NAME_PROP, "");
    RetryNode retryNode = new RetryNode(new ZkCoreNodeProps(nodeProps), null, "collection1", "shard1") {

        @Override
        public boolean checkRetry() {
            retries.incrementAndGet();
            return true;
        }
    };
    nodes.add(retryNode);
    AddUpdateCommand cmd = new AddUpdateCommand(null);
    cmd.solrDoc = sdoc("id", id.incrementAndGet());
    ModifiableSolrParams params = new ModifiableSolrParams();
    cmdDistrib.distribAdd(cmd, nodes, params);
    cmdDistrib.finish();
    assertEquals(6, retries.get());
    assertEquals(1, cmdDistrib.getErrors().size());
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) RetryNode(org.apache.solr.update.SolrCmdDistributor.RetryNode) ZkCoreNodeProps(org.apache.solr.common.cloud.ZkCoreNodeProps) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RetryNode(org.apache.solr.update.SolrCmdDistributor.RetryNode) StdNode(org.apache.solr.update.SolrCmdDistributor.StdNode) Node(org.apache.solr.update.SolrCmdDistributor.Node) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) ArrayList(java.util.ArrayList) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 2 with Node

use of org.apache.solr.update.SolrCmdDistributor.Node in project lucene-solr by apache.

the class SolrCmdDistributorTest method testOneRetry.

private void testOneRetry() throws Exception {
    final HttpSolrClient solrclient = (HttpSolrClient) clients.get(0);
    long numFoundBefore = solrclient.query(new SolrQuery("*:*")).getResults().getNumFound();
    final MockStreamingSolrClients streamingClients = new MockStreamingSolrClients(updateShardHandler);
    SolrCmdDistributor cmdDistrib = new SolrCmdDistributor(streamingClients, 5, 0);
    streamingClients.setExp(Exp.CONNECT_EXCEPTION);
    ArrayList<Node> nodes = new ArrayList<>();
    ZkNodeProps nodeProps = new ZkNodeProps(ZkStateReader.BASE_URL_PROP, solrclient.getBaseURL(), ZkStateReader.CORE_NAME_PROP, "");
    final AtomicInteger retries = new AtomicInteger();
    nodeProps = new ZkNodeProps(ZkStateReader.BASE_URL_PROP, solrclient.getBaseURL(), ZkStateReader.CORE_NAME_PROP, "");
    RetryNode retryNode = new RetryNode(new ZkCoreNodeProps(nodeProps), null, "collection1", "shard1") {

        @Override
        public boolean checkRetry() {
            streamingClients.setExp(null);
            retries.incrementAndGet();
            return true;
        }
    };
    nodes.add(retryNode);
    AddUpdateCommand cmd = new AddUpdateCommand(null);
    cmd.solrDoc = sdoc("id", id.incrementAndGet());
    ModifiableSolrParams params = new ModifiableSolrParams();
    CommitUpdateCommand ccmd = new CommitUpdateCommand(null, false);
    cmdDistrib.distribAdd(cmd, nodes, params);
    cmdDistrib.distribCommit(ccmd, nodes, params);
    cmdDistrib.finish();
    assertEquals(1, retries.get());
    long numFoundAfter = solrclient.query(new SolrQuery("*:*")).getResults().getNumFound();
    // we will get java.net.ConnectException which we retry on
    assertEquals(numFoundBefore + 1, numFoundAfter);
    assertEquals(0, cmdDistrib.getErrors().size());
}
Also used : RetryNode(org.apache.solr.update.SolrCmdDistributor.RetryNode) ZkCoreNodeProps(org.apache.solr.common.cloud.ZkCoreNodeProps) RetryNode(org.apache.solr.update.SolrCmdDistributor.RetryNode) StdNode(org.apache.solr.update.SolrCmdDistributor.StdNode) Node(org.apache.solr.update.SolrCmdDistributor.Node) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) ArrayList(java.util.ArrayList) SolrQuery(org.apache.solr.client.solrj.SolrQuery) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 3 with Node

use of org.apache.solr.update.SolrCmdDistributor.Node in project lucene-solr by apache.

the class DistributedUpdateProcessor method getCollectionUrls.

private List<Node> getCollectionUrls(SolrQueryRequest req, String collection, EnumSet<Replica.Type> types) {
    ClusterState clusterState = req.getCore().getCoreContainer().getZkController().getClusterState();
    Map<String, Slice> slices = clusterState.getSlicesMap(collection);
    if (slices == null) {
        throw new ZooKeeperException(ErrorCode.BAD_REQUEST, "Could not find collection in zk: " + clusterState);
    }
    final List<Node> urls = new ArrayList<>(slices.size());
    for (Map.Entry<String, Slice> sliceEntry : slices.entrySet()) {
        Slice replicas = slices.get(sliceEntry.getKey());
        Map<String, Replica> shardMap = replicas.getReplicasMap();
        for (Entry<String, Replica> entry : shardMap.entrySet()) {
            if (!types.contains(entry.getValue().getType())) {
                continue;
            }
            ZkCoreNodeProps nodeProps = new ZkCoreNodeProps(entry.getValue());
            if (clusterState.liveNodesContain(nodeProps.getNodeName())) {
                urls.add(new StdNode(nodeProps, collection, replicas.getName()));
            }
        }
    }
    if (urls.isEmpty()) {
        return null;
    }
    return urls;
}
Also used : ClusterState(org.apache.solr.common.cloud.ClusterState) ZkCoreNodeProps(org.apache.solr.common.cloud.ZkCoreNodeProps) RetryNode(org.apache.solr.update.SolrCmdDistributor.RetryNode) Node(org.apache.solr.update.SolrCmdDistributor.Node) StdNode(org.apache.solr.update.SolrCmdDistributor.StdNode) ArrayList(java.util.ArrayList) Replica(org.apache.solr.common.cloud.Replica) ZooKeeperException(org.apache.solr.common.cloud.ZooKeeperException) Slice(org.apache.solr.common.cloud.Slice) StdNode(org.apache.solr.update.SolrCmdDistributor.StdNode) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with Node

use of org.apache.solr.update.SolrCmdDistributor.Node in project lucene-solr by apache.

the class DistributedUpdateProcessor method getSubShardLeaders.

private List<Node> getSubShardLeaders(DocCollection coll, String shardId, String docId, SolrInputDocument doc) {
    Collection<Slice> allSlices = coll.getSlices();
    List<Node> nodes = null;
    for (Slice aslice : allSlices) {
        final Slice.State state = aslice.getState();
        if (state == Slice.State.CONSTRUCTION || state == Slice.State.RECOVERY) {
            DocRouter.Range myRange = coll.getSlice(shardId).getRange();
            if (myRange == null)
                myRange = new DocRouter.Range(Integer.MIN_VALUE, Integer.MAX_VALUE);
            boolean isSubset = aslice.getRange() != null && aslice.getRange().isSubsetOf(myRange);
            if (isSubset && (// in case of deletes
            docId == null || (docId != null && coll.getRouter().isTargetSlice(docId, doc, req.getParams(), aslice.getName(), coll)))) {
                Replica sliceLeader = aslice.getLeader();
                // slice leader can be null because node/shard is created zk before leader election
                if (sliceLeader != null && zkController.getClusterState().liveNodesContain(sliceLeader.getNodeName())) {
                    if (nodes == null)
                        nodes = new ArrayList<>();
                    ZkCoreNodeProps nodeProps = new ZkCoreNodeProps(sliceLeader);
                    nodes.add(new StdNode(nodeProps, coll.getName(), shardId));
                }
            }
        }
    }
    return nodes;
}
Also used : ZkCoreNodeProps(org.apache.solr.common.cloud.ZkCoreNodeProps) RetryNode(org.apache.solr.update.SolrCmdDistributor.RetryNode) Node(org.apache.solr.update.SolrCmdDistributor.Node) StdNode(org.apache.solr.update.SolrCmdDistributor.StdNode) ArrayList(java.util.ArrayList) Replica(org.apache.solr.common.cloud.Replica) Slice(org.apache.solr.common.cloud.Slice) State(org.apache.solr.common.cloud.Slice.State) DocRouter(org.apache.solr.common.cloud.DocRouter) StdNode(org.apache.solr.update.SolrCmdDistributor.StdNode)

Example 5 with Node

use of org.apache.solr.update.SolrCmdDistributor.Node in project lucene-solr by apache.

the class DistributedUpdateProcessor method setupRequestForDBQ.

// used for deleteByQuery to get the list of nodes this leader should forward to
private List<Node> setupRequestForDBQ() {
    List<Node> nodes = null;
    String shardId = cloudDesc.getShardId();
    try {
        Replica leaderReplica = zkController.getZkStateReader().getLeaderRetry(collection, shardId);
        isLeader = leaderReplica.getName().equals(req.getCore().getCoreDescriptor().getCloudDescriptor().getCoreNodeName());
        // TODO: what if we are no longer the leader?
        forwardToLeader = false;
        List<ZkCoreNodeProps> replicaProps = zkController.getZkStateReader().getReplicaProps(collection, shardId, leaderReplica.getName(), null, Replica.State.DOWN, EnumSet.of(Replica.Type.NRT, Replica.Type.TLOG));
        if (replicaProps != null) {
            nodes = new ArrayList<>(replicaProps.size());
            for (ZkCoreNodeProps props : replicaProps) {
                nodes.add(new StdNode(props, collection, shardId));
            }
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "", e);
    }
    return nodes;
}
Also used : ZooKeeperException(org.apache.solr.common.cloud.ZooKeeperException) ZkCoreNodeProps(org.apache.solr.common.cloud.ZkCoreNodeProps) RetryNode(org.apache.solr.update.SolrCmdDistributor.RetryNode) Node(org.apache.solr.update.SolrCmdDistributor.Node) StdNode(org.apache.solr.update.SolrCmdDistributor.StdNode) StdNode(org.apache.solr.update.SolrCmdDistributor.StdNode) Replica(org.apache.solr.common.cloud.Replica)

Aggregations

Node (org.apache.solr.update.SolrCmdDistributor.Node)14 RetryNode (org.apache.solr.update.SolrCmdDistributor.RetryNode)14 StdNode (org.apache.solr.update.SolrCmdDistributor.StdNode)14 ZkCoreNodeProps (org.apache.solr.common.cloud.ZkCoreNodeProps)11 ArrayList (java.util.ArrayList)10 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)9 Replica (org.apache.solr.common.cloud.Replica)7 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)5 SolrException (org.apache.solr.common.SolrException)5 DocCollection (org.apache.solr.common.cloud.DocCollection)5 Slice (org.apache.solr.common.cloud.Slice)5 ZkNodeProps (org.apache.solr.common.cloud.ZkNodeProps)5 ZooKeeperException (org.apache.solr.common.cloud.ZooKeeperException)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 SolrQuery (org.apache.solr.client.solrj.SolrQuery)4 CharsRefBuilder (org.apache.lucene.util.CharsRefBuilder)2 ClusterState (org.apache.solr.common.cloud.ClusterState)2 DocRouter (org.apache.solr.common.cloud.DocRouter)2 SolrParams (org.apache.solr.common.params.SolrParams)2 NamedList (org.apache.solr.common.util.NamedList)2