directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1208354 - /directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/
Date Wed, 30 Nov 2011 09:59:56 GMT
Author: saya
Date: Wed Nov 30 09:59:53 2011
New Revision: 1208354

URL: http://svn.apache.org/viewvc?rev=1208354&view=rev
Log:
Added txn demarcation for the ldap requests. Whether this is the right place is open to debate.
Currently I put the txn begin/end here for the following reasons:

*EntryFilteringCursor is left open and next() on it is called in search handler.
*There are cases where interceptor chain is reentered by calling session methods. All operations
triggered by an ldap request should be part of the same txn.


Modified:
    directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/AddHandler.java
    directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/BindHandler.java
    directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/CompareHandler.java
    directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/DeleteHandler.java
    directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/LdapRequestHandler.java
    directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyDnHandler.java
    directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyHandler.java
    directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java

Modified: directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/AddHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/AddHandler.java?rev=1208354&r1=1208353&r2=1208354&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/AddHandler.java
(original)
+++ directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/AddHandler.java
Wed Nov 30 09:59:53 2011
@@ -48,12 +48,37 @@ public class AddHandler extends LdapRequ
     {
         LOG.debug( "Handling request: {}", req );
         LdapResult result = req.getResultResponse().getLdapResult();
-
+        
         try
         {
-            // Call the underlying layer to inject the new entry 
-            CoreSession coreSession = session.getCoreSession();
-            coreSession.add( req );
+            boolean done = false;
+            
+            do
+            {
+                txnManager.beginTransaction( false );
+                
+                try
+                {    
+                    // Call the underlying layer to inject the new entry
+                    CoreSession coreSession = session.getCoreSession();
+                    coreSession.add( req );
+                }
+                catch ( Exception e )
+                {
+                  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
+                  // beginning of the loop if necessary.
+                  
+                  throw ( e );
+                }
+                
+                // If here then we are done.
+                txnManager.commitTransaction();
+                done = true;
+            }
+            while ( !done );
 
             // If success, here now, otherwise, we would have an exception.
             result.setResultCode( ResultCodeEnum.SUCCESS );

Modified: directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/BindHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/BindHandler.java?rev=1208354&r1=1208353&r2=1208354&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/BindHandler.java
(original)
+++ directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/BindHandler.java
Wed Nov 30 09:59:53 2011
@@ -601,15 +601,40 @@ public class BindHandler extends LdapReq
             ldapSession.getIoSession().write( bindRequest.getResultResponse() );
             return;
         }
-
-        // Deal with the two kinds of authentication : Simple and SASL
-        if ( bindRequest.isSimple() )
+        
+        boolean done = false;
+        
+        do
         {
-            handleSimpleAuth( ldapSession, bindRequest );
-        }
-        else
-        {
-            handleSaslAuth( ldapSession, bindRequest );
+            txnManager.beginTransaction( false );
+            
+            try
+            {    
+             // Deal with the two kinds of authentication : Simple and SASL
+                if ( bindRequest.isSimple() )
+                {
+                    handleSimpleAuth( ldapSession, bindRequest );
+                }
+                else
+                {
+                    handleSaslAuth( ldapSession, bindRequest );
+                }
+            }
+            catch ( Exception e )
+            {
+              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
+              // beginning of the loop if necessary.
+              
+              throw ( e );
+            }
+            
+            // If here then we are done.
+            txnManager.commitTransaction();
+            done = true;
         }
+        while ( !done );
     }
 }

Modified: directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/CompareHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/CompareHandler.java?rev=1208354&r1=1208353&r2=1208354&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/CompareHandler.java
(original)
+++ directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/CompareHandler.java
Wed Nov 30 09:59:53 2011
@@ -20,6 +20,7 @@
 package org.apache.directory.server.ldap.handlers;
 
 
+import org.apache.directory.server.core.api.CoreSession;
 import org.apache.directory.server.ldap.LdapSession;
 import org.apache.directory.shared.ldap.model.message.CompareRequest;
 import org.apache.directory.shared.ldap.model.message.LdapResult;
@@ -49,16 +50,30 @@ public class CompareHandler extends Ldap
         LdapResult result = req.getResultResponse().getLdapResult();
         
         try
