[infinispan-issues] [JBoss JIRA] (ISPN-1546) FineGrainedAtomicMap key and value iterators are not threadsafe
Vladimir Blagojevic (Commented) (JIRA)
jira-events at lists.jboss.org
Tue Dec 6 16:41:40 EST 2011
[ https://issues.jboss.org/browse/ISPN-1546?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12648626#comment-12648626 ]
Vladimir Blagojevic commented on ISPN-1546:
-------------------------------------------
Ok I think I have gotten to the bottom of why this is happening and why the fail-safe iterator I prepared is not going to be enough. Take a look at any write operation of FGAM:
{code}
public V put(K key, V value) {
AtomicHashMap<K, V> deltaMapForWrite = null;
try {
startAtomic();
deltaMapForWrite = getDeltaMapForWrite();
return deltaMapForWrite.put(key, value);
} finally {
invokeApplyDelta(deltaMapForWrite.getDelta());
endAtomic();
}
}
{code}
Recall the actual lock on the non thread safe AtomicHashMap is never obtained - by design. The locks are obtained per key of AtomicHashMap. Therefore in order to make a snapshot iterator of AtomicHashMap we have to somehow lock the entire AtomicHashMap for the duration of iterator creation. This lock also has to be obtained by other write ops on AtomicHashMap which in turn defeats the purpose of FineGrainedAtomicMap to begin with.
It seems like we are left with an option to use FGAM but without any iteration. If iteration is needed AtomicMap should be used instead.
Thoughts?
> FineGrainedAtomicMap key and value iterators are not threadsafe
> ---------------------------------------------------------------
>
> Key: ISPN-1546
> URL: https://issues.jboss.org/browse/ISPN-1546
> Project: Infinispan
> Issue Type: Bug
> Components: Core API, Locking and Concurrency
> Reporter: Sanne Grinovero
> Assignee: Vladimir Blagojevic
>
> Invoking #keySet() or #values() might fail, even when using a transaction to isolate threads:
> {code}
> java.util.ConcurrentModificationException
> at org.infinispan.util.FastCopyHashMap$FasyCopyHashMapIterator.nextEntry(FastCopyHashMap.java:484)
> at org.infinispan.util.FastCopyHashMap$KeyIterator.next(FastCopyHashMap.java:560)
> at java.util.AbstractCollection.addAll(AbstractCollection.java:305)
> at org.infinispan.atomic.FineGrainedAtomicHashMapProxy.keySet(FineGrainedAtomicHashMapProxy.java:104)
> at org.hibernate.ogm.dialect.infinispan.InfinispanAssociationSnapshot.getRowKeys(InfinispanAssociationSnapshot.java:59)
> at org.hibernate.ogm.datastore.spi.Association.getKeys(Association.java:132)
> at org.hibernate.ogm.loader.OgmLoader.getResultSet(OgmLoader.java:420)
> at org.hibernate.ogm.loader.OgmLoader.doQuery(OgmLoader.java:248)
> at org.hibernate.ogm.loader.OgmLoader.doQueryAndInitializeNonLazyCollections(OgmLoader.java:215)
> at org.hibernate.ogm.loader.OgmLoader.loadCollection(OgmLoader.java:185)
> at org.hibernate.ogm.loader.OgmBasicCollectionLoader.initialize(OgmBasicCollectionLoader.java:42)
> at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:622)
> at org.hibernate.event.internal.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:82)
> at org.hibernate.internal.SessionImpl.initializeCollection(SessionImpl.java:1607)
> at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:379)
> at org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:112)
> at org.hibernate.collection.internal.PersistentSet.iterator(PersistentSet.java:180)
> {code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the infinispan-issues
mailing list