Search in sources :

Example 1 with IllegalLifecycleStateException

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);
}
Also used : ComponentName(org.infinispan.factories.annotations.ComponentName) CacheNotFoundResponse(org.infinispan.remoting.responses.CacheNotFoundResponse) LogFactory(org.infinispan.util.logging.LogFactory) Cache(org.infinispan.Cache) Scopes(org.infinispan.factories.scopes.Scopes) Map(java.util.Map) SKIP_SHARED_CACHE_STORE(org.infinispan.context.Flag.SKIP_SHARED_CACHE_STORE) Transaction(javax.transaction.Transaction) ConsistentHash(org.infinispan.distribution.ch.ConsistentHash) CACHE_MODE_LOCAL(org.infinispan.context.Flag.CACHE_MODE_LOCAL) Set(java.util.Set) CacheTopology(org.infinispan.topology.CacheTopology) IntSet(org.infinispan.commons.util.IntSet) CompletionStage(java.util.concurrent.CompletionStage) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) FakeJTATransaction(org.infinispan.transaction.impl.FakeJTATransaction) CacheTransaction(org.infinispan.transaction.xa.CacheTransaction) TriangleOrderManager(org.infinispan.distribution.TriangleOrderManager) InternalCacheEntry(org.infinispan.container.entries.InternalCacheEntry) PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) CommandAckCollector(org.infinispan.util.concurrent.CommandAckCollector) EnumUtil(org.infinispan.commons.util.EnumUtil) ArrayList(java.util.ArrayList) Start(org.infinispan.factories.annotations.Start) PassthroughSingleResponseCollector(org.infinispan.remoting.transport.impl.PassthroughSingleResponseCollector) PRIVATE(org.infinispan.persistence.manager.PersistenceManager.AccessMode.PRIVATE) Configurations(org.infinispan.configuration.cache.Configurations) SingleResponseCollector(org.infinispan.remoting.transport.impl.SingleResponseCollector) Address(org.infinispan.remoting.transport.Address) InvocationContextFactory(org.infinispan.context.InvocationContextFactory) SKIP_OWNERSHIP_CHECK(org.infinispan.context.Flag.SKIP_OWNERSHIP_CHECK) Executor(java.util.concurrent.Executor) RollbackCommand(org.infinispan.commands.tx.RollbackCommand) ClusterListenerReplicateCallable(org.infinispan.notifications.cachelistener.cluster.ClusterListenerReplicateCallable) Publisher(org.reactivestreams.Publisher) ValidResponse(org.infinispan.remoting.responses.ValidResponse) CacheNotifier(org.infinispan.notifications.cachelistener.CacheNotifier) InternalConflictManager(org.infinispan.conflict.impl.InternalConflictManager) Inject(org.infinispan.factories.annotations.Inject) AtomicLong(java.util.concurrent.atomic.AtomicLong) InvalidateCommand(org.infinispan.commands.write.InvalidateCommand) GlobalTransaction(org.infinispan.transaction.xa.GlobalTransaction) DistributionManager(org.infinispan.distribution.DistributionManager) AggregateCompletionStage(org.infinispan.util.concurrent.AggregateCompletionStage) IntSets(org.infinispan.commons.util.IntSets) Stop(org.infinispan.factories.annotations.Stop) InvocationContext(org.infinispan.context.InvocationContext) LocalTxInvocationContext(org.infinispan.context.impl.LocalTxInvocationContext) ComponentRef(org.infinispan.factories.impl.ComponentRef) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SKIP_REMOTE_LOOKUP(org.infinispan.context.Flag.SKIP_REMOTE_LOOKUP) Scope(org.infinispan.factories.scopes.Scope) PERSISTENCE(org.infinispan.util.logging.Log.PERSISTENCE) RpcOptions(org.infinispan.remoting.rpc.RpcOptions) PrepareCommand(org.infinispan.commands.tx.PrepareCommand) CommandsFactory(org.infinispan.commands.CommandsFactory) CompletionStages.handleAndCompose(org.infinispan.util.concurrent.CompletionStages.handleAndCompose) Predicate(java.util.function.Predicate) LocalPublisherManager(org.infinispan.reactive.publisher.impl.LocalPublisherManager) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LockingMode(org.infinispan.transaction.LockingMode) List(java.util.List) PerCacheInboundInvocationHandler(org.infinispan.remoting.inboundhandler.PerCacheInboundInvocationHandler) LocalTransaction(org.infinispan.transaction.impl.LocalTransaction) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand) LocalTopologyManager(org.infinispan.topology.LocalTopologyManager) GuardedBy(net.jcip.annotations.GuardedBy) IGNORE_RETURN_VALUES(org.infinispan.context.Flag.IGNORE_RETURN_VALUES) SKIP_XSITE_BACKUP(org.infinispan.context.Flag.SKIP_XSITE_BACKUP) DataRehashed(org.infinispan.notifications.cachelistener.annotation.DataRehashed) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionStages(org.infinispan.util.concurrent.CompletionStages) PUT_FOR_STATE_TRANSFER(org.infinispan.context.Flag.PUT_FOR_STATE_TRANSFER) HashSet(java.util.HashSet) FlagBitSets(org.infinispan.context.impl.FlagBitSets) InternalMetadataImpl(org.infinispan.metadata.impl.InternalMetadataImpl) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) IRAC_STATE(org.infinispan.context.Flag.IRAC_STATE) Log(org.infinispan.util.logging.Log) Response(org.infinispan.remoting.responses.Response) Flowable(io.reactivex.rxjava3.core.Flowable) Iterator(java.util.Iterator) InternalDataContainer(org.infinispan.container.impl.InternalDataContainer) RpcManager(org.infinispan.remoting.rpc.RpcManager) TransactionMode(org.infinispan.transaction.TransactionMode) Completable(io.reactivex.rxjava3.core.Completable) NON_BLOCKING_EXECUTOR(org.infinispan.factories.KnownComponentNames.NON_BLOCKING_EXECUTOR) CompletionStages.ignoreValue(org.infinispan.util.concurrent.CompletionStages.ignoreValue) PrimitiveIterator(java.util.PrimitiveIterator) TimeUnit(java.util.concurrent.TimeUnit) IllegalLifecycleStateException(org.infinispan.commons.IllegalLifecycleStateException) CacheRpcCommand(org.infinispan.commands.remote.CacheRpcCommand) XSiteStateTransferManager(org.infinispan.xsite.statetransfer.XSiteStateTransferManager) SKIP_LOCKING(org.infinispan.context.Flag.SKIP_LOCKING) RemoteTransaction(org.infinispan.transaction.impl.RemoteTransaction) Configuration(org.infinispan.configuration.cache.Configuration) DistributionInfo(org.infinispan.distribution.DistributionInfo) DeliverOrder(org.infinispan.remoting.inboundhandler.DeliverOrder) TransactionManager(javax.transaction.TransactionManager) Collections(java.util.Collections) TransactionTable(org.infinispan.transaction.impl.TransactionTable) LimitedExecutor(org.infinispan.executors.LimitedExecutor) IllegalLifecycleStateException(org.infinispan.commons.IllegalLifecycleStateException) PrimitiveIterator(java.util.PrimitiveIterator) ArrayList(java.util.ArrayList) GuardedBy(net.jcip.annotations.GuardedBy)

