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 2017/10/15 22:17:54 UTC
svn commit: r1812237 - in
/directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree:
AbstractTransaction.java BTree.java WriteTransaction.java
Author: elecharny
Date: Sun Oct 15 22:17:54 2017
New Revision: 1812237
URL: http://svn.apache.org/viewvc?rev=1812237&view=rev
Log:
o Added the aborted flag that is set when an exception is raised why processing a transaction
o Handled exceptions in BTree operations so that the aborted flag is set and the transaction get rolled back (the try-with-resource system does not allow catching such exception and aborting the transaction. Now, if the flag 'aborted' is set to true, the transaction is aborted when it gets closed)
Modified:
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractTransaction.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTree.java
directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/WriteTransaction.java
Modified: directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractTransaction.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractTransaction.java?rev=1812237&r1=1812236&r2=1812237&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractTransaction.java (original)
+++ directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractTransaction.java Sun Oct 15 22:17:54 2017
@@ -53,6 +53,9 @@ public abstract class AbstractTransactio
/** A flag used to tell if a transaction is closed or not */
private volatile boolean closed;
+ /** A flag set to <tt>true</tt> if an exception has been raised */
+ protected volatile boolean aborted = false;
+
/** The reference to the recordManager */
protected RecordManager recordManager;
@@ -92,7 +95,15 @@ public abstract class AbstractTransactio
@Override
public <K, V> Page<K, V> getPage( BTreeInfo<K, V> btreeInfo, long offset ) throws IOException
{
- return ( Page<K, V> ) recordManager.getPage( btreeInfo, recordManagerHeader.pageSize, offset );
+ try
+ {
+ return ( Page<K, V> ) recordManager.getPage( btreeInfo, recordManagerHeader.pageSize, offset );
+ }
+ catch ( IOException ioe )
+ {
+ aborted = true;
+ throw ioe;
+ }
}
@@ -171,7 +182,7 @@ public abstract class AbstractTransactio
@Override
public void abort() throws IOException
{
- closed = true;
+ aborted = true;
}
@@ -197,6 +208,7 @@ public abstract class AbstractTransactio
if ( btree == null )
{
+ aborted = true;
throw new BTreeNotFoundException( "Cannot find btree " + name );
}
Modified: directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTree.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTree.java?rev=1812237&r1=1812236&r2=1812237&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTree.java (original)
+++ directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTree.java Sun Oct 15 22:17:54 2017
@@ -130,7 +130,7 @@ public class BTree<K, V> implements Clos
* @return A cursor on the B-tree
* @throws IOException
*/
- public TupleCursor<K, V> browse( Transaction transaction ) throws IOException, KeyNotFoundException, CursorException
+ public TupleCursor<K, V> browse( Transaction transaction ) throws IOException
{
if ( transaction == null )
{
@@ -138,14 +138,22 @@ public class BTree<K, V> implements Clos
}
else
{
- ParentPos<K, V>[] stack = ( ParentPos<K, V>[] ) Array.newInstance( ParentPos.class, MAX_STACK_DEPTH );
-
- TupleCursor<K, V> cursor = getRootPage().browse( transaction, stack, 0 );
-
- // Set the position before the first element
- cursor.beforeFirst();
-
- return cursor;
+ try
+ {
+ ParentPos<K, V>[] stack = ( ParentPos<K, V>[] ) Array.newInstance( ParentPos.class, MAX_STACK_DEPTH );
+
+ TupleCursor<K, V> cursor = getRootPage().browse( transaction, stack, 0 );
+
+ // Set the position before the first element
+ cursor.beforeFirst();
+
+ return cursor;
+ }
+ catch ( Exception e )
+ {
+ transaction.abort();
+ throw e;
+ }
}
}
@@ -168,7 +176,15 @@ public class BTree<K, V> implements Clos
ParentPos<K, V>[] stack = ( ParentPos<K, V>[] ) Array.newInstance( ParentPos.class, MAX_STACK_DEPTH );
- return getRootPage().browse( transaction, key, stack, 0 );
+ try
+ {
+ return getRootPage().browse( transaction, key, stack, 0 );
+ }
+ catch ( Exception e )
+ {
+ transaction.abort();
+ throw e;
+ }
}
@@ -197,7 +213,15 @@ public class BTree<K, V> implements Clos
}
else
{
- return getRootPage().contains( transaction, key, value );
+ try
+ {
+ return getRootPage().contains( transaction, key, value );
+ }
+ catch ( Exception e )
+ {
+ transaction.abort();
+ throw e;
+ }
}
}
@@ -219,24 +243,33 @@ public class BTree<K, V> implements Clos
if ( key == null )
{
+ transaction.abort();
throw new IllegalArgumentException( "Key must not be null" );
}
- DeleteResult<K, V> result = processDelete( transaction, key );
-
- // Check that we have found the element to delete
- if ( result instanceof NotPresentResult )
+ try
{
- // We haven't found the element in the B-tree, just get out
- // without updating the recordManager
-
- return null;
+ DeleteResult<K, V> result = processDelete( transaction, key );
+
+ // Check that we have found the element to delete
+ if ( result instanceof NotPresentResult )
+ {
+ // We haven't found the element in the B-tree, just get out
+ // without updating the recordManager
+
+ return null;
+ }
+
+ // The element was found, and removed
+ AbstractDeleteResult<K, V> deleteResult = ( AbstractDeleteResult<K, V> ) result;
+
+ return deleteResult.getRemovedElement();
+ }
+ catch ( Exception e )
+ {
+ transaction.abort();
+ throw e;
}
-
- // The element was found, and removed
- AbstractDeleteResult<K, V> deleteResult = ( AbstractDeleteResult<K, V> ) result;
-
- return deleteResult.getRemovedElement();
}
@@ -258,7 +291,15 @@ public class BTree<K, V> implements Clos
}
else
{
- return currentBtreeHeader.getRootPage().get( transaction, key );
+ try
+ {
+ return currentBtreeHeader.getRootPage().get( transaction, key );
+ }
+ catch ( Exception e )
+ {
+ transaction.abort();
+ throw e;
+ }
}
}
@@ -372,7 +413,7 @@ public class BTree<K, V> implements Clos
* @throws IOException If we have an error while trying to access the page
* @throws KeyNotFoundException If the key is not found in the B-tree
*/
- public boolean hasKey( Transaction transaction, K key ) throws IOException, KeyNotFoundException
+ public boolean hasKey( Transaction transaction, K key ) throws IOException
{
if ( key == null )
{
@@ -385,7 +426,15 @@ public class BTree<K, V> implements Clos
}
else
{
- return getRootPage().hasKey( transaction, key );
+ try
+ {
+ return getRootPage().hasKey( transaction, key );
+ }
+ catch ( IOException ioe )
+ {
+ transaction.abort();
+ throw ioe;
+ }
}
}
@@ -413,6 +462,7 @@ public class BTree<K, V> implements Clos
if ( key == null )
{
+ transaction.abort();
throw new IllegalArgumentException( "Key must not be null" );
}
@@ -530,8 +580,14 @@ public class BTree<K, V> implements Clos
}
catch ( IOException ioe )
{
+ transaction.aborted = true;
throw ioe;
}
+ catch ( RuntimeException re )
+ {
+ transaction.abort();
+ throw re;
+ }
}
Modified: directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/WriteTransaction.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/WriteTransaction.java?rev=1812237&r1=1812236&r2=1812237&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/WriteTransaction.java (original)
+++ directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/WriteTransaction.java Sun Oct 15 22:17:54 2017
@@ -72,16 +72,17 @@ public class WriteTransaction extends Ab
@Override
public void close() throws IOException
{
- if ( !isClosed() )
- {
- commit();
- }
- else
+ if ( aborted || isClosed() )
{
+ // We have had an exception, or the txn has been closed : rollback the transaction
newPages.clear();
copiedPageMap.clear();
super.close();
}
+ else
+ {
+ commit();
+ }
}