Skip to content

Commit

Permalink
WFLY-5998 ISPN-6007 workaround fails for caches using optimistic locking
Browse files Browse the repository at this point in the history
  • Loading branch information
pferraro committed Jan 14, 2016
1 parent a26a8be commit de66819
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Expand Up @@ -161,9 +161,11 @@ public Recordable<ImmutableSession> getInactiveSessionRecorder() {

private <L> SessionFactory<?, ?, L> createSessionFactory(LocalContextFactory<L> localContextFactory) {
Configuration config = this.config.getCache().getCacheConfiguration();
boolean lockOnRead = config.transaction().transactionMode().isTransactional() && (config.transaction().lockingMode() == LockingMode.PESSIMISTIC) && config.locking().isolationLevel() == IsolationLevel.REPEATABLE_READ;
boolean transactional = config.transaction().transactionMode().isTransactional();
boolean lockOnWrite = transactional && (config.transaction().lockingMode() == LockingMode.PESSIMISTIC);
boolean lockOnRead = lockOnWrite && (config.locking().isolationLevel() == IsolationLevel.REPEATABLE_READ);
boolean requireMarshallable = config.clustering().cacheMode().needsStateTransfer() || config.persistence().usingStores();
SessionMetaDataFactory<InfinispanSessionMetaData<L>, L> metaDataFactory = new InfinispanSessionMetaDataFactory<>(this.config.getCache(), lockOnRead);
SessionMetaDataFactory<InfinispanSessionMetaData<L>, L> metaDataFactory = new InfinispanSessionMetaDataFactory<>(this.config.getCache(), transactional, lockOnRead, lockOnWrite);
return new InfinispanSessionFactory<>(metaDataFactory, this.createSessionAttributesFactory(lockOnRead, requireMarshallable), localContextFactory);
}

Expand Down
Expand Up @@ -43,16 +43,18 @@ public class InfinispanSessionMetaDataFactory<L> implements SessionMetaDataFacto
private final Cache<SessionAccessMetaDataKey, SessionAccessMetaData> accessMetaDataCache;
private final boolean transactional;
private final boolean lockOnRead;
private final boolean lockOnWrite;

@SuppressWarnings("unchecked")
public InfinispanSessionMetaDataFactory(Cache<? extends Key<String>, ?> cache, boolean lockOnRead) {
public InfinispanSessionMetaDataFactory(Cache<? extends Key<String>, ?> cache, boolean transactional, boolean lockOnRead, boolean lockOnWrite) {
this.creationMetaDataCache = (Cache<SessionCreationMetaDataKey, SessionCreationMetaDataEntry<L>>) cache;
// 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.transactional = transactional;
this.lockOnRead = lockOnRead;
this.lockOnWrite = lockOnWrite;
}

@Override
Expand All @@ -78,7 +80,7 @@ private InfinispanSessionMetaData<L> getValue(String id, Cache<SessionCreationMe
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().getTransactionManager().getStatus() == Status.STATUS_ACTIVE) {
if (!creationMetaDataCache.getAdvancedCache().lock(key)) {
return null;
}
Expand Down Expand Up @@ -129,7 +131,7 @@ public boolean purge(String id) {

private boolean remove(String id, Cache<SessionCreationMetaDataKey, SessionCreationMetaDataEntry<L>> creationMetaDataCache) {
SessionCreationMetaDataKey key = new SessionCreationMetaDataKey(id);
if (creationMetaDataCache.getAdvancedCache().withFlags(Flag.ZERO_LOCK_ACQUISITION_TIMEOUT, Flag.FAIL_SILENTLY).lock(key)) {
if (this.lockOnWrite && creationMetaDataCache.getAdvancedCache().withFlags(Flag.ZERO_LOCK_ACQUISITION_TIMEOUT, Flag.FAIL_SILENTLY).lock(key)) {
creationMetaDataCache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES).remove(key);
this.accessMetaDataCache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES).remove(new SessionAccessMetaDataKey(id));
return true;
Expand Down

0 comments on commit de66819

Please sign in to comment.