Search in sources :

Example 1 with Response

use of org.infinispan.remoting.responses.Response in project infinispan by infinispan.

the class StateConsumerImpl method onTopologyUpdate.

@Override
public CompletionStage<CompletionStage<Void>> onTopologyUpdate(CacheTopology cacheTopology, boolean isRebalance) {
    final ConsistentHash newWriteCh = cacheTopology.getWriteConsistentHash();
    final CacheTopology previousCacheTopology = this.cacheTopology;
    final ConsistentHash previousWriteCh = previousCacheTopology != null ? previousCacheTopology.getWriteConsistentHash() : null;
    IntSet newWriteSegments = getOwnedSegments(newWriteCh);
    Address address = rpcManager.getAddress();
    final boolean isMember = cacheTopology.getMembers().contains(address);
    final boolean wasMember = previousWriteCh != null && previousWriteCh.getMembers().contains(address);
    if (log.isTraceEnabled())
        log.tracef("Received new topology for cache %s, isRebalance = %b, isMember = %b, topology = %s", cacheName, isRebalance, isMember, cacheTopology);
    if (!ownsData && isMember) {
        ownsData = true;
    } else if (ownsData && !isMember) {
        // This can happen after a merge, if the local node was in a minority partition.
        ownsData = false;
    }
    // If a member leaves/crashes immediately after a rebalance was started, the new CH_UPDATE
    // command may be executed before the REBALANCE_START command, so it has to start the rebalance.
    boolean addedPendingCH = cacheTopology.getPendingCH() != null && wasMember && previousCacheTopology.getPendingCH() == null;
    boolean startConflictResolution = !isRebalance && cacheTopology.getPhase() == CacheTopology.Phase.CONFLICT_RESOLUTION;
    boolean startStateTransfer = isRebalance || (addedPendingCH && !startConflictResolution);
    if (startStateTransfer && !isRebalance) {
        if (log.isTraceEnabled())
            log.tracef("Forcing startRebalance = true");
    }
    CompletionStage<Void> stage = CompletableFutures.completedNull();
    if (startStateTransfer) {
        // Only update the rebalance topology id when starting the rebalance, as we're going to ignore any state
        // response with a smaller topology id
        stateTransferTopologyId.compareAndSet(NO_STATE_TRANSFER_IN_PROGRESS, cacheTopology.getTopologyId());
        conflictManager.cancelVersionRequests();
        if (cacheNotifier.hasListener(DataRehashed.class)) {
            stage = cacheNotifier.notifyDataRehashed(cacheTopology.getCurrentCH(), cacheTopology.getPendingCH(), cacheTopology.getUnionCH(), cacheTopology.getTopologyId(), true);
        }
    }
    stage = stage.thenCompose(ignored -> {
        if (startConflictResolution) {
            // This stops state being applied from a prior rebalance and also prevents tracking from being stopped
            stateTransferTopologyId.set(NO_STATE_TRANSFER_IN_PROGRESS);
        }
        // Make sure we don't send a REBALANCE_CONFIRM command before we've added all the transfer tasks
        // even if some of the tasks are removed and re-added
        waitingForState.set(false);
        stateTransferFuture = new CompletableFuture<>();
        beforeTopologyInstalled(cacheTopology.getTopologyId(), previousWriteCh, newWriteCh);
        if (!configuration.clustering().cacheMode().isInvalidation()) {
            // Owned segments
            dataContainer.addSegments(newWriteSegments);
            // TODO Should we throw an exception if addSegments() returns false?
            return ignoreValue(persistenceManager.addSegments(newWriteSegments));
        }
        return CompletableFutures.completedNull();
    });
    stage = stage.thenCompose(ignored -> {
        // Tracking is stopped once the state transfer completes (i.e. all the entries have been inserted)
        if (startStateTransfer || startConflictResolution) {
            if (commitManager.isTracking(PUT_FOR_STATE_TRANSFER)) {
                log.debug("Starting state transfer but key tracking is already enabled");
            } else {
                if (log.isTraceEnabled())
                    log.tracef("Start keeping track of keys for state transfer");
                commitManager.startTrack(PUT_FOR_STATE_TRANSFER);
            }
        }
        // Ensures writes to the data container use the right consistent hash
        // Writers block on the state transfer shared lock, so we keep the exclusive lock as short as possible
        stateTransferLock.acquireExclusiveTopologyLock();
        try {
            this.cacheTopology = cacheTopology;
            distributionManager.setCacheTopology(cacheTopology);
        } finally {
            stateTransferLock.releaseExclusiveTopologyLock();
        }
        stateTransferLock.notifyTopologyInstalled(cacheTopology.getTopologyId());
        inboundInvocationHandler.checkForReadyTasks();
        xSiteStateTransferManager.onTopologyUpdated(cacheTopology, isStateTransferInProgress());
        if (!wasMember && isMember) {
            return fetchClusterListeners(cacheTopology);
        }
        return CompletableFutures.completedNull();
    });
    stage = stage.thenCompose(ignored -> {
        // fetch transactions and data segments from other owners if this is enabled
        if (startConflictResolution || (!isTransactional && !isFetchEnabled)) {
            return CompletableFutures.completedNull();
        }
        IntSet addedSegments, removedSegments;
        if (previousWriteCh == null) {
            // If we have any segments assigned in the initial CH, it means we are the first member.
            // If we are not the first member, we can only add segments via rebalance.
            removedSegments = IntSets.immutableEmptySet();
            addedSegments = IntSets.immutableEmptySet();
            if (log.isTraceEnabled()) {
                log.tracef("On cache %s we have: added segments: %s", cacheName, addedSegments);
            }
        } else {
            IntSet previousSegments = getOwnedSegments(previousWriteCh);
            if (newWriteSegments.size() == numSegments) {
                // Optimization for replicated caches
                removedSegments = IntSets.immutableEmptySet();
            } else {
                removedSegments = IntSets.mutableCopyFrom(previousSegments);
                removedSegments.removeAll(newWriteSegments);
            }
            // This is a rebalance, we need to request the segments we own in the new CH.
            addedSegments = IntSets.mutableCopyFrom(newWriteSegments);
            addedSegments.removeAll(previousSegments);
            if (log.isTraceEnabled()) {
                log.tracef("On cache %s we have: new segments: %s; old segments: %s", cacheName, newWriteSegments, previousSegments);
                log.tracef("On cache %s we have: added segments: %s; removed segments: %s", cacheName, addedSegments, removedSegments);
            }
            // remove inbound transfers for segments we no longer own
            cancelTransfers(removedSegments);
            // Scattered cache gets added segments on the first CH_UPDATE, and we want to keep these
            if (!startStateTransfer && !addedSegments.isEmpty() && !configuration.clustering().cacheMode().isScattered()) {
                // If the last owner of a segment leaves the cluster, a new set of owners is assigned,
                // but the new owners should not try to retrieve the segment from each other.
                // If this happens during a rebalance, we might have already sent our rebalance
                // confirmation, so the coordinator won't wait for us to retrieve those segments anyway.
                log.debugf("Not requesting segments %s because the last owner left the cluster", addedSegments);
                addedSegments.clear();
            }
            // check if any of the existing transfers should be restarted from a different source because
            // the initial source is no longer a member
            restartBrokenTransfers(cacheTopology, addedSegments);
        }
        IntSet transactionOnlySegments = computeTransactionOnlySegments(cacheTopology, address);
        return handleSegments(startStateTransfer, addedSegments, removedSegments, transactionOnlySegments);
    });
    stage = stage.thenCompose(ignored -> {
        int stateTransferTopologyId = this.stateTransferTopologyId.get();
        if (log.isTraceEnabled())
            log.tracef("Topology update processed, stateTransferTopologyId = %d, startRebalance = %s, pending CH = %s", (Object) stateTransferTopologyId, startStateTransfer, cacheTopology.getPendingCH());
        if (stateTransferTopologyId != NO_STATE_TRANSFER_IN_PROGRESS && !startStateTransfer && !cacheTopology.getPhase().isRebalance()) {
            // we have received a topology update without a pending CH, signalling the end of the rebalance
            boolean changed = this.stateTransferTopologyId.compareAndSet(stateTransferTopologyId, NO_STATE_TRANSFER_IN_PROGRESS);
            // but we only want to notify the @DataRehashed listeners once
            if (changed) {
                stopApplyingState(stateTransferTopologyId);
                if (cacheNotifier.hasListener(DataRehashed.class)) {
                    return cacheNotifier.notifyDataRehashed(previousCacheTopology.getCurrentCH(), previousCacheTopology.getPendingCH(), previousCacheTopology.getUnionCH(), cacheTopology.getTopologyId(), false);
                }
            }
        }
        return CompletableFutures.completedNull();
    });
    return handleAndCompose(stage, (ignored, throwable) -> {
        if (log.isTraceEnabled()) {
            log.tracef("Unlock State Transfer in Progress for topology ID %s", cacheTopology.getTopologyId());
        }
        stateTransferLock.notifyTransactionDataReceived(cacheTopology.getTopologyId());
        inboundInvocationHandler.checkForReadyTasks();
        // Only set the flag here, after all the transfers have been added to the transfersBySource map
        if (stateTransferTopologyId.get() != NO_STATE_TRANSFER_IN_PROGRESS && isMember) {
            waitingForState.set(true);
        }
        notifyEndOfStateTransferIfNeeded();
        // and after notifyTransactionDataReceived - otherwise the RollbackCommands would block.
        try {
            if (transactionTable != null) {
                transactionTable.cleanupLeaverTransactions(rpcManager.getTransport().getMembers());
            }
        } catch (Exception e) {
            // Do not fail state transfer when the cleanup fails. See ISPN-7437 for details.
            log.transactionCleanupError(e);
        }
        commandAckCollector.onMembersChange(newWriteCh.getMembers());
        // and STABLE does not have to be confirmed at all
        switch(cacheTopology.getPhase()) {
            case READ_ALL_WRITE_ALL:
            case READ_NEW_WRITE_ALL:
                stateTransferFuture.complete(null);
        }
        // and the other partition was available) or when L1 is enabled.
        if ((isMember || wasMember) && cacheTopology.getPhase() == CacheTopology.Phase.NO_REBALANCE) {
            int numSegments = newWriteCh.getNumSegments();
            IntSet removedSegments = IntSets.mutableEmptySet(numSegments);
            IntSet newSegments = getOwnedSegments(newWriteCh);
            for (int i = 0; i < numSegments; ++i) {
                if (!newSegments.contains(i)) {
                    removedSegments.set(i);
                }
            }
            return removeStaleData(removedSegments).thenApply(ignored1 -> {
                conflictManager.restartVersionRequests();
                // rethrow the original exception, if any
                CompletableFutures.rethrowExceptionIfPresent(throwable);
                return stateTransferFuture;
            });
        }
        CompletableFutures.rethrowExceptionIfPresent(throwable);
        return CompletableFuture.completedFuture(stateTransferFuture);
    });
}
Also used : ComponentName(org.infinispan.factories.annotations.ComponentName) CacheNotFoundResponse(org.infinispan.remoting.responses.CacheNotFoundResponse) LogFactory(org.infinispan.util.logging.LogFactory) Cache(org.infinispan.Cache) Scopes(org.infinispan.factories.scopes.Scopes) Map(java.util.Map) SKIP_SHARED_CACHE_STORE(org.infinispan.context.Flag.SKIP_SHARED_CACHE_STORE) Transaction(javax.transaction.Transaction) ConsistentHash(org.infinispan.distribution.ch.ConsistentHash) CACHE_MODE_LOCAL(org.infinispan.context.Flag.CACHE_MODE_LOCAL) Set(java.util.Set) CacheTopology(org.infinispan.topology.CacheTopology) IntSet(org.infinispan.commons.util.IntSet) CompletionStage(java.util.concurrent.CompletionStage) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) FakeJTATransaction(org.infinispan.transaction.impl.FakeJTATransaction) CacheTransaction(org.infinispan.transaction.xa.CacheTransaction) TriangleOrderManager(org.infinispan.distribution.TriangleOrderManager) InternalCacheEntry(org.infinispan.container.entries.InternalCacheEntry) PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) CommandAckCollector(org.infinispan.util.concurrent.CommandAckCollector) EnumUtil(org.infinispan.commons.util.EnumUtil) ArrayList(java.util.ArrayList) Start(org.infinispan.factories.annotations.Start) PassthroughSingleResponseCollector(org.infinispan.remoting.transport.impl.PassthroughSingleResponseCollector) PRIVATE(org.infinispan.persistence.manager.PersistenceManager.AccessMode.PRIVATE) Configurations(org.infinispan.configuration.cache.Configurations) SingleResponseCollector(org.infinispan.remoting.transport.impl.SingleResponseCollector) Address(org.infinispan.remoting.transport.Address) InvocationContextFactory(org.infinispan.context.InvocationContextFactory) SKIP_OWNERSHIP_CHECK(org.infinispan.context.Flag.SKIP_OWNERSHIP_CHECK) Executor(java.util.concurrent.Executor) RollbackCommand(org.infinispan.commands.tx.RollbackCommand) ClusterListenerReplicateCallable(org.infinispan.notifications.cachelistener.cluster.ClusterListenerReplicateCallable) Publisher(org.reactivestreams.Publisher) ValidResponse(org.infinispan.remoting.responses.ValidResponse) CacheNotifier(org.infinispan.notifications.cachelistener.CacheNotifier) InternalConflictManager(org.infinispan.conflict.impl.InternalConflictManager) Inject(org.infinispan.factories.annotations.Inject) AtomicLong(java.util.concurrent.atomic.AtomicLong) InvalidateCommand(org.infinispan.commands.write.InvalidateCommand) GlobalTransaction(org.infinispan.transaction.xa.GlobalTransaction) DistributionManager(org.infinispan.distribution.DistributionManager) AggregateCompletionStage(org.infinispan.util.concurrent.AggregateCompletionStage) IntSets(org.infinispan.commons.util.IntSets) Stop(org.infinispan.factories.annotations.Stop) InvocationContext(org.infinispan.context.InvocationContext) LocalTxInvocationContext(org.infinispan.context.impl.LocalTxInvocationContext) ComponentRef(org.infinispan.factories.impl.ComponentRef) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SKIP_REMOTE_LOOKUP(org.infinispan.context.Flag.SKIP_REMOTE_LOOKUP) Scope(org.infinispan.factories.scopes.Scope) PERSISTENCE(org.infinispan.util.logging.Log.PERSISTENCE) RpcOptions(org.infinispan.remoting.rpc.RpcOptions) PrepareCommand(org.infinispan.commands.tx.PrepareCommand) CommandsFactory(org.infinispan.commands.CommandsFactory) CompletionStages.handleAndCompose(org.infinispan.util.concurrent.CompletionStages.handleAndCompose) Predicate(java.util.function.Predicate) LocalPublisherManager(org.infinispan.reactive.publisher.impl.LocalPublisherManager) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LockingMode(org.infinispan.transaction.LockingMode) List(java.util.List) PerCacheInboundInvocationHandler(org.infinispan.remoting.inboundhandler.PerCacheInboundInvocationHandler) LocalTransaction(org.infinispan.transaction.impl.LocalTransaction) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand) LocalTopologyManager(org.infinispan.topology.LocalTopologyManager) GuardedBy(net.jcip.annotations.GuardedBy) IGNORE_RETURN_VALUES(org.infinispan.context.Flag.IGNORE_RETURN_VALUES) SKIP_XSITE_BACKUP(org.infinispan.context.Flag.SKIP_XSITE_BACKUP) DataRehashed(org.infinispan.notifications.cachelistener.annotation.DataRehashed) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionStages(org.infinispan.util.concurrent.CompletionStages) PUT_FOR_STATE_TRANSFER(org.infinispan.context.Flag.PUT_FOR_STATE_TRANSFER) HashSet(java.util.HashSet) FlagBitSets(org.infinispan.context.impl.FlagBitSets) InternalMetadataImpl(org.infinispan.metadata.impl.InternalMetadataImpl) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) IRAC_STATE(org.infinispan.context.Flag.IRAC_STATE) Log(org.infinispan.util.logging.Log) Response(org.infinispan.remoting.responses.Response) Flowable(io.reactivex.rxjava3.core.Flowable) Iterator(java.util.Iterator) InternalDataContainer(org.infinispan.container.impl.InternalDataContainer) RpcManager(org.infinispan.remoting.rpc.RpcManager) TransactionMode(org.infinispan.transaction.TransactionMode) Completable(io.reactivex.rxjava3.core.Completable) NON_BLOCKING_EXECUTOR(org.infinispan.factories.KnownComponentNames.NON_BLOCKING_EXECUTOR) CompletionStages.ignoreValue(org.infinispan.util.concurrent.CompletionStages.ignoreValue) PrimitiveIterator(java.util.PrimitiveIterator) TimeUnit(java.util.concurrent.TimeUnit) IllegalLifecycleStateException(org.infinispan.commons.IllegalLifecycleStateException) CacheRpcCommand(org.infinispan.commands.remote.CacheRpcCommand) XSiteStateTransferManager(org.infinispan.xsite.statetransfer.XSiteStateTransferManager) SKIP_LOCKING(org.infinispan.context.Flag.SKIP_LOCKING) RemoteTransaction(org.infinispan.transaction.impl.RemoteTransaction) Configuration(org.infinispan.configuration.cache.Configuration) DistributionInfo(org.infinispan.distribution.DistributionInfo) DeliverOrder(org.infinispan.remoting.inboundhandler.DeliverOrder) TransactionManager(javax.transaction.TransactionManager) Collections(java.util.Collections) TransactionTable(org.infinispan.transaction.impl.TransactionTable) LimitedExecutor(org.infinispan.executors.LimitedExecutor) ConsistentHash(org.infinispan.distribution.ch.ConsistentHash) CompletableFuture(java.util.concurrent.CompletableFuture) CacheTopology(org.infinispan.topology.CacheTopology) Address(org.infinispan.remoting.transport.Address) IntSet(org.infinispan.commons.util.IntSet) DataRehashed(org.infinispan.notifications.cachelistener.annotation.DataRehashed) IllegalLifecycleStateException(org.infinispan.commons.IllegalLifecycleStateException)

