Search in sources :

Example 1 with CacheJoinCommand

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

the class LocalCacheStatus method sendJoinRequest.

public CompletionStage<CacheStatusResponse> sendJoinRequest(String cacheName, CacheJoinInfo joinInfo, long timeout, long endTime) {
    int viewId = transport.getViewId();
    ReplicableCommand command = new CacheJoinCommand(cacheName, transport.getAddress(), joinInfo, viewId);
    return handleAndCompose(helper.executeOnCoordinator(transport, command, timeout), (response, throwable) -> {
        int currentViewId = transport.getViewId();
        if (viewId != currentViewId) {
            log.tracef("Received new view %d before join response for cache %s, retrying", currentViewId, cacheName);
            return sendJoinRequest(cacheName, joinInfo, timeout, endTime);
        }
        if (throwable == null) {
            if (response != null) {
                return CompletableFuture.completedFuture(((CacheStatusResponse) response));
            } else {
                log.debugf("Coordinator sent a null join response, retrying in view %d", viewId + 1);
                return retryJoinInView(cacheName, joinInfo, timeout, endTime, viewId + 1);
            }
        }
        Throwable t = CompletableFutures.extractException(throwable);
        if (t instanceof SuspectException) {
            // Either the coordinator is shutting down
            // Or the JGroups stack includes FORK and the coordinator hasn't connected its ForkChannel yet.
            log.debugf("Join request received CacheNotFoundResponse for cache %s, retrying", cacheName);
        } else {
            log.debugf(t, "Join request failed for cache %s", cacheName);
            if (t instanceof TimeoutException) {
                throw (TimeoutException) t;
            }
            throw (CacheJoinException) t.getCause();
        }
        // Can't use a value based on the state transfer timeout because cache org.infinispan.CONFIG
        // uses the default timeout, which is too long for tests (4 minutes)
        long delay = 100;
        return CompletionStages.scheduleNonBlocking(() -> sendJoinRequest(cacheName, joinInfo, timeout, endTime), timeoutExecutor, delay, MILLISECONDS);
    });
}
Also used : CacheJoinCommand(org.infinispan.commands.topology.CacheJoinCommand) ReplicableCommand(org.infinispan.commands.ReplicableCommand) SuspectException(org.infinispan.remoting.transport.jgroups.SuspectException) TimeoutException(org.infinispan.util.concurrent.TimeoutException)

Aggregations

ReplicableCommand (org.infinispan.commands.ReplicableCommand)1 CacheJoinCommand (org.infinispan.commands.topology.CacheJoinCommand)1 SuspectException (org.infinispan.remoting.transport.jgroups.SuspectException)1 TimeoutException (org.infinispan.util.concurrent.TimeoutException)1