Search in sources :

Example 1 with TransactionBoundaryCommand

use of org.infinispan.commands.tx.TransactionBoundaryCommand in project infinispan by infinispan.

the class TransactionSynchronizerInterceptor method visitCommand.

@Override
public Object visitCommand(InvocationContext ctx, VisitableCommand command) throws Throwable {
    if (ctx.isOriginLocal() || !(command instanceof TransactionBoundaryCommand)) {
        return invokeNext(ctx, command);
    }
    CompletableFuture<Void> releaseFuture = new CompletableFuture<>();
    RemoteTransaction remoteTransaction = ((TxInvocationContext<RemoteTransaction>) ctx).getCacheTransaction();
    Object result = asyncInvokeNext(ctx, command, remoteTransaction.enterSynchronizationAsync(releaseFuture));
    return makeStage(result).andFinally(ctx, command, (rCtx, rCommand, rv, t) -> {
        log.tracef("Completing tx command release future for %s", remoteTransaction);
        releaseFuture.complete(null);
    });
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RemoteTransaction(org.infinispan.transaction.impl.RemoteTransaction) TransactionBoundaryCommand(org.infinispan.commands.tx.TransactionBoundaryCommand) TxInvocationContext(org.infinispan.context.impl.TxInvocationContext)

Example 2 with TransactionBoundaryCommand

use of org.infinispan.commands.tx.TransactionBoundaryCommand in project infinispan by infinispan.

the class PartitionHandlingManagerImpl method completeTransaction.

private void completeTransaction(final TransactionInfo transactionInfo, CacheTopology cacheTopology) {
    List<Address> commitNodes = transactionInfo.getCommitNodes(cacheTopology);
    TransactionBoundaryCommand command = transactionInfo.buildCommand(commandsFactory);
    command.setTopologyId(cacheTopology.getTopologyId());
    CompletionStage<Map<Address, Response>> remoteInvocation = commitNodes != null ? rpcManager.invokeCommand(commitNodes, command, MapResponseCollector.ignoreLeavers(commitNodes.size()), rpcManager.getSyncRpcOptions()) : rpcManager.invokeCommandOnAll(command, MapResponseCollector.ignoreLeavers(), rpcManager.getSyncRpcOptions());
    remoteInvocation.whenComplete((responseMap, throwable) -> {
        final boolean trace = log.isTraceEnabled();
        final GlobalTransaction globalTransaction = transactionInfo.getGlobalTransaction();
        if (throwable != null) {
            log.failedPartitionHandlingTxCompletion(globalTransaction, throwable);
            return;
        }
        if (trace) {
            log.tracef("Future done for transaction %s. Response are %s", globalTransaction, responseMap);
        }
        for (Response response : responseMap.values()) {
            if (response == UnsureResponse.INSTANCE || response == CacheNotFoundResponse.INSTANCE) {
                if (trace) {
                    log.tracef("Topology changed while completing partial transaction %s", globalTransaction);
                }
                return;
            }
        }
        if (trace) {
            log.tracef("Performing cleanup for transaction %s", globalTransaction);
        }
        lockManager.unlockAll(transactionInfo.getLockedKeys(), globalTransaction);
        partialTransactions.remove(globalTransaction);
        TxCompletionNotificationCommand completionCommand = commandsFactory.buildTxCompletionNotificationCommand(null, globalTransaction);
        // A little bit overkill, but the state transfer can happen during a merge and some nodes can receive the
        // transaction that aren't in the original affected nodes.
        // no side effects.
        rpcManager.sendToAll(completionCommand, DeliverOrder.NONE);
    });
}
Also used : CacheNotFoundResponse(org.infinispan.remoting.responses.CacheNotFoundResponse) UnsureResponse(org.infinispan.remoting.responses.UnsureResponse) Response(org.infinispan.remoting.responses.Response) Address(org.infinispan.remoting.transport.Address) TransactionBoundaryCommand(org.infinispan.commands.tx.TransactionBoundaryCommand) TxCompletionNotificationCommand(org.infinispan.commands.remote.recovery.TxCompletionNotificationCommand) GlobalTransaction(org.infinispan.transaction.xa.GlobalTransaction) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 3 with TransactionBoundaryCommand

use of org.infinispan.commands.tx.TransactionBoundaryCommand in project infinispan by infinispan.

the class GlobalTxTable method onTransactionDecision.

private void onTransactionDecision(CacheXid cacheXid, TxState state, boolean commit) {
    ComponentRegistry cr = gcr.getNamedComponentRegistry(cacheXid.getCacheName());
    if (cr == null) {
        // we don't have the cache locally
        return;
    }
    RpcManager rpcManager = cr.getComponent(RpcManager.class);
    if (rpcManager == null || state.getOriginator().equals(rpcManager.getAddress())) {
        // local
        PerCacheTxTable txTable = cr.getComponent(PerCacheTxTable.class);
        EmbeddedTransaction tx = txTable.getLocalTx(cacheXid.getXid());
        if (tx == null) {
            // transaction completed
            onTransactionCompleted(cacheXid);
        } else {
            blockingManager.runBlocking(() -> completeLocal(txTable, cacheXid, tx, commit), cacheXid);
        }
    } else {
        if (commit) {
            TransactionBoundaryCommand rpcCommand;
            if (cr.getComponent(Configuration.class).transaction().lockingMode() == LockingMode.PESSIMISTIC) {
                rpcCommand = cr.getCommandsFactory().buildPrepareCommand(state.getGlobalTransaction(), state.getModifications(), true);
            } else {
                rpcCommand = cr.getCommandsFactory().buildCommitCommand(state.getGlobalTransaction());
            }
            rpcCommand.setTopologyId(rpcManager.getTopologyId());
            rpcManager.invokeCommandOnAll(rpcCommand, VoidResponseCollector.validOnly(), rpcManager.getSyncRpcOptions()).handle((aVoid, throwable) -> {
                // TODO?
                TxFunction function = new SetCompletedTransactionFunction(true);
                rwMap.eval(cacheXid, function);
                return null;
            });
        } else {
            rollbackRemote(cr, cacheXid, state);
        }
    }
}
Also used : EmbeddedTransaction(org.infinispan.transaction.tm.EmbeddedTransaction) RpcManager(org.infinispan.remoting.rpc.RpcManager) TransactionBoundaryCommand(org.infinispan.commands.tx.TransactionBoundaryCommand) Configuration(org.infinispan.configuration.cache.Configuration) SetCompletedTransactionFunction(org.infinispan.server.hotrod.tx.table.functions.SetCompletedTransactionFunction) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry) ComponentRegistry(org.infinispan.factories.ComponentRegistry) TxFunction(org.infinispan.server.hotrod.tx.table.functions.TxFunction)

