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

The following examples show how to use org.apache.solr.common.cloud.Replica#getCoreName() . 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: ReplaceNodeCmd.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
static List<ZkNodeProps> getReplicasOfNode(String source, ClusterState state) {
  List<ZkNodeProps> sourceReplicas = new ArrayList<>();
  for (Map.Entry<String, DocCollection> e : state.getCollectionsMap().entrySet()) {
    for (Slice slice : e.getValue().getSlices()) {
      for (Replica replica : slice.getReplicas()) {
        if (source.equals(replica.getNodeName())) {
          ZkNodeProps props = new ZkNodeProps(
              COLLECTION_PROP, e.getKey(),
              SHARD_ID_PROP, slice.getName(),
              ZkStateReader.CORE_NAME_PROP, replica.getCoreName(),
              ZkStateReader.REPLICA_PROP, replica.getName(),
              ZkStateReader.REPLICA_TYPE, replica.getType().name(),
              ZkStateReader.LEADER_PROP, String.valueOf(replica.equals(slice.getLeader())),
              CoreAdminParams.NODE, source);
          sourceReplicas.add(props);
        }
      }
    }
  }
  return sourceReplicas;
}
 
Example 2
Source File: SharedFSAutoReplicaFailoverTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * After failover, ulogDir should not be changed.
 */
private void assertUlogDir(String... collections) {
  for (String collection : collections) {
    Collection<Slice> slices = cloudClient.getZkStateReader().getClusterState().getCollection(collection).getSlices();
    for (Slice slice : slices) {
      for (Replica replica : slice.getReplicas()) {
        Map<String, Object> properties = replica.getProperties();
        String coreName = replica.getCoreName();
        String curUlogDir = (String) properties.get(CoreDescriptor.CORE_ULOGDIR);
        String prevUlogDir = collectionUlogDirMap.get(coreName);
        if (curUlogDir != null) {
          if (prevUlogDir == null) {
            collectionUlogDirMap.put(coreName, curUlogDir);
          } else {
            assertEquals(prevUlogDir, curUlogDir);
          }
        }
      }
    }
  }
}
 
Example 3
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 4
Source File: DeleteShardCmd.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private List<ZkNodeProps> getReplicasForSlice(String collectionName, Slice slice) {
  List<ZkNodeProps> sourceReplicas = new ArrayList<>();
  for (Replica replica : slice.getReplicas()) {
    ZkNodeProps props = new ZkNodeProps(
        COLLECTION_PROP, collectionName,
        SHARD_ID_PROP, slice.getName(),
        ZkStateReader.CORE_NAME_PROP, replica.getCoreName(),
        ZkStateReader.REPLICA_PROP, replica.getName(),
        CoreAdminParams.NODE, replica.getNodeName());
    sourceReplicas.add(props);
  }
  return sourceReplicas;
}
 
Example 5
Source File: TestStressThreadBackup.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void initCoreNameAndSolrCoreClient() {
  // Sigh.
  Replica r = cluster.getSolrClient().getZkStateReader().getClusterState()
    .getCollection(DEFAULT_TEST_COLLECTION_NAME).getActiveSlices().iterator().next()
    .getReplicas().iterator().next();
  coreName = r.getCoreName();
  coreClient = getHttpSolrClient(r.getCoreUrl());
}
 
Example 6
Source File: DistribDocExpirationUpdateProcessorTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * returns a map whose key is the coreNodeName and whose value is data about that core needed for the test
 */
private Map<String,ReplicaData> getTestDataForAllReplicas() throws IOException, SolrServerException {
  Map<String,ReplicaData> results = new HashMap<>();

  DocCollection collectionState = cluster.getSolrClient().getZkStateReader().getClusterState().getCollection(COLLECTION);

  for (Replica replica : collectionState.getReplicas()) {

    String coreName = replica.getCoreName();
    try (HttpSolrClient client = getHttpSolrClient(replica.getCoreUrl())) {

      ModifiableSolrParams params = new ModifiableSolrParams();
      params.set("command", "indexversion");
      params.set("_trace", "getIndexVersion");
      params.set("qt", ReplicationHandler.PATH);
      QueryRequest req = setAuthIfNeeded(new QueryRequest(params));

      NamedList<Object> res = client.request(req);
      assertNotNull("null response from server: " + coreName, res);

      Object version = res.get("indexversion");
      assertNotNull("null version from server: " + coreName, version);
      assertTrue("version isn't a long: " + coreName, version instanceof Long);

      long numDocs = 
        setAuthIfNeeded(new QueryRequest
                        (params("q", "*:*",
                                "distrib", "false",
                                "rows", "0",
                                "_trace", "counting_docs"))).process(client).getResults().getNumFound();

      final ReplicaData data = new ReplicaData(replica.getSlice(),coreName,(Long)version,numDocs);
      log.info("{}", data);
      results.put(coreName, data);

    }
  }

  return results;
}
 
Example 7
Source File: CoreSorterTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private CoreDescriptor newCoreDescriptor(Replica r) {
  @SuppressWarnings({"unchecked"})
  Map<String,String> props = map(
      CoreDescriptor.CORE_SHARD, r.getSlice(),
      CoreDescriptor.CORE_COLLECTION, r.getCollection(),
      CoreDescriptor.CORE_NODE_NAME, r.getNodeName()
  );
  return new CoreDescriptor(r.getCoreName(), TEST_PATH(), props , null, mock(ZkController.class));
}
 
