Search in sources :

Example 1 with CacheException

use of org.infinispan.commons.CacheException in project wildfly by wildfly.

the class InfinispanBatcher method resumeBatch.

@Override
public BatchContext resumeBatch(TransactionBatch batch) {
    TransactionBatch existingBatch = CURRENT_BATCH.get();
    // Trivial case - nothing to suspend/resume
    if (batch == existingBatch)
        return PASSIVE_BATCH_CONTEXT;
    Transaction tx = (batch != null) ? batch.getTransaction() : null;
    // Non-tx case, just swap thread local
    if ((batch == null) || (tx == null)) {
        CURRENT_BATCH.set(batch);
        return () -> {
            CURRENT_BATCH.set(existingBatch);
        };
    }
    try {
        if (existingBatch != null) {
            Transaction existingTx = this.tm.suspend();
            if (existingBatch.getTransaction() != existingTx) {
                throw new IllegalStateException();
            }
        }
        this.tm.resume(tx);
        CURRENT_BATCH.set(batch);
        return () -> {
            try {
                this.tm.suspend();
                if (existingBatch != null) {
                    try {
                        this.tm.resume(existingBatch.getTransaction());
                        CURRENT_BATCH.set(existingBatch);
                    } catch (InvalidTransactionException e) {
                        throw new CacheException(e);
                    }
                } else {
                    CURRENT_BATCH.remove();
                }
            } catch (SystemException e) {
                throw new CacheException(e);
            }
        };
    } catch (SystemException | InvalidTransactionException e) {
        throw new CacheException(e);
    }
}
Also used : Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) CacheException(org.infinispan.commons.CacheException) InvalidTransactionException(javax.transaction.InvalidTransactionException)

Example 2 with CacheException

use of org.infinispan.commons.CacheException in project wildfly by wildfly.

the class InfinispanBatcher method createBatch.

@Override
public TransactionBatch createBatch() {
    if (this.tm == null)
        return NON_TX_BATCH;
    TransactionBatch batch = CURRENT_BATCH.get();
    if (batch != null) {
        return batch.interpose();
    }
    try {
        this.tm.suspend();
        this.tm.begin();
        Transaction tx = this.tm.getTransaction();
        tx.registerSynchronization(CURRENT_BATCH_REMOVER);
        batch = new InfinispanBatch(tx);
        CURRENT_BATCH.set(batch);
        return batch;
    } catch (RollbackException | SystemException | NotSupportedException e) {
        throw new CacheException(e);
    }
}
Also used : Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) CacheException(org.infinispan.commons.CacheException) RollbackException(javax.transaction.RollbackException) NotSupportedException(javax.transaction.NotSupportedException)

Example 3 with CacheException

use of org.infinispan.commons.CacheException in project wildfly by wildfly.

the class ChannelFactoryTransport method initChannel.

@Override
protected void initChannel() {
    try {
        this.channel = this.factory.createChannel(this.configuration.globalJmxStatistics().cacheManagerName());
        this.channel.setDiscardOwnMessages(false);
    } catch (Exception e) {
        throw new CacheException(e);
    }
}
Also used : CacheException(org.infinispan.commons.CacheException) CacheException(org.infinispan.commons.CacheException)

Example 4 with CacheException

use of org.infinispan.commons.CacheException in project wildfly by wildfly.

the class CacheRegistry method topologyChanged.