Example 2 with Response

use of org.infinispan.remoting.responses.Response in project infinispan by infinispan.

the class ScatteredStateConsumerImpl method backupEntries.

private void backupEntries(List<InternalCacheEntry<?, ?>> entries) {
    long incrementedCounter = chunkCounter.incrementAndGet();
    if (log.isTraceEnabled())
        log.tracef("Backing up entries, chunk counter is %d", incrementedCounter);
    Map<Object, InternalCacheValue<?>> map = new HashMap<>();
    for (InternalCacheEntry<?, ?> entry : entries) {
        map.put(entry.getKey(), entry.toInternalCacheValue());
    }
    PutMapCommand putMapCommand = commandsFactory.buildPutMapCommand(map, null, STATE_TRANSFER_FLAGS);
    putMapCommand.setTopologyId(rpcManager.getTopologyId());
    rpcManager.invokeCommand(backupAddress, putMapCommand, SingleResponseCollector.validOnly(), rpcManager.getSyncRpcOptions()).whenComplete(((response, throwable) -> {
        try {
            if (throwable != null) {
                log.failedOutBoundTransferExecution(throwable);
            }
        } finally {
            long decrementedCounter = chunkCounter.decrementAndGet();
            if (log.isTraceEnabled())
                log.tracef("Backed up entries, chunk counter is %d", decrementedCounter);
            if (decrementedCounter == 0) {
                notifyEndOfStateTransferIfNeeded();
            }
        }
    }));
}
Also used : IntSets(org.infinispan.commons.util.IntSets) LogFactory(org.infinispan.util.logging.LogFactory) EntryVersion(org.infinispan.container.versioning.EntryVersion) RemoteMetadata(org.infinispan.container.entries.RemoteMetadata) ClusteredGetAllCommand(org.infinispan.commands.remote.ClusteredGetAllCommand) CONTAINER(org.infinispan.util.logging.Log.CONTAINER) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) Map(java.util.Map) PERSISTENCE(org.infinispan.util.logging.Log.PERSISTENCE) ConsistentHash(org.infinispan.distribution.ch.ConsistentHash) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BlockingQueue(java.util.concurrent.BlockingQueue) CacheTopology(org.infinispan.topology.CacheTopology) ComponentStatus(org.infinispan.lifecycle.ComponentStatus) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) IntSet(org.infinispan.commons.util.IntSet) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand) InboundTransferTask(org.infinispan.statetransfer.InboundTransferTask) GuardedBy(net.jcip.annotations.GuardedBy) InternalCacheValue(org.infinispan.container.entries.InternalCacheValue) InvalidateVersionsCommand(org.infinispan.commands.write.InvalidateVersionsCommand) InternalCacheEntry(org.infinispan.container.entries.InternalCacheEntry) HashMap(java.util.HashMap) Metadata(org.infinispan.metadata.Metadata) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) MapResponseCollector(org.infinispan.remoting.transport.impl.MapResponseCollector) FlagBitSets(org.infinispan.context.impl.FlagBitSets) InternalMetadataImpl(org.infinispan.metadata.impl.InternalMetadataImpl) Configurations(org.infinispan.configuration.cache.Configurations) SingleResponseCollector(org.infinispan.remoting.transport.impl.SingleResponseCollector) Log(org.infinispan.util.logging.Log) MarshallableEntry(org.infinispan.persistence.spi.MarshallableEntry) Address(org.infinispan.remoting.transport.Address) Response(org.infinispan.remoting.responses.Response) InternalEntryFactory(org.infinispan.container.impl.InternalEntryFactory) CacheException(org.infinispan.commons.CacheException) Flowable(io.reactivex.rxjava3.core.Flowable) Iterator(java.util.Iterator) Publisher(org.reactivestreams.Publisher) PutMapCommand(org.infinispan.commands.write.PutMapCommand) SimpleClusteredVersion(org.infinispan.container.versioning.SimpleClusteredVersion) Inject(org.infinispan.factories.annotations.Inject) StateConsumerImpl(org.infinispan.statetransfer.StateConsumerImpl) PrimitiveIterator(java.util.PrimitiveIterator) AtomicLong(java.util.concurrent.atomic.AtomicLong) CacheRpcCommand(org.infinispan.commands.remote.CacheRpcCommand) Collections(java.util.Collections) ScatteredVersionManager(org.infinispan.scattered.ScatteredVersionManager) SuspectException(org.infinispan.remoting.transport.jgroups.SuspectException) PutMapCommand(org.infinispan.commands.write.PutMapCommand) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) InternalCacheValue(org.infinispan.container.entries.InternalCacheValue)