Example 8
Source File: ReindexCollectionCmd.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private String getDaemonUrl(SolrResponse rsp, DocCollection coll) {
  @SuppressWarnings({"unchecked"})
  Map<String, Object> rs = (Map<String, Object>)rsp.getResponse().get("result-set");
  if (rs == null || rs.isEmpty()) {
    if (log.isDebugEnabled()) {
      log.debug(" -- Missing daemon information in response: {}", Utils.toJSONString(rsp));
    }
  }
  @SuppressWarnings({"unchecked"})
  List<Object> list = (List<Object>)rs.get("docs");
  if (list == null) {
    if (log.isDebugEnabled()) {
      log.debug(" -- Missing daemon information in response: {}", Utils.toJSONString(rsp));
    }
    return null;
  }
  String replicaName = null;
  for (Object o : list) {
    @SuppressWarnings({"unchecked"})
    Map<String, Object> map = (Map<String, Object>)o;
    String op = (String)map.get("DaemonOp");
    if (op == null) {
      continue;
    }
    String[] parts = op.split("\\s+");
    if (parts.length != 4) {
      log.debug(" -- Invalid daemon location info, expected 4 tokens: {}", op);
      return null;
    }
    // check if it's plausible
    if (parts[3].contains("shard") && parts[3].contains("replica")) {
      replicaName = parts[3];
      break;
    } else {
      log.debug(" -- daemon location info likely invalid: {}", op);
      return null;
    }
  }
  if (replicaName == null) {
    return null;
  }
  // build a baseUrl of the replica
  for (Replica r : coll.getReplicas()) {
    if (replicaName.equals(r.getCoreName())) {
      return r.getBaseUrl() + "/" + r.getCoreName();
    }
  }
  return null;
}
 
Example 9
Source File: DeleteReplicaTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Test
public void deleteReplicaFromClusterState() throws Exception {
  final String collectionName = "deleteFromClusterStateCollection";
  CollectionAdminRequest.createCollection(collectionName, "conf", 1, 3)
      .process(cluster.getSolrClient());
  
  cluster.waitForActiveCollection(collectionName, 1, 3);
  
  cluster.getSolrClient().add(collectionName, new SolrInputDocument("id", "1"));
  cluster.getSolrClient().add(collectionName, new SolrInputDocument("id", "2"));
  cluster.getSolrClient().commit(collectionName);

  cluster.waitForActiveCollection(collectionName, 1, 3);

  Slice shard = getCollectionState(collectionName).getSlice("shard1");

  // don't choose the leader to shutdown, it just complicates things unnecessarily
  Replica replica = getRandomReplica(shard, (r) ->
                                     ( r.getState() == Replica.State.ACTIVE &&
                                       ! r.equals(shard.getLeader())));
  
  JettySolrRunner replicaJetty = cluster.getReplicaJetty(replica);
  ZkStateReaderAccessor accessor = new ZkStateReaderAccessor(replicaJetty.getCoreContainer().getZkController().getZkStateReader());

  final long preDeleteWatcherCount = countUnloadCoreOnDeletedWatchers
    (accessor.getStateWatchers(collectionName));

  ZkNodeProps m = new ZkNodeProps(
      Overseer.QUEUE_OPERATION, OverseerAction.DELETECORE.toLower(),
      ZkStateReader.CORE_NAME_PROP, replica.getCoreName(),
      ZkStateReader.NODE_NAME_PROP, replica.getNodeName(),
      ZkStateReader.COLLECTION_PROP, collectionName,
      ZkStateReader.CORE_NODE_NAME_PROP, replica.getName(),
      ZkStateReader.BASE_URL_PROP, replica.getBaseUrl());

  cluster.getOpenOverseer().getStateUpdateQueue().offer(Utils.toJSON(m));

  waitForState("Timeout waiting for replica get deleted", collectionName,
      (liveNodes, collectionState) -> collectionState.getSlice("shard1").getReplicas().size() == 2);

  TimeOut timeOut = new TimeOut(60, TimeUnit.SECONDS, TimeSource.NANO_TIME);
  timeOut.waitFor("Waiting for replica get unloaded", () ->
      replicaJetty.getCoreContainer().getCoreDescriptor(replica.getCoreName()) == null
  );
  
  // the core should no longer have a watch collection state since it was removed
  timeOut = new TimeOut(60, TimeUnit.SECONDS, TimeSource.NANO_TIME);
  timeOut.waitFor("Waiting for core's watcher to be removed", () -> {
      final long postDeleteWatcherCount = countUnloadCoreOnDeletedWatchers
        (accessor.getStateWatchers(collectionName));
      log.info("preDeleteWatcherCount={} vs postDeleteWatcherCount={}",
               preDeleteWatcherCount, postDeleteWatcherCount);
      return (preDeleteWatcherCount - 1L == postDeleteWatcherCount);
    });
  
  CollectionAdminRequest.deleteCollection(collectionName).process(cluster.getSolrClient());
}