Search in sources :

Example 21 with InvocationStage

use of org.infinispan.interceptors.InvocationStage in project infinispan by infinispan.

the class TxInterceptor method visitCommitCommand.

@Override
public Object visitCommitCommand(@SuppressWarnings("rawtypes") TxInvocationContext ctx, CommitCommand command) throws Throwable {
    // TODO The local origin check is needed for CommitFailsTest, but it doesn't appear correct to roll back an in-doubt tx
    if (!ctx.isOriginLocal()) {
        GlobalTransaction gtx = ctx.getGlobalTransaction();
        if (txTable.isTransactionCompleted(gtx)) {
            if (log.isTraceEnabled())
                log.tracef("Transaction %s already completed, skipping commit", gtx);
            return null;
        }
        InvocationStage replayStage = replayRemoteTransactionIfNeeded((RemoteTxInvocationContext) ctx, command.getTopologyId());
        if (replayStage != null) {
            return replayStage.andHandle(ctx, command, (rCtx, rCommand, rv, t) -> finishCommit((TxInvocationContext<?>) rCtx, rCommand));
        } else {
            return finishCommit(ctx, command);
        }
    }
    return finishCommit(ctx, command);
}
Also used : InvocationStage(org.infinispan.interceptors.InvocationStage) LocalTxInvocationContext(org.infinispan.context.impl.LocalTxInvocationContext) TxInvocationContext(org.infinispan.context.impl.TxInvocationContext) RemoteTxInvocationContext(org.infinispan.context.impl.RemoteTxInvocationContext) GlobalTransaction(org.infinispan.transaction.xa.GlobalTransaction)

Example 22 with InvocationStage

use of org.infinispan.interceptors.InvocationStage 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)

Example 23 with InvocationStage

use of org.infinispan.interceptors.InvocationStage in project infinispan by infinispan.

the class VersionedEntryWrappingInterceptor method prepareHandler.

private Object prepareHandler(InvocationContext nonTxCtx, VersionedPrepareCommand command, Object nil) {
    TxInvocationContext<?> ctx = (TxInvocationContext<?>) nonTxCtx;
    CompletionStage<Map<Object, IncrementableEntryVersion>> originVersionData;
    if (ctx.getCacheTransaction().isFromStateTransfer()) {
        storeEntryVersionForStateTransfer(ctx);
        originVersionData = CompletableFutures.completedNull();
    } else if (ctx.isOriginLocal()) {
        originVersionData = checkWriteSkew(ctx, command);
    } else {
        originVersionData = CompletableFutures.completedNull();
    }
    InvocationStage originVersionStage = makeStage(asyncInvokeNext(ctx, command, originVersionData));
    InvocationStage newVersionStage = originVersionStage.thenApplyMakeStage(ctx, command, (rCtx, rCommand, rv) -> {
        CompletionStage<Map<Object, IncrementableEntryVersion>> stage = rCtx.isOriginLocal() ? originVersionData : checkWriteSkew((TxInvocationContext<?>) rCtx, rCommand);
        return asyncValue(stage.thenApply(vMap -> mergeInPrepareResponse(vMap, asPrepareResponse(rv))));
    });
    return newVersionStage.thenApply(ctx, command, afterPrepareHandler);
}
Also used : PrepareCommand(org.infinispan.commands.tx.PrepareCommand) WriteCommand(org.infinispan.commands.write.WriteCommand) IncrementableEntryVersion(org.infinispan.container.versioning.IncrementableEntryVersion) CacheEntry(org.infinispan.container.entries.CacheEntry) LogFactory(org.infinispan.util.logging.LogFactory) VersionGenerator(org.infinispan.container.versioning.VersionGenerator) VersionedCommitCommand(org.infinispan.commands.tx.VersionedCommitCommand) WriteSkewHelper.mergeInPrepareResponse(org.infinispan.transaction.impl.WriteSkewHelper.mergeInPrepareResponse) CommitCommand(org.infinispan.commands.tx.CommitCommand) VersionedPrepareCommand(org.infinispan.commands.tx.VersionedPrepareCommand) Inject(org.infinispan.factories.annotations.Inject) InvocationSuccessFunction(org.infinispan.interceptors.InvocationSuccessFunction) PrepareResponse.asPrepareResponse(org.infinispan.remoting.responses.PrepareResponse.asPrepareResponse) InvocationContext(org.infinispan.context.InvocationContext) CompletionStage(java.util.concurrent.CompletionStage) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) Flag(org.infinispan.context.Flag) TxInvocationContext(org.infinispan.context.impl.TxInvocationContext) Map(java.util.Map) Log(org.infinispan.util.logging.Log) PrivateMetadata(org.infinispan.metadata.impl.PrivateMetadata) InvocationStage(org.infinispan.interceptors.InvocationStage) InvocationFinallyFunction(org.infinispan.interceptors.InvocationFinallyFunction) FlagAffectedCommand(org.infinispan.commands.FlagAffectedCommand) InvocationStage(org.infinispan.interceptors.InvocationStage) TxInvocationContext(org.infinispan.context.impl.TxInvocationContext) Map(java.util.Map)