Example 3 with Response

use of org.infinispan.remoting.responses.Response in project infinispan by infinispan.

the class SingleClusterExecutor method submit.

@Override
public CompletableFuture<Void> submit(Runnable runnable) {
    Address target = findTarget();
    if (target == null) {
        return CompletableFutures.completedExceptionFuture(new SuspectException("No available nodes!"));
    }
    if (log.isTraceEnabled()) {
        log.tracef("Submitting runnable to single remote node - JGroups Address %s", target);
    }
    CompletableFuture<Void> future = new CompletableFuture<>();
    if (target == me) {
        return super.submit(runnable);
    } else {
        ReplicableCommand command = new ReplicableRunnableCommand(runnable);
        CompletionStage<Response> request = transport.invokeCommand(target, command, PassthroughSingleResponseCollector.INSTANCE, DeliverOrder.NONE, time, unit);
        request.whenComplete((r, t) -> {
            if (t != null) {
                future.completeExceptionally(t);
            } else {
                consumeResponse(r, target, future::completeExceptionally);
                future.complete(null);
            }
        });
    }
    return future;
}
Also used : Response(org.infinispan.remoting.responses.Response) CompletableFuture(java.util.concurrent.CompletableFuture) Address(org.infinispan.remoting.transport.Address) ReplicableCommand(org.infinispan.commands.ReplicableCommand) SuspectException(org.infinispan.remoting.transport.jgroups.SuspectException)

