[jbosscache-issues] [JBoss JIRA] Commented: (JBCACHE-1551) Locking parent node?

Alexander Likulin (JIRA) jira-events at lists.jboss.org
Wed Dec 2 07:14:29 EST 2009


    [ https://jira.jboss.org/jira/browse/JBCACHE-1551?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12497706#action_12497706 ] 

Alexander Likulin commented on JBCACHE-1551:
--------------------------------------------

I think problem is in org.jboss.cache.util.concurrent.locks.OwnableReentrantSharedLockContainer method 
   public final OwnableReentrantLock getLock(E object)
   {
      return sharedLocks[hashToIndex(object)];
   }

If  we have have write lock on node, then we cannot get lock on node with the same hashToIndex result

   final int hashToIndex(E object)
   {
      return (hash(object) >>> lockSegmentShift) & lockSegmentMask;
   }
By default lockSegmentMask = 511
Maybe such code more efficient then HashMap<E, OwnableReentrantLock> but 
 if we have 1 lock and 510 OwnableReentrantLock are free - we still cannot write to node with the same hashToIndex

Example 
fqn1  /testa02fee9e34f14631bad790d56f/test33823cca20724d85aa66263823
fqn2 /testa02fee9e34f14631bad790d56f/test00c5bdfdf1fc4d258c6bd6c749

We cannot write to fqn1 and fqn2 at the same time in different transaction
Is this bug or feature?



Test case 

import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.NotSupportedException;
import javax.transaction.RollbackException;
import javax.transaction.SystemException;
import javax.transaction.Transaction;

import org.jboss.cache.Cache;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import org.jboss.cache.invocation.CacheInvocationDelegate;
import org.jboss.cache.transaction.DummyTransactionManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

   @Test 
   public void testLock() throws NotSupportedException, SystemException, SecurityException, IllegalStateException,
            RollbackException, HeuristicMixedException, HeuristicRollbackException
    {
        Cache<String, String> c = new DefaultCacheFactory<String, String>().createCache("/cache/default.xml");
        Fqn<String> parentFqn = Fqn.fromElements("testa02fee9e34f14631bad790d56f");
        Fqn<String> child1Fqn = Fqn.fromElements("test33823cca20724d85aa66263823");
        Fqn<String> child2Fqn = Fqn.fromElements("test00c5bdfdf1fc4d258c6bd6c749");

        DummyTransactionManager instance = DummyTransactionManager.getInstance();

        instance.begin();
        c.getRoot().addChild(parentFqn);
        instance.commit();

        instance.begin();
        c.getRoot().getChild(parentFqn).addChild(child1Fqn);
        Transaction t1 = instance.suspend();

        instance.begin();
        c.getRoot().getChild(parentFqn).addChild(child2Fqn);
        //!! got Exception here
    }

> Locking parent node?
> --------------------
>
>                 Key: JBCACHE-1551
>                 URL: https://jira.jboss.org/jira/browse/JBCACHE-1551
>             Project: JBoss Cache
>          Issue Type: Bug
>      Security Level: Public(Everyone can see) 
>          Components: Locking
>    Affects Versions: 3.2.0.GA, 3.2.1.GA
>            Reporter: Nikolay Shestakov
>            Assignee: Manik Surtani
>         Attachments: SuspendTxTest.java
>
>
> I have next test:
>     @Test
>     public void nodes()
>     {
>         // setup
>         Fqn<String> fqn1 = Fqn.fromElements(UUID.randomUUID().toString().replace("-", ""));
>         String attribute1 = UUID.randomUUID().toString().replace("-", "");
>         String value1 = UUID.randomUUID().toString().replace("-", "");
>         Fqn<String> fqn2 = Fqn.fromElements(UUID.randomUUID().toString().replace("-", ""));
>         String attribute2 = UUID.randomUUID().toString().replace("-", "");
>         String value2 = UUID.randomUUID().toString().replace("-", "");
>         Assert.assertFalse(fqn1.equals(fqn2));
>         // call
>         TransactionHelper.begin();
>         _cache.put(fqn1, attribute1, value1);
>         TransactionHelper.begin(); // suspend and begin new
>         _cache.put(fqn2, attribute2, value2);
>         TransactionHelper.commit();
>         TransactionHelper.commit();
>         // assertions
>         Assert.assertEquals(value1, _cache.get(fqn1, attribute1));
>         Assert.assertEquals(value2, _cache.get(fqn2, attribute2));
>         // clear
>     }
> sometimes this test is fail (~ one time from 1000 executions): 
> Unable to acquire lock on Fqn [/test19cb7eae7cc546b1909261c289] after [10000] milliseconds for requestor [GlobalTransaction:<null>:3]! Lock held by [GlobalTransaction:<null>:2]
> at org.jboss.cache.mvcc.MVCCNodeHelper.acquireLock(MVCCNodeHelper.java:159)
> 	at org.jboss.cache.mvcc.MVCCNodeHelper.wrapNodeForWriting(MVCCNodeHelper.java:236)
> 	at org.jboss.cache.mvcc.MVCCNodeHelper.wrapNodeForWriting(MVCCNodeHelper.java:186)
> 	at org.jboss.cache.interceptors.MVCCLockingInterceptor.handlePutKeyValueCommand(MVCCLockingInterceptor.java:101)
> 	at org.jboss.cache.interceptors.base.PrePostProcessingCommandInterceptor.visitPutKeyValueCommand(PrePostProcessingCommandInterceptor.java:88)
> 	at org.jboss.cache.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:100)
> 	at org.jboss.cache.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:116)
> 	at org.jboss.cache.interceptors.base.CommandInterceptor.handleDefault(CommandInterceptor.java:131)
> 	at org.jboss.cache.commands.AbstractVisitor.visitPutKeyValueCommand(AbstractVisitor.java:65)
> 	at org.jboss.cache.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:100)
> 	at org.jboss.cache.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:116)
> 	at org.jboss.cache.interceptors.TxInterceptor.attachGtxAndPassUpChain(TxInterceptor.java:301)
> 	at org.jboss.cache.interceptors.TxInterceptor.handleDefault(TxInterceptor.java:283)
> 	at org.jboss.cache.commands.AbstractVisitor.visitPutKeyValueCommand(AbstractVisitor.java:65)
> 	at org.jboss.cache.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:100)
> 	at org.jboss.cache.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:116)
> 	at org.jboss.cache.interceptors.CacheMgmtInterceptor.visitPutKeyValueCommand(CacheMgmtInterceptor.java:119)
> 	at org.jboss.cache.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:100)
> 	at org.jboss.cache.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:116)
> 	at org.jboss.cache.interceptors.InvocationContextInterceptor.handleAll(InvocationContextInterceptor.java:178)
> 	at org.jboss.cache.interceptors.InvocationContextInterceptor.visitPutKeyValueCommand(InvocationContextInterceptor.java:82)
> 	at org.jboss.cache.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:100)
> 	at org.jboss.cache.interceptors.InterceptorChain.invoke(InterceptorChain.java:287)
> 	at org.jboss.cache.invocation.CacheInvocationDelegate.put(CacheInvocationDelegate.java:555)
> config file is:
> <?xml version="1.0" encoding="UTF-8"?>
> <jbosscache
> 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> 	xmlns="urn:jboss:jbosscache-core:config:3.2">
> 	<transaction
> 		transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup" />
> 	<locking
> 		isolationLevel="REPEATABLE_READ"
> 		lockParentForChildInsertRemove="false"
> 		nodeLockingScheme="mvcc" />
> 	<jmxStatistics
> 		enabled="true" />
> </jbosscache>

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the jbosscache-issues mailing list