You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by sa...@apache.org on 2012/02/28 10:19:40 UTC

svn commit: r1294534 - in /directory/apacheds/branches/apacheds-txns: core-api/src/main/java/org/apache/directory/server/core/api/filtering/ core-api/src/main/java/org/apache/directory/server/core/api/txn/ core-shared/ core-shared/src/main/java/org/apa...

Author: saya
Date: Tue Feb 28 09:19:39 2012
New Revision: 1294534

URL: http://svn.apache.org/viewvc?rev=1294534&view=rev
Log:
Fixed quite a bit of txn boundary issues:
  - On entry to a an entry filtering cursor, txn handle is restored
  - default operation manager takes possibility of an existing txn when starting an operation.
  - bind operation starts a rw transaction.
  - If an abandon listener is to close a txn, it waits for the thread that is currently executing the txn to be done with it. Per cursor txnBusy is introduced for this reason.

Tests are passing but there is quite a bit of todo overall.

Modified:
    directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/AbstractEntryFilteringCursor.java
    directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/BaseEntryFilteringCursor.java
    directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/CursorList.java
    directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnHandle.java
    directory/apacheds/branches/apacheds-txns/core-shared/pom.xml
    directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnManager.java
    directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/Transaction.java
    directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java
    directory/apacheds/branches/apacheds-txns/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/store/MultiBaseSearch.java
    directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java
    directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/extended/CertGenerationRequestHandler.java

Modified: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/AbstractEntryFilteringCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/AbstractEntryFilteringCursor.java?rev=1294534&r1=1294533&r2=1294534&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/AbstractEntryFilteringCursor.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/AbstractEntryFilteringCursor.java Tue Feb 28 09:19:39 2012
@@ -19,9 +19,13 @@
 package org.apache.directory.server.core.api.filtering;
 
 
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
+
 import org.apache.directory.server.core.api.interceptor.context.SearchingOperationContext;
 import org.apache.directory.server.core.api.txn.TxnHandle;
 import org.apache.directory.server.core.api.txn.TxnManager;
+import org.apache.directory.shared.ldap.model.exception.OperationAbandonedException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -43,6 +47,9 @@ public abstract class AbstractEntryFilte
 
     /** The associated transaction */
     protected TxnHandle transaction;
+    
+    /** True if a thread is using the txn */
+    protected AtomicBoolean txnBusy = new AtomicBoolean(false);
 
 
     /**
@@ -62,7 +69,7 @@ public abstract class AbstractEntryFilte
     public void setTxnManager( TxnManager txnManager )
     {
         this.txnManager = txnManager;
-        this.transaction = txnManager.getCurTxn();
+        transaction = txnManager.getCurTxn() ;
     }
 
 
@@ -106,4 +113,115 @@ public abstract class AbstractEntryFilte
             LOG.info( "Cursor has been abandoned." );
         }
     }
+    
+    protected boolean maybeSetCurTxn() throws Exception
+    {
+        if ( transaction != null )
+        {
+            TxnHandle curTxn = txnManager.getCurTxn();
+            
+            if ( curTxn != null )
+            {
+                if ( curTxn != transaction )
+                {
+                    throw new 
+                        IllegalStateException("Shouldnt Have another txn running if cursor has a txn ");
+                }
+            }
+            else
+            {
+                boolean busy = !txnBusy.compareAndSet( false, true );
+                
+                // This can happen if the abondon listener sneaked in and
+                // closed the cursor. return immediately
+                if ( busy )
+                {
+                    throw new OperationAbandonedException();
+                }
+                
+                txnManager.setCurTxn( transaction );
+                
+                return true;
+            }
+        }
+        
+        return false;
+    }
+    
+    protected void endTxnAtClose(boolean abort) throws Exception
+    {
+        if ( transaction == null )
+        {
+            return;
+        }
+        
+        // If this thread already owns the txn, then end it and return
+        TxnHandle curTxn = txnManager.getCurTxn();
+        
+        if ( curTxn != null )
+        {
+            if ( curTxn != transaction )
+            {
+                throw new 
+                    IllegalStateException("Shouldnt Have another txn running if cursor has a txn ");
+            }
+            
+            if ( abort == false )
+            {
+                txnManager.commitTransaction();
+            }
+            else
+            {
+                txnManager.abortTransaction();
+            }
+            
+            txnBusy.set( false );
+            txnManager.setCurTxn( null );
+        }
+        else
+        {
+            while ( !(transaction.getState() == TxnHandle.State.COMMIT || 
+                transaction.getState() == TxnHandle.State.ABORT) )
+            {
+                boolean busy = !txnBusy.compareAndSet( false, true );
+                
+                // This can happen if the abondon listener sneaked in and
+                // closed the cursor. return immediately
+                if ( busy )
+                {
+                    try
+                    {
+                        System.out.println("sleeping " + this);
+                        Thread.sleep( 100 );
+                    }
+                    catch( Exception e )
+                    {
+                        //ignore
+                    }
+                    continue;
+                }
+                
+                if (transaction.getState() == TxnHandle.State.COMMIT || 
+                    transaction.getState() == TxnHandle.State.ABORT)
+                {
+                    txnBusy.set( false );
+                    break;
+                }
+                
+                txnManager.setCurTxn( transaction ); 
+                
+                if ( abort == false )
+                {
+                    txnManager.commitTransaction();
+                }
+                else
+                {
+                    txnManager.abortTransaction();
+                }
+                
+                txnBusy.set( false );
+                txnManager.setCurTxn( null );
+            }
+        }
+    }
 }

Modified: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/BaseEntryFilteringCursor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/BaseEntryFilteringCursor.java?rev=1294534&r1=1294533&r2=1294534&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/BaseEntryFilteringCursor.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/BaseEntryFilteringCursor.java Tue Feb 28 09:19:39 2012
@@ -169,9 +169,22 @@ public class BaseEntryFilteringCursor ex
      * {@inheritDoc}
      */
     public void afterLast() throws Exception
