You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2014/04/29 18:42:34 UTC
svn commit: r1591019 - in /directory/mavibot/branches/with-txns/mavibot/src:
main/java/org/apache/directory/mavibot/btree/
test/java/org/apache/directory/mavibot/btree/
Author: elecharny
Date: Tue Apr 29 16:42:33 2014
New Revision: 1591019
URL: http://svn.apache.org/r1591019
Log:
o Fixed the multi threaded insert test : the InMemoryTransactionManager was not implementing any of the beginTransaction/commit/rollback operations...
o Fixed a bug in the RecordManager.commit() method : we were not returning immediately when the number of pending transaction was 0, leading to a double decrement of the lock hold.
Modified:
directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryTransactionManager.java
directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java
directory/mavibot/branches/with-txns/mavibot/src/test/java/org/apache/directory/mavibot/btree/MultiThreadedInMemoryBtreeTest.java
Modified: directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryTransactionManager.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryTransactionManager.java?rev=1591019&r1=1591018&r2=1591019&view=diff
==============================================================================
--- directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryTransactionManager.java (original)
+++ directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryTransactionManager.java Tue Apr 29 16:42:33 2014
@@ -19,6 +19,12 @@
*/
package org.apache.directory.mavibot.btree;
+import java.io.IOException;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.apache.directory.mavibot.btree.exception.RecordManagerException;
+
/**
* An implementation of a TransactionManager for in-memory B-trees
*
@@ -26,12 +32,33 @@ package org.apache.directory.mavibot.btr
*/
public class InMemoryTransactionManager extends AbstractTransactionManager
{
+ /** A lock to protect the transaction handling */
+ private Lock transactionLock = new ReentrantLock();
+
+ /** A ThreadLocalStorage used to store the current transaction */
+ private static final ThreadLocal<Integer> context = new ThreadLocal<Integer>();
+
/**
* {@inheritDoc}
*/
@Override
public void beginTransaction()
{
+ // First, take the lock
+ transactionLock.lock();
+
+ // Now, check the TLS state
+ Integer nbTxnLevel = context.get();
+
+ if ( nbTxnLevel == null )
+ {
+ context.set( 1 );
+ }
+ else
+ {
+ // And increment the counter of inner txn.
+ context.set( nbTxnLevel + 1 );
+ }
}
@@ -41,6 +68,24 @@ public class InMemoryTransactionManager
@Override
public void commit()
{
+ int nbTxnStarted = context.get();
+
+ if ( nbTxnStarted == 0 )
+ {
+ // The transaction was rollbacked, quit immediatelly
+ transactionLock.unlock();
+
+ return;
+ }
+ else
+ {
+
+ // And decrement the number of started transactions
+ context.set( nbTxnStarted - 1 );
+ }
+
+ // Finally, release the global lock
+ transactionLock.unlock();
}
@@ -50,5 +95,10 @@ public class InMemoryTransactionManager
@Override
public void rollback()
{
+ // Reset the counter
+ context.set( 0 );
+
+ // Finally, release the global lock
+ transactionLock.unlock();
}
}
Modified: directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java?rev=1591019&r1=1591018&r2=1591019&view=diff
==============================================================================
--- directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java (original)
+++ directory/mavibot/branches/with-txns/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java Tue Apr 29 16:42:33 2014
@@ -568,6 +568,8 @@ public class RecordManager extends Abstr
{
// The transaction was rollbacked, quit immediatelly
transactionLock.unlock();
+
+ return;
}
else
{
Modified: directory/mavibot/branches/with-txns/mavibot/src/test/java/org/apache/directory/mavibot/btree/MultiThreadedInMemoryBtreeTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/with-txns/mavibot/src/test/java/org/apache/directory/mavibot/btree/MultiThreadedInMemoryBtreeTest.java?rev=1591019&r1=1591018&r2=1591019&view=diff
==============================================================================
--- directory/mavibot/branches/with-txns/mavibot/src/test/java/org/apache/directory/mavibot/btree/MultiThreadedInMemoryBtreeTest.java (original)
+++ directory/mavibot/branches/with-txns/mavibot/src/test/java/org/apache/directory/mavibot/btree/MultiThreadedInMemoryBtreeTest.java Tue Apr 29 16:42:33 2014
@@ -210,7 +210,6 @@ public class MultiThreadedInMemoryBtreeT
* Test that we can use many threads inserting data in a BTree
* @throws InterruptedException
*/
- @Ignore
@Test
public void testInsertMultiThreads() throws InterruptedException, IOException
{