use of org.infinispan.commons.IllegalLifecycleStateException in project infinispan by infinispan.
the class StateConsumerImpl method addTransfer.
@GuardedBy("transferMapsLock")
protected void addTransfer(InboundTransferTask inboundTransfer, IntSet segments) {
if (!running)
throw new IllegalLifecycleStateException("State consumer is not running for cache " + cacheName);
for (PrimitiveIterator.OfInt iter = segments.iterator(); iter.hasNext(); ) {
int segmentId = iter.nextInt();
transfersBySegment.computeIfAbsent(segmentId, s -> new ArrayList<>()).add(inboundTransfer);
}
transfersBySource.computeIfAbsent(inboundTransfer.getSource(), s -> new ArrayList<>()).add(inboundTransfer);
}
use of org.infinispan.commons.IllegalLifecycleStateException in project infinispan by infinispan.
the class OutboundTransferTask method sendEntries.
private CompletionStage<Void> sendEntries(List<InternalCacheEntry<Object, Object>> entries, boolean isLast) {
Map<Integer, StateChunk> chunks = new HashMap<>();
for (InternalCacheEntry<Object, Object> ice : entries) {
int segmentId = keyPartitioner.getSegment(ice.getKey());
if (segments.contains(segmentId)) {
StateChunk chunk = chunks.computeIfAbsent(segmentId, segment -> new StateChunk(segment, new ArrayList<>(), isLast));
chunk.getCacheEntries().add(ice);
}
}
if (isLast) {
for (PrimitiveIterator.OfInt iter = segments.iterator(); iter.hasNext(); ) {
int segmentId = iter.nextInt();
chunks.computeIfAbsent(segmentId, segment -> new StateChunk(segment, Collections.emptyList(), true));
}
}
if (chunks.isEmpty())
return CompletableFutures.completedNull();
if (log.isTraceEnabled()) {
if (isLast) {
log.tracef("Sending last chunk to node %s containing %d cache entries from segments %s", destination, entries.size(), segments);
} else {
log.tracef("Sending to node %s %d cache entries from segments %s", destination, entries.size(), chunks.keySet());
}
}
StateResponseCommand cmd = commandsFactory.buildStateResponseCommand(topologyId, chunks.values(), applyState, pushTransfer);
try {
return rpcManager.invokeCommand(destination, cmd, SingleResponseCollector.validOnly(), rpcOptions).handle((response, throwable) -> {
if (throwable == null) {
onChunkReplicated.accept(chunks.values());
return null;
}
logSendException(throwable);
cancel();
return null;
});
} catch (IllegalLifecycleStateException e) {
// Manager is shutting down, ignore the error
cancel();
} catch (Exception e) {
logSendException(e);
cancel();
}
return CompletableFutures.completedNull();
}
use of org.infinispan.commons.IllegalLifecycleStateException in project infinispan by infinispan.
the class ConditionFuture method update.
/**
* Update the value and complete any outstanding condition stages for which the value satisfies the predicate.
*/
public void update(T value) {
if (!running)
throw new IllegalLifecycleStateException();
lastValue = Objects.requireNonNull(value);
checkConditions(value);
}
use of org.infinispan.commons.IllegalLifecycleStateException in project infinispan by infinispan.
the class TerminatedCacheWhileInTxTest method testNotAllowCallsWhileStopping.
/**
* The aim of this test is to make sure that invocations not belonging to
* on-going transactions or non-transactional invocations are not allowed
* once the cache is in stopping mode.
*/
public void testNotAllowCallsWhileStopping(final Method m) throws Throwable {
cacheManager.defineConfiguration("cache-" + m.getName(), cacheManager.getDefaultCacheConfiguration());
final Cache<String, String> cache1 = cacheManager.getCache("cache-" + m.getName());
final CyclicBarrier barrier = new CyclicBarrier(2);
final CountDownLatch latch = new CountDownLatch(1);
final TransactionManager tm = TestingUtil.getTransactionManager(cache1);
Future<Void> waitAfterModFuture = fork(() -> {
log.debug("Wait for all executions paths to be ready to perform calls.");
tm.begin();
cache1.put(k(m, 1), v(m, 1));
log.debug("Cache modified, wait for cache to be stopped.");
barrier.await();
// Delay the commit, but it must still happen while cache.stop() is waiting for transactions
assertFalse(latch.await(5, TimeUnit.SECONDS));
tm.commit();
return null;
});
// wait for the transaction to have started
barrier.await();
Future<Void> callStoppingCacheFuture = fork(() -> {
log.debug("Wait very briefly and then make call.");
Thread.sleep(2000);
cache1.put(k(m, 2), v(m, 2));
return null;
});
// now stop the cache
cache1.stop();
// now that cache has been stopped, let the thread continue
latch.countDown();
waitAfterModFuture.get();
try {
callStoppingCacheFuture.get();
fail("Should have thrown an IllegalLifecycleStateException");
} catch (ExecutionException e) {
assertTrue(e.toString(), e.getCause() instanceof IllegalLifecycleStateException);
}
}
use of org.infinispan.commons.IllegalLifecycleStateException in project infinispan by infinispan.
the class PrepareProcessedAfterOriginatorCrashTest method testBelatedTransactionDoesntLeak.
public void testBelatedTransactionDoesntLeak() throws Throwable {
CountDownLatch prepareReceived = new CountDownLatch(1);
CountDownLatch prepareBlocked = new CountDownLatch(1);
CountDownLatch prepareExecuted = new CountDownLatch(1);
Cache receiver = cache(1);
PerCacheInboundInvocationHandler originalInvocationHandler = TestingUtil.extractComponent(receiver, PerCacheInboundInvocationHandler.class);
PerCacheInboundInvocationHandler blockingInvocationHandler = new AbstractDelegatingHandler(originalInvocationHandler) {
@Override
public void handle(CacheRpcCommand command, Reply reply, DeliverOrder order) {
if (!(command instanceof PrepareCommand)) {
delegate.handle(command, reply, order);
return;
}
try {
prepareReceived.countDown();
prepareBlocked.await(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new IllegalLifecycleStateException(e);
}
log.trace("Processing belated prepare");
delegate.handle(command, returnValue -> {
prepareExecuted.countDown();
reply.reply(returnValue);
}, order);
}
};
TestingUtil.replaceComponent(receiver, PerCacheInboundInvocationHandler.class, blockingInvocationHandler, true);
TestingUtil.extractComponentRegistry(receiver).cacheComponents();
final Object key = getKeyForCache(1);
fork(() -> {
try {
cache(0).put(key, "v");
} catch (Throwable e) {
// possible as the node is being killed
}
});
prepareReceived.await(10, TimeUnit.SECONDS);
killMember(0);
// give TransactionTable.cleanupStaleTransactions some time to run
Thread.sleep(5000);
prepareBlocked.countDown();
prepareExecuted.await(10, TimeUnit.SECONDS);
log.trace("Finished waiting for belated prepare to complete");
final TransactionTable transactionTable = TestingUtil.getTransactionTable(receiver);
assertEquals(0, transactionTable.getRemoteTxCount());
assertEquals(0, transactionTable.getLocalTxCount());
assertFalse(receiver.getAdvancedCache().getLockManager().isLocked(key));
}
Aggregations