-    {
-        wrapped.afterLast();
-        prefetched = null;
+    {   
+        boolean setCurTxn = maybeSetCurTxn();
+        
+        try
+        {
+            wrapped.afterLast();
+            prefetched = null;
+        }
+        finally
+        {
+            if ( setCurTxn )
+            {
+                txnBusy.set( false );
+                txnManager.setCurTxn( null );
+            }
+        }
     }
 
 
@@ -198,8 +211,21 @@ public class BaseEntryFilteringCursor ex
      */
     public void beforeFirst() throws Exception
     {
-        wrapped.beforeFirst();
-        prefetched = null;
+        boolean setCurTxn = maybeSetCurTxn();
+        
+        try
+        {
+            wrapped.beforeFirst();
+            prefetched = null;
+        }
+        finally
+        {
+            if ( setCurTxn )
+            {
+                txnBusy.set( false );
+                txnManager.setCurTxn( null );
+            }
+        }
     }
 
 
@@ -207,27 +233,15 @@ public class BaseEntryFilteringCursor ex
      * {@inheritDoc}
      */
     public void close() throws Exception
-    {
-        wrapped.close();
-        prefetched = null;
-
-        if ( txnManager != null )
+    {        
+        try
+        {            
+            wrapped.close();
+            prefetched = null;
+        }
+        finally
         {
-            TxnHandle curTxn = txnManager.getCurTxn();
-
-            if ( curTxn != null )
-            {
-                if ( transaction != curTxn )
-                {
-                    TxnHandle previousTransaction = txnManager.setCurTxn( transaction );
-                    txnManager.commitTransaction();
-                    txnManager.setCurTxn( previousTransaction );
-                }
-                else
-                {
-                    txnManager.commitTransaction();
-                }
-            }
+            endTxnAtClose( false );
         }
     }
 
@@ -237,14 +251,14 @@ public class BaseEntryFilteringCursor ex
      */
     public void close( Exception reason ) throws Exception
     {
-        wrapped.close( reason );
-        prefetched = null;
-
-        if ( txnManager != null )
+        try
+        {   
+            wrapped.close( reason );
+            prefetched = null;
+        }
+        finally
         {
-            TxnHandle previousTransaction = txnManager.setCurTxn( transaction );
-            txnManager.abortTransaction();
-            txnManager.setCurTxn( previousTransaction );
+            endTxnAtClose( true );
         }
     }
 
@@ -269,9 +283,22 @@ public class BaseEntryFilteringCursor ex
             close();
             throw new OperationAbandonedException();
         }
-
-        beforeFirst();
-        return next();
+        
+        boolean setCurTxn = maybeSetCurTxn();
+        
+        try
+        {
+            beforeFirst();
+            return next();
+        }
+        finally
+        {
+            if ( setCurTxn )
+            {
+                txnBusy.set( false );
+                txnManager.setCurTxn( null );
+            }
+        }
     }
 
 
@@ -309,9 +336,22 @@ public class BaseEntryFilteringCursor ex
             close();
             throw new OperationAbandonedException();
         }
-
-        afterLast();
-        return previous();
+        
+        boolean setCurTxn = maybeSetCurTxn();
+        
+        try
+        {
+            afterLast();
+            return previous();
+        }
+        finally
+        {
+            if ( setCurTxn )
+            {
+                txnBusy.set( false );
+                txnManager.setCurTxn( null );
+            }
+        }
     }
 
 
@@ -446,19 +486,13 @@ public class BaseEntryFilteringCursor ex
             close();
             throw new OperationAbandonedException();
         }
