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/01/02 00:43:23 UTC
svn commit: r1226317 - 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/src/main/java/org/apache/directory...
Author: elecharny
Date: Sun Jan 1 23:43:22 2012
New Revision: 1226317
URL: http://svn.apache.org/viewvc?rev=1226317&view=rev
Log:
Fixed many errors ( 38 ) by allowing RX txns into RO txns and RO txns into RO txns (5) :
o added a setCurTxn() method in the txnManager
o set the curTxn when doing a cursor.next(), moving it back to the previous value
o The beginTransaction() now returns the txn, so that it can be stored into the cursor
Modified:
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/txn/TxnManager.java
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/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java
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=1226317&r1=1226316&r2=1226317&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 Sun Jan 1 23:43:22 2012
@@ -28,6 +28,7 @@ import java.util.List;
import org.apache.directory.server.core.api.entry.ClonedServerEntry;
import org.apache.directory.server.core.api.entry.ClonedServerEntrySearch;
import org.apache.directory.server.core.api.interceptor.context.SearchingOperationContext;
+import org.apache.directory.server.core.api.txn.TxnHandle;
import org.apache.directory.shared.i18n.I18n;
import org.apache.directory.shared.ldap.model.cursor.ClosureMonitor;
import org.apache.directory.shared.ldap.model.cursor.Cursor;
@@ -210,9 +211,23 @@ public class BaseEntryFilteringCursor ex
wrapped.close();
prefetched = null;
- if ( ( txnManager != null ) && ( txnManager.getCurTxn() != null ) )
+ if ( txnManager != null )
{
- txnManager.commitTransaction();
+ TxnHandle curTxn = txnManager.getCurTxn();
+
+ if ( curTxn != null )
+ {
+ if ( transaction != curTxn )
+ {
+ TxnHandle previousTransaction = txnManager.setCurTxn( transaction );
+ txnManager.commitTransaction();
+ txnManager.setCurTxn( previousTransaction );
+ }
+ else
+ {
+ txnManager.commitTransaction();
+ }
+ }
}
}
@@ -227,7 +242,9 @@ public class BaseEntryFilteringCursor ex
if ( txnManager != null )
{
+ TxnHandle previousTransaction = txnManager.setCurTxn( transaction );
txnManager.abortTransaction();
+ txnManager.setCurTxn( previousTransaction );
}
}
@@ -432,60 +449,71 @@ public class BaseEntryFilteringCursor ex
Entry tempResult = null;
- outer: while ( wrapped.next() )
+ // Switch the current transaction
+ TxnHandle previousTxn = txnManager.setCurTxn( transaction );
+
+ try
{
- boolean accepted = true;
+ outer: while ( wrapped.next() )
+ {
+ boolean accepted = true;
- Entry tempEntry = wrapped.get();
+ Entry tempEntry = wrapped.get();
- if ( tempEntry instanceof ClonedServerEntry )
- {
- tempResult = tempEntry;
- }
- else
- {
- tempResult = new ClonedServerEntrySearch( tempEntry );
- }
+ if ( tempEntry instanceof ClonedServerEntry )
+ {
+ tempResult = tempEntry;
+ }
+ else
+ {
+ tempResult = new ClonedServerEntrySearch( tempEntry );
+ }
- /*
- * 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.
- */
+ /*
+ * 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.isEmpty() )
+ {
+ prefetched = tempResult;
+ filterContents( prefetched );
+ return true;
+ }
- if ( ( filters.size() == 1 ) && filters.get( 0 ).accept( getOperationContext(), tempResult ) )
- {
- 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 ) ) )
+ /* E N D O P T I M I Z A T I O N */
+ for ( EntryFilter filter : filters )
{
- continue outer;
+ // 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 );
+ /*
+ * Here the entry has been accepted by all filters.
+ */
+ prefetched = tempResult;
+ filterContents( prefetched );
- return true;
+ return true;
+ }
+ }
+ finally
+ {
+ // Switch back the previous transaction
+ txnManager.setCurTxn( previousTxn );
}
prefetched = null;
Modified: directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnManager.java?rev=1226317&r1=1226316&r2=1226317&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnManager.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-api/src/main/java/org/apache/directory/server/core/api/txn/TxnManager.java Sun Jan 1 23:43:22 2012
@@ -31,8 +31,9 @@ public interface TxnManager
*
* @throws Exception
*/
- void beginTransaction( boolean readOnly ) throws Exception;
-
+ TxnHandle beginTransaction( boolean readOnly ) throws Exception;
+
+
/**
* Tries to commit the current txn associated with the current thread. ReadWrite txns have to be verified against txns
* that committed after they started for any conflicting change and conflicting
@@ -79,6 +80,14 @@ public interface TxnManager
/**
+ * Sets a handle as the current txn
+ *
+ * @param the new current txn
+ */
+ TxnHandle setCurTxn( TxnHandle txn );
+
+
+ /**
* Flushes the committed txns to partitions.
*/
void applyPendingTxns();
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=1226317&r1=1226316&r2=1226317&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 Sun Jan 1 23:43:22 2012
@@ -174,23 +174,34 @@ class DefaultTxnManager implements TxnMa
/**
* {@inheritDoc}
*/
- public void beginTransaction( boolean readOnly ) throws Exception
+ public Transaction beginTransaction( boolean readOnly ) throws Exception
{
Transaction curTxn = getCurTxn();
if ( curTxn != null )
{
+ if ( curTxn instanceof ReadOnlyTxn )
+ {
+ Transaction transaction = beginReadOnlyTxn();
+
+ return transaction;
+ }
+
throw new IllegalStateException( "Cannot begin a txn when txn is already running: " +
curTxn );
}
if ( readOnly )
{
- beginReadOnlyTxn();
+ Transaction transaction = beginReadOnlyTxn();
+
+ return transaction;
}
else
{
- beginReadWriteTxn();
+ Transaction transaction = beginReadWriteTxn();
+
+ return transaction;
}
}
@@ -206,7 +217,7 @@ class DefaultTxnManager implements TxnMa
{
throw new IllegalStateException( " trying to commit non existent txn " );
}
-
+
if ( flushFailed )
{
throw new IOException( "Flushing of txns failed" );
@@ -223,7 +234,7 @@ class DefaultTxnManager implements TxnMa
commitReadWriteTxn( ( ReadWriteTxn ) txn );
}
- txnVar.set( null );
+ setCurTxn( null );
}
@@ -248,7 +259,7 @@ class DefaultTxnManager implements TxnMa
}
txn.abortTxn();
- txnVar.set( null );
+ setCurTxn( null );
}
@@ -258,9 +269,9 @@ class DefaultTxnManager implements TxnMa
public TxnHandle suspendCurTxn()
{
Transaction curTxn = txnVar.get();
-
- txnVar.set( null );
-
+
+ setCurTxn( null );
+
return curTxn;
}
@@ -268,21 +279,22 @@ class DefaultTxnManager implements TxnMa
/**
* {@inheritDoc}
*/
- public void resumeTxn( TxnHandle txnHandle)
+ public void resumeTxn( TxnHandle txnHandle )
{
if ( txnHandle == null )
{
throw new IllegalArgumentException( "Cannot accept a null handle when resuming a txn " );
}
-
+
Transaction curTxn = txnVar.get();
-
+
if ( curTxn != null )
{
- throw new IllegalStateException( " Trying to resume txn" + txnHandle +" while there is already a txn running:" + curTxn );
+ throw new IllegalStateException( " Trying to resume txn" + txnHandle
+ + " while there is already a txn running:" + curTxn );
}
-
- txnVar.set( ( Transaction )txnHandle );
+
+ setCurTxn( ( Transaction ) txnHandle );
}
@@ -298,6 +310,19 @@ class DefaultTxnManager implements TxnMa
/**
* {@inheritDoc}
*/
+ public Transaction setCurTxn( TxnHandle transaction )
+ {
+ Transaction previousTransaction = ( Transaction ) txnVar.get();
+
+ txnVar.set( ( Transaction ) transaction );
+
+ return previousTransaction;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
public void applyPendingTxns()
{
flushLock.lock();
@@ -323,7 +348,7 @@ class DefaultTxnManager implements TxnMa
* Begins a read only txn. A read only txn does not put any log edits
* to the txn log.Its start time is the latest committed txn's commit time.
*/
- private void beginReadOnlyTxn()
+ private Transaction beginReadOnlyTxn()
{
ReadOnlyTxn txn = new ReadOnlyTxn();
ReadWriteTxn lastTxnToCheck = null;
@@ -373,7 +398,10 @@ class DefaultTxnManager implements TxnMa
// " pending " + pending.incrementAndGet() );
buildCheckList( txn, lastTxnToCheck );
- txnVar.set( txn );
+
+ setCurTxn( txn );
+
+ return txn;
}
@@ -382,7 +410,7 @@ class DefaultTxnManager implements TxnMa
* into the txn log and the lsn of that log record is the
* start time.
*/
- private void beginReadWriteTxn() throws Exception
+ private Transaction beginReadWriteTxn() throws Exception
{
ReadWriteTxn txn = new ReadWriteTxn();
@@ -456,7 +484,9 @@ class DefaultTxnManager implements TxnMa
// Finally build the check list
buildCheckList( txn, lastTxnToCheck );
- txnVar.set( txn );
+ setCurTxn( txn );
+
+ return txn;
}
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=1226317&r1=1226316&r2=1226317&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 Sun Jan 1 23:43:22 2012
@@ -44,6 +44,7 @@ import org.apache.directory.server.core.
import org.apache.directory.server.core.api.interceptor.context.RenameOperationContext;
import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;
import org.apache.directory.server.core.api.interceptor.context.UnbindOperationContext;
+import org.apache.directory.server.core.api.txn.TxnHandle;
import org.apache.directory.server.core.api.txn.TxnManager;
import org.apache.directory.server.i18n.I18n;
import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
@@ -282,11 +283,11 @@ public class DefaultOperationManager imp
/**
* Starts a Read only transaction
*/
- private void beginTransactionR( TxnManager txnManager ) throws LdapException
+ private TxnHandle beginTransactionR( TxnManager txnManager ) throws LdapException
{
try
{
- txnManager.beginTransaction( true );
+ return txnManager.beginTransaction( true );
}
catch ( Exception e )
{
@@ -298,11 +299,11 @@ public class DefaultOperationManager imp
/**
* Starts a RW transaction
*/
- private void beginTransactionRW( TxnManager txnManager ) throws LdapException
+ private TxnHandle beginTransactionRW( TxnManager txnManager ) throws LdapException
{
try
{
- txnManager.beginTransaction( false );
+ return txnManager.beginTransaction( false );
}
catch ( Exception e )
{