use of org.infinispan.persistence.manager.PersistenceManager.AccessMode.PRIVATE in project infinispan by infinispan.
the class StateConsumerImpl method invalidateStaleEntries.
private CompletionStage<Void> invalidateStaleEntries(IntSet removedSegments, Boolean removed) {
// If there are no stores that couldn't remove segments, we don't have to worry about invaliding entries
if (removed) {
return CompletableFutures.completedNull();
}
// All these segments have been removed from the data container, so we only care about private stores
AtomicLong removedEntriesCounter = new AtomicLong();
Predicate<Object> filter = key -> removedSegments.contains(getSegment(key));
Publisher<Object> publisher = persistenceManager.publishKeys(filter, PRIVATE);
return Flowable.fromPublisher(publisher).onErrorResumeNext(throwable -> {
PERSISTENCE.failedLoadingKeysFromCacheStore(throwable);
return Flowable.empty();
}).buffer(configuration.clustering().stateTransfer().chunkSize()).concatMapCompletable(keysToRemove -> {
removedEntriesCounter.addAndGet(keysToRemove.size());
return Completable.fromCompletionStage(invalidateBatch(keysToRemove));
}).toCompletionStage(null).thenRun(() -> {
if (log.isTraceEnabled())
log.tracef("Removed %d keys, data container now has %d keys", removedEntriesCounter.get(), dataContainer.sizeIncludingExpired());
});
}
use of org.infinispan.persistence.manager.PersistenceManager.AccessMode.PRIVATE 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