Example 2 with IllegalLifecycleStateException

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();
}
Also used : PrimitiveIterator(java.util.PrimitiveIterator) IllegalLifecycleStateException(org.infinispan.commons.IllegalLifecycleStateException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IllegalLifecycleStateException(org.infinispan.commons.IllegalLifecycleStateException) SuspectException(org.infinispan.remoting.transport.jgroups.SuspectException) StateResponseCommand(org.infinispan.commands.statetransfer.StateResponseCommand)

Example 3 with IllegalLifecycleStateException

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);
}
Also used : IllegalLifecycleStateException(org.infinispan.commons.IllegalLifecycleStateException)

Example 4 with IllegalLifecycleStateException

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);
    }
}
Also used : IllegalLifecycleStateException(org.infinispan.commons.IllegalLifecycleStateException) TransactionManager(javax.transaction.TransactionManager) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionException(java.util.concurrent.ExecutionException) CyclicBarrier(java.util.concurrent.CyclicBarrier)

Example 5 with 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));
}
Also used : PerCacheInboundInvocationHandler(org.infinispan.remoting.inboundhandler.PerCacheInboundInvocationHandler) IllegalLifecycleStateException(org.infinispan.commons.IllegalLifecycleStateException) DeliverOrder(org.infinispan.remoting.inboundhandler.DeliverOrder) TransactionTable(org.infinispan.transaction.impl.TransactionTable) PrepareCommand(org.infinispan.commands.tx.PrepareCommand) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractDelegatingHandler(org.infinispan.remoting.inboundhandler.AbstractDelegatingHandler) CacheRpcCommand(org.infinispan.commands.remote.CacheRpcCommand) Reply(org.infinispan.remoting.inboundhandler.Reply) Cache(org.infinispan.Cache)

Aggregations

IllegalLifecycleStateException (org.infinispan.commons.IllegalLifecycleStateException)15 HashMap (java.util.HashMap)4 Map (java.util.Map)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 PrimitiveIterator (java.util.PrimitiveIterator)2 Set (java.util.Set)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 TransactionManager (javax.transaction.TransactionManager)2 Cache (org.infinispan.Cache)2 CacheRpcCommand (org.infinispan.commands.remote.CacheRpcCommand)2 PrepareCommand (org.infinispan.commands.tx.PrepareCommand)2 CacheConfigurationException (org.infinispan.commons.CacheConfigurationException)2 CacheException (org.infinispan.commons.CacheException)2 DeliverOrder (org.infinispan.remoting.inboundhandler.DeliverOrder)2 PerCacheInboundInvocationHandler (org.infinispan.remoting.inboundhandler.PerCacheInboundInvocationHandler)2