Example 4 with Response

use of org.infinispan.remoting.responses.Response in project infinispan by infinispan.

the class RecoveryManagerImpl method forceTransactionCompletionFromCluster.

@Override
public String forceTransactionCompletionFromCluster(XidImpl xid, Address where, boolean commit) {
    CompleteTransactionCommand ctc = commandFactory.buildCompleteTransactionCommand(xid, commit);
    CompletionStage<Map<Address, Response>> completionStage = rpcManager.invokeCommand(where, ctc, MapResponseCollector.validOnly(), rpcManager.getSyncRpcOptions());
    Map<Address, Response> responseMap = rpcManager.blocking(completionStage);
    if (responseMap.size() != 1 || responseMap.get(where) == null) {
        log.expectedJustOneResponse(responseMap);
        throw new CacheException("Expected response size is 1, received " + responseMap);
    }
    // noinspection rawtypes
    return (String) ((SuccessfulResponse) responseMap.get(where)).getResponseValue();
}
Also used : CompleteTransactionCommand(org.infinispan.commands.remote.recovery.CompleteTransactionCommand) Response(org.infinispan.remoting.responses.Response) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) Address(org.infinispan.remoting.transport.Address) CacheException(org.infinispan.commons.CacheException) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Example 5 with Response

use of org.infinispan.remoting.responses.Response in project infinispan by infinispan.

