Source:
private CompletionStage<?> doApplyState(Address sender, int segmentId, Collection<InternalCacheEntry> cacheEntries) { if (cacheEntries == null || cacheEntries.isEmpty()) return CompletableFutures.completedNull(); if (trace) log.tracef("Applying new state chunk for segment %d of cache %s from node %s: received %d cache entries", segmentId, cacheName, sender, cacheEntries.size()); boolean transactional = transactionManager != null; if (transactional) { Object key = "N/A"; Transaction transaction = new ApplyStateTransaction(); 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); if (localTransaction != null) { return invokeRollback(localTransaction).handle((rv, t1) -> { transactionTable.removeLocalTransaction(localTransaction); if (t1 != null) { t.addSuppressed(t1); } return null; }); } else { return CompletableFutures.completedNull(); } } return invoke1PCPrepare(localTransaction).whenComplete((rv, t) -> { transactionTable.removeLocalTransaction(localTransaction); if (t != null) { logApplyException(t, NO_KEY); } }); } else { AggregateCompletionStage<Void> aggregateStage = CompletionStages.aggregateCompletionStage(); for (InternalCacheEntry e : cacheEntries) { InvocationContext ctx = icf.createSingleKeyNonTxInvocationContext(); CompletionStage<?> putStage = invokePut(segmentId, ctx, e); aggregateStage.dependsOn(putStage.handle((v, t) -> { if (t != null) { logApplyException(t, e.getKey()); } return null; })); } return aggregateStage.freeze(); } }

Target:
private CompletionStage<?> doApplyState(Address sender, int segmentId, Collection<InternalCacheEntry> cacheEntries) { if (cacheEntries == null || cacheEntries.isEmpty()) return CompletableFutures.completedNull(); if (trace) log.tracef("Applying new state chunk for segment %d of cache %s from node %s: received %d cache entries", segmentId, cacheName, sender, cacheEntries.size()); boolean transactional = transactionManager != null; if (transactional) { Object key = NO_KEY; Transaction transaction = new ApplyStateTransaction(); 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 { 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(); } }