Search in sources :

Example 1 with RpcResult

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);
    }
}
Also used : RpcEndpoint(com.couchbase.connector.cluster.consul.rpc.RpcEndpoint) RpcResult(com.couchbase.connector.cluster.consul.rpc.RpcResult) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) Broadcaster(com.couchbase.connector.cluster.consul.rpc.Broadcaster) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with RpcResult

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);
    }
}
Also used : RpcEndpoint(com.couchbase.connector.cluster.consul.rpc.RpcEndpoint) RpcResult(com.couchbase.connector.cluster.consul.rpc.RpcResult) RpcEndpoint(com.couchbase.connector.cluster.consul.rpc.RpcEndpoint)

Aggregations

RpcEndpoint (com.couchbase.connector.cluster.consul.rpc.RpcEndpoint)2 RpcResult (com.couchbase.connector.cluster.consul.rpc.RpcResult)2 Broadcaster (com.couchbase.connector.cluster.consul.rpc.Broadcaster)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 IOException (java.io.IOException)1 Map (java.util.Map)1 TimeoutException (java.util.concurrent.TimeoutException)1