org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder.setWaitForNoRelocatingShards()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(4.7k)|赞(0)|评价(0)|浏览(84)

本文整理了Java中org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder.setWaitForNoRelocatingShards()方法的一些代码示例,展示了ClusterHealthRequestBuilder.setWaitForNoRelocatingShards()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ClusterHealthRequestBuilder.setWaitForNoRelocatingShards()方法的具体详情如下:
包路径:org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder
类名称:ClusterHealthRequestBuilder
方法名:setWaitForNoRelocatingShards

ClusterHealthRequestBuilder.setWaitForNoRelocatingShards介绍

[英]Sets whether the request should wait for there to be no relocating shards before retrieving the cluster health status. Defaults to false, meaning the operation does not wait on there being no more relocating shards. Set to true to wait until the number of relocating shards in the cluster is 0.
[中]设置请求在检索群集运行状况状态之前是否应等待没有重新定位碎片。默认值为false,这意味着操作不会等待不再重新定位碎片。设置为true以等待群集中重新定位的碎片数为0。

代码示例

代码示例来源:origin: com.strapdata.elasticsearch.test/framework

protected void ensureNodeCount(InternalTestCluster cluster) {
  assertFalse("cluster failed to form after disruption was healed", cluster.client().admin().cluster().prepareHealth()
    .setWaitForNodes(String.valueOf(cluster.size()))
    .setWaitForNoRelocatingShards(true)
    .get().isTimedOut());
}

代码示例来源:origin: com.strapdata.elasticsearch.test/framework

protected void ensureNodeCount(InternalTestCluster cluster) {
    assertFalse("cluster failed to form after disruption was healed", cluster.client().admin().cluster().prepareHealth()
        .setWaitForNodes(String.valueOf(cluster.size()))
        .setWaitForNoRelocatingShards(true)
        .get().isTimedOut());
  }
}

代码示例来源:origin: org.eclipse.rdf4j/rdf4j-sail-elasticsearch

healthReqBuilder.setWaitForNoRelocatingShards(Boolean.parseBoolean(waitForNoRelocatingShards));

代码示例来源:origin: com.strapdata.elasticsearch.test/framework

/**
 * Ensures the cluster has a green state via the cluster health API. This method will also wait for relocations.
 * It is useful to ensure that all action on the cluster have finished and all shards that were currently relocating
 * are now allocated and started.
 *
 * @param timeout time out value to set on {@link org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest}
 */
public ClusterHealthStatus ensureGreen(TimeValue timeout, String... indices) {
  ClusterHealthRequestBuilder builder = client().admin().cluster().prepareHealth(indices);
  builder.setTimeout(timeout)
    .setWaitForGreenStatus()
    .setWaitForEvents(Priority.LANGUID)
    .setWaitForNoRelocatingShards(true);
  ClusterHealthResponse actionGet = builder.get();
  if (actionGet.isTimedOut()) {
    logger.info("ensureGreen timed out, cluster state:\n{}\n{}", client().admin().cluster().prepareState().get().getState(),
      client().admin().cluster().preparePendingClusterTasks().get());
    assertThat("timed out waiting for green state", actionGet.isTimedOut(), equalTo(false));
  }
  assertThat(actionGet.getStatus(), equalTo(ClusterHealthStatus.GREEN));
  logger.debug("indices {} are green", indices.length == 0 ? "[_all]" : indices);
  return actionGet.getStatus();
}

代码示例来源:origin: com.strapdata.elasticsearch.test/framework

protected void ensureStableCluster(int nodeCount, TimeValue timeValue, boolean local, @Nullable String viaNode) {
  if (viaNode == null) {
    viaNode = randomFrom(internalCluster().getNodeNames());
  }
  logger.debug("ensuring cluster is stable with [{}] nodes. access node: [{}]. timeout: [{}]", nodeCount, viaNode, timeValue);
  ClusterHealthResponse clusterHealthResponse = client(viaNode).admin().cluster().prepareHealth()
    .setWaitForEvents(Priority.LANGUID)
    .setWaitForNodes(Integer.toString(nodeCount))
    .setTimeout(timeValue)
    .setLocal(local)
    .setWaitForNoRelocatingShards(true)
    .get();
  if (clusterHealthResponse.isTimedOut()) {
    ClusterStateResponse stateResponse = client(viaNode).admin().cluster().prepareState().get();
    fail("failed to reach a stable cluster of [" + nodeCount + "] nodes. Tried via [" + viaNode + "]. last cluster state:\n"
      + stateResponse.getState());
  }
  assertThat(clusterHealthResponse.isTimedOut(), is(false));
  ensureFullyConnectedCluster();
}

代码示例来源:origin: com.strapdata.elasticsearch.test/framework

protected IndexService createIndex(String index, CreateIndexRequestBuilder createIndexRequestBuilder) {
  assertAcked(createIndexRequestBuilder.get());
  // Wait for the index to be allocated so that cluster state updates don't override
  // changes that would have been done locally
  ClusterHealthRequestBuilder builder = client().admin().cluster().prepareHealth(index);
  builder.setWaitForYellowStatus()
    .setWaitForEvents(Priority.LANGUID)
    .setWaitForNoRelocatingShards(true);
  ClusterHealthResponse health = builder.get();
  assertThat(health.getStatus(), lessThanOrEqualTo(ClusterHealthStatus.YELLOW));
  assertThat("Cluster must be a single node cluster", health.getNumberOfDataNodes(), equalTo(1));
  IndicesService instanceFromNode = getInstanceFromNode(IndicesService.class);
  return instanceFromNode.indexServiceSafe(resolveIndex(index));
}

相关文章