-
-        Entry tempResult = null;
-
-        // Switch the current transaction
-        TxnHandle previousTxn = null;
-
-        if ( txnManager != null )
-        {
-            previousTxn = txnManager.setCurTxn( transaction );
-        }
-
+        
+        boolean setCurTxn = maybeSetCurTxn();
+        
         try
-        {
+        { 
+            Entry tempResult = null;
+
             outer: while ( wrapped.next() )
             {
                 boolean accepted = true;
@@ -514,18 +548,18 @@ public class BaseEntryFilteringCursor ex
 
                 return true;
             }
+        
+            prefetched = null;
+            return false;
         }
         finally
         {
-            // Switch back the previous transaction
-            if ( txnManager != null )
+            if ( setCurTxn )
             {
-                txnManager.setCurTxn( previousTxn );
+                txnBusy.set( false );
+                txnManager.setCurTxn( null );
             }
         }
-
-        prefetched = null;
-        return false;
     }
 
 
@@ -540,58 +574,71 @@ public class BaseEntryFilteringCursor ex
             close();
             throw new OperationAbandonedException();
         }
-
-        Entry tempResult = null;
-
-        outer: while ( wrapped.previous() )
+        
+        boolean setCurTxn = maybeSetCurTxn();
+        
+        try
         {
-            boolean accepted = true;
-            tempResult = new ClonedServerEntrySearch( wrapped.get() );
-
-            /*
-             * O P T I M I Z A T I O N
-             * -----------------------
-             * 
-             * Don't want to waste cycles on enabling a loop for processing 
-             * filters if we have zero or one filter.
-             */
-
-            if ( filters.isEmpty() )
-            {
-                prefetched = tempResult;
-                filterContents( prefetched );
-                return true;
-            }
-
-            if ( ( filters.size() == 1 ) && filters.get( 0 ).accept( getOperationContext(), tempResult ) )
+            Entry tempResult = null;
+    
+            outer: while ( wrapped.previous() )
             {
+                boolean accepted = true;
+                tempResult = new ClonedServerEntrySearch( wrapped.get() );
+    
+                /*
+                 * O P T I M I Z A T I O N
+                 * -----------------------
+                 * 
+                 * Don't want to waste cycles on enabling a loop for processing 
+                 * filters if we have zero or one filter.
+                 */
+    
+                if ( filters.isEmpty() )
+                {
+                    prefetched = tempResult;
+                    filterContents( prefetched );
+                    return true;
+                }
+    
+                if ( ( filters.size() == 1 ) && filters.get( 0 ).accept( getOperationContext(), tempResult ) )
+                {
+                    prefetched = tempResult;
+                    filterContents( prefetched );
+                    return true;
+                }
+    
+                /* E N D   O P T I M I Z A T I O N */
+    
+                for ( EntryFilter filter : filters )
+                {
+                    // if a filter rejects then short and continue with outer loop
+                    if ( !( accepted &= filter.accept( getOperationContext(), tempResult ) ) )
+                    {
+                        continue outer;
+                    }
+                }
+    
+                /*
+                 * Here the entry has been accepted by all filters.
+                 */
                 prefetched = tempResult;
                 filterContents( prefetched );
                 return true;
             }
-
-            /* E N D   O P T I M I Z A T I O N */
-
-            for ( EntryFilter filter : filters )
+    
+            prefetched = null;
+    
+            return false;     
+        }
+        finally
+        {
+            if ( setCurTxn )
             {
-                // if a filter rejects then short and continue with outer loop
-                if ( !( accepted &= filter.accept( getOperationContext(), tempResult ) ) )
-                {
-                    continue outer;
-                }
+                txnBusy.set( false );
+                txnManager.setCurTxn( null );
             }
-
-            /*
-             * Here the entry has been accepted by all filters.
-             */
-            prefetched = tempResult;
-            filterContents( prefetched );
-            return true;
         }
-
-        prefetched = null;
-
-        return false;
     }
 
 
@@ -641,5 +688,10 @@ public class BaseEntryFilteringCursor ex
     {
         throw new UnsupportedOperationException( I18n.err( I18n.ERR_02014_UNSUPPORTED_OPERATION, getClass().getName()
             .concat( "." ).concat( "isLast()" ) ) );
-    }
+    } 
 }
+
+
+    
+    
+    
\ No newline at end of file

Modified: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/CursorList.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/CursorList.java?rev=1294534&r1=1294533&r2=1294534&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/CursorList.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/filtering/CursorList.java Tue Feb 28 09:19:39 2012
@@ -162,8 +162,21 @@ public class CursorList extends Abstract
      */
     public void beforeFirst() throws Exception
     {
-        this.index = 0;
-        list.get( index ).beforeFirst();
+        boolean setCurTxn = maybeSetCurTxn();
+        
+        try
+        {
+            this.index = 0;
+            list.get( index ).beforeFirst();
+        }
+        finally
+        {
+            if ( setCurTxn )
+            {
+                txnBusy.set( false );
+                txnManager.setCurTxn( null );
+            }
+        }
     }
 
 
