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;
 }
Esempio n. 2
0
  private void requestSync(String baseUrl, String replica, String leaderUrl, String coreName) {
    ShardCoreRequest sreq = new ShardCoreRequest();
    sreq.coreName = coreName;
    sreq.baseUrl = baseUrl;
    sreq.purpose = 1;
    sreq.shards = new String[] {replica};
    sreq.actualShards = sreq.shards;
    sreq.params = new ModifiableSolrParams();
    sreq.params.set("qt", "/get");
    sreq.params.set("distrib", false);
    sreq.params.set("getVersions", Integer.toString(100));
    sreq.params.set("sync", leaderUrl);

    shardHandler.submit(sreq, replica, sreq.params);
  }
Esempio n. 3
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());
      }
    }
  }