use of org.infinispan.interceptors.InvocationStage in project infinispan by infinispan.
the class OptimisticLockingInterceptor method visitPrepareCommand.
@Override
public Object visitPrepareCommand(TxInvocationContext ctx, PrepareCommand command) throws Throwable {
final Collection<?> keysToLock = command.getKeysToLock();
InvocationStage lockStage = InvocationStage.completedNullStage();
((TxInvocationContext<?>) ctx).addAllAffectedKeys(command.getAffectedKeys());
if (!keysToLock.isEmpty()) {
if (command.isRetriedCommand()) {
// Don't keep backup locks if the local node is the primary owner in the current topology
// The lock/prepare command is being retried, so it's not a "pending" transaction
// However, keep the backup locks if the prepare command is being replayed because of state transfer
ctx.getCacheTransaction().cleanupBackupLocks();
}
lockStage = lockAllOrRegisterBackupLock(ctx, command, keysToLock, command.hasZeroLockAcquisition() ? 0 : cacheConfiguration.locking().lockAcquisitionTimeout());
}
if (command.isOnePhaseCommit()) {
return lockStage.thenApply(ctx, command, onePhaseCommitFunction);
} else {
return asyncInvokeNext(ctx, command, lockStage);
}
}
use of org.infinispan.interceptors.InvocationStage in project infinispan by infinispan.
the class ProtobufMetadataManagerInterceptor method visitPutMapCommand.
@Override
public Object visitPutMapCommand(InvocationContext ctx, PutMapCommand command) {
if (!ctx.isOriginLocal()) {
return invokeNext(ctx, command);
}
final Map<Object, Object> map = command.getMap();
FileDescriptorSource source = new FileDescriptorSource();
for (Object key : map.keySet()) {
final Object value = map.get(key);
if (!(key instanceof String)) {
throw log.keyMustBeString(key.getClass());
}
if (!(value instanceof String)) {
throw log.valueMustBeString(value.getClass());
}
if (shouldIntercept(key)) {
if (!((String) key).endsWith(PROTO_KEY_SUFFIX)) {
throw log.keyMustBeStringEndingWithProto(key);
}
source.addProtoFile((String) key, (String) value);
}
}
// lock global errors key
VisitableCommand cmd = commandsFactory.buildLockControlCommand(ERRORS_KEY_SUFFIX, command.getFlagsBitSet(), null);
InvocationStage stage = invoker.running().invokeStage(ctx, cmd);
return makeStage(asyncInvokeNext(ctx, command, stage)).thenApply(ctx, command, (rCtx, rCommand, rv) -> {
long flagsBitSet = copyFlags(rCommand);
ProgressCallback progressCallback = null;
if (rCtx.isOriginLocal()) {
progressCallback = new ProgressCallback();
source.withProgressCallback(progressCallback);
} else {
source.withProgressCallback(EMPTY_CALLBACK);
}
registerFileDescriptorSource(source, source.getFiles().keySet().toString());
if (progressCallback != null) {
List<KeyValuePair<String, String>> errorUpdates = computeErrorUpdates(progressCallback);
return updateSchemaErrorsIterator(rCtx, flagsBitSet, errorUpdates.iterator());
}
return InvocationStage.completedNullStage();
});
}
use of org.infinispan.interceptors.InvocationStage 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.interceptors.InvocationStage in project infinispan by infinispan.
the class CacheMgmtInterceptorTest method testVisitGetCacheEntryCommand.
public void testVisitGetCacheEntryCommand() throws Throwable {
GetCacheEntryCommand command = new GetCacheEntryCommand(KEY, 0, 0);
InvocationStage stage = makeStage(interceptor.visitGetCacheEntryCommand(ctx, command));
assertFalse(stage.isDone());
timeService.advance(1);
nextInterceptor.completeLastInvocation(null);
assertNull(stage.get());
assertEquals(1, interceptor.getAverageReadTime());
}
use of org.infinispan.interceptors.InvocationStage in project infinispan by infinispan.
the class CacheMgmtInterceptorTest method testVisitPutKeyValueCommandException.
public void testVisitPutKeyValueCommandException() throws Throwable {
PutKeyValueCommand command = new PutKeyValueCommand(KEY, VALUE, false, null, 0, 0, null);
InvocationStage stage = makeStage(interceptor.visitPutKeyValueCommand(ctx, command));
assertFalse(stage.isDone());
timeService.advance(1);
nextInterceptor.completeLastInvocationExceptionally(new TestException());
expectInvocationException(stage);
assertEquals(1, interceptor.getAverageWriteTime());
}
Aggregations