use of org.infinispan.transaction.impl.AbstractCacheTransaction in project infinispan by infinispan.
the class VersionedDistributionInterceptor method unwrapFunctionalResultOnOrigin.
@Override
protected Object unwrapFunctionalResultOnOrigin(InvocationContext ctx, Object key, Object responseValue) {
VersionedResult vr = (VersionedResult) responseValue;
// As an optimization, read-only single-key commands are executed in SingleKeyNonTxInvocationContext
if (ctx.isInTxScope()) {
AbstractCacheTransaction tx = ((TxInvocationContext) ctx).getCacheTransaction();
checkAndAddReadVersion(tx, key, vr.version);
}
return vr.result;
}
use of org.infinispan.transaction.impl.AbstractCacheTransaction in project infinispan by infinispan.
the class AbstractTxLockingInterceptor method lockAllOrRegisterBackupLock.
/**
* Same as {@link #lockOrRegisterBackupLock(TxInvocationContext, VisitableCommand, Object, long)}
*
* @return a collection with the keys locked.
*/
final InvocationStage lockAllOrRegisterBackupLock(TxInvocationContext<?> ctx, VisitableCommand command, Collection<?> keys, long lockTimeout) {
if (keys.isEmpty()) {
return InvocationStage.completedNullStage();
}
Collection<Object> keysToLock = new ArrayList<>(keys.size());
AbstractCacheTransaction cacheTransaction = ctx.getCacheTransaction();
LocalizedCacheTopology cacheTopology = cdl.getCacheTopology();
for (Object key : keys) {
// Skip keys that are already locked (when retrying a lock/prepare command)
if (cacheTransaction.ownsLock(key))
continue;
switch(cacheTopology.getDistribution(key).writeOwnership()) {
case PRIMARY:
keysToLock.add(key);
break;
case BACKUP:
cacheTransaction.addBackupLockForKey(key);
break;
default:
break;
}
}
if (keysToLock.isEmpty()) {
return InvocationStage.completedNullStage();
}
return checkPendingAndLockAllKeys(ctx, command, keysToLock, lockTimeout);
}
use of org.infinispan.transaction.impl.AbstractCacheTransaction in project infinispan by infinispan.
the class TxQueryInterceptor method commitModificationsToIndexFuture.
private InvocationStage commitModificationsToIndexFuture(InvocationContext ctx, VisitableCommand cmd, Object rv) {
TxInvocationContext txCtx = (TxInvocationContext) ctx;
Map<Object, Object> removed = txOldValues.remove(txCtx.getGlobalTransaction());
final Map<Object, Object> oldValues = removed == null ? Collections.emptyMap() : removed;
AbstractCacheTransaction transaction = txCtx.getCacheTransaction();
return asyncValue(CompletableFuture.allOf(transaction.getAllModifications().stream().filter(mod -> !mod.hasAnyFlag(FlagBitSets.SKIP_INDEXING)).flatMap(mod -> mod.getAffectedKeys().stream()).map(key -> {
CacheEntry<?, ?> entry = txCtx.lookupEntry(key);
if (entry != null) {
Object oldValue = oldValues.getOrDefault(key, QueryInterceptor.UNKNOWN);
return queryInterceptor.processChange(ctx, null, key, oldValue, entry.getValue());
}
return CompletableFutures.completedNull();
}).toArray(CompletableFuture[]::new)));
}
use of org.infinispan.transaction.impl.AbstractCacheTransaction in project infinispan by infinispan.
the class VersionedDistributionInterceptor method wrapRemoteEntry.
@Override
protected void wrapRemoteEntry(InvocationContext ctx, Object key, CacheEntry ice, boolean isWrite) {
if (ctx.isInTxScope()) {
AbstractCacheTransaction cacheTransaction = ((TxInvocationContext<?>) ctx).getCacheTransaction();
EntryVersion seenVersion = cacheTransaction.getVersionsRead().get(key);
if (seenVersion != null) {
IncrementableEntryVersion newVersion = versionFromEntry(ice);
if (newVersion == null) {
throw new IllegalStateException("Wrapping entry without version");
}
if (seenVersion.compareTo(newVersion) != InequalVersionComparisonResult.EQUAL) {
if (ctx.lookupEntry(key) == null) {
// the full entry, but we cannot provide the same version as the already read one.
throw CONTAINER.writeSkewOnRead(key, key, seenVersion, newVersion);
} else {
// We can safely ignore the newly fetched value.
return;
}
}
}
}
super.wrapRemoteEntry(ctx, key, ice, isWrite);
}
use of org.infinispan.transaction.impl.AbstractCacheTransaction in project infinispan by infinispan.
the class CacheWriterInterceptor method commitModifications.
protected InvocationStage commitModifications(TxInvocationContext<AbstractCacheTransaction> ctx) throws Throwable {
List<WriteCommand> allModifications = ctx.getCacheTransaction().getAllModifications();
if (!allModifications.isEmpty()) {
GlobalTransaction tx = ctx.getGlobalTransaction();
if (log.isTraceEnabled())
getLog().tracef("Persisting transaction %s modifications: %s", tx, allModifications);
Transaction xaTx = null;
try {
xaTx = suspendRunningTx(ctx);
return store(ctx);
} finally {
resumeRunningTx(xaTx);
}
} else {
return null;
}
}
Aggregations