@@ -172,8 +185,23 @@ public class CursorList extends Abstract
      */
     public void afterLast() throws Exception
     {
-        this.index = end - 1;
-        list.get( index ).afterLast();
+        boolean setCurTxn = maybeSetCurTxn();
+        
+        try
+        {
+            this.index = end - 1;
+            list.get( index ).afterLast();
+        }
+        finally
+        {
+            if ( setCurTxn )
+            {
+                txnBusy.set( false );
+                txnManager.setCurTxn( null );
+            }
+        }
+
+         
     }
 
 
@@ -182,13 +210,26 @@ public class CursorList extends Abstract
      */
     public boolean first() throws Exception
     {
-        if ( list.size() > 0 )
+        boolean setCurTxn = maybeSetCurTxn();
+        
+        try
         {
-            index = start;
-            return list.get( index ).first();
+            if ( list.size() > 0 )
+            {
+                index = start;
+                return list.get( index ).first();
+            }
+    
+            return false;
+        }
+        finally
+        {
+            if ( setCurTxn )
+            {
+                txnBusy.set( false );
+                txnManager.setCurTxn( null );
+            }
         }
-
-        return false;
     }
 
 
@@ -197,13 +238,26 @@ public class CursorList extends Abstract
      */
     public boolean last() throws Exception
     {
-        if ( list.size() > 0 )
+        boolean setCurTxn = maybeSetCurTxn();
+        
+        try
         {
-            index = end - 1;
-            return list.get( index ).last();
+            if ( list.size() > 0 )
+            {
+                index = end - 1;
+                return list.get( index ).last();
+            }
+    
+            return false;
+        }
+        finally
+        {
+            if ( setCurTxn )
+            {
+                txnBusy.set( false );
+                txnManager.setCurTxn( null );
+            }
         }
-
-        return false;
     }
 
 
@@ -212,7 +266,21 @@ public class CursorList extends Abstract
      */
     public boolean isFirst() throws Exception
     {
-        return ( list.size() > 0 ) && ( index == start ) && list.get( index ).first();
+        boolean setCurTxn = maybeSetCurTxn();
+        
+        try
+        {
+            return ( list.size() > 0 ) && ( index == start ) && list.get( index ).first();
+        }
+        finally
+        {
+            if ( setCurTxn )
+            {
+                txnBusy.set( false );
+                txnManager.setCurTxn( null );
+            }
+        }
+        
     }
 
 
@@ -221,7 +289,20 @@ public class CursorList extends Abstract
      */
     public boolean isLast() throws Exception
     {
-        return ( list.size() > 0 ) && ( index == end - 1 ) && list.get( index ).last();
+        boolean setCurTxn = maybeSetCurTxn();
+        
+        try
+        {
+            return ( list.size() > 0 ) && ( index == end - 1 ) && list.get( index ).last();
+        }
+        finally
+        {
+            if ( setCurTxn )
+            {
+                txnBusy.set( false );
+                txnManager.setCurTxn( null );
+            }
+        }
     }
 
 
@@ -248,58 +329,72 @@ public class CursorList extends Abstract
      */
     public boolean previous() throws Exception
     {
-        // if parked at -1 we cannot go backwards
-        if ( index == -1 )
+        boolean setCurTxn = maybeSetCurTxn();
+        
+        try
         {
-            return false;
-        }
-
-        // if the index moved back is still greater than or eq to start then OK
-        if ( index - 1 >= start )
-        {
-            if ( index == end )
+            // if parked at -1 we cannot go backwards
+            if ( index == -1 )
             {
-                index--;
+                return false;
             }
-
-            if ( !list.get( index ).previous() )
+    
+            // if the index moved back is still greater than or eq to start then OK
+            if ( index - 1 >= start )
             {
-                index--;
-                if ( index != -1 )
+                if ( index == end )
                 {
-                    return list.get( index ).previous();
+                    index--;
+                }
+    
+                if ( !list.get( index ).previous() )
+                {
+                    index--;
+                    if ( index != -1 )
+                    {
+                        return list.get( index ).previous();
+                    }
+                    else
+                    {
+                        return false;
+                    }
                 }
                 else
                 {
-                    return false;
+                    return true;
                 }
             }
-            else
+    
+            // if the index currently less than or equal to start we need to park it at -1 and return false
+            if ( index <= start )
             {
-                return true;
+                if ( !list.get( index ).previous() )
+                {
+                    index = -1;
+                    return false;
+                }
+                else
+                {
+                    return true;
+                }
             }
-        }
-
-        // if the index currently less than or equal to start we need to park it at -1 and return false
-        if ( index <= start )
-        {
-            if ( !list.get( index ).previous() )
+    
+            if ( list.size() <= 0 )
             {
                 index = -1;
-                return false;
-            }
-            else
-            {
-                return true;
             }
+    
+            return false;
+        
         }
-
-        if ( list.size() <= 0 )
+        finally
         {
-            index = -1;
+            if ( setCurTxn )
+            {
+                txnBusy.set( false );
+                txnManager.setCurTxn( null );
+            }
         }
-
-        return false;
     }
 
 