the class RecoveryManagerImpl method getAllPreparedTxFromCluster.

private Map<Address, Response> getAllPreparedTxFromCluster() {
    GetInDoubtTransactionsCommand command = commandFactory.buildGetInDoubtTransactionsCommand();
    CompletionStage<Map<Address, Response>> completionStage = rpcManager.invokeCommandOnAll(command, MapResponseCollector.ignoreLeavers(), rpcManager.getSyncRpcOptions());
    Map<Address, Response> addressResponseMap = rpcManager.blocking(completionStage);
    if (log.isTraceEnabled())
        log.tracef("getAllPreparedTxFromCluster received from cluster: %s", addressResponseMap);
    return addressResponseMap;
}
Also used : Response(org.infinispan.remoting.responses.Response) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) Address(org.infinispan.remoting.transport.Address) GetInDoubtTransactionsCommand(org.infinispan.commands.remote.recovery.GetInDoubtTransactionsCommand) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Aggregations

Response (org.infinispan.remoting.responses.Response)43 Address (org.infinispan.remoting.transport.Address)33 Map (java.util.Map)29 SuccessfulResponse (org.infinispan.remoting.responses.SuccessfulResponse)29 HashMap (java.util.HashMap)21 CacheNotFoundResponse (org.infinispan.remoting.responses.CacheNotFoundResponse)19 UnsureResponse (org.infinispan.remoting.responses.UnsureResponse)14 CompletionStage (java.util.concurrent.CompletionStage)13 CompletableFutures (org.infinispan.util.concurrent.CompletableFutures)13 Log (org.infinispan.util.logging.Log)13 LogFactory (org.infinispan.util.logging.LogFactory)13 List (java.util.List)12 CompletableFuture (java.util.concurrent.CompletableFuture)12 RpcOptions (org.infinispan.remoting.rpc.RpcOptions)12 ArrayList (java.util.ArrayList)11 Collection (java.util.Collection)11 PutKeyValueCommand (org.infinispan.commands.write.PutKeyValueCommand)11 CacheException (org.infinispan.commons.CacheException)11 Collections (java.util.Collections)10 ReplicableCommand (org.infinispan.commands.ReplicableCommand)10