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


Java ZkStateReader.updateClusterState方法代码示例

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


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

示例1: assertAllActive

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
protected void assertAllActive(String collection,ZkStateReader zkStateReader)
    throws KeeperException, InterruptedException {

    zkStateReader.updateClusterState(true);
    ClusterState clusterState = zkStateReader.getClusterState();
    Map<String,Slice> slices = clusterState.getSlicesMap(collection);
    if (slices == null) {
      throw new IllegalArgumentException("Cannot find collection:" + collection);
    }
    for (Map.Entry<String,Slice> entry : slices.entrySet()) {
      Map<String,Replica> shards = entry.getValue().getReplicasMap();
      for (Map.Entry<String,Replica> shard : shards.entrySet()) {

        String state = shard.getValue().getStr(ZkStateReader.STATE_PROP);
        if (!state.equals(ZkStateReader.ACTIVE)) {
          fail("Not all shards are ACTIVE - found a shard that is: " + state);
        }
      }
    }
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:AbstractDistribZkTestBase.java

示例2: waitTillRecovered

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
private void waitTillRecovered() throws Exception {
  for (int i = 0; i < 30; i++) {
    Thread.sleep(3000);
    ZkStateReader zkStateReader = cloudClient.getZkStateReader();
    zkStateReader.updateClusterState(true);
    ClusterState clusterState = zkStateReader.getClusterState();
    DocCollection collection1 = clusterState.getCollection("collection1");
    Slice slice = collection1.getSlice("shard1");
    Collection<Replica> replicas = slice.getReplicas();
    boolean allActive = true;
    for (Replica replica : replicas) {
      if (!clusterState.liveNodesContain(replica.getNodeName())
          || !replica.get(ZkStateReader.STATE_PROP).equals(
          ZkStateReader.ACTIVE)) {
        allActive = false;
        break;
      }
    }
    if (allActive) {
      return;
    }
  }
  printLayout();
  fail("timeout waiting to see recovered node");
}
 
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:ChaosMonkeyShardSplitTest.java

示例3: waitTillAllNodesActive

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
private void waitTillAllNodesActive() throws Exception {
  for (int i = 0; i < 60; i++) { 
    Thread.sleep(3000);
    ZkStateReader zkStateReader = cloudClient.getZkStateReader();
    zkStateReader.updateClusterState(true);
    ClusterState clusterState = zkStateReader.getClusterState();
    DocCollection collection1 = clusterState.getCollection("collection1");
    Slice slice = collection1.getSlice("shard1");
    Collection<Replica> replicas = slice.getReplicas();
    boolean allActive = true;
    for (Replica replica : replicas) {
      if (!clusterState.liveNodesContain(replica.getNodeName())
          || !replica.get(ZkStateReader.STATE_PROP).equals(
              ZkStateReader.ACTIVE)) {
        allActive = false;
        break;
      }
    }
    if (allActive) {
      return;
    }
  }
  printLayout();
  fail("timeout waiting to see all nodes active");
}
 
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:SyncSliceTest.java

示例4: confirmShardDeletion

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
protected void confirmShardDeletion(String shard) throws SolrServerException, KeeperException,
    InterruptedException {
  ZkStateReader zkStateReader = cloudClient.getZkStateReader();
  ClusterState clusterState = zkStateReader.getClusterState();
  int counter = 10;
  while (counter-- > 0) {
    zkStateReader.updateClusterState(true);
    clusterState = zkStateReader.getClusterState();
    if (clusterState.getSlice("collection1", shard) == null) {
      break;
    }
    Thread.sleep(1000);
  }

  assertNull("Cluster still contains shard1 even after waiting for it to be deleted.",
      clusterState.getSlice(AbstractDistribZkTestBase.DEFAULT_COLLECTION, SHARD1));
}
 
开发者ID:europeana,项目名称:search,代码行数:18,代码来源:DeleteShardTest.java

示例5: waitForCollections

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
private void waitForCollections(ZkStateReader stateReader, String... collections) throws InterruptedException, KeeperException {
  int maxIterations = 100;
  while (0 < maxIterations--) {
    stateReader.updateClusterState(true);
    final ClusterState state = stateReader.getClusterState();
    Set<String> availableCollections = state.getCollections();
    int availableCount = 0;
    for(String requiredCollection: collections) {
      if(availableCollections.contains(requiredCollection)) {
        availableCount++;
      }
      if(availableCount == collections.length) return;
      Thread.sleep(50);
    }
  }
  log.warn("Timeout waiting for collections: " + Arrays.asList(collections) + " state:" + stateReader.getClusterState());
}
 
开发者ID:europeana,项目名称:search,代码行数:18,代码来源:OverseerTest.java

示例6: checkIfCollectionExists

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
/**
 * Checks if the collection has already been created in Solr.
 */
private static boolean checkIfCollectionExists(CloudSolrClient server, String collection) throws KeeperException, InterruptedException {
    ZkStateReader zkStateReader = server.getZkStateReader();
    zkStateReader.updateClusterState(true);
    ClusterState clusterState = zkStateReader.getClusterState();
    return clusterState.getCollectionOrNull(collection) != null;
}
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:10,代码来源:SolrIndex.java

示例7: waitForRecoveriesToFinish

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
/**
 * Wait for all the collection shards to be ready.
 */
private static void waitForRecoveriesToFinish(CloudSolrClient server, String collection) throws KeeperException, InterruptedException {
    ZkStateReader zkStateReader = server.getZkStateReader();
    try {
        boolean cont = true;

        while (cont) {
            boolean sawLiveRecovering = false;
            zkStateReader.updateClusterState(true);
            ClusterState clusterState = zkStateReader.getClusterState();
            Map<String, Slice> slices = clusterState.getSlicesMap(collection);
            Preconditions.checkNotNull("Could not find collection:" + collection, slices);

           // change paths for Replica.State per Solr refactoring
           // remove SYNC state per: http://tinyurl.com/pag6rwt
           for (Map.Entry<String, Slice> entry : slices.entrySet()) {
                Map<String, Replica> shards = entry.getValue().getReplicasMap();
                for (Map.Entry<String, Replica> shard : shards.entrySet()) {
                    String state = shard.getValue().getStr(ZkStateReader.STATE_PROP);
                    if ((state.equals(Replica.State.RECOVERING) || state.equals(Replica.State.DOWN))
                            && clusterState.liveNodesContain(shard.getValue().getStr(
                            ZkStateReader.NODE_NAME_PROP))) {
                        sawLiveRecovering = true;
                    }
                }
            }


            if (!sawLiveRecovering) {
                cont = false;
            } else {
                Thread.sleep(1000);
            }
        }
    } finally {
        logger.info("Exiting solr wait");
    }
}
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:41,代码来源:SolrIndex.java

示例8: checkIfCollectionExists

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
/**
 * Checks if the collection has already been created in Solr.
 */
private static boolean checkIfCollectionExists(CloudSolrClient server, String collection) throws KeeperException, InterruptedException {
    ZkStateReader zkStateReader = server.getZkStateReader();
    zkStateReader.updateClusterState();
    ClusterState clusterState = zkStateReader.getClusterState();
    return clusterState.getCollectionOrNull(collection) != null;
}
 
开发者ID:apache,项目名称:incubator-atlas,代码行数:10,代码来源:Solr5Index.java

示例9: waitForRecoveriesToFinish

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
/**
 * Wait for all the collection shards to be ready.
 */
private static void waitForRecoveriesToFinish(CloudSolrClient server, String collection) throws KeeperException, InterruptedException {
    ZkStateReader zkStateReader = server.getZkStateReader();
    try {
        boolean cont = true;

        while (cont) {
            boolean sawLiveRecovering = false;
            zkStateReader.updateClusterState();
            ClusterState clusterState = zkStateReader.getClusterState();
            Map<String, Slice> slices = clusterState.getSlicesMap(collection);
            Preconditions.checkNotNull("Could not find collection:" + collection, slices);

            for (Map.Entry<String, Slice> entry : slices.entrySet()) {
                Map<String, Replica> shards = entry.getValue().getReplicasMap();
                for (Map.Entry<String, Replica> shard : shards.entrySet()) {
                    String state = shard.getValue().getStr(ZkStateReader.STATE_PROP);
                    if ((state.equals(Replica.State.RECOVERING.toString())
                            || state.equals(Replica.State.DOWN.toString()))
                            && clusterState.liveNodesContain(shard.getValue().getStr(
                            ZkStateReader.NODE_NAME_PROP))) {
                        sawLiveRecovering = true;
                    }
                }
            }
            if (!sawLiveRecovering) {
                cont = false;
            } else {
                Thread.sleep(1000);
            }
        }
    } finally {
        logger.info("Exiting solr wait");
    }
}
 
开发者ID:apache,项目名称:incubator-atlas,代码行数:38,代码来源:Solr5Index.java

示例10: setSliceState

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
protected void setSliceState(String slice, String state) throws SolrServerException, IOException,
    KeeperException, InterruptedException {
  DistributedQueue inQueue = Overseer.getInQueue(cloudClient.getZkStateReader().getZkClient());
  Map<String, Object> propMap = new HashMap<>();
  propMap.put(Overseer.QUEUE_OPERATION, "updateshardstate");
  propMap.put(slice, state);
  propMap.put(ZkStateReader.COLLECTION_PROP, "collection1");
  ZkNodeProps m = new ZkNodeProps(propMap);
  ZkStateReader zkStateReader = cloudClient.getZkStateReader();
  inQueue.offer(ZkStateReader.toJSON(m));
  boolean transition = false;

  for (int counter = 10; counter > 0; counter--) {
    zkStateReader.updateClusterState(true);
    ClusterState clusterState = zkStateReader.getClusterState();
    String sliceState = clusterState.getSlice("collection1", slice).getState();
    if (sliceState.equals(state)) {
      transition = true;
      break;
    }
    Thread.sleep(1000);
  }

  if (!transition) {
    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Could not set shard [" + slice + "] as " + state);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:28,代码来源:DeleteShardTest.java

示例11: verifyShardLeader

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
private void verifyShardLeader(ZkStateReader reader, String collection, String shard, String expectedCore) throws InterruptedException, KeeperException {
  int maxIterations = 200;
  while(maxIterations-->0) {
    reader.updateClusterState(true); // poll state
    ZkNodeProps props =  reader.getClusterState().getLeader(collection, shard);
    if(props!=null) {
      if(expectedCore.equals(props.getStr(ZkStateReader.CORE_NAME_PROP))) {
        return;
      }
    }
    Thread.sleep(200);
  }
  
  assertEquals("Unexpected shard leader coll:" + collection + " shard:" + shard, expectedCore, (reader.getClusterState().getLeader(collection, shard)!=null)?reader.getClusterState().getLeader(collection, shard).getStr(ZkStateReader.CORE_NAME_PROP):null);
}
 
开发者ID:europeana,项目名称:search,代码行数:16,代码来源:OverseerTest.java

示例12: waitForRecoveriesToFinish

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
/**
 * Wait for all the collection shards to be ready.
 */
private static void waitForRecoveriesToFinish(CloudSolrServer server, String collection) throws KeeperException, InterruptedException {
    ZkStateReader zkStateReader = server.getZkStateReader();
    try {
        boolean cont = true;

        while (cont) {
            boolean sawLiveRecovering = false;
            zkStateReader.updateClusterState(true);
            ClusterState clusterState = zkStateReader.getClusterState();
            Map<String, Slice> slices = clusterState.getSlicesMap(collection);
            Preconditions.checkNotNull("Could not find collection:" + collection, slices);

            for (Map.Entry<String, Slice> entry : slices.entrySet()) {
                Map<String, Replica> shards = entry.getValue().getReplicasMap();
                for (Map.Entry<String, Replica> shard : shards.entrySet()) {
                    String state = shard.getValue().getStr(ZkStateReader.STATE_PROP);
                    if ((state.equals(ZkStateReader.RECOVERING)
                            || state.equals(ZkStateReader.SYNC) || state
                            .equals(ZkStateReader.DOWN))
                            && clusterState.liveNodesContain(shard.getValue().getStr(
                            ZkStateReader.NODE_NAME_PROP))) {
                        sawLiveRecovering = true;
                    }
                }
            }
            if (!sawLiveRecovering) {
                cont = false;
            } else {
                Thread.sleep(1000);
            }
        }
    } finally {
        logger.info("Exiting solr wait");
    }
}
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:39,代码来源:SolrIndex.java

示例13: checkIfCollectionExists

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
/**
 * Checks if the collection has already been created in Solr.
 */
private static boolean checkIfCollectionExists(CloudSolrServer server, String collection) throws KeeperException, InterruptedException {
    ZkStateReader zkStateReader = server.getZkStateReader();
    zkStateReader.updateClusterState(true);
    ClusterState clusterState = zkStateReader.getClusterState();
    return clusterState.getCollectionOrNull(collection) != null;
}
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:10,代码来源:SolrIndex.java

示例14: ensureAllReplicasAreActive

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

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

  ClusterState cs = zkr.getClusterState();
  Collection<Slice> slices = cs.getActiveSlices(testCollectionName);
  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().updateClusterState();
    }

    cs = cloudSolrClient.getZkStateReader().getClusterState();
    assertNotNull(cs);
    allReplicasUp = true; // assume true
    for (Slice shard : cs.getActiveSlices(testCollectionName)) {
      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) {
        String replicaState = replica.getStr(ZkStateReader.STATE_PROP);
        if (!"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,项目名称:storm-solr,代码行数:61,代码来源:TestSolrCloudClusterSupport.java

示例15: waitForRecoveriesToFinish

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
public static void waitForRecoveriesToFinish(String collection,
    ZkStateReader zkStateReader, boolean verbose, boolean failOnTimeout, int timeoutSeconds)
    throws Exception {
  log.info("Wait for recoveries to finish - collection: " + collection + " failOnTimeout:" + failOnTimeout + " timeout (sec):" + timeoutSeconds);
  boolean cont = true;
  int cnt = 0;
  
  while (cont) {
    if (verbose) System.out.println("-");
    boolean sawLiveRecovering = false;
    zkStateReader.updateClusterState(true);
    ClusterState clusterState = zkStateReader.getClusterState();
    Map<String,Slice> slices = clusterState.getSlicesMap(collection);
    assertNotNull("Could not find collection:" + collection, slices);
    for (Map.Entry<String,Slice> entry : slices.entrySet()) {
      Map<String,Replica> shards = entry.getValue().getReplicasMap();
      for (Map.Entry<String,Replica> shard : shards.entrySet()) {
        if (verbose) System.out.println("replica:" + shard.getValue().getName() + " rstate:"
            + shard.getValue().getStr(ZkStateReader.STATE_PROP)
            + " live:"
            + clusterState.liveNodesContain(shard.getValue().getNodeName()));
        String state = shard.getValue().getStr(ZkStateReader.STATE_PROP);
        if ((state.equals(ZkStateReader.RECOVERING) || state
            .equals(ZkStateReader.SYNC) || state.equals(ZkStateReader.DOWN))
            && clusterState.liveNodesContain(shard.getValue().getStr(
            ZkStateReader.NODE_NAME_PROP))) {
          sawLiveRecovering = true;
        }
      }
    }
    if (!sawLiveRecovering || cnt == timeoutSeconds) {
      if (!sawLiveRecovering) {
        if (verbose) System.out.println("no one is recoverying");
      } else {
        if (verbose) System.out.println("Gave up waiting for recovery to finish..");
        if (failOnTimeout) {
          Diagnostics.logThreadDumps("Gave up waiting for recovery to finish.  THREAD DUMP:");
          zkStateReader.getZkClient().printLayoutToStdOut();
          fail("There are still nodes recoverying - waited for " + timeoutSeconds + " seconds");
          // won't get here
          return;
        }
      }
      cont = false;
    } else {
      Thread.sleep(1000);
    }
    cnt++;
  }

  log.info("Recoveries finished - collection: " + collection);
}
 
开发者ID:europeana,项目名称:search,代码行数:53,代码来源:AbstractDistribZkTestBase.java


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