use of org.infinispan.transaction.impl.FakeJTATransaction in project infinispan by infinispan.
the class PreloadManager method preloadEntry.
private Single<?> preloadEntry(long flags, MarshallableEntry<Object, Object> me, DataConversion keyDataConversion, DataConversion valueDataConversion) {
// CallInterceptor will preserve the timestamps if the metadata is an InternalMetadataImpl instance
InternalMetadataImpl metadata = new InternalMetadataImpl(me.getMetadata(), me.created(), me.lastUsed());
// TODO If the storage media type is application/x-protostream, this will convert to POJOs and back
Object key = keyDataConversion.toStorage(me.getKey());
Object value = valueDataConversion.toStorage(me.getValue());
PutKeyValueCommand cmd = commandsFactory.buildPutKeyValueCommand(key, value, keyPartitioner.getSegment(key), metadata, flags);
cmd.setInternalMetadata(me.getInternalMetadata());
CompletionStage<?> stage;
if (configuration.transaction().transactionMode().isTransactional()) {
try {
Transaction transaction = new FakeJTATransaction();
InvocationContext ctx = invocationContextFactory.createInvocationContext(transaction, false);
LocalTransaction localTransaction = ((LocalTxInvocationContext) ctx).getCacheTransaction();
stage = CompletionStages.handleAndCompose(invocationHelper.invokeAsync(ctx, cmd), (__, t) -> completeTransaction(key, localTransaction, t)).whenComplete((__, t) -> transactionTable.removeLocalTransaction(localTransaction));
} catch (Exception e) {
throw log.problemPreloadingKey(key, e);
}
} else {
stage = invocationHelper.invokeAsync(cmd, 1);
}
// The return value doesn't matter, but it cannot be null
return Completable.fromCompletionStage(stage).toSingleDefault(me);
}
use of org.infinispan.transaction.impl.FakeJTATransaction 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