directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1214107 - in /directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers: ./ controls/ extended/
Date Wed, 14 Dec 2011 08:36:31 GMT
Author: saya
Date: Wed Dec 14 08:36:30 2011
New Revision: 1214107

URL: http://svn.apache.org/viewvc?rev=1214107&view=rev
Log:
added some missing txn demarcaction. moved txn conflict handling to the right place in handlers

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/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
    directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/controls/PagedSearchContext.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/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=1214107&r1=1214106&r2=1214107&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 Dec 14 08:36:30 2011
@@ -66,17 +66,22 @@ public class AddHandler extends LdapRequ
                 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;
+                
+                try
+                {
+                    txnManager.commitTransaction();
+                }
+                catch( Exception e )
+                {
+                    // TODO check for conflict
+                    throw e;
+                }
             }
             while ( !done );
 

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=1214107&r1=1214106&r2=1214107&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 Dec 14 08:36:30 2011
@@ -622,6 +622,7 @@ public class BindHandler extends LdapReq
             }
             catch ( Exception e )
             {
+                e.printStackTrace();
               txnManager.abortTransaction();
               
               // TODO Instead of rethrowing the exception here all the time, check

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=1214107&r1=1214106&r2=1214107&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 Dec 14 08:36:30 2011
@@ -66,16 +66,21 @@ public class DeleteHandler extends LdapR
                 {
                   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;
+                
+                try
+                {
+                    txnManager.commitTransaction();
+                }
+                catch( Exception e )
+                {
+                    // TODO check for conflict
+                    throw e;
+                }
             }
             while ( !done );
             

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=1214107&r1=1214106&r2=1214107&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 Dec 14 08:36:30 2011
@@ -22,6 +22,7 @@ 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.DirectoryService;
 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;
@@ -65,12 +66,6 @@ public abstract class LdapRequestHandler
 
     /** Txn Manager */
     protected TxnManager txnManager;
-   
-    
-    public LdapRequestHandler()
-    {
-        txnManager = TxnManagerFactory.txnManagerInstance();
-    }
     
     
     /**
@@ -89,6 +84,13 @@ public abstract class LdapRequestHandler
     public final void setLdapServer( LdapServer ldapServer )
     {
         this.ldapServer = ldapServer;
+        
+        DirectoryService service = ldapServer.getDirectoryService();
+        
+        if ( service != null )
+        {
+            txnManager = ldapServer.getDirectoryService().getTxnManager();
+        }
     }
 
 

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=1214107&r1=1214106&r2=1214107&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 Dec 14 08:36:30 2011
@@ -137,16 +137,21 @@ public class ModifyDnHandler extends Lda
                     {
                       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;
+                    
+                    try
+                    {
+                        txnManager.commitTransaction();
+                    }
+                    catch( Exception e )
+                    {
+                        // TODO check for conflict
+                        throw e;
+                    }
                 }
                 while ( !done );
             }
@@ -164,7 +169,6 @@ 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=1214107&r1=1214106&r2=1214107&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 Dec 14 08:36:30 2011
@@ -66,18 +66,21 @@ public class ModifyHandler extends LdapR
                 {
                   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;
+                
+                try
+                {
+                    txnManager.commitTransaction();
+                }
+                catch( Exception e )
+                {
+                    // TODO check for conflict
+                    throw e;
+                }
             }
             while ( !done );
             

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=1214107&r1=1214106&r2=1214107&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 Dec 14 08:36:30 2011
@@ -34,6 +34,7 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.api.event.NotificationCriteria;
 import org.apache.directory.server.core.api.filtering.EntryFilteringCursor;
 import org.apache.directory.server.core.api.partition.PartitionNexus;
+import org.apache.directory.server.core.api.txn.TxnHandle;
 import org.apache.directory.server.i18n.I18n;
 import org.apache.directory.server.ldap.LdapSession;
 import org.apache.directory.server.ldap.handlers.controls.PagedSearchContext;
@@ -207,7 +208,28 @@ public class SearchHandler extends LdapR
             // SearchResponseEntry elements instead of
             // SearchResponseReference elements.
             LOG.debug( "ManageDsaITControl detected." );
-            handleIgnoringReferrals( session, req );
+            boolean txnStarted = false;
+            
+            try
+            {
+                beginTxnForSearch( session, req );
+                txnStarted = true;
+                
+                handleIgnoringReferrals( session, req );
+                
+            }
+            catch ( Exception e )
+            {
+                if  ( txnStarted )
+                {
+                    endTxnForSearch( true );
+                }
+                
+                throw e;
+            }
+            
+            // if here, we are done
+            endTxnForSearch( false );
         }
         else
         {
@@ -218,7 +240,29 @@ public class SearchHandler extends LdapR
             switch ( req.getType() )
             {
                 case SEARCH_REQUEST:
-                    handleWithReferrals( session, req );
+                    
+                    boolean txnStarted = false;
+                    
+                    try
+                    {
+                        beginTxnForSearch( session, req );
+                        txnStarted = true;
+                    
+                        handleWithReferrals( session, req );
+                    }
+                    catch ( Exception e )
+                    {
+                        if  ( txnStarted )
+                        {
+                            endTxnForSearch( true );
+                        }
+                        
+                        throw e;
+                    }
+                    
+                    // if here, we are done
+                    endTxnForSearch( false );
+                    
                     break;
 
                 default:
@@ -401,7 +445,7 @@ public class SearchHandler extends LdapR
             LOG.debug( "Sending {}", entry.getDn() );
             count++;
         }
-
+        
         // DO NOT WRITE THE RESPONSE - JUST RETURN IT
         ldapResult.setResultCode( ResultCodeEnum.SUCCESS );
 
@@ -492,6 +536,11 @@ public class SearchHandler extends LdapR
 
                 // Stores the cursor current position
                 pagedContext.incrementCurrentPosition( pageCount );
+                
+                // Suspend the current txn
+                TxnHandle txnHandle = txnManager.suspendCurTxn();
+                pagedContext.setTxnHandle( txnHandle );
+                
                 return;
             }
             else
@@ -787,44 +836,31 @@ public class SearchHandler extends LdapR
         
         try
         {
-            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 );
-            }
+            // A normal search
+            // Check that we have a cursor or not.
+            // No cursor : do a search.
+            cursor = session.getCoreSession().search( req );
 
-            // If here then we are done.
-            txnManager.commitTransaction();
+            // 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 );
         }
         finally
         {
@@ -1655,4 +1691,70 @@ 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/controls/PagedSearchContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/controls/PagedSearchContext.java?rev=1214107&r1=1214106&r2=1214107&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/controls/PagedSearchContext.java
(original)
+++ directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/controls/PagedSearchContext.java
Wed Dec 14 08:36:30 2011
@@ -24,6 +24,7 @@ import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.directory.server.core.api.filtering.EntryFilteringCursor;
+import org.apache.directory.server.core.api.txn.TxnHandle;
 import org.apache.directory.server.ldap.LdapSession;
 import org.apache.directory.shared.asn1.ber.tlv.Value;
 import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
@@ -56,6 +57,9 @@ public class PagedSearchContext
 
     /** The associated cursor for the current search request */
     private EntryFilteringCursor cursor;
+    
+    /** Suspended txn..Not null if a txn is suspended */
+    TxnHandle txnHandle;
 
     /**
      * Creates a new instance of this class, storing the SearchRequest into it.
@@ -305,6 +309,21 @@ public class PagedSearchContext
     {
         this.cursor = cursor;
     }
+    
+    
+    /**
+     * Set suspendedn txn Handle
+     */
+    public void setTxnHandle( TxnHandle handle )
+    {
+        txnHandle = handle;
+    }
+    
+    
+    public TxnHandle getTxnHandle()
+    {
+        return txnHandle;
+    }
 
 
     /**

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=1214107&r1=1214106&r2=1214107&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
Wed Dec 14 08:36:30 2011
@@ -25,7 +25,9 @@ import java.util.HashSet;
 import java.util.Set;
 
 import org.apache.directory.server.core.api.entry.ClonedServerEntry;
+import org.apache.directory.server.core.api.txn.TxnManager;
 import org.apache.directory.server.core.security.TlsKeyGenerator;
+import org.apache.directory.server.core.shared.txn.TxnManagerFactory;
 import org.apache.directory.server.ldap.ExtendedOperationHandler;
 import org.apache.directory.server.ldap.LdapServer;
 import org.apache.directory.server.ldap.LdapSession;
@@ -77,16 +79,44 @@ public class CertGenerationRequestHandle
      */
     public void handleExtendedOperation( LdapSession session, CertGenerationRequest req )
throws Exception
     {
-        Entry entry = session.getCoreSession().lookup( new Dn( req.getTargetDN() ) );
+        TxnManager txnManager = session.getCoreSession().getDirectoryService().getTxnManager();
+        boolean done = false;
 
-        if ( entry != null )
+        do
         {
-            TlsKeyGenerator.addKeyPair( 
-                ( ( ClonedServerEntry ) entry ).getOriginalEntry(), 
-                req.getIssuerDN(),
-                req.getSubjectDN(), 
-                req.getKeyAlgorithm() );
+            txnManager.beginTransaction( false );
+
+            try
+            {
+                Entry entry = session.getCoreSession().lookup( new Dn( req.getTargetDN()
) );
+
+                if ( entry != null )
+                {
+                    TlsKeyGenerator.addKeyPair(
+                        ( ( ClonedServerEntry ) entry ).getOriginalEntry(),
+                        req.getIssuerDN(),
+                        req.getSubjectDN(),
+                        req.getKeyAlgorithm() );
+                }
+            }
+            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 );
     }
 
 



Mime
View raw message