@TopologyChanged
public void topologyChanged(TopologyChangedEvent<Node, Map.Entry<K, V>> event) {
    if (event.isPre())
        return;
    ConsistentHash previousHash = event.getConsistentHashAtStart();
    List<Address> previousMembers = previousHash.getMembers();
    ConsistentHash hash = event.getConsistentHashAtEnd();
    List<Address> members = hash.getMembers();
    Address localAddress = event.getCache().getCacheManager().getAddress();
    // Determine which nodes have left the cache view
    Set<Address> addresses = new HashSet<>(previousMembers);
    addresses.removeAll(members);
    try {
        this.topologyChangeExecutor.submit(() -> {
            if (!addresses.isEmpty()) {
                // We're only interested in the entries for which we are the primary owner
                List<Node> nodes = addresses.stream().filter(address -> hash.locatePrimaryOwner(address).equals(localAddress)).map(address -> this.factory.createNode(address)).collect(Collectors.toList());
                if (!nodes.isEmpty()) {
                    Cache<Node, Map.Entry<K, V>> cache = this.cache.getAdvancedCache().withFlags(Flag.FORCE_SYNCHRONOUS);
                    Map<K, V> removed = new HashMap<>();
                    try (Batch batch = this.batcher.createBatch()) {
                        for (Node node : nodes) {
                            Map.Entry<K, V> old = cache.remove(node);
                            if (old != null) {
                                removed.put(old.getKey(), old.getValue());
                            }
                        }
                    } catch (CacheException e) {
                        ClusteringServerLogger.ROOT_LOGGER.registryPurgeFailed(e, this.cache.getCacheManager().toString(), this.cache.getName(), nodes);
                    }
                    // Invoke listeners outside above tx context
                    if (!removed.isEmpty()) {
                        this.notifyListeners(Event.Type.CACHE_ENTRY_REMOVED, removed);
                    }
                }
            } else {
                // This is a merge after cluster split: re-populate the cache registry with lost registry entries
                if (!previousMembers.contains(localAddress)) {
                    // If this node is not a member at merge start, its mapping is lost and needs to be recreated and listeners notified
                    try {
                        this.populateRegistry();
                        // Local cache events do not trigger notifications
                        this.notifyListeners(Event.Type.CACHE_ENTRY_CREATED, this.entry);
                    } catch (CacheException e) {
                        ClusteringServerLogger.ROOT_LOGGER.failedToRestoreLocalRegistryEntry(e, this.cache.getCacheManager().toString(), this.cache.getName());
                    }
                }
            }
        });
    } catch (RejectedExecutionException e) {
    // Executor was shutdown
    }
}
Also used : CacheEntryRemoved(org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved) TopologyChanged(org.infinispan.notifications.cachelistener.annotation.TopologyChanged) ClusteringLogger(org.jboss.as.clustering.logging.ClusteringLogger) HashMap(java.util.HashMap) Cache(org.infinispan.Cache) HashSet(java.util.HashSet) ClassLoaderThreadFactory(org.wildfly.clustering.service.concurrent.ClassLoaderThreadFactory) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Map(java.util.Map) CacheEntryModified(org.infinispan.notifications.cachelistener.annotation.CacheEntryModified) CacheEntryRemovedEvent(org.infinispan.notifications.cachelistener.event.CacheEntryRemovedEvent) ThreadFactory(java.util.concurrent.ThreadFactory) NodeFactory(org.wildfly.clustering.group.NodeFactory) ExecutorService(java.util.concurrent.ExecutorService) Address(org.infinispan.remoting.transport.Address) JBossThreadFactory(org.jboss.threads.JBossThreadFactory) CacheException(org.infinispan.commons.CacheException) ConsistentHash(org.infinispan.distribution.ch.ConsistentHash) Batcher(org.wildfly.clustering.ee.Batcher) Registry(org.wildfly.clustering.registry.Registry) Group(org.wildfly.clustering.group.Group) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) PrivilegedAction(java.security.PrivilegedAction) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) TopologyChangedEvent(org.infinispan.notifications.cachelistener.event.TopologyChangedEvent) TimeUnit(java.util.concurrent.TimeUnit) CacheEntryCreated(org.infinispan.notifications.cachelistener.annotation.CacheEntryCreated) AbstractMap(java.util.AbstractMap) List(java.util.List) WildFlySecurityManager(org.wildfly.security.manager.WildFlySecurityManager) Flag(org.infinispan.context.Flag) KeyFilter(org.infinispan.filter.KeyFilter) CacheEntryEvent(org.infinispan.notifications.cachelistener.event.CacheEntryEvent) Batch(org.wildfly.clustering.ee.Batch) Event(org.infinispan.notifications.cachelistener.event.Event) Node(org.wildfly.clustering.group.Node) ClusteringServerLogger(org.wildfly.clustering.server.logging.ClusteringServerLogger) Collections(java.util.Collections) ConsistentHash(org.infinispan.distribution.ch.ConsistentHash) Address(org.infinispan.remoting.transport.Address) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CacheException(org.infinispan.commons.CacheException) Node(org.wildfly.clustering.group.Node) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Batch(org.wildfly.clustering.ee.Batch) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AbstractMap(java.util.AbstractMap) HashSet(java.util.HashSet) TopologyChanged(org.infinispan.notifications.cachelistener.annotation.TopologyChanged)

Example 5 with CacheException

use of org.infinispan.commons.CacheException in project wildfly by wildfly.

the class CacheConfigurationServiceConfigurator method accept.

@Override
public void accept(ConfigurationBuilder builder) {
    TransactionConfiguration tx = this.transaction.get();
    builder.memory().read(this.memory.get());
    builder.expiration().read(this.expiration.get());
    builder.locking().read(this.locking.get());
    builder.persistence().read(this.persistence.get());
    builder.transaction().read(tx);
    builder.statistics().enabled(this.statisticsEnabled);
    // See WFLY-14356
    if (this.memory.get().storage().canStoreReferences()) {
        builder.encoding().mediaType(MediaType.APPLICATION_OBJECT_TYPE);
    }
    try {
        // Configure invocation batching based on transaction configuration
        builder.invocationBatching().enable(tx.transactionMode().isTransactional() && (tx.transactionManagerLookup().getTransactionManager() == EmbeddedTransactionManager.getInstance()));
    } catch (Exception e) {
        throw new CacheException(e);
    }
}
Also used : TransactionConfiguration(org.infinispan.configuration.cache.TransactionConfiguration) CacheException(org.infinispan.commons.CacheException) CacheException(org.infinispan.commons.CacheException) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Aggregations

CacheException (org.infinispan.commons.CacheException)8 AbstractMap (java.util.AbstractMap)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ExecutorService (java.util.concurrent.ExecutorService)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 SystemException (javax.transaction.SystemException)2 Transaction (javax.transaction.Transaction)2 Cache (org.infinispan.Cache)2 ConsistentHash (org.infinispan.distribution.ch.ConsistentHash)2 TopologyChanged (org.infinispan.notifications.cachelistener.annotation.TopologyChanged)2 Address (org.infinispan.remoting.transport.Address)2 Batch (org.wildfly.clustering.ee.Batch)2 Serializable (java.io.Serializable)1 PrivilegedAction (java.security.PrivilegedAction)1 Collections (java.util.Collections)1 LinkedList (java.util.LinkedList)1