org.elasticsearch.cluster.ClusterState.getVersion()方法的使用及代码示例

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

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

ClusterState.getVersion介绍

暂无

代码示例

代码示例来源:origin: org.elasticsearch/elasticsearch

private static Long getVersion(ClusterState clusterState) {
  if (clusterState != null) {
    return clusterState.getVersion();
  } else {
    return null;
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

private void allNodesResponded() {
  if (activeCopies.get() != expectedActiveCopies) {
    logger.trace("not deleting shard {}, expected {} active copies, but only {} found active copies",
      shardId, expectedActiveCopies, activeCopies.get());
    return;
  }
  ClusterState latestClusterState = clusterService.state();
  if (clusterStateVersion != latestClusterState.getVersion()) {
    logger.trace("not deleting shard {}, the latest cluster state version[{}] is not equal to cluster state " +
      "before shard active api call [{}]", shardId, latestClusterState.getVersion(), clusterStateVersion);
    return;
  }
  clusterService.getClusterApplierService().runOnApplierThread("indices_store ([" + shardId + "] active fully on other nodes)",
    currentState -> {
      if (clusterStateVersion != currentState.getVersion()) {
        logger.trace("not deleting shard {}, the update task state version[{}] is not equal to cluster state before " +
          "shard active api call [{}]", shardId, currentState.getVersion(), clusterStateVersion);
        return;
      }
      try {
        indicesService.deleteShardStore("no longer used", shardId, currentState);
      } catch (Exception ex) {
        logger.debug(() -> new ParameterizedMessage("{} failed to delete unallocated shard, ignoring", shardId), ex);
      }
    },
    (source, e) -> logger.error(() -> new ParameterizedMessage("{} unexpected error during deletion of unallocated shard",
      shardId), e)
  );
}

代码示例来源:origin: org.elasticsearch/elasticsearch

ClusterStateObserver observer = new ClusterStateObserver(clusterState, clusterService, TimeValue.timeValueMinutes(5), logger,
  threadPool.getThreadContext());
if (clusterState.getVersion() >= clusterStateVersion) {
  logger.trace("node has cluster state with version higher than {} (current: {})", clusterStateVersion,
    clusterState.getVersion());
  return;
} else {
  logger.trace("waiting for cluster state version {} (current: {})", clusterStateVersion, clusterState.getVersion());
  final PlainActionFuture<Long> future = new PlainActionFuture<>();
  observer.waitForNextChange(new ClusterStateObserver.Listener() {
      future.onFailure(new IllegalStateException("cluster state never updated to version " + clusterStateVersion));
  }, newState -> newState.getVersion() >= clusterStateVersion);
  try {
    long currentVersion = future.get();
    logger.debug(() -> new ParameterizedMessage(
        "failed waiting for cluster state with version {} (current: {})",
        clusterStateVersion, clusterService.state().getVersion()), e);
    throw ExceptionsHelper.convertToRuntime(e);

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
public void runInternal() {
  if (clusterService.localNode().isMasterNode()) {
    final ClusterState state = clusterService.state();
    logger.trace("periodic persistent task assignment check running for cluster state {}", state.getVersion());
    if (isAnyTaskUnassigned(state.getMetaData().custom(PersistentTasksCustomMetaData.TYPE))) {
      reassignPersistentTasks();
    }
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
public void clusterChanged(ClusterChangedEvent event) {
  if (event.localNodeMaster()) {
    if (shouldReassignPersistentTasks(event)) {
      // We want to avoid a periodic check duplicating this work
      periodicRechecker.cancel();
      logger.trace("checking task reassignment for cluster state {}", event.state().getVersion());
      reassignPersistentTasks();
    }
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

private void deleteShardIfExistElseWhere(ClusterState state, IndexShardRoutingTable indexShardRoutingTable) {
  List<Tuple<DiscoveryNode, ShardActiveRequest>> requests = new ArrayList<>(indexShardRoutingTable.size());
  String indexUUID = indexShardRoutingTable.shardId().getIndex().getUUID();
  ClusterName clusterName = state.getClusterName();
  for (ShardRouting shardRouting : indexShardRoutingTable) {
    assert shardRouting.started() : "expected started shard but was " + shardRouting;
    DiscoveryNode currentNode = state.nodes().get(shardRouting.currentNodeId());
    requests.add(new Tuple<>(currentNode,
      new ShardActiveRequest(clusterName, indexUUID, shardRouting.shardId(), deleteShardTimeout)));
  }
  ShardActiveResponseHandler responseHandler = new ShardActiveResponseHandler(indexShardRoutingTable.shardId(), state.getVersion(),
    requests.size());
  for (Tuple<DiscoveryNode, ShardActiveRequest> request : requests) {
    logger.trace("{} sending shard active check to {}", request.v2().shardId, request.v1());
    transportService.sendRequest(request.v1(), ACTION_SHARD_EXISTS, request.v2(), responseHandler);
  }
}

代码示例来源:origin: harbby/presto-connectors

@Override
public ClusterState execute(ClusterState currentState) throws Exception {
  if (clusterStateVersion != currentState.getVersion()) {
    logger.trace("not deleting shard {}, the update task state version[{}] is not equal to cluster state before shard active api call [{}]", shardId, currentState.getVersion(), clusterStateVersion);
    return currentState;
  }
  try {
    indicesService.deleteShardStore("no longer used", shardId, currentState);
  } catch (Throwable ex) {
    logger.debug("{} failed to delete unallocated shard, ignoring", ex, shardId);
  }
  return currentState;
}

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

@Override
public ClusterTasksResult<LocalClusterUpdateTask> execute(ClusterState currentState) throws Exception {
  if (clusterStateVersion != currentState.getVersion()) {
    logger.trace("not deleting shard {}, the update task state version[{}] is not equal to cluster state before shard active api call [{}]", shardId, currentState.getVersion(), clusterStateVersion);
    return unchanged();
  }
  try {
    indicesService.deleteShardStore("no longer used", shardId, currentState);
  } catch (Exception ex) {
    logger.debug((Supplier<?>) () -> new ParameterizedMessage("{} failed to delete unallocated shard, ignoring", shardId), ex);
  }
  return unchanged();
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

private void allNodesResponded() {
  if (activeCopies.get() != expectedActiveCopies) {
    logger.trace("not deleting shard {}, expected {} active copies, but only {} found active copies", shardId, expectedActiveCopies, activeCopies.get());
    return;
  }
  ClusterState latestClusterState = clusterService.state();
  if (clusterStateVersion != latestClusterState.getVersion()) {
    logger.trace("not deleting shard {}, the latest cluster state version[{}] is not equal to cluster state before shard active api call [{}]", shardId, latestClusterState.getVersion(), clusterStateVersion);
    return;
  }
  clusterService.getClusterApplierService().runOnApplierThread("indices_store ([" + shardId + "] active fully on other nodes)",
    currentState -> {
      if (clusterStateVersion != currentState.getVersion()) {
        logger.trace("not deleting shard {}, the update task state version[{}] is not equal to cluster state before shard active api call [{}]", shardId, currentState.getVersion(), clusterStateVersion);
        return;
      }
      try {
        indicesService.deleteShardStore("no longer used", shardId, currentState);
      } catch (Exception ex) {
        logger.debug(() -> new ParameterizedMessage("{} failed to delete unallocated shard, ignoring", shardId), ex);
      }
    },
    (source, e) -> logger.error(() -> new ParameterizedMessage("{} unexpected error during deletion of unallocated shard", shardId), e)
  );
}

代码示例来源:origin: apache/servicemix-bundles

private void allNodesResponded() {
  if (activeCopies.get() != expectedActiveCopies) {
    logger.trace("not deleting shard {}, expected {} active copies, but only {} found active copies", shardId, expectedActiveCopies, activeCopies.get());
    return;
  }
  ClusterState latestClusterState = clusterService.state();
  if (clusterStateVersion != latestClusterState.getVersion()) {
    logger.trace("not deleting shard {}, the latest cluster state version[{}] is not equal to cluster state before shard active api call [{}]", shardId, latestClusterState.getVersion(), clusterStateVersion);
    return;
  }
  clusterService.getClusterApplierService().runOnApplierThread("indices_store ([" + shardId + "] active fully on other nodes)",
    currentState -> {
      if (clusterStateVersion != currentState.getVersion()) {
        logger.trace("not deleting shard {}, the update task state version[{}] is not equal to cluster state before shard active api call [{}]", shardId, currentState.getVersion(), clusterStateVersion);
        return;
      }
      try {
        indicesService.deleteShardStore("no longer used", shardId, currentState);
      } catch (Exception ex) {
        logger.debug(() -> new ParameterizedMessage("{} failed to delete unallocated shard, ignoring", shardId), ex);
      }
    },
    (source, e) -> logger.error(() -> new ParameterizedMessage("{} unexpected error during deletion of unallocated shard", shardId), e)
  );
}

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

private void allNodesResponded() {
  if (activeCopies.get() != expectedActiveCopies) {
    logger.trace("not deleting shard {}, expected {} active copies, but only {} found active copies", shardId, expectedActiveCopies, activeCopies.get());
    return;
  }
  ClusterState latestClusterState = clusterService.state();
  if (clusterStateVersion != latestClusterState.getVersion()) {
    logger.trace("not deleting shard {}, the latest cluster state version[{}] is not equal to cluster state before shard active api call [{}]", shardId, latestClusterState.getVersion(), clusterStateVersion);
    return;
  }
  clusterService.submitStateUpdateTask("indices_store ([" + shardId + "] active fully on other nodes)", new LocalClusterUpdateTask() {
    @Override
    public ClusterTasksResult<LocalClusterUpdateTask> execute(ClusterState currentState) throws Exception {
      if (clusterStateVersion != currentState.getVersion()) {
        logger.trace("not deleting shard {}, the update task state version[{}] is not equal to cluster state before shard active api call [{}]", shardId, currentState.getVersion(), clusterStateVersion);
        return unchanged();
      }
      try {
        indicesService.deleteShardStore("no longer used", shardId, currentState);
      } catch (Exception ex) {
        logger.debug((Supplier<?>) () -> new ParameterizedMessage("{} failed to delete unallocated shard, ignoring", shardId), ex);
      }
      return unchanged();
    }
    @Override
    public void onFailure(String source, Exception e) {
      logger.error((Supplier<?>) () -> new ParameterizedMessage("{} unexpected error during deletion of unallocated shard", shardId), e);
    }
  });
}

代码示例来源:origin: harbby/presto-connectors

private void allNodesResponded() {
  if (activeCopies.get() != expectedActiveCopies) {
    logger.trace("not deleting shard {}, expected {} active copies, but only {} found active copies", shardId, expectedActiveCopies, activeCopies.get());
    return;
  }
  ClusterState latestClusterState = clusterService.state();
  if (clusterStateVersion != latestClusterState.getVersion()) {
    logger.trace("not deleting shard {}, the latest cluster state version[{}] is not equal to cluster state before shard active api call [{}]", shardId, latestClusterState.getVersion(), clusterStateVersion);
    return;
  }
  clusterService.submitStateUpdateTask("indices_store ([" + shardId + "] active fully on other nodes)", new ClusterStateNonMasterUpdateTask() {
    @Override
    public ClusterState execute(ClusterState currentState) throws Exception {
      if (clusterStateVersion != currentState.getVersion()) {
        logger.trace("not deleting shard {}, the update task state version[{}] is not equal to cluster state before shard active api call [{}]", shardId, currentState.getVersion(), clusterStateVersion);
        return currentState;
      }
      try {
        indicesService.deleteShardStore("no longer used", shardId, currentState);
      } catch (Throwable ex) {
        logger.debug("{} failed to delete unallocated shard, ignoring", ex, shardId);
      }
      return currentState;
    }
    @Override
    public void onFailure(String source, Throwable t) {
      logger.error("{} unexpected error during deletion of unallocated shard", t, shardId);
    }
  });
}

代码示例来源:origin: apache/servicemix-bundles

ClusterStateObserver observer = new ClusterStateObserver(clusterState, clusterService, TimeValue.timeValueMinutes(5), logger,
  threadPool.getThreadContext());
if (clusterState.getVersion() >= clusterStateVersion) {
  logger.trace("node has cluster state with version higher than {} (current: {})", clusterStateVersion,
    clusterState.getVersion());
  return;
} else {
  logger.trace("waiting for cluster state version {} (current: {})", clusterStateVersion, clusterState.getVersion());
  final PlainActionFuture<Long> future = new PlainActionFuture<>();
  observer.waitForNextChange(new ClusterStateObserver.Listener() {
      future.onFailure(new IllegalStateException("cluster state never updated to version " + clusterStateVersion));
  }, newState -> newState.getVersion() >= clusterStateVersion);
  try {
    long currentVersion = future.get();
    logger.debug(() -> new ParameterizedMessage(
        "failed waiting for cluster state with version {} (current: {})",
        clusterStateVersion, clusterService.state().getVersion()), e);
    throw ExceptionsHelper.convertToRuntime(e);

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

@Override
public void clusterChanged(ClusterChangedEvent event) {
  if (event.localNodeMaster()) {
    if (shouldReassignPersistentTasks(event)) {
      logger.trace("checking task reassignment for cluster state {}", event.state().getVersion());
      clusterService.submitStateUpdateTask("reassign persistent tasks", new ClusterStateUpdateTask() {
        @Override
        public ClusterState execute(ClusterState currentState) {
          return reassignTasks(currentState);
        }
        @Override
        public void onFailure(String source, Exception e) {
          logger.warn("failed to reassign persistent tasks", e);
        }
      });
    }
  }
}

代码示例来源:origin: apache/servicemix-bundles

@Override
public void clusterChanged(ClusterChangedEvent event) {
  if (event.localNodeMaster()) {
    if (shouldReassignPersistentTasks(event)) {
      logger.trace("checking task reassignment for cluster state {}", event.state().getVersion());
      clusterService.submitStateUpdateTask("reassign persistent tasks", new ClusterStateUpdateTask() {
        @Override
        public ClusterState execute(ClusterState currentState) {
          return reassignTasks(currentState);
        }
        @Override
        public void onFailure(String source, Exception e) {
          logger.warn("failed to reassign persistent tasks", e);
        }
      });
    }
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

private void deleteShardIfExistElseWhere(ClusterState state, IndexShardRoutingTable indexShardRoutingTable) {
  List<Tuple<DiscoveryNode, ShardActiveRequest>> requests = new ArrayList<>(indexShardRoutingTable.size());
  String indexUUID = indexShardRoutingTable.shardId().getIndex().getUUID();
  ClusterName clusterName = state.getClusterName();
  for (ShardRouting shardRouting : indexShardRoutingTable) {
    assert shardRouting.started() : "expected started shard but was " + shardRouting;
    DiscoveryNode currentNode = state.nodes().get(shardRouting.currentNodeId());
    requests.add(new Tuple<>(currentNode, new ShardActiveRequest(clusterName, indexUUID, shardRouting.shardId(), deleteShardTimeout)));
  }
  ShardActiveResponseHandler responseHandler = new ShardActiveResponseHandler(indexShardRoutingTable.shardId(), state.getVersion(),
    requests.size());
  for (Tuple<DiscoveryNode, ShardActiveRequest> request : requests) {
    logger.trace("{} sending shard active check to {}", request.v2().shardId, request.v1());
    transportService.sendRequest(request.v1(), ACTION_SHARD_EXISTS, request.v2(), responseHandler);
  }
}

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

private void deleteShardIfExistElseWhere(ClusterState state, IndexShardRoutingTable indexShardRoutingTable) {
  List<Tuple<DiscoveryNode, ShardActiveRequest>> requests = new ArrayList<>(indexShardRoutingTable.size());
  String indexUUID = indexShardRoutingTable.shardId().getIndex().getUUID();
  ClusterName clusterName = state.getClusterName();
  for (ShardRouting shardRouting : indexShardRoutingTable) {
    assert shardRouting.started() : "expected started shard but was " + shardRouting;
    DiscoveryNode currentNode = state.nodes().get(shardRouting.currentNodeId());
    requests.add(new Tuple<>(currentNode, new ShardActiveRequest(clusterName, indexUUID, shardRouting.shardId(), deleteShardTimeout)));
  }
  ShardActiveResponseHandler responseHandler = new ShardActiveResponseHandler(indexShardRoutingTable.shardId(), state.getVersion(),
    requests.size());
  for (Tuple<DiscoveryNode, ShardActiveRequest> request : requests) {
    logger.trace("{} sending shard active check to {}", request.v2().shardId, request.v1());
    transportService.sendRequest(request.v1(), ACTION_SHARD_EXISTS, request.v2(), responseHandler);
  }
}

代码示例来源:origin: apache/servicemix-bundles

private void deleteShardIfExistElseWhere(ClusterState state, IndexShardRoutingTable indexShardRoutingTable) {
  List<Tuple<DiscoveryNode, ShardActiveRequest>> requests = new ArrayList<>(indexShardRoutingTable.size());
  String indexUUID = indexShardRoutingTable.shardId().getIndex().getUUID();
  ClusterName clusterName = state.getClusterName();
  for (ShardRouting shardRouting : indexShardRoutingTable) {
    assert shardRouting.started() : "expected started shard but was " + shardRouting;
    DiscoveryNode currentNode = state.nodes().get(shardRouting.currentNodeId());
    requests.add(new Tuple<>(currentNode, new ShardActiveRequest(clusterName, indexUUID, shardRouting.shardId(), deleteShardTimeout)));
  }
  ShardActiveResponseHandler responseHandler = new ShardActiveResponseHandler(indexShardRoutingTable.shardId(), state.getVersion(),
    requests.size());
  for (Tuple<DiscoveryNode, ShardActiveRequest> request : requests) {
    logger.trace("{} sending shard active check to {}", request.v2().shardId, request.v1());
    transportService.sendRequest(request.v1(), ACTION_SHARD_EXISTS, request.v2(), responseHandler);
  }
}

代码示例来源:origin: harbby/presto-connectors

private void deleteShardIfExistElseWhere(ClusterState state, IndexShardRoutingTable indexShardRoutingTable) {
  List<Tuple<DiscoveryNode, ShardActiveRequest>> requests = new ArrayList<>(indexShardRoutingTable.size());
  String indexUUID = state.getMetaData().index(indexShardRoutingTable.shardId().getIndex()).getIndexUUID();
  ClusterName clusterName = state.getClusterName();
  for (ShardRouting shardRouting : indexShardRoutingTable) {
    // Node can't be null, because otherwise shardCanBeDeleted() would have returned false
    DiscoveryNode currentNode = state.nodes().get(shardRouting.currentNodeId());
    assert currentNode != null;
    requests.add(new Tuple<>(currentNode, new ShardActiveRequest(clusterName, indexUUID, shardRouting.shardId(), deleteShardTimeout)));
    if (shardRouting.relocatingNodeId() != null) {
      DiscoveryNode relocatingNode = state.nodes().get(shardRouting.relocatingNodeId());
      assert relocatingNode != null;
      requests.add(new Tuple<>(relocatingNode, new ShardActiveRequest(clusterName, indexUUID, shardRouting.shardId(), deleteShardTimeout)));
    }
  }
  ShardActiveResponseHandler responseHandler = new ShardActiveResponseHandler(indexShardRoutingTable.shardId(), state.getVersion(),
    requests.size());
  for (Tuple<DiscoveryNode, ShardActiveRequest> request : requests) {
    logger.trace("{} sending shard active check to {}", request.v2().shardId, request.v1());
    transportService.sendRequest(request.v1(), ACTION_SHARD_EXISTS, request.v2(), responseHandler);
  }
}

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

private RecoverySourceHandler createRecoverySourceHandler(StartRecoveryRequest request, IndexShard shard) {
  RecoverySourceHandler handler;
  final RemoteRecoveryTargetHandler recoveryTarget =
    new RemoteRecoveryTargetHandler(request.recoveryId(), request.shardId(), transportService, request.targetNode(),
      recoverySettings, throttleTime -> shard.recoveryStats().addThrottleTime(throttleTime));
  Supplier<Long> currentClusterStateVersionSupplier = () -> clusterService.state().getVersion();
  if (shard.indexSettings().isOnSharedFilesystem()) {
    handler = new SharedFSRecoverySourceHandler(shard, recoveryTarget, request, currentClusterStateVersionSupplier,
      this::delayNewRecoveries, logger);
  } else {
    handler = new RecoverySourceHandler(shard, recoveryTarget, request, currentClusterStateVersionSupplier,
      this::delayNewRecoveries, recoverySettings.getChunkSize().bytesAsInt(), logger);
  }
  return handler;
}

相关文章