@@ -308,54 +403,67 @@ public class CursorList extends Abstract
      */
     public boolean next() throws Exception
     {
-        // if parked at -1 we advance to the start index and return true
-        if ( list.size() > 0 && index == -1 )
-        {
-            index = start;
-            return list.get( index ).next();
-        }
-
-        // if the index plus one is less than the end then increment and return true
-        if ( list.size() > 0 && index + 1 < end )
+        boolean setCurTxn = maybeSetCurTxn();
+        
+        try
         {
-            if ( !list.get( index ).next() )
+            // if parked at -1 we advance to the start index and return true
+            if ( list.size() > 0 && index == -1 )
             {
-                index++;
-                if ( index < end )
+                index = start;
+                return list.get( index ).next();
+            }
+    
+            // if the index plus one is less than the end then increment and return true
+            if ( list.size() > 0 && index + 1 < end )
+            {
+                if ( !list.get( index ).next() )
                 {
-                    return list.get( index ).next();
+                    index++;
+                    if ( index < end )
+                    {
+                        return list.get( index ).next();
+                    }
+                    else
+                    {
+                        return false;
+                    }
                 }
                 else
                 {
+                    return true;
+                }
+            }
+    
+            // if the index plus one is equal to the end then increment and return false
+            if ( list.size() > 0 && index + 1 == end )
+            {
+                if ( !list.get( index ).next() )
+                {
+                    index++;
                     return false;
                 }
+                else
+                {
+                    return true;
+                }
             }
-            else
+    
+            if ( list.size() <= 0 )
             {
-                return true;
+                index = end;
             }
+    
+            return false;
         }
-
-        // if the index plus one is equal to the end then increment and return false
-        if ( list.size() > 0 && index + 1 == end )
+        finally
         {
-            if ( !list.get( index ).next() )
-            {
-                index++;
-                return false;
-            }
-            else
+            if ( setCurTxn )
             {
-                return true;
+                txnBusy.set( false );
+                txnManager.setCurTxn( null );
             }
         }
-
-        if ( list.size() <= 0 )
-        {
-            index = end;
-        }
-
-        return false;
     }
 
 
@@ -449,16 +557,13 @@ public class CursorList extends Abstract
             }
         }
 
-        if ( txnManager != null )
+        if ( reason == null )
         {
-            if ( reason == null )
-            {
-                txnManager.commitTransaction();
-            }
-            else
-            {
-                txnManager.abortTransaction();
-            }
+            this.endTxnAtClose( false );
+        }
+        else
+        {
+            this.endTxnAtClose( true );
         }
     }
 

Modified: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnHandle.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnHandle.java?rev=1294534&r1=1294533&r2=1294534&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnHandle.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnHandle.java Tue Feb 28 09:19:39 2012
@@ -27,5 +27,19 @@ package org.apache.directory.server.core
  */
 public interface TxnHandle
 {
-    public long getId();
+    /**
+     * Returns the current state of the txn
+     *
+     * @return
+     */
+    State getState();
+    
+    enum State
+    {
+        INITIAL,
+        READ,
+        COMMIT,
+        ABORT
+    }
+
 }

Modified: directory/apacheds/branches/apacheds-txns/core-shared/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/pom.xml?rev=1294534&r1=1294533&r2=1294534&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-shared/pom.xml (original)
+++ directory/apacheds/branches/apacheds-txns/core-shared/pom.xml Tue Feb 28 09:19:39 2012
@@ -80,7 +80,6 @@
     <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
-       <scope>test</scope>
     </dependency>
   </dependencies>
 

Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnManager.java?rev=1294534&r1=1294533&r2=1294534&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnManager.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnManager.java Tue Feb 28 09:19:39 2012
@@ -227,7 +227,7 @@ class DefaultTxnManager implements TxnMa
         {
             throw new IOException( "Flushing of txns failed" );
         }
-
+        
         prepareForEndingTxn( txn );
 
         if ( txn instanceof ReadOnlyTxn )

Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/Transaction.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/Transaction.java?rev=1294534&r1=1294533&r2=1294534&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/Transaction.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/Transaction.java Tue Feb 28 09:19:39 2012
@@ -91,14 +91,6 @@ interface Transaction extends TxnHandle
 
 
     /**
-     * Returns the current state of the txn
-     *
-     * @return
-     */
-    State getState();
-
-
-    /**
      * Provides a transactionally consistent view of the entry.
      *
      * @param partitionDn dn of the partition the entry lives in.
@@ -146,11 +138,4 @@ interface Transaction extends TxnHandle
      */
     boolean mergeExistence( Dn partitionDN, String attributeOid, IndexEntry<?> indexEntry, boolean currentlyExists );
 
