Buggy code:
try { deleteCollection ( new ZkNodeProps ( props ) , results ) ; } catch ( Exception e ) { OverseerCollectionProcessor . log . warn ( ( "Unable<seq2seq4repair_space>to<seq2seq4repair_space>clean<seq2seq4repair_space>up<seq2seq4repair_space>existing<seq2seq4repair_space>temporary<seq2seq4repair_space>collection:<seq2seq4repair_space>" + tempSourceCollectionName ) , e ) ; } } CompositeIdRouter sourceRouter = ( ( CompositeIdRouter ) ( sourceCollection . getRouter ( ) ) ) ; DocRouter . Range keyHashRange = sourceRouter . keyHashRange ( splitKey ) ; OverseerCollectionProcessor . log . info ( "Hash<seq2seq4repair_space>range<seq2seq4repair_space>for<seq2seq4repair_space>split.key:<seq2seq4repair_space>{}<seq2seq4repair_space>is:<seq2seq4repair_space>{}" , splitKey , keyHashRange ) ; DocRouter . Range splitRange = intersect ( targetSlice . getRange ( ) , intersect ( sourceSlice . getRange ( ) , keyHashRange ) ) ; if ( splitRange == null ) { OverseerCollectionProcessor . log . info ( "No<seq2seq4repair_space>common<seq2seq4repair_space>hashes<seq2seq4repair_space>between<seq2seq4repair_space>source<seq2seq4repair_space>shard:<seq2seq4repair_space>{}<seq2seq4repair_space>and<seq2seq4repair_space>target<seq2seq4repair_space>shard:<seq2seq4repair_space>{}" , sourceSlice . getName ( ) , targetSlice . getName ( ) ) ; return ; } OverseerCollectionProcessor . log . info ( ( "Common<seq2seq4repair_space>hash<seq2seq4repair_space>range<seq2seq4repair_space>between<seq2seq4repair_space>source<seq2seq4repair_space>shard:<seq2seq4repair_space>{}<seq2seq4repair_space>and<seq2seq4repair_space>target<seq2seq4repair_space>shard:<seq2seq4repair_space>{}<seq2seq4repair_space>=<seq2seq4repair_space>" + splitRange ) , sourceSlice . getName ( ) , targetSlice . getName ( ) ) ; Replica targetLeader = targetSlice . getLeader ( ) ; OverseerCollectionProcessor . log . info ( ( ( ( ( "Asking<seq2seq4repair_space>target<seq2seq4repair_space>leader<seq2seq4repair_space>node:<seq2seq4repair_space>" + ( targetLeader . getNodeName ( ) ) ) + "<seq2seq4repair_space>core:<seq2seq4repair_space>" ) + ( targetLeader . getStr ( "core" ) ) ) + "<seq2seq4repair_space>to<seq2seq4repair_space>buffer<seq2seq4repair_space>updates" ) ) ; ModifiableSolrParams params = new ModifiableSolrParams ( ) ; params . set ( ACTION , REQUESTBUFFERUPDATES . toString ( ) ) ; params . set ( NAME , targetLeader . getStr ( "core" ) ) ; sendShardRequest ( targetLeader . getNodeName ( ) , params ) ; collectShardResponses ( results , true , "MIGRATE<seq2seq4repair_space>failed<seq2seq4repair_space>to<seq2seq4repair_space>request<seq2seq4repair_space>node<seq2seq4repair_space>to<seq2seq4repair_space>buffer<seq2seq4repair_space>updates" ) ; ZkNodeProps m = new ZkNodeProps ( Overseer . QUEUE_OPERATION , Overseer . ADD_ROUTING_RULE , COLLECTION_PROP , sourceCollection . getName ( ) , SHARD_ID_PROP , sourceSlice . getName ( ) , "routeKey" , ( ( SolrIndexSplitter . getRouteKey ( splitKey ) ) + "!" ) , "range" , splitRange . toString ( ) , "targetCollection" , targetCollection . getName ( ) , "expireAt" , String . valueOf ( ( ( System . currentTimeMillis ( ) ) + timeout ) ) ) ; OverseerCollectionProcessor . log . info ( ( "Adding<seq2seq4repair_space>routing<seq2seq4repair_space>rule:<seq2seq4repair_space>" + m ) ) ; Overseer . getInQueue ( zkStateReader . getZkClient ( ) ) . offer ( ZkStateReader . toJSON ( m ) ) ; OverseerCollectionProcessor . log . info ( "Waiting<seq2seq4repair_space>to<seq2seq4repair_space>see<seq2seq4repair_space>routing<seq2seq4repair_space>rule<seq2seq4repair_space>updated<seq2seq4repair_space>in<seq2seq4repair_space>clusterstate" ) ; long waitUntil = ( System . currentTimeMillis ( ) ) + 60000 ; boolean added = false ; while ( ( System . currentTimeMillis ( ) ) < waitUntil ) { Thread . sleep ( 100 ) ; Map < String , RoutingRule > rules = zkStateReader . getClusterState ( ) . getSlice ( sourceCollection . getName ( ) , sourceSlice . getName ( ) ) . getRoutingRules ( ) ; if ( rules != null ) { RoutingRule rule = rules . get ( ( ( SolrIndexSplitter . getRouteKey ( splitKey ) ) + "!" ) ) ; if ( ( rule != null ) && ( rule . getRouteRanges ( ) . contains ( splitRange ) ) ) { added = true ; break ; } } } if ( ! added ) { throw new org . apache . solr . common . SolrException ( ErrorCode . SERVER_ERROR , ( "Could<seq2seq4repair_space>not<seq2seq4repair_space>add<seq2seq4repair_space>routing<seq2seq4repair_space>rule:<seq2seq4repair_space>" + m ) ) ; } OverseerCollectionProcessor . log . info ( "Routing<seq2seq4repair_space>rule<seq2seq4repair_space>added<seq2seq4repair_space>successfully" ) ; Replica sourceLeader = sourceSlice . getLeader ( ) ; String configName = zkStateReader . readConfigName ( sourceCollection . getName ( ) ) ; Map < String , Object > props = ZkNodeProps . makeMap ( OverseerCollectionProcessor . QUEUE_OPERATION , OverseerCollectionProcessor . CREATECOLLECTION , "name" , tempSourceCollectionName , OverseerCollectionProcessor . REPLICATION_FACTOR , 1 , OverseerCollectionProcessor . NUM_SLICES , 1 , OverseerCollectionProcessor . COLL_CONF , configName , OverseerCollectionProcessor . CREATE_NODE_SET , sourceLeader . getNodeName ( ) ) ; OverseerCollectionProcessor . log . info ( ( "Creating<seq2seq4repair_space>temporary<seq2seq4repair_space>collection:<seq2seq4repair_space>" + props ) ) ; createCollection ( clusterState , new ZkNodeProps ( props ) , results ) ; clusterState = zkStateReader . getClusterState ( ) ; Slice tempSourceSlice = clusterState . getCollection ( tempSourceCollectionName ) . getSlices ( ) . iterator ( ) . next ( ) ; <START_BUG> Replica tempSourceLeader = clusterState . getLeader ( tempSourceCollectionName , tempSourceSlice . getName ( ) ) ; <END_BUG> String tempCollectionReplica1 = ( ( tempSourceCollectionName + "_" ) + ( tempSourceSlice . getName ( ) ) ) + "_replica1" ; String coreNodeName = waitForCoreNodeName ( clusterState . getCollection ( tempSourceCollectionName ) , zkStateReader . getZkClient ( ) . getBaseUrlForNodeName ( sourceLeader . getNodeName ( ) ) , tempCollectionReplica1 ) ; OverseerCollectionProcessor . log . info ( ( ( ( "Asking<seq2seq4repair_space>source<seq2seq4repair_space>leader<seq2seq4repair_space>to<seq2seq4repair_space>wait<seq2seq4repair_space>for:<seq2seq4repair_space>" + tempCollectionReplica1 ) + "<seq2seq4repair_space>to<seq2seq4repair_space>be<seq2seq4repair_space>alive<seq2seq4repair_space>on:<seq2seq4repair_space>" ) + ( sourceLeader . getNodeName ( ) ) ) ) ; CoreAdminRequest . WaitForState cmd = new CoreAdminRequest . WaitForState ( ) ; cmd . setCoreName ( tempCollectionReplica1 ) ; cmd . setNodeName ( sourceLeader . getNodeName ( ) ) ; cmd . setCoreNodeName ( coreNodeName ) ; cmd . setState ( ACTIVE ) ; cmd . setCheckLive ( true ) ; cmd . setOnlyIfLeader ( true ) ; sendShardRequest ( tempSourceLeader . getNodeName ( ) , new ModifiableSolrParams ( cmd . getParams ( ) ) ) ; collectShardResponses ( results , true , "MIGRATE<seq2seq4repair_space>failed<seq2seq4repair_space>to<seq2seq4repair_space>create<seq2seq4repair_space>temp<seq2seq4repair_space>collection<seq2seq4repair_space>leader<seq2seq4repair_space>or<seq2seq4repair_space>timed<seq2seq4repair_space>out<seq2seq4repair_space>waiting<seq2seq4repair_space>for<seq2seq4repair_space>it<seq2seq4repair_space>to<seq2seq4repair_space>come<seq2seq4repair_space>up" ) ; OverseerCollectionProcessor . log . info ( "Asking<seq2seq4repair_space>source<seq2seq4repair_space>leader<seq2seq4repair_space>to<seq2seq4repair_space>split<seq2seq4repair_space>index" ) ; params = new ModifiableSolrParams ( ) ; params . set ( ACTION , SPLIT . toString ( ) ) ; params . set ( CORE , sourceLeader . getStr ( "core" ) ) ; params . add ( TARGET_CORE , tempSourceLeader . getStr ( "core" ) ) ; params . set ( RANGES , splitRange . toString ( ) ) ; params . set ( "split.key" , splitKey ) ; sendShardRequest ( sourceLeader . getNodeName ( ) , params ) ; collectShardResponses ( results , true , "MIGRATE<seq2seq4repair_space>failed<seq2seq4repair_space>to<seq2seq4repair_space>invoke<seq2seq4repair_space>SPLIT<seq2seq4repair_space>core<seq2seq4repair_space>admin<seq2seq4repair_space>command" ) ; OverseerCollectionProcessor . log . info ( "Creating<seq2seq4repair_space>a<seq2seq4repair_space>replica<seq2seq4repair_space>of<seq2seq4repair_space>temporary<seq2seq4repair_space>collection:<seq2seq4repair_space>{}<seq2seq4repair_space>on<seq2seq4repair_space>the<seq2seq4repair_space>target<seq2seq4repair_space>leader<seq2seq4repair_space>node:<seq2seq4repair_space>{}" , tempSourceCollectionName , targetLeader . getNodeName ( ) ) ;

Fix:
Replica tempSourceLeader = zkStateReader . getLeaderRetry ( tempSourceCollectionName , tempSourceSlice . getName ( ) , 60000 ) ;