You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2012/08/29 20:10:17 UTC
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
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" );