Return-Path: X-Original-To: apmail-directory-commits-archive@www.apache.org Delivered-To: apmail-directory-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 59D36A04 for ; Wed, 29 Aug 2012 18:11:06 +0000 (UTC) Received: (qmail 55950 invoked by uid 500); 29 Aug 2012 18:11:06 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 55908 invoked by uid 500); 29 Aug 2012 18:11:06 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 55901 invoked by uid 99); 29 Aug 2012 18:11:06 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Aug 2012 18:11:06 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Aug 2012 18:11:02 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id BB288238897F for ; Wed, 29 Aug 2012 18:10:17 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1378667 - in /directory/apacheds/branches/apacheds-mvbt: core-shared/src/main/java/org/apache/directory/server/core/shared/partition/DefaultPartitionNexus.java core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java Date: Wed, 29 Aug 2012 18:10:17 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120829181017.BB288238897F@eris.apache.org> Author: elecharny Date: Wed Aug 29 18:10:17 2012 New Revision: 1378667 URL: http://svn.apache.org/viewvc?rev=1378667&view=rev Log: Moved the readWriteLock from the PartitionNexus to the Operationmanager Modified: directory/apacheds/branches/apacheds-mvbt/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/DefaultPartitionNexus.java directory/apacheds/branches/apacheds-mvbt/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java Modified: directory/apacheds/branches/apacheds-mvbt/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/DefaultPartitionNexus.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-mvbt/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/DefaultPartitionNexus.java?rev=1378667&r1=1378666&r2=1378667&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-mvbt/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/DefaultPartitionNexus.java (original) +++ directory/apacheds/branches/apacheds-mvbt/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/DefaultPartitionNexus.java Wed Aug 29 18:10:17 2012 @@ -31,8 +31,6 @@ import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.UUID; -import java.util.concurrent.locks.ReadWriteLock; -import java.util.concurrent.locks.ReentrantReadWriteLock; import javax.naming.ConfigurationException; @@ -143,9 +141,6 @@ public class DefaultPartitionNexus exten /** The cn=schema Dn */ private Dn subschemSubentryDn; - /** A lock used to protect against concurrent operations */ - private ReadWriteLock rwLock = new ReentrantReadWriteLock( true ); - /** * Creates the root nexus singleton of the entire system. The root DSE has @@ -451,17 +446,8 @@ public class DefaultPartitionNexus exten */ public void add( AddOperationContext addContext ) throws LdapException { - try - { - rwLock.writeLock().lock(); - - Partition partition = getPartition( addContext.getDn() ); - partition.add( addContext ); - } - finally - { - rwLock.writeLock().unlock(); - } + Partition partition = getPartition( addContext.getDn() ); + partition.add( addContext ); Attribute at = addContext.getEntry().get( SchemaConstants.ENTRY_CSN_AT ); directoryService.setContextCsn( at.getString() ); @@ -516,17 +502,8 @@ public class DefaultPartitionNexus exten */ public void delete( DeleteOperationContext deleteContext ) throws LdapException { - try - { - rwLock.writeLock().lock(); - - Partition partition = getPartition( deleteContext.getDn() ); - partition.delete( deleteContext ); - } - finally - { - rwLock.writeLock().unlock(); - } + Partition partition = getPartition( deleteContext.getDn() ); + partition.delete( deleteContext ); } @@ -547,18 +524,9 @@ public class DefaultPartitionNexus exten return true; } - try - { - rwLock.readLock().lock(); - - Partition partition = getPartition( dn ); + Partition partition = getPartition( dn ); - return partition.hasEntry( hasEntryContext ); - } - finally - { - rwLock.readLock().unlock(); - } + return partition.hasEntry( hasEntryContext ); } @@ -567,18 +535,9 @@ public class DefaultPartitionNexus exten */ public EntryFilteringCursor list( ListOperationContext listContext ) throws LdapException { - try - { - rwLock.readLock().lock(); + Partition partition = getPartition( listContext.getDn() ); - Partition partition = getPartition( listContext.getDn() ); - - return partition.list( listContext ); - } - finally - { - rwLock.readLock().unlock(); - } + return partition.list( listContext ); } @@ -602,27 +561,18 @@ public class DefaultPartitionNexus exten return retval; } - try - { - rwLock.readLock().lock(); - - Partition partition = getPartition( dn ); - Entry entry = partition.lookup( lookupContext ); - - if ( entry == null ) - { - LdapNoSuchObjectException e = new LdapNoSuchObjectException( "Attempt to lookup non-existant entry: " - + dn.getName() ); - - throw e; - } + Partition partition = getPartition( dn ); + Entry entry = partition.lookup( lookupContext ); - return entry; - } - finally + if ( entry == null ) { - rwLock.readLock().unlock(); + LdapNoSuchObjectException e = new LdapNoSuchObjectException( "Attempt to lookup non-existant entry: " + + dn.getName() ); + + throw e; } + + return entry; } @@ -637,18 +587,9 @@ public class DefaultPartitionNexus exten return; } - try - { - rwLock.writeLock().lock(); + Partition partition = getPartition( modifyContext.getDn() ); - Partition partition = getPartition( modifyContext.getDn() ); - - partition.modify( modifyContext ); - } - finally - { - rwLock.writeLock().unlock(); - } + partition.modify( modifyContext ); Entry alteredEntry = modifyContext.getAlteredEntry(); @@ -664,22 +605,13 @@ public class DefaultPartitionNexus exten */ public void move( MoveOperationContext moveContext ) throws LdapException { - try - { - rwLock.writeLock().lock(); + // Get the current partition + Partition partition = getPartition( moveContext.getDn() ); - // Get the current partition - Partition partition = getPartition( moveContext.getDn() ); + // We also have to get the new partition as it can be different + //Partition newBackend = getPartition( opContext.getNewDn() ); - // We also have to get the new partition as it can be different - //Partition newBackend = getPartition( opContext.getNewDn() ); - - partition.move( moveContext ); - } - finally - { - rwLock.writeLock().unlock(); - } + partition.move( moveContext ); } @@ -688,17 +620,8 @@ public class DefaultPartitionNexus exten */ public void moveAndRename( MoveAndRenameOperationContext moveAndRenameContext ) throws LdapException { - try - { - rwLock.writeLock().lock(); - - Partition partition = getPartition( moveAndRenameContext.getDn() ); - partition.moveAndRename( moveAndRenameContext ); - } - finally - { - rwLock.writeLock().unlock(); - } + Partition partition = getPartition( moveAndRenameContext.getDn() ); + partition.moveAndRename( moveAndRenameContext ); } @@ -707,17 +630,8 @@ public class DefaultPartitionNexus exten */ public void rename( RenameOperationContext renameContext ) throws LdapException { - try - { - rwLock.writeLock().lock(); - - Partition partition = getPartition( renameContext.getDn() ); - partition.rename( renameContext ); - } - finally - { - rwLock.writeLock().unlock(); - } + Partition partition = getPartition( renameContext.getDn() ); + partition.rename( renameContext ); } @@ -895,18 +809,9 @@ public class DefaultPartitionNexus exten base.apply( schemaManager ); } - try - { - rwLock.readLock().lock(); - - Partition backend = getPartition( base ); + Partition backend = getPartition( base ); - return backend.search( searchContext ); - } - finally - { - rwLock.readLock().unlock(); - } + return backend.search( searchContext ); } Modified: directory/apacheds/branches/apacheds-mvbt/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-mvbt/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java?rev=1378667&r1=1378666&r2=1378667&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-mvbt/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java (original) +++ directory/apacheds/branches/apacheds-mvbt/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java Wed Aug 29 18:10:17 2012 @@ -22,6 +22,8 @@ package org.apache.directory.server.core import java.util.ArrayList; import java.util.List; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; import org.apache.directory.server.core.api.CoreSession; import org.apache.directory.server.core.api.DirectoryService; @@ -81,6 +83,9 @@ public class DefaultOperationManager imp /** The directory service instance */ private final DirectoryService directoryService; + /** A lock used to protect against concurrent operations */ + private ReadWriteLock rwLock = new ReentrantReadWriteLock( true ); + public DefaultOperationManager( DirectoryService directoryService ) { @@ -321,7 +326,16 @@ public class DefaultOperationManager imp // Call the Add method Interceptor head = directoryService.getInterceptor( addContext.getNextInterceptor() ); - head.add( addContext ); + try + { + rwLock.writeLock().lock(); + + head.add( addContext ); + } + finally + { + rwLock.writeLock().unlock(); + } } LOG.debug( "<< AddOperation successful" ); @@ -341,7 +355,16 @@ public class DefaultOperationManager imp // Call the Delete method Interceptor head = directoryService.getInterceptor( bindContext.getNextInterceptor() ); - head.bind( bindContext ); + try + { + rwLock.readLock().lock(); + + head.bind( bindContext ); + } + finally + { + rwLock.readLock().unlock(); + } LOG.debug( "<< BindOperation successful" ); } @@ -415,7 +438,18 @@ public class DefaultOperationManager imp // Call the Compare method Interceptor head = directoryService.getInterceptor( compareContext.getNextInterceptor() ); - boolean result = head.compare( compareContext ); + boolean result = false; + + try + { + rwLock.readLock().lock(); + + result = head.compare( compareContext ); + } + finally + { + rwLock.readLock().unlock(); + } LOG.debug( "<< CompareOperation successful" ); @@ -494,7 +528,16 @@ public class DefaultOperationManager imp // Call the Delete method Interceptor head = directoryService.getInterceptor( deleteContext.getNextInterceptor() ); - head.delete( deleteContext ); + try + { + rwLock.writeLock().lock(); + + head.delete( deleteContext ); + } + finally + { + rwLock.writeLock().unlock(); + } LOG.debug( "<< DeleteOperation successful" ); LOG_CHANGES.debug( "<< DeleteOperation successful" ); @@ -531,7 +574,18 @@ public class DefaultOperationManager imp Interceptor head = directoryService.getInterceptor( hasEntryContext.getNextInterceptor() ); - boolean result = head.hasEntry( hasEntryContext ); + boolean result = false; + + try + { + rwLock.readLock().lock(); + + result = head.hasEntry( hasEntryContext ); + } + finally + { + rwLock.readLock().unlock(); + } LOG.debug( "<< HasEntryOperation successful" ); @@ -550,7 +604,18 @@ public class DefaultOperationManager imp Interceptor head = directoryService.getInterceptor( listContext.getNextInterceptor() ); - EntryFilteringCursor cursor = head.list( listContext ); + EntryFilteringCursor cursor = null; + + try + { + rwLock.readLock().lock(); + + cursor = head.list( listContext ); + } + finally + { + rwLock.readLock().unlock(); + } LOG.debug( "<< ListOperation successful" ); @@ -569,7 +634,18 @@ public class DefaultOperationManager imp Interceptor head = directoryService.getInterceptor( lookupContext.getNextInterceptor() ); - Entry entry = head.lookup( lookupContext ); + Entry entry = null; + + try + { + rwLock.readLock().lock(); + + entry = head.lookup( lookupContext ); + } + finally + { + rwLock.readLock().unlock(); + } LOG.debug( "<< LookupOperation successful" ); @@ -657,7 +733,16 @@ public class DefaultOperationManager imp // Call the Modify method Interceptor head = directoryService.getInterceptor( modifyContext.getNextInterceptor() ); - head.modify( modifyContext ); + try + { + rwLock.writeLock().lock(); + + head.modify( modifyContext ); + } + finally + { + rwLock.writeLock().unlock(); + } LOG.debug( "<< ModifyOperation successful" ); LOG_CHANGES.debug( "<< ModifyOperation successful" ); @@ -756,7 +841,16 @@ public class DefaultOperationManager imp // Call the Move method Interceptor head = directoryService.getInterceptor( moveContext.getNextInterceptor() ); - head.move( moveContext ); + try + { + rwLock.writeLock().lock(); + + head.move( moveContext ); + } + finally + { + rwLock.writeLock().unlock(); + } LOG.debug( "<< MoveOperation successful" ); LOG_CHANGES.debug( "<< MoveOperation successful" ); @@ -856,7 +950,16 @@ public class DefaultOperationManager imp // Call the MoveAndRename method Interceptor head = directoryService.getInterceptor( moveAndRenameContext.getNextInterceptor() ); - head.moveAndRename( moveAndRenameContext ); + try + { + rwLock.writeLock().lock(); + + head.moveAndRename( moveAndRenameContext ); + } + finally + { + rwLock.writeLock().unlock(); + } LOG.debug( "<< MoveAndRenameOperation successful" ); LOG_CHANGES.debug( "<< MoveAndRenameOperation successful" ); @@ -948,7 +1051,16 @@ public class DefaultOperationManager imp // Call the Rename method Interceptor head = directoryService.getInterceptor( renameContext.getNextInterceptor() ); - head.rename( renameContext ); + try + { + rwLock.writeLock().lock(); + + head.rename( renameContext ); + } + finally + { + rwLock.writeLock().unlock(); + } LOG.debug( "<< RenameOperation successful" ); LOG_CHANGES.debug( "<< RenameOperation successful" ); @@ -1025,7 +1137,18 @@ public class DefaultOperationManager imp // Call the Search method Interceptor head = directoryService.getInterceptor( searchContext.getNextInterceptor() ); - EntryFilteringCursor cursor = head.search( searchContext ); + EntryFilteringCursor cursor = null; + + try + { + rwLock.readLock().lock(); + + cursor = head.search( searchContext ); + } + finally + { + rwLock.readLock().unlock(); + } LOG.debug( "<< SearchOperation successful" );