-    enum State
-    {
-        INITIAL,
-        READ,
-        COMMIT,
-        ABORT
-    }
 }

Modified: directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java?rev=1294534&r1=1294533&r2=1294534&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java (original)
+++ directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java Tue Feb 28 09:19:39 2012
@@ -397,13 +397,19 @@ public class DefaultOperationManager imp
             // Call the Add method
             Interceptor head = directoryService.getInterceptor( addContext.getNextInterceptor() );
 
+            boolean startedTxn = false;
             TxnManager txnManager = directoryService.getTxnManager();
+            TxnHandle curTxn = txnManager.getCurTxn();
 
             boolean done = false;
 
             do
             {
-                beginTransactionRW( txnManager );
+                if( curTxn == null )
+                {
+                    beginTransactionRW( txnManager );
+                    startedTxn = true;
+                }
 
                 try
                 {
@@ -413,12 +419,19 @@ public class DefaultOperationManager imp
                 }
                 catch ( LdapException le )
                 {
-                    abortTransaction( txnManager, le );
+                    if ( startedTxn )
+                    {
+                        abortTransaction( txnManager, le );
+                    }
 
                     throw le;
                 }
 
-                commitTransaction( txnManager );
+                if ( startedTxn )
+                {
+                    commitTransaction( txnManager );
+                }
+                
                 txnManager.applyPendingTxns();
             }
             while ( !done );
@@ -443,10 +456,10 @@ public class DefaultOperationManager imp
 
         boolean done = false;
         TxnManager txnManager = directoryService.getTxnManager();
