use of io.crate.common.unit.TimeValue in project crate by crate.
the class RamAccountingQueueSinkTest method testTimedRamAccountingQueueSink.
@Test
public void testTimedRamAccountingQueueSink() throws Exception {
ConcurrentLinkedQueue<NoopLog> q = new ConcurrentLinkedQueue<>();
RamAccountingQueue<NoopLog> ramAccountingQueue = new RamAccountingQueue<>(q, breaker(), NOOP_ESTIMATOR);
TimeValue timeValue = TimeValue.timeValueSeconds(1L);
ScheduledFuture<?> task = TimeBasedQEviction.scheduleTruncate(1000L, 1000L, q, scheduler, timeValue);
logSink = new QueueSink<>(ramAccountingQueue, () -> {
task.cancel(false);
ramAccountingQueue.release();
});
for (int j = 0; j < 100; j++) {
logSink.add(new NoopLog());
}
assertThat(ramAccountingQueue.size(), is(100));
Thread.sleep(2000L);
assertThat(ramAccountingQueue.size(), is(0));
}
use of io.crate.common.unit.TimeValue in project crate by crate.
the class TransportDistributedResultAction method retryOrFailureResponse.
private CompletableFuture<DistributedResultResponse> retryOrFailureResponse(DistributedResultRequest request, @Nullable Iterator<TimeValue> retryDelay) {
if (retryDelay == null) {
retryDelay = backoffPolicy.iterator();
}
if (retryDelay.hasNext()) {
TimeValue delay = retryDelay.next();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("scheduling retry to start node operation for jobId: {} in {}ms", request.jobId(), delay.getMillis());
}
NodeOperationRunnable operationRunnable = new NodeOperationRunnable(request, retryDelay);
scheduler.schedule(operationRunnable::run, delay.getMillis(), TimeUnit.MILLISECONDS);
return operationRunnable;
} else {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Received a result for job={} but couldn't find a RootTask for it", request.jobId());
}
List<String> excludedNodeIds = Collections.singletonList(clusterService.localNode().getId());
/* The upstream (DistributingConsumer) forwards failures to other downstreams and eventually considers its job done.
* But it cannot inform the handler-merge about a failure because the JobResponse is sent eagerly.
*
* The handler local-merge would get stuck if not all its upstreams send their requests, so we need to invoke
* a kill to make sure that doesn't happen.
*/
KillJobsRequest killRequest = new KillJobsRequest(List.of(request.jobId()), User.CRATE_USER.name(), "Received data for job=" + request.jobId() + " but there is no job context present. " + "This can happen due to bad network latency or if individual nodes are unresponsive due to high load");
killJobsAction.broadcast(killRequest, new ActionListener<>() {
@Override
public void onResponse(Long numKilled) {
}
@Override
public void onFailure(Exception e) {
LOGGER.debug("Could not kill " + request.jobId(), e);
}
}, excludedNodeIds);
return CompletableFuture.failedFuture(new TaskMissing(TaskMissing.Type.ROOT, request.jobId()));
}
}
use of io.crate.common.unit.TimeValue in project crate by crate.
the class TransportAddVotingConfigExclusionsAction method masterOperation.
@Override
protected void masterOperation(AddVotingConfigExclusionsRequest request, ClusterState state, ActionListener<AddVotingConfigExclusionsResponse> listener) throws Exception {
// throws IAE if no nodes matched or maximum exceeded
resolveVotingConfigExclusionsAndCheckMaximum(request, state);
clusterService.submitStateUpdateTask("add-voting-config-exclusions", new ClusterStateUpdateTask(Priority.URGENT) {
private Set<VotingConfigExclusion> resolvedExclusions;
@Override
public ClusterState execute(ClusterState currentState) {
assert resolvedExclusions == null : resolvedExclusions;
resolvedExclusions = resolveVotingConfigExclusionsAndCheckMaximum(request, currentState);
final CoordinationMetadata.Builder builder = CoordinationMetadata.builder(currentState.coordinationMetadata());
resolvedExclusions.forEach(builder::addVotingConfigExclusion);
final Metadata newMetadata = Metadata.builder(currentState.metadata()).coordinationMetadata(builder.build()).build();
final ClusterState newState = ClusterState.builder(currentState).metadata(newMetadata).build();
assert newState.getVotingConfigExclusions().size() <= MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING.get(currentState.metadata().settings());
return newState;
}
@Override
public void onFailure(String source, Exception e) {
listener.onFailure(e);
}
@Override
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
final ClusterStateObserver observer = new ClusterStateObserver(clusterService, request.getTimeout(), logger);
final Set<String> excludedNodeIds = resolvedExclusions.stream().map(VotingConfigExclusion::getNodeId).collect(Collectors.toSet());
final Predicate<ClusterState> allNodesRemoved = clusterState -> {
final Set<String> votingConfigNodeIds = clusterState.getLastCommittedConfiguration().getNodeIds();
return excludedNodeIds.stream().noneMatch(votingConfigNodeIds::contains);
};
final Listener clusterStateListener = new Listener() {
@Override
public void onNewClusterState(ClusterState state) {
listener.onResponse(new AddVotingConfigExclusionsResponse());
}
@Override
public void onClusterServiceClose() {
listener.onFailure(new ElasticsearchException("cluster service closed while waiting for voting config exclusions " + resolvedExclusions + " to take effect"));
}
@Override
public void onTimeout(TimeValue timeout) {
listener.onFailure(new ElasticsearchTimeoutException("timed out waiting for voting config exclusions " + resolvedExclusions + " to take effect"));
}
};
if (allNodesRemoved.test(newState)) {
clusterStateListener.onNewClusterState(newState);
} else {
observer.waitForNextChange(clusterStateListener, allNodesRemoved);
}
}
});
}
use of io.crate.common.unit.TimeValue in project crate by crate.
the class Coordinator method startElectionScheduler.
private void startElectionScheduler() {
assert electionScheduler == null : electionScheduler;
if (getLocalNode().isMasterEligibleNode() == false) {
return;
}
// TODO variable grace period
final TimeValue gracePeriod = TimeValue.ZERO;
electionScheduler = electionSchedulerFactory.startElectionScheduler(gracePeriod, new Runnable() {
@Override
public void run() {
synchronized (mutex) {
if (mode == Mode.CANDIDATE) {
final ClusterState lastAcceptedState = coordinationState.get().getLastAcceptedState();
if (localNodeMayWinElection(lastAcceptedState) == false) {
LOGGER.trace("skip prevoting as local node may not win election: {}", lastAcceptedState.coordinationMetadata());
return;
}
if (prevotingRound != null) {
prevotingRound.close();
}
prevotingRound = preVoteCollector.start(lastAcceptedState, getDiscoveredNodes());
}
}
}
@Override
public String toString() {
return "scheduling of new prevoting round";
}
});
}
use of io.crate.common.unit.TimeValue in project crate by crate.
the class Publication method logIncompleteNodes.
void logIncompleteNodes(Level level) {
final String message = publicationTargets.stream().filter(PublicationTarget::isActive).map(publicationTarget -> publicationTarget.getDiscoveryNode() + " [" + publicationTarget.getState() + "]").collect(Collectors.joining(", "));
if (message.isEmpty() == false) {
final TimeValue elapsedTime = TimeValue.timeValueMillis(currentTimeSupplier.getAsLong() - startTime);
logger.log(level, "after [{}] publication of cluster state version [{}] is still waiting for {}", elapsedTime, publishRequest.getAcceptedState().version(), message);
}
}
Aggregations