Search in sources :

Example 1 with State

use of org.apache.solr.common.cloud.Slice.State 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 2 with State

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

the class DistributedUpdateProcessor method couldIbeSubShardLeader.

private boolean couldIbeSubShardLeader(DocCollection coll) {
    // Could I be the leader of a shard in "construction/recovery" state?
    String myShardId = req.getCore().getCoreDescriptor().getCloudDescriptor().getShardId();
    Slice mySlice = coll.getSlice(myShardId);
    State state = mySlice.getState();
    return state == Slice.State.CONSTRUCTION || state == Slice.State.RECOVERY;
}
Also used : Slice(org.apache.solr.common.cloud.Slice) ClusterState(org.apache.solr.common.cloud.ClusterState) State(org.apache.solr.common.cloud.Slice.State)

Example 3 with State

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

the class DistributedUpdateProcessor method amISubShardLeader.

private boolean amISubShardLeader(DocCollection coll, Slice parentSlice, String id, SolrInputDocument doc) throws InterruptedException {
    // Am I the leader of a shard in "construction/recovery" state?
    String myShardId = req.getCore().getCoreDescriptor().getCloudDescriptor().getShardId();
    Slice mySlice = coll.getSlice(myShardId);
    final State state = mySlice.getState();
    if (state == Slice.State.CONSTRUCTION || state == Slice.State.RECOVERY) {
        Replica myLeader = zkController.getZkStateReader().getLeaderRetry(collection, myShardId);
        boolean amILeader = myLeader.getName().equals(req.getCore().getCoreDescriptor().getCloudDescriptor().getCoreNodeName());
        if (amILeader) {
            // Does the document belong to my hash range as well?
            DocRouter.Range myRange = mySlice.getRange();
            if (myRange == null)
                myRange = new DocRouter.Range(Integer.MIN_VALUE, Integer.MAX_VALUE);
            if (parentSlice != null) {
                boolean isSubset = parentSlice.getRange() != null && myRange.isSubsetOf(parentSlice.getRange());
                return isSubset && coll.getRouter().isTargetSlice(id, doc, req.getParams(), myShardId, coll);
            } else {
                // delete by query case -- as long as I am a sub shard leader we're fine
                return true;
            }
        }
    }
    return false;
}
Also used : Slice(org.apache.solr.common.cloud.Slice) ClusterState(org.apache.solr.common.cloud.ClusterState) State(org.apache.solr.common.cloud.Slice.State) DocRouter(org.apache.solr.common.cloud.DocRouter) Replica(org.apache.solr.common.cloud.Replica)

Aggregations

Slice (org.apache.solr.common.cloud.Slice)3 State (org.apache.solr.common.cloud.Slice.State)3 ClusterState (org.apache.solr.common.cloud.ClusterState)2 DocRouter (org.apache.solr.common.cloud.DocRouter)2 Replica (org.apache.solr.common.cloud.Replica)2 ArrayList (java.util.ArrayList)1 ZkCoreNodeProps (org.apache.solr.common.cloud.ZkCoreNodeProps)1 Node (org.apache.solr.update.SolrCmdDistributor.Node)1 RetryNode (org.apache.solr.update.SolrCmdDistributor.RetryNode)1 StdNode (org.apache.solr.update.SolrCmdDistributor.StdNode)1