-        {
-            if ( session.getCoreSession().compare( req ) )
+        {   
+            txnManager.beginTransaction( true );
+
+            try
             {
-                result.setResultCode( ResultCodeEnum.COMPARE_TRUE );
+                if ( session.getCoreSession().compare( req ) )
+                {
+                    result.setResultCode( ResultCodeEnum.COMPARE_TRUE );
+                }
+                else
+                {
+                    result.setResultCode( ResultCodeEnum.COMPARE_FALSE );
+                }
             }
-            else
+            catch ( Exception e )
             {
-                result.setResultCode( ResultCodeEnum.COMPARE_FALSE );
+                txnManager.abortTransaction();
+                throw ( e );
             }
 
+            // If here then we are done.
+            txnManager.commitTransaction();
+            
+
             result.setMatchedDn( req.getName() );
             session.getIoSession().write( req.getResultResponse() );
         }

Modified: directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/DeleteHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/DeleteHandler.java?rev=1208354&r1=1208353&r2=1208354&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/DeleteHandler.java
(original)
+++ directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/DeleteHandler.java
Wed Nov 30 09:59:53 2011
@@ -49,10 +49,35 @@ public class DeleteHandler extends LdapR
         LdapResult result = req.getResultResponse().getLdapResult();
 
         try
-        {
-            // Call the underlying layer to delete the entry 
-            CoreSession coreSession = session.getCoreSession();
-            coreSession.delete( req );
+        {   
+            boolean done = false;
+            
+            do
+            {
+                txnManager.beginTransaction( false );
+                
+                try
+                {    
+                    // Call the underlying layer to delete the entry 
+                    CoreSession coreSession = session.getCoreSession();
+                    coreSession.delete( req );
+                }
+                catch ( Exception e )
+                {
+                  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
+                  // beginning of the loop if necessary.
+                  
+                  throw ( e );
+                }
+                
+                // If here then we are done.
+                txnManager.commitTransaction();
+                done = true;
+            }
+            while ( !done );
             
             // If success, here now, otherwise, we would have an exception.
             result.setResultCode( ResultCodeEnum.SUCCESS );

Modified: directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/LdapRequestHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/LdapRequestHandler.java?rev=1208354&r1=1208353&r2=1208354&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/LdapRequestHandler.java
(original)
+++ directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/LdapRequestHandler.java
Wed Nov 30 09:59:53 2011
@@ -22,6 +22,8 @@ package org.apache.directory.server.ldap
 
 import org.apache.commons.lang.exception.ExceptionUtils;
 import org.apache.directory.server.core.api.CoreSession;
+import org.apache.directory.server.core.api.txn.TxnManager;
+import org.apache.directory.server.core.shared.txn.TxnManagerFactory;
 import org.apache.directory.server.i18n.I18n;
 import org.apache.directory.server.ldap.LdapServer;
 import org.apache.directory.server.ldap.LdapSession;
@@ -61,7 +63,16 @@ public abstract class LdapRequestHandler
     /** The reference on the Ldap server instance */
     protected LdapServer ldapServer;
 
-
+    /** Txn Manager */
+    protected TxnManager txnManager;
+   
+    
+    public LdapRequestHandler()
+    {
+        txnManager = TxnManagerFactory.txnManagerInstance();
+    }
+    
+    
     /**
      * @return The associated ldap server instance
      */

Modified: directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyDnHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyDnHandler.java?rev=1208354&r1=1208353&r2=1208354&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyDnHandler.java
(original)
+++ directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyDnHandler.java
Wed Nov 30 09:59:53 2011
@@ -85,20 +85,70 @@ public class ModifyDnHandler extends Lda
             CoreSession coreSession = session.getCoreSession();
             
             if ( rdnChanged )
-            {
-                if ( req.getNewSuperior() != null )
-                {
-                    coreSession.moveAndRename( req );
-                }
-                else
+            {   
+                boolean done = false;
+                
+                do
                 {
-                    coreSession.rename( req );
+                    txnManager.beginTransaction( false );
+                    
+                    try
+                    {    
+                        if ( req.getNewSuperior() != null )
+                        {
+                            coreSession.moveAndRename( req );
+                        }
+                        else
+                        {
+                            coreSession.rename( req );
+                        }
+                    }
+                    catch ( Exception e )
+                    {
+                      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
+                      // beginning of the loop if necessary.
+                      
+                      throw ( e );
+                    }
+                    
+                    // If here then we are done.
+                    txnManager.commitTransaction();
+                    done = true;
                 }
+                while ( !done );
             }
             else if ( req.getNewSuperior() != null )
             {
-                req.setNewRdn( null );
-                coreSession.move( req );
+                boolean done = false;
+                
+                do
+                {
+                    txnManager.beginTransaction( false );
+                    
+                    try
+                    {    
+                        req.setNewRdn( null );
+                        coreSession.move( req );
+                    }
+                    catch ( Exception e )
+                    {
+                      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
+                      // beginning of the loop if necessary.
+                      
+                      throw ( e );
+                    }
+                    
+                    // If here then we are done.
+                    txnManager.commitTransaction();
+                    done = true;
+                }
+                while ( !done );
             }
             else
             {
@@ -114,6 +164,7 @@ public class ModifyDnHandler extends Lda
         }
         catch ( Exception e )
         {
+            e.printStackTrace();
             handleException( session, req, e );
         }
     }

Modified: directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyHandler.java?rev=1208354&r1=1208353&r2=1208354&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyHandler.java
(original)
+++ directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyHandler.java
Wed Nov 30 09:59:53 2011
@@ -50,9 +50,36 @@ public class ModifyHandler extends LdapR
 
         try
         {
-            // Call the underlying layer to delete the entry
-            CoreSession coreSession = session.getCoreSession();
-            coreSession.modify( req );
+            boolean done = false;
+            
+            do
+            {
+                txnManager.beginTransaction( false );
+                
+                try
+                {    
+                    // Call the underlying layer to delete the entry
+                    CoreSession coreSession = session.getCoreSession();
+                    coreSession.modify( req );
+                }
+                catch ( Exception e )
+                {
+                  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
+                  // beginning of the loop if necessary.
+                  
+                  e.printStackTrace();
+                  
+                  throw ( e );
+                }
+                
+                // If here then we are done.
+                txnManager.commitTransaction();
+                done = true;
+            }
+            while ( !done );
             
             // If success, here now, otherwise, we would have an exception.
             result.setResultCode( ResultCodeEnum.SUCCESS );

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=1208354&r1=1208353&r2=1208354&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
Wed Nov 30 09:59:53 2011
@@ -783,32 +783,48 @@ public class SearchHandler extends LdapR
             return doPagedSearch( session, req, ( PagedResultsDecorator ) control );
         }
 
-        // A normal search
-        // Check that we have a cursor or not.
-        // No cursor : do a search.
-        EntryFilteringCursor cursor = session.getCoreSession().search( req );
-
-        // Position the cursor at the beginning
-        cursor.beforeFirst();
-
-        /*
-         * Iterate through all search results building and sending back responses
-         * for each search result returned.
-         */
+        EntryFilteringCursor cursor = null;
+        
         try
         {
-            // Get the size limits
-            // Don't bother setting size limits for administrators that don't ask for it
-            long serverLimit = getServerSizeLimit( session, req );
-
-            long requestLimit = req.getSizeLimit() == 0L ? Long.MAX_VALUE : req.getSizeLimit();
-
-            req.addAbandonListener( new SearchAbandonListener( ldapServer, cursor ) );
-            setTimeLimitsOnCursor( req, session, cursor );
-            LOG.debug( "using <{},{}> for size limit", requestLimit, serverLimit );
-            long sizeLimit = min( requestLimit, serverLimit );
+            txnManager.beginTransaction( true );
+            
+            try
+            {
+                // A normal search
+                // Check that we have a cursor or not.
+                // No cursor : do a search.
+                cursor = session.getCoreSession().search( req );
+        
+                // Position the cursor at the beginning
+                cursor.beforeFirst();
+        
+                /*
+                 * Iterate through all search results building and sending back responses
+                 * for each search result returned.
+                 */
+               
+                    // Get the size limits
+                    // Don't bother setting size limits for administrators that don't ask
for it
+                    long serverLimit = getServerSizeLimit( session, req );
+        
+                    long requestLimit = req.getSizeLimit() == 0L ? Long.MAX_VALUE : req.getSizeLimit();
+        
+                    req.addAbandonListener( new SearchAbandonListener( ldapServer, cursor
) );
+                    setTimeLimitsOnCursor( req, session, cursor );
+                    LOG.debug( "using <{},{}> for size limit", requestLimit, serverLimit
);
+                    long sizeLimit = min( requestLimit, serverLimit );
+        
+                    readResults( session, req, ldapResult, cursor, sizeLimit );
+            }
+            catch ( Exception e )
+            {
+                txnManager.abortTransaction();
+                throw ( e );
+            }
 
-            readResults( session, req, ldapResult, cursor, sizeLimit );
+            // If here then we are done.
+            txnManager.commitTransaction();
         }
         finally
         {



Mime
View raw message