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);
}
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);
}
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);
}
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);
}
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));
}
Aggregations