protected List<SubmitCapture> mockShardHandlerForCreateJob(
     Integer numberOfSlices, Integer numberOfReplica) {
   List<SubmitCapture> submitCaptures = new ArrayList<>();
   for (int i = 0; i < (numberOfSlices * numberOfReplica); i++) {
     SubmitCapture submitCapture = new SubmitCapture();
     shardHandlerMock.submit(
         capture(submitCapture.shardRequestCapture),
         capture(submitCapture.nodeUrlsWithoutProtocolPartCapture),
         capture(submitCapture.params));
     expectLastCall();
     submitCaptures.add(submitCapture);
     ShardResponse shardResponseWithoutException = new ShardResponse();
     shardResponseWithoutException.setSolrResponse(new QueryResponse());
     expect(shardHandlerMock.takeCompletedOrError()).andReturn(shardResponseWithoutException);
   }
   expect(shardHandlerMock.takeCompletedOrError()).andReturn(null);
   return submitCaptures;
 }
Ejemplo n.º 2
0
  private void syncToMe(
      ZkController zkController,
      String collection,
      String shardId,
      ZkNodeProps leaderProps,
      CoreDescriptor cd) {

    // sync everyone else
    // TODO: we should do this in parallel at least
    List<ZkCoreNodeProps> nodes =
        zkController
            .getZkStateReader()
            .getReplicaProps(collection, shardId, cd.getCloudDescriptor().getCoreNodeName());
    if (nodes == null) {
      log.info(ZkCoreNodeProps.getCoreUrl(leaderProps) + " has no replicas");
      return;
    }

    ZkCoreNodeProps zkLeader = new ZkCoreNodeProps(leaderProps);
    for (ZkCoreNodeProps node : nodes) {
      try {
        log.info(
            ZkCoreNodeProps.getCoreUrl(leaderProps)
                + ": try and ask "
                + node.getCoreUrl()
                + " to sync");

        requestSync(
            node.getBaseUrl(), node.getCoreUrl(), zkLeader.getCoreUrl(), node.getCoreName());

      } catch (Exception e) {
        SolrException.log(log, "Error syncing replica to leader", e);
      }
    }

    for (; ; ) {
      ShardResponse srsp = shardHandler.takeCompletedOrError();
      if (srsp == null) break;
      boolean success = handleResponse(srsp);
      if (srsp.getException() != null) {
        SolrException.log(log, "Sync request error: " + srsp.getException());
      }

      if (!success) {
        try {
          log.info(
              ZkCoreNodeProps.getCoreUrl(leaderProps)
                  + ": Sync failed - asking replica ("
                  + srsp.getShardAddress()
                  + ") to recover.");
          if (isClosed) {
            log.info("We have been closed, don't request that a replica recover");
          } else {
            requestRecovery(
                leaderProps,
                ((ShardCoreRequest) srsp.getShardRequest()).baseUrl,
                ((ShardCoreRequest) srsp.getShardRequest()).coreName);
          }
        } catch (Exception e) {
          SolrException.log(
              log,
              ZkCoreNodeProps.getCoreUrl(leaderProps) + ": Could not tell a replica to recover",
              e);
        }
      } else {
        log.info(
            ZkCoreNodeProps.getCoreUrl(leaderProps)
                + ": "
                + " sync completed with "
                + srsp.getShardAddress());
      }
    }
  }