use of com.couchbase.connector.cluster.consul.rpc.RpcResult in project couchbase-elasticsearch-connector by couchbase.
the class DocumentKeys method waitForClusterToQuiesce.
private void waitForClusterToQuiesce(Duration timeout) throws TimeoutException {
final TimeoutEnforcer timeoutEnforcer = new TimeoutEnforcer(timeout);
try (Broadcaster broadcaster = new Broadcaster()) {
while (true) {
final List<RpcEndpoint> allEndpoints = listRpcEndpoints();
final Map<RpcEndpoint, RpcResult<Boolean>> results = broadcaster.broadcast("stopped?", allEndpoints, WorkerService.class, WorkerService::stopped);
boolean stopped = true;
for (Map.Entry<RpcEndpoint, RpcResult<Boolean>> e : results.entrySet()) {
if (e.getValue().isFailed()) {
LOGGER.warn("Status request failed for endpoint " + e.getKey());
stopped = false;
} else if (!e.getValue().get()) {
LOGGER.warn("Endpoint is still working: " + e.getKey());
stopped = false;
}
}
if (stopped) {
return;
}
timeoutEnforcer.throwIfExpired();
LOGGER.info("Retrying in just a moment...");
SECONDS.sleep(2);
}
} catch (Exception e) {
throwIfUnchecked(e);
propagateIfPossible(e, TimeoutException.class);
throw new RuntimeException(e);
}
}
use of com.couchbase.connector.cluster.consul.rpc.RpcResult in project couchbase-elasticsearch-connector by couchbase.
the class LeaderTask method stopStreaming.
private void stopStreaming() throws InterruptedException {
int attempt = 1;
// Repeat until all endpoints successfully acknowledge they have been shut down
while (true) {
throwIfDone();
final List<RpcEndpoint> endpoints = ctx.keys().listRpcEndpoints(Duration.ofSeconds(15));
final Map<RpcEndpoint, RpcResult<Void>> stopResults = broadcaster.broadcast("stop", endpoints, WorkerService.class, WorkerService::stopStreaming);
if (stopResults.entrySet().stream().noneMatch(e -> e.getValue().isFailed())) {
if (attempt != 1) {
LOGGER.warn("Multiple attempts were required to quiesce the cluster. Sleeping for an additional {} to allow unreachable nodes to terminate.", quietPeriodAfterFailedShutdownRequest);
sleep(quietPeriodAfterFailedShutdownRequest);
}
LOGGER.info("Cluster quiesced.");
return;
}
LOGGER.warn("Attempt #{} to quiesce the cluster failed. Will retry.", attempt);
attempt++;
SECONDS.sleep(5);
}
}
Aggregations