当前位置: 首页>>代码示例>>Java>>正文


Java Replica.getState方法代码示例

本文整理汇总了Java中org.apache.solr.common.cloud.Replica.getState方法的典型用法代码示例。如果您正苦于以下问题:Java Replica.getState方法的具体用法?Java Replica.getState怎么用?Java Replica.getState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.solr.common.cloud.Replica的用法示例。


在下文中一共展示了Replica.getState方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: split

import org.apache.solr.common.cloud.Replica; //导入方法依赖的package包/类
@Override
public List<? extends BoundedSource<SolrDocument>> split(
    long desiredBundleSizeBytes, PipelineOptions options) throws Exception {
  ConnectionConfiguration connectionConfig = spec.getConnectionConfiguration();
  List<BoundedSolrSource> sources = new ArrayList<>();
  try (AuthorizedSolrClient<CloudSolrClient> client = connectionConfig.createClient()) {
    String collection = spec.getCollection();
    final ClusterState clusterState = AuthorizedSolrClient.getClusterState(client);
    DocCollection docCollection = clusterState.getCollection(collection);
    for (Slice slice : docCollection.getSlices()) {
      ArrayList<Replica> replicas = new ArrayList<>(slice.getReplicas());
      Collections.shuffle(replicas);
      // Load balancing by randomly picking an active replica
      Replica randomActiveReplica = null;
      for (Replica replica : replicas) {
        // We need to check both state of the replica and live nodes
        // to make sure that the replica is alive
        if (replica.getState() == Replica.State.ACTIVE
            && clusterState.getLiveNodes().contains(replica.getNodeName())) {
          randomActiveReplica = replica;
          break;
        }
      }
      // TODO in case of this replica goes inactive while the pipeline runs.
      // We should pick another active replica of this shard.
      checkState(
          randomActiveReplica != null,
          "Can not found an active replica for slice %s",
          slice.getName());
      sources.add(new BoundedSolrSource(spec, randomActiveReplica));
    }
  }
  return sources;
}
 
开发者ID:apache,项目名称:beam,代码行数:35,代码来源:SolrIO.java

示例2: ensureAllReplicasAreActive

import org.apache.solr.common.cloud.Replica; //导入方法依赖的package包/类
protected static void ensureAllReplicasAreActive(String testCollectionName, int shards, int rf,
    int maxWaitSecs) throws Exception {
  long startMs = System.currentTimeMillis();

  ZkStateReader zkr = cloudSolrClient.getZkStateReader();
  zkr.forceUpdateCollection(testCollectionName); // force the state to be fresh

  ClusterState cs = zkr.getClusterState();
  DocCollection docCollection = cs.getCollection(testCollectionName);
  Collection<Slice> slices = docCollection.getActiveSlices();
  assertTrue(slices.size() == shards);
  boolean allReplicasUp = false;
  long waitMs = 0L;
  long maxWaitMs = maxWaitSecs * 1000L;
  Replica leader = null;
  while (waitMs < maxWaitMs && !allReplicasUp) {
    // refresh state every 2 secs
    if (waitMs % 2000 == 0) {
      log.info("Updating ClusterState");
      cloudSolrClient.getZkStateReader().forceUpdateCollection(testCollectionName);
    }

    cs = cloudSolrClient.getZkStateReader().getClusterState();
    assertNotNull(cs);
    allReplicasUp = true; // assume true
    for (Slice shard : docCollection.getActiveSlices()) {
      String shardId = shard.getName();
      assertNotNull("No Slice for " + shardId, shard);
      Collection<Replica> replicas = shard.getReplicas();
      assertTrue(replicas.size() == rf);
      leader = shard.getLeader();
      assertNotNull(leader);
      log.info("Found " + replicas.size() + " replicas and leader on " +
          leader.getNodeName() + " for " + shardId + " in " + testCollectionName);

      // ensure all replicas are "active"
      for (Replica replica : replicas) {
        Replica.State replicaState = replica.getState();
        if (!Replica.State.ACTIVE.equals(replicaState)) {
          log.info("Replica " + replica.getName() + " for shard " + shardId + " is currently "
              + replicaState);
          allReplicasUp = false;
        }
      }
    }

    if (!allReplicasUp) {
      try {
        Thread.sleep(500L);
      } catch (Exception ignoreMe) {
      }
      waitMs += 500L;
    }
  } // end while

  if (!allReplicasUp) {
    fail("Didn't see all replicas for " + testCollectionName +
        " come up within " + maxWaitMs + " ms! ClusterState: " + printClusterStateInfo(
        testCollectionName));
  }
  long diffMs = (System.currentTimeMillis() - startMs);
  log.info("Took " + diffMs + " ms to see all replicas become active for " + testCollectionName);
}
 
开发者ID:lucidworks,项目名称:solr-hadoop-common,代码行数:64,代码来源:SolrCloudClusterSupport.java

示例3: isReplicaActive

import org.apache.solr.common.cloud.Replica; //导入方法依赖的package包/类
/** Returns true if the replica is on a live node and active. */
public boolean isReplicaActive(Replica replica) {
    return getClusterState().liveNodesContain(replica.getNodeName())
            && replica.getState() == Replica.State.ACTIVE;
}
 
开发者ID:shaie,项目名称:lucenelab,代码行数:6,代码来源:CollectionsStateHelper.java

示例4: isReplicaDown

import org.apache.solr.common.cloud.Replica; //导入方法依赖的package包/类
/** Returns true if the replica is in a DOWN state. */
public boolean isReplicaDown(Replica replica) {
    return !getClusterState().liveNodesContain(replica.getNodeName())
            || replica.getState() == Replica.State.DOWN;
}
 
开发者ID:shaie,项目名称:lucenelab,代码行数:6,代码来源:CollectionsStateHelper.java


注:本文中的org.apache.solr.common.cloud.Replica.getState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。