use of io.crate.common.unit.TimeValue in project crate by crate.
the class RetryOnFailureResultReceiver method fail.
@Override
public void fail(@Nonnull Throwable wrappedError) {
final Throwable error = SQLExceptions.unwrap(wrappedError);
if (attempt <= Constants.MAX_SHARD_MISSING_RETRIES && (SQLExceptions.isShardFailure(error) || error instanceof ConnectTransportException || indexWasTemporaryUnavailable(error))) {
if (clusterService.state().blocks().hasGlobalBlockWithStatus(RestStatus.SERVICE_UNAVAILABLE)) {
delegate.fail(error);
} else {
ClusterStateObserver clusterStateObserver = new ClusterStateObserver(initialState, clusterService, null, LOGGER);
clusterStateObserver.waitForNextChange(new ClusterStateObserver.Listener() {
@Override
public void onNewClusterState(ClusterState state) {
attempt += 1;
retry();
}
@Override
public void onClusterServiceClose() {
delegate.fail(error);
}
@Override
public void onTimeout(TimeValue timeout) {
delegate.fail(error);
}
});
}
} else {
delegate.fail(error);
}
}
use of io.crate.common.unit.TimeValue in project crate by crate.
the class TransportClusterHealthAction method executeHealth.
private void executeHealth(final ClusterHealthRequest request, final ClusterState currentState, final ActionListener<ClusterHealthResponse> listener, final int waitCount, final Consumer<ClusterState> onNewClusterStateAfterDelay) {
if (request.timeout().millis() == 0) {
listener.onResponse(getResponse(request, currentState, waitCount, true));
return;
}
final Predicate<ClusterState> validationPredicate = newState -> validateRequest(request, newState, waitCount);
if (validationPredicate.test(currentState)) {
listener.onResponse(getResponse(request, currentState, waitCount, false));
} else {
final ClusterStateObserver observer = new ClusterStateObserver(currentState, clusterService, null, LOGGER);
final ClusterStateObserver.Listener stateListener = new ClusterStateObserver.Listener() {
@Override
public void onNewClusterState(ClusterState newState) {
onNewClusterStateAfterDelay.accept(newState);
}
@Override
public void onClusterServiceClose() {
listener.onFailure(new IllegalStateException("ClusterService was close during health call"));
}
@Override
public void onTimeout(TimeValue timeout) {
listener.onResponse(getResponse(request, observer.setAndGetObservedState(), waitCount, true));
}
};
observer.waitForNextChange(stateListener, validationPredicate, request.timeout());
}
}
use of io.crate.common.unit.TimeValue in project crate by crate.
the class TransportClearVotingConfigExclusionsAction method masterOperation.
@Override
protected void masterOperation(ClearVotingConfigExclusionsRequest request, ClusterState initialState, ActionListener<ClearVotingConfigExclusionsResponse> listener) throws Exception {
final long startTimeMillis = threadPool.relativeTimeInMillis();
final Predicate<ClusterState> allExclusionsRemoved = newState -> {
for (VotingConfigExclusion tombstone : initialState.getVotingConfigExclusions()) {
// NB checking for the existence of any node with this persistent ID, because persistent IDs are how votes are counted.
if (newState.nodes().nodeExists(tombstone.getNodeId())) {
return false;
}
}
return true;
};
if (request.getWaitForRemoval() && allExclusionsRemoved.test(initialState) == false) {
final ClusterStateObserver clusterStateObserver = new ClusterStateObserver(initialState, clusterService, request.getTimeout(), logger);
clusterStateObserver.waitForNextChange(new Listener() {
@Override
public void onNewClusterState(ClusterState state) {
submitClearVotingConfigExclusionsTask(request, startTimeMillis, listener);
}
@Override
public void onClusterServiceClose() {
listener.onFailure(new ElasticsearchException("cluster service closed while waiting for removal of nodes " + initialState.getVotingConfigExclusions()));
}
@Override
public void onTimeout(TimeValue timeout) {
listener.onFailure(new ElasticsearchTimeoutException("timed out waiting for removal of nodes; if nodes should not be removed, set waitForRemoval to false. " + initialState.getVotingConfigExclusions()));
}
}, allExclusionsRemoved);
} else {
submitClearVotingConfigExclusionsTask(request, startTimeMillis, listener);
}
}
use of io.crate.common.unit.TimeValue in project crate by crate.
the class UDCService method doStart.
@Override
protected void doStart() throws ElasticsearchException {
String url = UDC_URL_SETTING.get(settings);
TimeValue initialDelay = UDC_INITIAL_DELAY_SETTING.get(settings);
TimeValue interval = UDC_INTERVAL_SETTING.get(settings);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Starting with delay {} and period {}.", initialDelay.getSeconds(), interval.getSeconds());
}
PingTask pingTask = new PingTask(clusterService, extendedNodeInfo, url);
timer.scheduleAtFixedRate(pingTask, initialDelay.millis(), interval.millis());
}
use of io.crate.common.unit.TimeValue in project crate by crate.
the class ProjectionToProjectorVisitor method visitDeleteProjection.
@Override
public Projector visitDeleteProjection(DeleteProjection projection, Context context) {
checkShardLevel("Delete projection can only be executed on a shard");
TimeValue reqTimeout = ShardingUpsertExecutor.BULK_REQUEST_TIMEOUT_SETTING.get(settings);
ShardDMLExecutor<?, ?, ?, ?> shardDMLExecutor = new ShardDMLExecutor<>(context.jobId, ShardDMLExecutor.DEFAULT_BULK_SIZE, threadPool.scheduler(), threadPool.executor(ThreadPool.Names.SEARCH), resolveUidCollectExpression(context.txnCtx, projection.uidSymbol()), clusterService, nodeJobsCounter, () -> new ShardDeleteRequest(shardId, context.jobId).timeout(reqTimeout), ShardDeleteRequest.Item::new, transportActionProvider.transportShardDeleteAction()::execute, ShardDMLExecutor.ROW_COUNT_COLLECTOR);
return new DMLProjector(shardDMLExecutor);
}
Aggregations