Java Code Examples for org.apache.solr.common.cloud.Replica#getType()

The following examples show how to use org.apache.solr.common.cloud.Replica#getType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestPullReplica.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Asserts that Update logs don't exist for replicas of type {@link org.apache.solr.common.cloud.Replica.Type#PULL}
 */
private void assertUlogPresence(DocCollection collection) {
  for (Slice s:collection.getSlices()) {
    for (Replica r:s.getReplicas()) {
      if (r.getType() == Replica.Type.NRT) {
        continue;
      }
      SolrCore core = null;
      try {
        core = cluster.getReplicaJetty(r).getCoreContainer().getCore(r.getCoreName());
        assertNotNull(core);
        assertFalse("Update log should not exist for replicas of type Passive but file is present: " + core.getUlogDir(),
            new java.io.File(core.getUlogDir()).exists());
      } finally {
        core.close();
      }
    }
  }
}
 
Example 2
Source File: TestPullReplica.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private CollectionStatePredicate activeReplicaCount(int numNrtReplicas, int numTlogReplicas, int numPullReplicas) {
  return (liveNodes, collectionState) -> {
    int nrtFound = 0, tlogFound = 0, pullFound = 0;
    if (collectionState == null)
      return false;
    for (Slice slice : collectionState) {
      for (Replica replica : slice) {
        if (replica.isActive(liveNodes))
          switch (replica.getType()) {
            case TLOG:
              tlogFound++;
              break;
            case PULL:
              pullFound++;
              break;
            case NRT:
              nrtFound++;
              break;
            default:
              throw new AssertionError("Unexpected replica type");
          }
      }
    }
    return numNrtReplicas == nrtFound && numTlogReplicas == tlogFound && numPullReplicas == pullFound;
  };
}
 
Example 3
Source File: TestTlogReplica.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private CollectionStatePredicate activeReplicaCount(int numNrtReplicas, int numTlogReplicas, int numPullReplicas) {
  return (liveNodes, collectionState) -> {
    int nrtFound = 0, tlogFound = 0, pullFound = 0;
    if (collectionState == null)
      return false;
    for (Slice slice : collectionState) {
      for (Replica replica : slice) {
        if (replica.isActive(liveNodes))
          switch (replica.getType()) {
            case TLOG:
              tlogFound++;
              break;
            case PULL:
              pullFound++;
              break;
            case NRT:
              nrtFound++;
              break;
            default:
              throw new AssertionError("Unexpected replica type");
          }
      }
    }
    return numNrtReplicas == nrtFound && numTlogReplicas == tlogFound && numPullReplicas == pullFound;
  };
}
 
Example 4
Source File: TestPullReplicaErrorHandling.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private CollectionStatePredicate activeReplicaCount(int numWriter, int numActive, int numPassive) {
  return (liveNodes, collectionState) -> {
    int writersFound = 0, activesFound = 0, passivesFound = 0;
    if (collectionState == null)
      return false;
    for (Slice slice : collectionState) {
      for (Replica replica : slice) {
        if (replica.isActive(liveNodes))
          switch (replica.getType()) {
            case TLOG:
              activesFound++;
              break;
            case PULL:
              passivesFound++;
              break;
            case NRT:
              writersFound++;
              break;
            default:
              throw new AssertionError("Unexpected replica type");
          }
      }
    }
    return numWriter == writersFound && numActive == activesFound && numPassive == passivesFound;
  };
}
 
Example 5
Source File: ReplicaInfo.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public ReplicaInfo(String coll, String shard, Replica r, Map<String, Object> vals) {
  this.name = r.getName();
  this.core = r.getCoreName();
  this.collection = coll;
  this.shard = shard;
  this.type = r.getType();
  this.node = r.getNodeName();
  boolean maybeLeader = r.getBool(LEADER_PROP, false);
  if (vals != null) {
    this.variables.putAll(vals);
    maybeLeader = "true".equals(String.valueOf(vals.getOrDefault(LEADER_PROP, maybeLeader)));
  }
  this.isLeader = maybeLeader;
  validate();
}
 
Example 6
Source File: DeleteNodeTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Test
public void test() throws Exception {
  CloudSolrClient cloudClient = cluster.getSolrClient();
  String coll = "deletenodetest_coll";
  ClusterState state = cloudClient.getZkStateReader().getClusterState();
  Set<String> liveNodes = state.getLiveNodes();
  ArrayList<String> l = new ArrayList<>(liveNodes);
  Collections.shuffle(l, random());
  CollectionAdminRequest.Create create = pickRandom(
      CollectionAdminRequest.createCollection(coll, "conf1", 5, 2, 0, 0),
      CollectionAdminRequest.createCollection(coll, "conf1", 5, 1, 1, 0),
      CollectionAdminRequest.createCollection(coll, "conf1", 5, 0, 1, 1),
      // check RF=1
      CollectionAdminRequest.createCollection(coll, "conf1", 5, 1, 0, 0),
      CollectionAdminRequest.createCollection(coll, "conf1", 5, 0, 1, 0)
      );
  create.setCreateNodeSet(StrUtils.join(l, ',')).setMaxShardsPerNode(3);
  cloudClient.request(create);
  state = cloudClient.getZkStateReader().getClusterState();
  String node2bdecommissioned = l.get(0);
  // check what replicas are on the node, and whether the call should fail
  boolean shouldFail = false;
  DocCollection docColl = state.getCollection(coll);
  log.info("#### DocCollection: {}", docColl);
  List<Replica> replicas = docColl.getReplicas(node2bdecommissioned);
  if (replicas != null) {
    for (Replica replica : replicas) {
      String shard = docColl.getShardId(node2bdecommissioned, replica.getStr(ZkStateReader.CORE_NAME_PROP));
      Slice slice = docColl.getSlice(shard);
      boolean hasOtherNonPullReplicas = false;
      for (Replica r: slice.getReplicas()) {
        if (!r.getName().equals(replica.getName()) &&
            !r.getNodeName().equals(node2bdecommissioned) &&
            r.getType() != Replica.Type.PULL) {
          hasOtherNonPullReplicas = true;
          break;
        }
      }
      if (!hasOtherNonPullReplicas) {
        shouldFail = true;
        break;
      }
    }
  }
  new CollectionAdminRequest.DeleteNode(node2bdecommissioned).processAsync("003", cloudClient);
  CollectionAdminRequest.RequestStatus requestStatus = CollectionAdminRequest.requestStatus("003");
  CollectionAdminRequest.RequestStatusResponse rsp = null;
  for (int i = 0; i < 200; i++) {
    rsp = requestStatus.process(cloudClient);
    if (rsp.getRequestStatus() == RequestStatusState.FAILED || rsp.getRequestStatus() == RequestStatusState.COMPLETED) {
      break;
    }
    Thread.sleep(50);
  }
  if (log.isInfoEnabled()) {
    log.info("####### DocCollection after: {}", cloudClient.getZkStateReader().getClusterState().getCollection(coll));
  }
  if (shouldFail) {
    assertTrue(String.valueOf(rsp), rsp.getRequestStatus() == RequestStatusState.FAILED);
  } else {
    assertFalse(String.valueOf(rsp), rsp.getRequestStatus() == RequestStatusState.FAILED);
  }
}