-
+        
         do
         {
-            beginTransactionR( txnManager );
+            beginTransactionRW( txnManager );
 
             try
             {
@@ -454,7 +467,15 @@ public class DefaultOperationManager imp
             }
             catch ( LdapException le )
             {
-                abortTransaction( txnManager, le );
+                /*
+                 *  TODO : Bind expects the changes to be committed even if the
+                 *  authentication fails. We should certainly skip some exceptions
+                 *  here. For now commit on every exception other than maybe
+                 *  conflict exception.
+                 */
+                
+                commitTransaction( txnManager );
+               
 
                 throw ( le );
             }
@@ -627,13 +648,19 @@ public class DefaultOperationManager imp
         // Unlock the ReferralManager
         directoryService.getReferralManager().unlock();
 
+        boolean startedTxn = false;
         TxnManager txnManager = directoryService.getTxnManager();
+        TxnHandle curTxn = txnManager.getCurTxn();
 
         boolean done = false;
 
         do
         {
-            beginTransactionRW( txnManager );
+            if ( curTxn == null )
+            {
+                beginTransactionRW( txnManager );
+                startedTxn = true;
+            }
 
             try
             {
@@ -650,12 +677,18 @@ public class DefaultOperationManager imp
             }
             catch ( LdapException le )
             {
-                abortTransaction( txnManager, le );
+                if ( startedTxn )
+                {
+                    abortTransaction( txnManager, le );
+                }
 
                 throw le;
             }
 
-            commitTransaction( txnManager );
+            if ( startedTxn )
+            {
+                commitTransaction( txnManager );
+            }
             txnManager.applyPendingTxns();
         }
         while ( !done );
@@ -743,6 +776,7 @@ public class DefaultOperationManager imp
             cursor = head.list( listContext );
 
             cursor.setTxnManager( txnManager );
+            txnManager.setCurTxn( null );
         }
         catch ( LdapException le )
         {
@@ -868,11 +902,17 @@ public class DefaultOperationManager imp
         referralManager.unlock();
 
         boolean done = false;
+        boolean startedTxn = false;
         TxnManager txnManager = directoryService.getTxnManager();
+        TxnHandle curTxn = txnManager.getCurTxn();
 
         do
         {
-            beginTransactionRW( txnManager );
+            if ( curTxn == null )
+            {
+                beginTransactionRW( txnManager );
+                startedTxn = true;
+            }
 
             try
             {
@@ -886,7 +926,10 @@ public class DefaultOperationManager imp
             }
             catch ( LdapException le )
             {
-                abortTransaction( txnManager, le );
+                if ( startedTxn )
+                {
+                    abortTransaction( txnManager, le );
+                }
 
                 throw ( le );
             }
@@ -894,7 +937,10 @@ public class DefaultOperationManager imp
             // If here then we are done.
             done = true;
 
-            commitTransaction( txnManager );
+            if ( startedTxn )
+            {
+                commitTransaction( txnManager );
+            }
             txnManager.applyPendingTxns();
         }
         while ( !done );
@@ -990,11 +1036,17 @@ public class DefaultOperationManager imp
         directoryService.getReferralManager().unlock();
 
         boolean done = false;
+        boolean startedTxn = false;
         TxnManager txnManager = directoryService.getTxnManager();
+        TxnHandle curTxn = txnManager.getCurTxn();
 
         do
         {
-            beginTransactionRW( txnManager );
+            if ( curTxn == null )
+            {
+                beginTransactionRW( txnManager );
+                startedTxn = true;
+            }
 
             try
             {
@@ -1009,7 +1061,10 @@ public class DefaultOperationManager imp
             }
             catch ( LdapException le )
             {
-                abortTransaction( txnManager, le );
+                if ( startedTxn )
+                {
+                    abortTransaction( txnManager, le );
+                }
 
                 throw ( le );
             }
@@ -1017,7 +1072,10 @@ public class DefaultOperationManager imp
             // If here then we are done.
             done = true;
 
-            commitTransaction( txnManager );
+            if ( startedTxn )
+            {
+                commitTransaction( txnManager );
+            }
             txnManager.applyPendingTxns();
         }
         while ( !done );
@@ -1115,11 +1173,17 @@ public class DefaultOperationManager imp
         directoryService.getReferralManager().unlock();
 
         boolean done = false;
+        boolean startedTxn = false;
         TxnManager txnManager = directoryService.getTxnManager();
+        TxnHandle curTxn = txnManager.getCurTxn();
 
         do
         {
-            beginTransactionRW( txnManager );
+            if ( curTxn == null )
+            {
+                beginTransactionRW( txnManager );
+                startedTxn = true;
+            }
 
             try
             {
@@ -1133,7 +1197,10 @@ public class DefaultOperationManager imp
             }
             catch ( LdapException le )
             {
-                abortTransaction( txnManager, le );
+                if ( startedTxn )
+                {
+                    abortTransaction( txnManager, le );
+                }
 
                 throw ( le );
             }
@@ -1141,7 +1208,10 @@ public class DefaultOperationManager imp
             // If here then we are done.
             done = true;
 
-            commitTransaction( txnManager );
+            if ( startedTxn )
+            {
+                commitTransaction( txnManager );
+            }
             txnManager.applyPendingTxns();
         }
         while ( !done );
@@ -1227,11 +1297,17 @@ public class DefaultOperationManager imp
         directoryService.getReferralManager().unlock();
 
         boolean done = false;
+        boolean startedTxn = false;
         TxnManager txnManager = directoryService.getTxnManager();
+        TxnHandle curTxn = txnManager.getCurTxn();
 
         do
         {
-            beginTransactionRW( txnManager );
+            if ( curTxn == null )
+            {
+                beginTransactionRW( txnManager );
+                startedTxn = true;
+            }
 
             try
             {
@@ -1249,7 +1325,10 @@ public class DefaultOperationManager imp
             }
             catch ( LdapException le )
             {
-                abortTransaction( txnManager, le );
+                if ( startedTxn )
+                {
+                    abortTransaction( txnManager, le );
+                }
 
                 throw ( le );
             }
@@ -1257,7 +1336,10 @@ public class DefaultOperationManager imp
             // If here then we are done.
             done = true;
 
-            commitTransaction( txnManager );
+            if ( startedTxn )
+            {
+                commitTransaction( txnManager );
+            }
             txnManager.applyPendingTxns();
         }
         while ( !done );
@@ -1347,6 +1429,7 @@ public class DefaultOperationManager imp
             cursor = head.search( searchContext );
 
             cursor.setTxnManager( txnManager );
+            txnManager.setCurTxn( null );
         }
         catch ( LdapException le )
         {

Modified: directory/apacheds/branches/apacheds-txns/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/store/MultiBaseSearch.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/store/MultiBaseSearch.java?rev=1294534&r1=1294533&r2=1294534&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/store/MultiBaseSearch.java (original)
+++ directory/apacheds/branches/apacheds-txns/kerberos-codec/src/main/java/org/apache/directory/server/kerberos/shared/store/MultiBaseSearch.java Tue Feb 28 09:19:39 2012
@@ -61,7 +61,7 @@ class MultiBaseSearch implements Princip
         
         try
         {
-            txnManager.beginTransaction( true );
+            //txnManager.beginTransaction( true );
             
             try
             {
@@ -70,12 +70,12 @@ class MultiBaseSearch implements Princip
             }
             catch ( Exception e )
             {
-                txnManager.abortTransaction();
+                //txnManager.abortTransaction();
 
                 throw e;
             }
             
-            txnManager.commitTransaction();
+            //txnManager.commitTransaction();
 
         }
         catch ( Exception e )
@@ -92,7 +92,7 @@ class MultiBaseSearch implements Princip
         
         try
         {
-            txnManager.beginTransaction( true );
+            //txnManager.beginTransaction( true );
             
             try
             {
@@ -100,12 +100,12 @@ class MultiBaseSearch implements Princip
             }
             catch ( NamingException ne )
             {
-                txnManager.abortTransaction();
+                //txnManager.abortTransaction();
 
                 throw ne;
             }
             
-            txnManager.commitTransaction();
+            //txnManager.commitTransaction();
 
         }
         catch ( Exception e )
@@ -127,7 +127,7 @@ class MultiBaseSearch implements Princip
         {
             do
             {
-                txnManager.beginTransaction( false );
+                //txnManager.beginTransaction( false );
             
                 try
                 {
@@ -135,7 +135,7 @@ class MultiBaseSearch implements Princip
                 }
                 catch ( NamingException ne )
                 {
-                    txnManager.abortTransaction();
+                    //txnManager.abortTransaction();
     
                     throw ne;
                 }
@@ -144,7 +144,7 @@ class MultiBaseSearch implements Princip
                 
                 try
                 {
-                    txnManager.commitTransaction();
+                    //txnManager.commitTransaction();
                 }
                 catch ( Exception e )
                 {

Modified: directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java?rev=1294534&r1=1294533&r2=1294534&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java (original)
+++ directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java Tue Feb 28 09:19:39 2012
@@ -539,8 +539,8 @@ public class SearchHandler extends LdapR
                 pagedContext.incrementCurrentPosition( pageCount );
 
                 // Suspend the current txn
-                TxnHandle txnHandle = txnManager.suspendCurTxn();
-                pagedContext.setTxnHandle( txnHandle );
+               // TxnHandle txnHandle = txnManager.suspendCurTxn();
+                //pagedContext.setTxnHandle( txnHandle );
 
                 return;
             }
@@ -1693,70 +1693,4 @@ public class SearchHandler extends LdapR
     {
         this.replicationReqHandler = replicationReqHandler;
     }
-
-
-    private boolean checkPagedSearchTxnResume( LdapSession session, SearchRequest req )
-    {
-        boolean resumedTxn = false;
-
-        PagedResultsDecorator pagedSearchControl = ( PagedResultsDecorator ) req.getControls().get( PagedResults.OID );
-
-        if ( pagedSearchControl != null )
-        {
-            byte[] cookie = pagedSearchControl.getCookie();
-
-            if ( !Strings.isEmpty( cookie ) )
-            {
-                int cookieValue = pagedSearchControl.getCookieValue();
-                PagedSearchContext pagedContext = session.getPagedSearchContext( cookieValue );
-
-                if ( pagedContext != null )
-                {
-                    TxnHandle txnHandle = pagedContext.getTxnHandle();
-                    pagedContext.setTxnHandle( null );
-                    txnManager.resumeTxn( txnHandle );
-                    resumedTxn = true;
-                }
-            }
-        }
-
-        return resumedTxn;
-    }
-
-
-    private void beginTxnForSearch( LdapSession session, SearchRequest req ) throws Exception
-    {
-        boolean resumedTxn = checkPagedSearchTxnResume( session, req );
-
-        // If resumed an existing txn then just return
-
-        if ( resumedTxn )
-        {
-            return;
-        }
-
-        txnManager.beginTransaction( true );
-    }
-
-
-    private void endTxnForSearch( boolean abort ) throws Exception
-    {
-        // Paged search might have suspended the execution of the txn
-        TxnHandle txnHandle = txnManager.getCurTxn();
-
-        if ( txnHandle == null )
-        {
-            return;
-        }
-
-        if ( abort == false )
-        {
-            txnManager.commitTransaction();
-        }
-        else
-        {
-            txnManager.abortTransaction();
-        }
-
-    }
 }

Modified: directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/extended/CertGenerationRequestHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/extended/CertGenerationRequestHandler.java?rev=1294534&r1=1294533&r2=1294534&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/extended/CertGenerationRequestHandler.java (original)
+++ directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/extended/CertGenerationRequestHandler.java Tue Feb 28 09:19:39 2012
@@ -83,7 +83,7 @@ public class CertGenerationRequestHandle
 
         do
         {
-            txnManager.beginTransaction( false );
+            //txnManager.beginTransaction( false );
 
             try
             {
@@ -100,7 +100,7 @@ public class CertGenerationRequestHandle
             }
             catch ( Exception e )
             {
-                txnManager.abortTransaction();
+                //txnManager.abortTransaction();
 
                 // TODO Instead of rethrowing the exception here all the time, check
                 // if the root cause if conflictexception and retry by going to he
@@ -112,7 +112,7 @@ public class CertGenerationRequestHandle
             }
 
             // If here then we are done.
-            txnManager.commitTransaction();
+            //txnManager.commitTransaction();
             done = true;
         }
         while ( !done );