Skip to content

Commit

Permalink
WFLY-5011 Add workaround for ISPN-6007
Browse files Browse the repository at this point in the history
  • Loading branch information
pferraro committed Dec 2, 2015
1 parent 1ed22f0 commit 38cb044
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 8 deletions.
Expand Up @@ -25,7 +25,6 @@
import java.util.concurrent.ScheduledExecutorService;

import org.infinispan.Cache;
import org.infinispan.context.Flag;
import org.infinispan.remoting.transport.Address;
import org.infinispan.transaction.LockingMode;
import org.infinispan.util.concurrent.IsolationLevel;
Expand Down Expand Up @@ -82,7 +81,7 @@ public BeanManager<G, I, T, TransactionBatch> createBeanManager(final Identifier
final boolean passivationEnabled = evictionAllowed && config.persistence().passivation();
final boolean persistent = config.clustering().cacheMode().isClustered() || (evictionAllowed && !passivationEnabled);
boolean lockOnRead = config.transaction().transactionMode().isTransactional() && (config.transaction().lockingMode() == LockingMode.PESSIMISTIC) && (config.locking().isolationLevel() == IsolationLevel.REPEATABLE_READ);
BeanFactory<G, I, T> beanFactory = new InfinispanBeanFactory<>(beanName, groupFactory, lockOnRead ? beanCache.getAdvancedCache().withFlags(Flag.FORCE_WRITE_LOCK) : beanCache, this.configuration.getBeanContext().getTimeout(), persistent ? passivationListener : null);
BeanFactory<G, I, T> beanFactory = new InfinispanBeanFactory<>(beanName, groupFactory, beanCache, lockOnRead, this.configuration.getBeanContext().getTimeout(), persistent ? passivationListener : null);
Configuration<I, BeanKey<I>, BeanEntry<G>, BeanFactory<G, I, T>> beanConfiguration = new SimpleConfiguration<>(beanCache, beanFactory, beanIdentifierFactory);
final NodeFactory<Address> nodeFactory = this.configuration.getNodeFactory();
final Registry<String, ?> registry = this.configuration.getRegistry();
Expand Down
Expand Up @@ -50,13 +50,19 @@ public class InfinispanBeanFactory<G, I, T> implements BeanFactory<G, I, T> {
private final String beanName;
private final BeanGroupFactory<G, I, T> groupFactory;
private final Cache<BeanKey<I>, BeanEntry<G>> cache;
private final Cache<BeanKey<I>, BeanEntry<G>> findCache;
private final Time timeout;
private final PassivationListener<T> listener;
private final boolean lockOnRead;

public InfinispanBeanFactory(String beanName, BeanGroupFactory<G, I, T> groupFactory, Cache<BeanKey<I>, BeanEntry<G>> beanCache, Time timeout, PassivationListener<T> listener) {
public InfinispanBeanFactory(String beanName, BeanGroupFactory<G, I, T> groupFactory, Cache<BeanKey<I>, BeanEntry<G>> cache, boolean lockOnRead, Time timeout, PassivationListener<T> listener) {
this.beanName = beanName;
this.groupFactory = groupFactory;
this.cache = beanCache;
this.cache = cache;
// this.findCache = lockOnRead ? this.cache.getAdvancedCache().withFlags(Flag.FORCE_WRITE_LOCK) : this.cache;
// Workaround for ISPN-6007
this.findCache = this.cache;
this.lockOnRead = lockOnRead;
this.timeout = timeout;
this.listener = listener;
}
Expand All @@ -78,9 +84,15 @@ public Bean<G, I, T> createBean(I id, BeanEntry<G> entry) {
return new InfinispanBean<>(id, entry, group, mutator, this, this.timeout, this.listener);
}

@SuppressWarnings("unchecked")
@Override
public BeanEntry<G> findValue(I id) {
return this.cache.get(this.createKey(id));
BeanKey<I> key = this.createKey(id);
// Workaround for ISPN-6007
if (this.lockOnRead) {
this.findCache.getAdvancedCache().lock(key);
}
return this.findCache.get(key);
}

@Override
Expand Down
Expand Up @@ -22,6 +22,9 @@

package org.wildfly.clustering.web.infinispan.session;

import javax.transaction.Status;
import javax.transaction.SystemException;

import org.infinispan.Cache;
import org.infinispan.context.Flag;
import org.wildfly.clustering.ee.infinispan.CacheEntryMutator;
Expand All @@ -39,13 +42,17 @@ public class InfinispanSessionMetaDataFactory<L> implements SessionMetaDataFacto
private final Cache<SessionCreationMetaDataKey, SessionCreationMetaDataEntry<L>> findCreationMetaDataCache;
private final Cache<SessionAccessMetaDataKey, SessionAccessMetaData> accessMetaDataCache;
private final boolean transactional;
private final boolean lockOnRead;

@SuppressWarnings("unchecked")
public InfinispanSessionMetaDataFactory(Cache<? extends Key<String>, ?> cache, boolean lockOnRead) {
this.creationMetaDataCache = (Cache<SessionCreationMetaDataKey, SessionCreationMetaDataEntry<L>>) cache;
this.findCreationMetaDataCache = lockOnRead ? this.creationMetaDataCache.getAdvancedCache().withFlags(Flag.FORCE_WRITE_LOCK) : this.creationMetaDataCache;
// this.findCreationMetaDataCache = lockOnRead ? this.creationMetaDataCache.getAdvancedCache().withFlags(Flag.FORCE_WRITE_LOCK) : this.creationMetaDataCache;
// Workaround for ISPN-6007
this.findCreationMetaDataCache = this.creationMetaDataCache;
this.accessMetaDataCache = (Cache<SessionAccessMetaDataKey, SessionAccessMetaData>) cache;
this.transactional = cache.getCacheConfiguration().transaction().transactionMode().isTransactional();
this.lockOnRead = lockOnRead;
}

@Override
Expand All @@ -67,6 +74,19 @@ public InfinispanSessionMetaData<L> tryValue(String id) {

private InfinispanSessionMetaData<L> getValue(String id, Cache<SessionCreationMetaDataKey, SessionCreationMetaDataEntry<L>> creationMetaDataCache) {
SessionCreationMetaDataKey creationMetaDataKey = new SessionCreationMetaDataKey(id);
// Workaround for ISPN-6007
if (this.lockOnRead) {
try {
// lock() can only be called within an active tx context
if (this.transactional && (creationMetaDataCache.getAdvancedCache().getTransactionManager().getStatus() == Status.STATUS_ACTIVE)) {
if (!creationMetaDataCache.getAdvancedCache().lock(creationMetaDataKey)) {
return null;
}
}
} catch (SystemException e) {
throw new IllegalStateException(e);
}
}
SessionCreationMetaDataEntry<L> creationMetaDataEntry = creationMetaDataCache.get(creationMetaDataKey);
if (creationMetaDataEntry != null) {
SessionAccessMetaDataKey accessMetaDataKey = new SessionAccessMetaDataKey(id);
Expand Down
Expand Up @@ -45,16 +45,22 @@
public class CoarseSSOFactory<A, D, L> implements SSOFactory<CoarseSSOEntry<A, D, L>, A, D, L> {

private final Cache<AuthenticationKey, AuthenticationEntry<A, D, L>> authenticationCache;
private final Cache<AuthenticationKey, AuthenticationEntry<A, D, L>> findAuthenticationCache;
private final Cache<CoarseSessionsKey, Map<D, String>> sessionsCache;
private final Marshaller<A, MarshalledValue<A, MarshallingContext>, MarshallingContext> marshaller;
private final LocalContextFactory<L> localContextFactory;
private final boolean lockOnRead;

@SuppressWarnings("unchecked")
public CoarseSSOFactory(Cache<? extends Key<String>, ?> cache, Marshaller<A, MarshalledValue<A, MarshallingContext>, MarshallingContext> marshaller, LocalContextFactory<L> localContextFactory, boolean lockOnRead) {
this.authenticationCache = (Cache<AuthenticationKey, AuthenticationEntry<A, D, L>>) (lockOnRead ? cache.getAdvancedCache().withFlags(Flag.FORCE_WRITE_LOCK) : cache);
this.authenticationCache = (Cache<AuthenticationKey, AuthenticationEntry<A, D, L>>) cache;
// this.findAuthenticationCache = lockOnRead ? this.authenticationCache.getAdvancedCache().withFlags(Flag.FORCE_WRITE_LOCK) : this.authenticationCache;
// Workaround for ISPN-6007
this.findAuthenticationCache = this.authenticationCache;
this.sessionsCache = (Cache<CoarseSessionsKey, Map<D, String>>) cache;
this.marshaller = marshaller;
this.localContextFactory = localContextFactory;
this.lockOnRead = lockOnRead;
}

@Override
Expand Down Expand Up @@ -83,7 +89,11 @@ public CoarseSSOEntry<A, D, L> createValue(String id, A authentication) {
@Override
public CoarseSSOEntry<A, D, L> findValue(String id) {
AuthenticationKey key = new AuthenticationKey(id);
AuthenticationEntry<A, D, L> entry = this.authenticationCache.get(key);
// Workaround for ISPN-6007
if (this.lockOnRead) {
this.findAuthenticationCache.getAdvancedCache().lock(key);
}
AuthenticationEntry<A, D, L> entry = this.findAuthenticationCache.get(key);
if (entry != null) {
Map<D, String> map = this.sessionsCache.get(new CoarseSessionsKey(id));
if (map != null) {
Expand Down
Expand Up @@ -37,6 +37,7 @@

<dependencies>
<module name="javax.servlet.api"/>
<module name="javax.transaction.api"/>

<module name="net.jcip"/>
<module name="org.infinispan"/>
Expand Down

0 comments on commit 38cb044

Please sign in to comment.