Example 24 with InvocationStage

use of org.infinispan.interceptors.InvocationStage in project infinispan by infinispan.

the class AbstractLockingInterceptor method visitNonTxDataWriteCommand.

// We need this method in here because of putForExternalRead
final Object visitNonTxDataWriteCommand(InvocationContext ctx, DataWriteCommand command) {
    // Non-tx invalidation mode ignores the primary owner, always locks on the originator
    boolean shouldLockKey = invalidationMode ? ctx.isOriginLocal() : shouldLockKey(command);
    if (hasSkipLocking(command) || !shouldLockKey) {
        return invokeNext(ctx, command);
    }
    InvocationStage lockStage = lockAndRecord(ctx, command, command.getKey(), getLockTimeoutMillis(command));
    return nonTxLockAndInvokeNext(ctx, command, lockStage, unlockAllReturnHandler);
}
Also used : InvocationStage(org.infinispan.interceptors.InvocationStage)

Example 25 with InvocationStage

use of org.infinispan.interceptors.InvocationStage in project infinispan by infinispan.

the class ProtobufMetadataManagerInterceptor method updateSchemaErrorsIterator.

private InvocationStage updateSchemaErrorsIterator(InvocationContext ctx, long flagsBitSet, Iterator<KeyValuePair<String, String>> iterator) {
    if (!iterator.hasNext())
        return InvocationStage.completedNullStage();
    KeyValuePair<String, String> keyErrorPair = iterator.next();
    Object errorsKey = keyErrorPair.getKey() + ERRORS_KEY_SUFFIX;
    String errorsValue = keyErrorPair.getValue();
    int segment = keyPartitioner.getSegment(errorsKey);
    WriteCommand writeCommand;
    if (errorsValue == null) {
        writeCommand = commandsFactory.buildRemoveCommand(errorsKey, null, segment, flagsBitSet);
    } else {
        PutKeyValueCommand put = commandsFactory.buildPutKeyValueCommand(errorsKey, errorsValue, segment, DEFAULT_METADATA, flagsBitSet);
        put.setPutIfAbsent(true);
        writeCommand = put;
    }
    InvocationStage stage = invoker.running().invokeStage(ctx, writeCommand);
    return stage.thenApplyMakeStage(ctx, writeCommand, (rCtx, rCommand, rv) -> updateSchemaErrorsIterator(rCtx, flagsBitSet, iterator));
}
Also used : WriteCommand(org.infinispan.commands.write.WriteCommand) InvocationStage(org.infinispan.interceptors.InvocationStage) SyncInvocationStage(org.infinispan.interceptors.SyncInvocationStage) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand)

Aggregations

InvocationStage (org.infinispan.interceptors.InvocationStage)29 TestException (org.infinispan.test.TestException)7 TxInvocationContext (org.infinispan.context.impl.TxInvocationContext)6 SyncInvocationStage (org.infinispan.interceptors.SyncInvocationStage)6 PutKeyValueCommand (org.infinispan.commands.write.PutKeyValueCommand)5 Map (java.util.Map)4 VisitableCommand (org.infinispan.commands.VisitableCommand)4 LockControlCommand (org.infinispan.commands.control.LockControlCommand)4 PrepareCommand (org.infinispan.commands.tx.PrepareCommand)4 PutMapCommand (org.infinispan.commands.write.PutMapCommand)4 RemoveCommand (org.infinispan.commands.write.RemoveCommand)4 ReplaceCommand (org.infinispan.commands.write.ReplaceCommand)4 WriteCommand (org.infinispan.commands.write.WriteCommand)4 InvocationContext (org.infinispan.context.InvocationContext)4 KeyValuePair (org.infinispan.util.KeyValuePair)4 FlagAffectedCommand (org.infinispan.commands.FlagAffectedCommand)3 CommitCommand (org.infinispan.commands.tx.CommitCommand)3 CacheEntry (org.infinispan.container.entries.CacheEntry)3 FlagBitSets (org.infinispan.context.impl.FlagBitSets)3 Inject (org.infinispan.factories.annotations.Inject)3