use of org.infinispan.context.Flag.CACHE_MODE_LOCAL in project infinispan by infinispan.
the class StateConsumerImpl method doApplyState.
private CompletionStage<?> doApplyState(Address sender, int segmentId, Collection<InternalCacheEntry<?, ?>> cacheEntries) {
if (cacheEntries == null || cacheEntries.isEmpty())
return CompletableFutures.completedNull();
if (log.isTraceEnabled())
log.tracef("Applying new state chunk for segment %d of cache %s from node %s: received %d cache entries", segmentId, cacheName, sender, cacheEntries.size());
// CACHE_MODE_LOCAL avoids handling by StateTransferInterceptor and any potential locks in StateTransferLock
boolean transactional = transactionManager != null;
if (transactional) {
Object key = NO_KEY;
Transaction transaction = new FakeJTATransaction();
InvocationContext ctx = icf.createInvocationContext(transaction, false);
LocalTransaction localTransaction = ((LocalTxInvocationContext) ctx).getCacheTransaction();
try {
localTransaction.setStateTransferFlag(PUT_FOR_STATE_TRANSFER);
for (InternalCacheEntry<?, ?> e : cacheEntries) {
key = e.getKey();
CompletableFuture<?> future = invokePut(segmentId, ctx, e);
if (!future.isDone()) {
throw new IllegalStateException("State transfer in-tx put should always be synchronous");
}
}
} catch (Throwable t) {
logApplyException(t, key);
return invokeRollback(localTransaction).handle((rv, t1) -> {
transactionTable.removeLocalTransaction(localTransaction);
if (t1 != null) {
t.addSuppressed(t1);
}
return null;
});
}
return invoke1PCPrepare(localTransaction).whenComplete((rv, t) -> {
transactionTable.removeLocalTransaction(localTransaction);
if (t != null) {
logApplyException(t, NO_KEY);
}
});
} else {
// non-tx cache
AggregateCompletionStage<Void> aggregateStage = CompletionStages.aggregateCompletionStage();
for (InternalCacheEntry<?, ?> e : cacheEntries) {
InvocationContext ctx = icf.createSingleKeyNonTxInvocationContext();
CompletionStage<?> putStage = invokePut(segmentId, ctx, e);
aggregateStage.dependsOn(putStage.exceptionally(t -> {
logApplyException(t, e.getKey());
return null;
}));
}
return aggregateStage.freeze();
}
}
Aggregations