Example 4 with TransactionBoundaryCommand

use of org.infinispan.commands.tx.TransactionBoundaryCommand in project infinispan by infinispan.

the class TxDistributionInterceptor method handleSecondPhaseCommand.

private Object handleSecondPhaseCommand(TxInvocationContext ctx, TransactionBoundaryCommand command) {
    if (shouldInvokeRemoteTxCommand(ctx)) {
        Collection<Address> recipients = getCommitNodes(ctx, command);
        CompletionStage<Map<Address, Response>> remoteInvocation;
        if (recipients != null) {
            MapResponseCollector collector = MapResponseCollector.ignoreLeavers(recipients.size());
            remoteInvocation = rpcManager.invokeCommand(recipients, command, collector, rpcManager.getSyncRpcOptions());
        } else {
            MapResponseCollector collector = MapResponseCollector.ignoreLeavers();
            remoteInvocation = rpcManager.invokeCommandOnAll(command, collector, rpcManager.getSyncRpcOptions());
        }
        InvocationStage remoteResponse = asyncValue(remoteInvocation.thenAccept(responses -> checkTxCommandResponses(responses, command, ctx, recipients, null)));
        return invokeNextThenApply(ctx, command, remoteResponse::thenReturn);
    }
    return invokeNext(ctx, command);
}
Also used : WriteCommand(org.infinispan.commands.write.WriteCommand) Arrays(java.util.Arrays) CacheNotFoundResponse(org.infinispan.remoting.responses.CacheNotFoundResponse) LogFactory(org.infinispan.util.logging.LogFactory) BiFunction(java.util.function.BiFunction) ReplaceCommand(org.infinispan.commands.write.ReplaceCommand) UnsureResponse(org.infinispan.remoting.responses.UnsureResponse) VersionedCommitCommand(org.infinispan.commands.tx.VersionedCommitCommand) EntryView(org.infinispan.functional.EntryView) InvocationContext(org.infinispan.context.InvocationContext) LocalTxInvocationContext(org.infinispan.context.impl.LocalTxInvocationContext) PrepareResponse(org.infinispan.remoting.responses.PrepareResponse) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) TxInvocationContext(org.infinispan.context.impl.TxInvocationContext) RemoveExpiredCommand(org.infinispan.commands.write.RemoveExpiredCommand) OutdatedTopologyException(org.infinispan.statetransfer.OutdatedTopologyException) Map(java.util.Map) TxReadOnlyKeyCommand(org.infinispan.commands.functional.TxReadOnlyKeyCommand) TxReadOnlyManyCommand(org.infinispan.commands.functional.TxReadOnlyManyCommand) RpcOptions(org.infinispan.remoting.rpc.RpcOptions) PrepareCommand(org.infinispan.commands.tx.PrepareCommand) RemoveCommand(org.infinispan.commands.write.RemoveCommand) CommandsFactory(org.infinispan.commands.CommandsFactory) Collection(java.util.Collection) ReadWriteManyEntriesCommand(org.infinispan.commands.functional.ReadWriteManyEntriesCommand) ReadWriteKeyValueCommand(org.infinispan.commands.functional.ReadWriteKeyValueCommand) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) LocalTransaction(org.infinispan.transaction.impl.LocalTransaction) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand) DataConversion(org.infinispan.encoding.DataConversion) PartitionHandlingManager(org.infinispan.partitionhandling.impl.PartitionHandlingManager) InvocationStage(org.infinispan.interceptors.InvocationStage) FlagAffectedCommand(org.infinispan.commands.FlagAffectedCommand) TopologyAffectedCommand(org.infinispan.commands.TopologyAffectedCommand) WriteSkewHelper.mergePrepareResponses(org.infinispan.transaction.impl.WriteSkewHelper.mergePrepareResponses) ComputeCommand(org.infinispan.commands.write.ComputeCommand) EntryViews(org.infinispan.functional.impl.EntryViews) HashMap(java.util.HashMap) TransactionBoundaryCommand(org.infinispan.commands.tx.TransactionBoundaryCommand) CompletionStages(org.infinispan.util.concurrent.CompletionStages) Mutation(org.infinispan.commands.functional.Mutation) ReadOnlyKeyCommand(org.infinispan.commands.functional.ReadOnlyKeyCommand) ArrayList(java.util.ArrayList) WriteOnlyManyEntriesCommand(org.infinispan.commands.functional.WriteOnlyManyEntriesCommand) MapResponseCollector(org.infinispan.remoting.transport.impl.MapResponseCollector) FlagBitSets(org.infinispan.context.impl.FlagBitSets) AbstractDataWriteCommand(org.infinispan.commands.write.AbstractDataWriteCommand) IracPutKeyValueCommand(org.infinispan.commands.write.IracPutKeyValueCommand) Log(org.infinispan.util.logging.Log) SegmentSpecificCommand(org.infinispan.commands.SegmentSpecificCommand) LockControlCommand(org.infinispan.commands.control.LockControlCommand) ValueMatcher(org.infinispan.commands.write.ValueMatcher) Address(org.infinispan.remoting.transport.Address) IncrementableEntryVersion(org.infinispan.container.versioning.IncrementableEntryVersion) Response(org.infinispan.remoting.responses.Response) Iterator(java.util.Iterator) CacheEntry(org.infinispan.container.entries.CacheEntry) WriteOnlyKeyValueCommand(org.infinispan.commands.functional.WriteOnlyKeyValueCommand) RollbackCommand(org.infinispan.commands.tx.RollbackCommand) WriteOnlyManyCommand(org.infinispan.commands.functional.WriteOnlyManyCommand) PutMapCommand(org.infinispan.commands.write.PutMapCommand) CommitCommand(org.infinispan.commands.tx.CommitCommand) Inject(org.infinispan.factories.annotations.Inject) FunctionalCommand(org.infinispan.commands.functional.FunctionalCommand) ReadOnlyManyCommand(org.infinispan.commands.functional.ReadOnlyManyCommand) MVCCEntry(org.infinispan.container.entries.MVCCEntry) ReadWriteKeyCommand(org.infinispan.commands.functional.ReadWriteKeyCommand) ComputeIfAbsentCommand(org.infinispan.commands.write.ComputeIfAbsentCommand) LocalizedCacheTopology(org.infinispan.distribution.LocalizedCacheTopology) GlobalTransaction(org.infinispan.transaction.xa.GlobalTransaction) DistributionInfo(org.infinispan.distribution.DistributionInfo) WriteOnlyKeyCommand(org.infinispan.commands.functional.WriteOnlyKeyCommand) VisitableCommand(org.infinispan.commands.VisitableCommand) ReadWriteManyCommand(org.infinispan.commands.functional.ReadWriteManyCommand) Collections(java.util.Collections) InvocationStage(org.infinispan.interceptors.InvocationStage) Address(org.infinispan.remoting.transport.Address) Map(java.util.Map) HashMap(java.util.HashMap) MapResponseCollector(org.infinispan.remoting.transport.impl.MapResponseCollector)

Aggregations

TransactionBoundaryCommand (org.infinispan.commands.tx.TransactionBoundaryCommand)4 Map (java.util.Map)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionStage (java.util.concurrent.CompletionStage)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 BiFunction (java.util.function.BiFunction)1 CommandsFactory (org.infinispan.commands.CommandsFactory)1 FlagAffectedCommand (org.infinispan.commands.FlagAffectedCommand)1 SegmentSpecificCommand (org.infinispan.commands.SegmentSpecificCommand)1 TopologyAffectedCommand (org.infinispan.commands.TopologyAffectedCommand)1 VisitableCommand (org.infinispan.commands.VisitableCommand)1 LockControlCommand (org.infinispan.commands.control.LockControlCommand)1 FunctionalCommand (org.infinispan.commands.functional.FunctionalCommand)1