Search in sources :

Example 1 with CacheStatusRequestCommand

use of org.infinispan.commands.topology.CacheStatusRequestCommand in project infinispan by infinispan.

the class ClusterTopologyManagerImpl method fetchClusterStatus.

private CompletionStage<CacheStatusResponseCollector> fetchClusterStatus(int newViewId) {
    int attemptCount = recoveryAttemptCount.getAndIncrement();
    if (log.isTraceEnabled())
        log.debugf("Recovering cluster status for view %d, attempt %d", newViewId, attemptCount);
    ReplicableCommand command = new CacheStatusRequestCommand(newViewId);
    CacheStatusResponseCollector responseCollector = new CacheStatusResponseCollector();
    int timeout = getGlobalTimeout() / CLUSTER_RECOVERY_ATTEMPTS;
    CompletionStage<CacheStatusResponseCollector> remoteStage = helper.executeOnClusterSync(transport, command, timeout, responseCollector);
    return CompletionStages.handleAndCompose(remoteStage, (collector, throwable) -> {
        if (newViewId < transport.getViewId()) {
            if (log.isTraceEnabled())
                log.tracef("Ignoring cluster state responses for view %d, we already have view %d", newViewId, transport.getViewId());
            return SKIP_RECOVERY_FUTURE;
        } else if (throwable == null) {
            if (log.isTraceEnabled())
                log.tracef("Received valid cluster state responses for view %d", newViewId);
            if (!collector.getSuspectedMembers().isEmpty()) {
                // We got a CacheNotFoundResponse but the view is still the same, assume the JGroups stack
                // includes FORK and the suspected node hasn't connected its ForkChannel yet.
                // That means the node doesn't have any caches running yet, so we can ignore it.
                log.debugf("Missing cache status responses from nodes %s", collector.getSuspectedMembers());
            }
            return CompletableFuture.completedFuture(collector);
        }
        Throwable t = CompletableFutures.extractException(throwable);
        if (t instanceof IllegalLifecycleStateException) {
            // Stop retrying, we are shutting down
            return SKIP_RECOVERY_FUTURE;
        }
        // If we got a TimeoutException, assume JGroupsChannelLookup and shouldConnect == false,
        // and the node that timed out hasn't installed its UpHandler yet.
        // Retry at most CLUSTER_RECOVERY_ATTEMPTS times, then throw the timeout exception
        log.failedToRecoverClusterState(t);
        if (t instanceof TimeoutException && attemptCount < CLUSTER_RECOVERY_ATTEMPTS) {
            return fetchClusterStatus(newViewId);
        }
        throw CompletableFutures.asCompletionException(t);
    });
}
Also used : IllegalLifecycleStateException(org.infinispan.commons.IllegalLifecycleStateException) ReplicableCommand(org.infinispan.commands.ReplicableCommand) CacheStatusRequestCommand(org.infinispan.commands.topology.CacheStatusRequestCommand) TimeoutException(org.infinispan.util.concurrent.TimeoutException)

Aggregations

ReplicableCommand (org.infinispan.commands.ReplicableCommand)1 CacheStatusRequestCommand (org.infinispan.commands.topology.CacheStatusRequestCommand)1 IllegalLifecycleStateException (org.infinispan.commons.IllegalLifecycleStateException)1 TimeoutException (org.infinispan.util.concurrent.TimeoutException)1