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 9FEAD95E0 for ; Wed, 14 Dec 2011 08:08:19 +0000 (UTC) Received: (qmail 95491 invoked by uid 500); 14 Dec 2011 08:08:14 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 95437 invoked by uid 500); 14 Dec 2011 08:08:12 -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 95426 invoked by uid 99); 14 Dec 2011 08:08:11 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Dec 2011 08:08:11 +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, 14 Dec 2011 08:08:04 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 567292388980 for ; Wed, 14 Dec 2011 08:07:41 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1214089 - in /directory/apacheds/branches/apacheds-txns/core-shared/src: main/java/org/apache/directory/server/core/shared/partition/ main/java/org/apache/directory/server/core/shared/txn/ test/java/org/apache/directory/server/core/shared/... Date: Wed, 14 Dec 2011 08:07:40 -0000 To: commits@directory.apache.org From: saya@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111214080741.567292388980@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: saya Date: Wed Dec 14 08:07:39 2011 New Revision: 1214089 URL: http://svn.apache.org/viewvc?rev=1214089&view=rev Log: make static txnmanager and execution manager variables non static. Add refs to instances of these classes to various classes. Added: directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/Utils.java Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/DefaultOperationExecutionManager.java directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/DefaultPartitionNexus.java directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/EntryCursorAdaptor.java directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/OperationExecutionManagerFactory.java directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnLogManager.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-shared/src/main/java/org/apache/directory/server/core/shared/txn/IndexCursorWrapper.java directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/IndexWrapper.java directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/MasterTableWrapper.java directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/ReadWriteTxn.java directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/Transaction.java directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/TxnManagerFactory.java directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/DefaultTxnManagerTest.java directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/EntryUpdateMergeTest.java directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/IndexCursorWrapperTest.java directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/TxnConflicTest.java directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/TxnIndexCursorTest.java Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/DefaultOperationExecutionManager.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/DefaultOperationExecutionManager.java?rev=1214089&r1=1214088&r2=1214089&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/DefaultOperationExecutionManager.java (original) +++ directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/DefaultOperationExecutionManager.java Wed Dec 14 08:07:39 2011 @@ -84,10 +84,13 @@ public class DefaultOperationExecutionMa /** Txn log manager kept for fast access */ private TxnLogManager txnLogManager; + /** Txn manager Factory */ + private TxnManagerFactory txnManagerFactory; - public DefaultOperationExecutionManager() + public DefaultOperationExecutionManager( TxnManagerFactory txnManagerFactory ) { - txnLogManager = TxnManagerFactory.txnLogManagerInstance(); + this.txnManagerFactory = txnManagerFactory; + txnLogManager = txnManagerFactory.txnLogManagerInstance(); } //--------------------------------------------------------------------------------------------- @@ -358,7 +361,7 @@ public class DefaultOperationExecutionMa master = txnLogManager.wrap( partition.getSuffixDn(), master ); // First get the entry - Entry entry = master.get( id ); + Entry entry = getEntry( partition, master, id ); if ( entry == null ) { @@ -526,7 +529,7 @@ public class DefaultOperationExecutionMa UUID id = getEntryId( partition, dn ); MasterTable master = partition.getMasterTable(); master = txnLogManager.wrap( partition.getSuffixDn(), master ); - Entry originalEntry = master.get( id ); + Entry originalEntry = getEntry( partition, master, id ); Entry entry = originalEntry.clone(); DataChangeContainer changeContainer = new DataChangeContainer( partition ); @@ -1020,7 +1023,12 @@ public class DefaultOperationExecutionMa Dn oldDn = renameContext.getDn(); Rdn newRdn = renameContext.getNewRdn(); boolean deleteOldRdn = renameContext.getDeleteOldRdn(); - Entry originalEntry = ( ( ClonedServerEntry )renameContext.getOriginalEntry() ).getOriginalEntry(); + Entry originalEntry = ( ( ClonedServerEntry )renameContext.getOriginalEntry() ); + + if ( originalEntry != null ) + { + originalEntry = ( ( ClonedServerEntry )originalEntry ).getOriginalEntry(); + } if ( renameContext.getEntry() != null ) { @@ -1352,7 +1360,12 @@ public class DefaultOperationExecutionMa Dn newSuperior = moveContext.getNewSuperior(); Dn newDn = moveContext.getNewDn(); Entry modifiedEntry = moveContext.getModifiedEntry(); - Entry originalEntry = ( ( ClonedServerEntry )moveContext.getOriginalEntry() ).getOriginalEntry(); + Entry originalEntry = ( ClonedServerEntry )moveContext.getOriginalEntry(); + + if ( originalEntry != null ) + { + originalEntry = ( ( ClonedServerEntry )originalEntry ).getOriginalEntry(); + } move( partition, oldDn, newSuperior, newDn, modifiedEntry, originalEntry ); @@ -1414,7 +1427,7 @@ public class DefaultOperationExecutionMa master = txnLogManager.wrap( partition.getSuffixDn(), master ); // First get the entry - originalEntry = master.get( entryId ); + originalEntry = getEntry( partition, master, entryId ); } if ( modifiedEntry == null ) @@ -1453,7 +1466,12 @@ public class DefaultOperationExecutionMa Rdn newRdn = moveAndRenameContext.getNewRdn(); boolean deleteOldRdn = moveAndRenameContext.getDeleteOldRdn(); Entry modifiedEntry = moveAndRenameContext.getModifiedEntry(); - Entry originalEntry = ( ( ClonedServerEntry )moveAndRenameContext.getOriginalEntry() ).getOriginalEntry(); + Entry originalEntry = ( ClonedServerEntry )moveAndRenameContext.getOriginalEntry(); + + if ( originalEntry != null ) + { + originalEntry = ( ( ClonedServerEntry )originalEntry ).getOriginalEntry(); + } moveAndRename( partition, oldDn, newSuperiorDn, newRdn, modifiedEntry, originalEntry, deleteOldRdn ); } @@ -1520,7 +1538,7 @@ public class DefaultOperationExecutionMa master = txnLogManager.wrap( partition.getSuffixDn(), master ); // First get the entry - originalEntry = master.get( oldId ); + originalEntry = getEntry( partition, master, oldId ); } if ( modifiedEntry == null ) @@ -1648,14 +1666,10 @@ public class DefaultOperationExecutionMa { MasterTable master = partition.getMasterTable(); master = txnLogManager.wrap( partition.getSuffixDn(), master ); - Entry entry = master.get( id ); + Entry entry = getEntry( partition, master, id ); if ( entry != null ) { - // We have to store the DN in this entry - Dn dn = buildEntryDn( partition, id ); - entry.setDn( dn ); - return new ClonedServerEntry( entry ); } @@ -1700,7 +1714,8 @@ public class DefaultOperationExecutionMa { return new BaseEntryFilteringCursor( new EntryCursorAdaptor( partition, - list( partition, getEntryId( partition, listContext.getDn() ) ) ), listContext ); + list( partition, getEntryId( partition, listContext.getDn() ) ), + txnManagerFactory ), listContext ); } catch ( Exception e ) { @@ -1820,6 +1835,19 @@ public class DefaultOperationExecutionMa return dn; } + + private Entry getEntry( Partition partition, MasterTable wrappedTable, UUID id ) throws Exception + { + Entry entry = wrappedTable.get( id ); + + if ( entry != null ) + { + Dn dn = buildEntryDn( partition, id ); + entry.setDn( dn ); + } + + return entry; + } /** @@ -2083,7 +2111,7 @@ public class DefaultOperationExecutionMa master = txnLogManager.wrap( partition.getSuffixDn(), master ); // First get the entry - originalEntry = master.get( id ); + originalEntry = getEntry( partition, master, id ); } if ( entry == null ) @@ -2283,7 +2311,7 @@ public class DefaultOperationExecutionMa continue; } - childEntry = master.get( childId ); + childEntry = getEntry( partition, master, childId ); clonedChildEntry = childEntry.clone(); childDn = childEntry.getDn(); Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/DefaultPartitionNexus.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/DefaultPartitionNexus.java?rev=1214089&r1=1214088&r2=1214089&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/DefaultPartitionNexus.java (original) +++ directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/DefaultPartitionNexus.java Wed Dec 14 08:07:39 2011 @@ -158,10 +158,12 @@ public class DefaultPartitionNexus exten * @param rootDse the root entry for the DSA * @throws javax.naming.Exception on failure to initialize */ - public DefaultPartitionNexus( Entry rootDse ) throws Exception + public DefaultPartitionNexus( Entry rootDse, OperationExecutionManagerFactory executionManagerFactory ) throws Exception { id = ID; suffixDn = null; + + operationExecutionManager = executionManagerFactory.instance(); // setup that root DSE this.rootDse = rootDse; @@ -203,9 +205,7 @@ public class DefaultPartitionNexus exten { // NOTE: We ignore ContextPartitionConfiguration parameter here. if ( !initialized ) - { - operationExecutionManager = OperationExecutionManagerFactory.instance(); - + { // Add the supported controls Iterator ctrlOidItr = directoryService.getLdapCodecService().registeredControls(); Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/EntryCursorAdaptor.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/EntryCursorAdaptor.java?rev=1214089&r1=1214088&r2=1214089&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/EntryCursorAdaptor.java (original) +++ directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/EntryCursorAdaptor.java Wed Dec 14 08:07:39 2011 @@ -52,11 +52,11 @@ public class EntryCursorAdaptor implemen /** Master table of the partition */ MasterTable masterTable; - public EntryCursorAdaptor( Partition db, IndexCursor indexCursor ) throws Exception + public EntryCursorAdaptor( Partition db, IndexCursor indexCursor, TxnManagerFactory txnManagerFactory ) throws Exception { this.db = db; this.indexCursor = indexCursor; - TxnLogManager txnLogManager = TxnManagerFactory.txnLogManagerInstance(); + TxnLogManager txnLogManager = txnManagerFactory.txnLogManagerInstance(); masterTable = txnLogManager.wrap( db.getSuffixDn(), db.getMasterTable() ); } Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/OperationExecutionManagerFactory.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/OperationExecutionManagerFactory.java?rev=1214089&r1=1214088&r2=1214089&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/OperationExecutionManagerFactory.java (original) +++ directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/OperationExecutionManagerFactory.java Wed Dec 14 08:07:39 2011 @@ -20,20 +20,27 @@ package org.apache.directory.server.core.shared.partition; import org.apache.directory.server.core.api.partition.OperationExecutionManager; +import org.apache.directory.server.core.shared.txn.TxnManagerFactory; public class OperationExecutionManagerFactory { /** Operation Manager instance */ - private static OperationExecutionManager executionManager; + private OperationExecutionManager executionManager; - public static void init() + public OperationExecutionManagerFactory( TxnManagerFactory txnManagerFactory ) + { + executionManager = new DefaultOperationExecutionManager( txnManagerFactory ); + } + + + public void uninit() { - executionManager = new DefaultOperationExecutionManager(); + //do nothing; } - public static OperationExecutionManager instance() + public OperationExecutionManager instance() { return executionManager; } Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnLogManager.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnLogManager.java?rev=1214089&r1=1214088&r2=1214089&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnLogManager.java (original) +++ directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnLogManager.java Wed Dec 14 08:07:39 2011 @@ -55,6 +55,8 @@ public class DefaultTxnLogManager implem /** Txn Manager */ private TxnManagerInternal txnManager; + /** Txn Manager Factory */ + TxnManagerFactory txnManagerFactory; /** * Inits the the txn log manager @@ -62,10 +64,17 @@ public class DefaultTxnLogManager implem * @param logger write ahead logger * @param txnManager txn Manager */ - public void init( Log logger, TxnManagerInternal txnManager ) + public DefaultTxnLogManager( Log logger, TxnManagerFactory txnManagerFactory ) { wal = logger; - this.txnManager = txnManager; + this.txnManager = txnManagerFactory.txnManagerInternalInstance(); + this.txnManagerFactory = txnManagerFactory; + } + + + public void uninit() + { + // Do nothing } @@ -223,7 +232,7 @@ public class DefaultTxnLogManager implem return wrappedCursor; } - return new IndexCursorWrapper( partitionDn, wrappedCursor, comparator, attributeOid, forwardIndex, onlyValueKey, onlyIDKey ); + return new IndexCursorWrapper( txnManagerFactory, partitionDn, wrappedCursor, comparator, attributeOid, forwardIndex, onlyValueKey, onlyIDKey ); } @@ -240,7 +249,7 @@ public class DefaultTxnLogManager implem return ( Index )wrappedIndex; } - return new IndexWrapper( partitionDn, ( Index ) wrappedIndex ); + return new IndexWrapper( txnManagerFactory, partitionDn, ( Index ) wrappedIndex ); } @@ -256,7 +265,7 @@ public class DefaultTxnLogManager implem return wrappedTable; } - return new MasterTableWrapper( partitionDn, wrappedTable ); + return new MasterTableWrapper( txnManagerFactory, partitionDn, wrappedTable ); } 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=1214089&r1=1214088&r2=1214089&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 Wed Dec 14 08:07:39 2011 @@ -22,6 +22,7 @@ package org.apache.directory.server.core import org.apache.directory.server.core.api.partition.Partition; import org.apache.directory.server.core.api.txn.TxnConflictException; +import org.apache.directory.server.core.api.txn.TxnHandle; import org.apache.directory.server.core.api.txn.TxnLogManager; import org.apache.directory.server.core.shared.txn.logedit.TxnStateChange; import org.apache.directory.server.core.api.log.LogAnchor; @@ -39,6 +40,7 @@ import java.util.concurrent.locks.Condit import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicLong; @@ -84,6 +86,9 @@ class DefaultTxnManager implements TxnMa /** Flush lock */ private Lock flushLock = new ReentrantLock(); + /** Number of flushes */ + private int numFlushes; + /** Flush Condition object */ private Condition flushCondition = flushLock.newCondition(); @@ -94,10 +99,12 @@ class DefaultTxnManager implements TxnMa private HashSet flushedToPartitions = new HashSet(); /** Backgorund syncing thread */ - LogSyncer syncer; + private LogSyncer syncer; /** Initial committed txn */ - ReadWriteTxn dummyTxn = new ReadWriteTxn(); + private ReadWriteTxn dummyTxn = new ReadWriteTxn(); + + private AtomicInteger pending = new AtomicInteger(); /** Per thread txn context */ static final ThreadLocal txnVar = @@ -134,6 +141,39 @@ class DefaultTxnManager implements TxnMa syncer.setDaemon( true ); syncer.start(); } + + + public void uninit() + { + syncer.interrupt(); + + try + { + syncer.join(); + } + catch ( InterruptedException e ) + { + // Ignore + } + + // Do a best effort last flush + flushLock.lock(); + + try + { + flushTxns(); + } + catch ( Exception e ) + { + e.printStackTrace(); + } + finally + { + flushLock.unlock(); + } + + syncer = null; + } /** @@ -220,12 +260,68 @@ class DefaultTxnManager implements TxnMa /** * {@inheritDoc} */ - @SuppressWarnings("unchecked") + public TxnHandle suspendCurTxn() + { + Transaction curTxn = txnVar.get(); + + txnVar.set( null ); + + return curTxn; + } + + + /** + * {@inheritDoc} + */ + 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 ); + } + + txnVar.set( ( Transaction )txnHandle ); + } + + + /** + * {@inheritDoc} + */ public Transaction getCurTxn() { return ( Transaction ) txnVar.get(); } + + /** + * {@inheritDoc} + */ + public void applyPendingTxns() + { + flushLock.lock(); + + try + { + flushTxns(); + } + catch( Exception e ) + { + e.printStackTrace(); + // Ignore + } + finally + { + flushLock.unlock(); + } + + } /** * Begins a read only txn. A read only txn does not put any log edits @@ -275,6 +371,10 @@ class DefaultTxnManager implements TxnMa } txn.startTxn( startTime ); + +// int refCount = lastTxnToCheck.getRefCount().get(); +// System.out.println("start time" + startTime + " " + refCount + +// " pending " + pending.incrementAndGet() ); buildCheckList( txn, lastTxnToCheck ); txnVar.set( txn ); @@ -462,6 +562,13 @@ class DefaultTxnManager implements TxnMa } lastTxnToCheck.getRefCount().decrementAndGet(); + +// if ( txn instanceof ReadOnlyTxn ) +// { +// System.out.println(" txn end " + txn.getStartTime() + " " + +// lastTxnToCheck.getRefCount() +// + " pending " + pending.decrementAndGet() ); +// } } } @@ -634,7 +741,7 @@ class DefaultTxnManager implements TxnMa flushedToPartitions.clear(); Iterator it = committedQueue.iterator(); - ReadWriteTxn txnToFlush; + ReadWriteTxn txnToFlush = null; while ( it.hasNext() ) { @@ -654,6 +761,15 @@ class DefaultTxnManager implements TxnMa break; } + numFlushes++; + +// if ( numFlushes % 100 == 0 ) +// { +// System.out.println( "lastFlushed lsn: " + latestFlushedTxnLSN + " " + committedQueue.size() ); +// +// System.out.println( " last commit txn: " + latestCommitted.getCommitTime() ); +// System.out.println( "txnToFlush: " + txnToFlush.getRefCount() + " " + txnToFlush.getCommitTime() ); +// } /* * If the latest flushed txn has ref count > 0, then @@ -662,6 +778,7 @@ class DefaultTxnManager implements TxnMa if ( txnToFlush.getRefCount().get() > 0 ) { + // System.out.println( "breaking out: " + txnToFlush.getCommitTime() + " " + committedQueue.size() ); break; } @@ -685,11 +802,10 @@ class DefaultTxnManager implements TxnMa @Override public void run() { + flushLock.lock(); try { - flushLock.lock(); - while ( !this.isInterrupted() ) { flushCondition.await( flushInterval, TimeUnit.MILLISECONDS ); @@ -706,6 +822,10 @@ class DefaultTxnManager implements TxnMa e.printStackTrace(); flushFailed = true; } + finally + { + flushLock.unlock(); + } } } Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/IndexCursorWrapper.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/IndexCursorWrapper.java?rev=1214089&r1=1214088&r2=1214089&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/IndexCursorWrapper.java (original) +++ directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/IndexCursorWrapper.java Wed Dec 14 08:07:39 2011 @@ -92,15 +92,19 @@ public class IndexCursorWrapper extends /** Last value returned: here to keep memory overhead low */ private ForwardIndexEntry lastValue = new ForwardIndexEntry(); + + /** Txn Manager */ + TxnManagerInternal txnManager; - public IndexCursorWrapper( Dn partitionDn, IndexCursor wrappedCursor, IndexComparator comparator, String attributeOid, boolean forwardIndex, Object onlyValueKey, UUID onlyIDKey ) + public IndexCursorWrapper( TxnManagerFactory txnManagerFactory, Dn partitionDn, + IndexCursor wrappedCursor, IndexComparator comparator, String attributeOid, boolean forwardIndex, Object onlyValueKey, UUID onlyIDKey ) { this.partitionDn = partitionDn; this.forwardIndex = forwardIndex; this.attributeOid = attributeOid; this.comparator = comparator; - TxnManagerInternal txnManager = TxnManagerFactory.txnManagerInternalInstance(); + txnManager = txnManagerFactory.txnManagerInternalInstance(); Transaction curTxn = txnManager.getCurTxn(); List toCheck = curTxn.getTxnsToCheck(); @@ -778,7 +782,7 @@ public class IndexCursorWrapper extends return null; } - Transaction curTxn = TxnManagerFactory.txnManagerInternalInstance().getCurTxn(); + Transaction curTxn = txnManager.getCurTxn(); if ( txn == curTxn ) { Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/IndexWrapper.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/IndexWrapper.java?rev=1214089&r1=1214088&r2=1214089&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/IndexWrapper.java (original) +++ directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/IndexWrapper.java Wed Dec 14 08:07:39 2011 @@ -53,11 +53,11 @@ public class IndexWrapper implements Ind /** Txn log manager */ private TxnLogManager txnLogManager; - public IndexWrapper( Dn partitionDn, Index wrappedIndex ) + public IndexWrapper( TxnManagerFactory txnManagerFactory, Dn partitionDn, Index wrappedIndex ) { this.partitionDn = partitionDn; this.wrappedIndex = wrappedIndex; - txnLogManager = TxnManagerFactory.txnLogManagerInstance(); + txnLogManager = txnManagerFactory.txnLogManagerInstance(); } @@ -468,7 +468,8 @@ public class IndexWrapper implements Ind */ public boolean forwardGreaterOrEq( Object attrVal, UUID id ) throws Exception { - IndexCursor cursor = forwardCursor(); + // Lock down the index by the key + IndexCursor cursor = forwardCursor( attrVal ); try { @@ -518,7 +519,8 @@ public class IndexWrapper implements Ind */ public boolean reverseGreaterOrEq( UUID id, Object attrVal ) throws Exception { - IndexCursor cursor = reverseCursor(); + // lock down the index by the key + IndexCursor cursor = reverseCursor( id ); try { @@ -568,7 +570,7 @@ public class IndexWrapper implements Ind */ public boolean forwardLessOrEq( Object attrVal, UUID id ) throws Exception { - IndexCursor cursor = forwardCursor(); + IndexCursor cursor = forwardCursor( attrVal ); try { @@ -618,7 +620,7 @@ public class IndexWrapper implements Ind */ public boolean reverseLessOrEq( UUID id, Object attrVal ) throws Exception { - IndexCursor cursor = reverseCursor(); + IndexCursor cursor = reverseCursor( id ); try { Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/MasterTableWrapper.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/MasterTableWrapper.java?rev=1214089&r1=1214088&r2=1214089&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/MasterTableWrapper.java (original) +++ directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/MasterTableWrapper.java Wed Dec 14 08:07:39 2011 @@ -42,11 +42,15 @@ public class MasterTableWrapper implemen /** partition the table belongs to */ private Dn partitionDn; + /** Txn log manager */ + private TxnLogManager logManager; - public MasterTableWrapper( Dn partitionDn, MasterTable wrappedTable ) + + public MasterTableWrapper( TxnManagerFactory txnManagerFactory, Dn partitionDn, MasterTable wrappedTable ) { this.partitionDn = partitionDn; this.wrappedTable = wrappedTable; + logManager = txnManagerFactory.txnLogManagerInstance(); } @@ -170,7 +174,6 @@ public class MasterTableWrapper implemen return null; } - TxnLogManager logManager = TxnManagerFactory.txnLogManagerInstance(); Entry originalEntry = wrappedTable.get( key ); Entry entry = logManager.mergeUpdates( partitionDn, key, originalEntry ); Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/ReadWriteTxn.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/ReadWriteTxn.java?rev=1214089&r1=1214088&r2=1214089&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/ReadWriteTxn.java (original) +++ directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/ReadWriteTxn.java Wed Dec 14 08:07:39 2011 @@ -607,6 +607,13 @@ import org.apache.directory.shared.ldap. List txnWriteDns = txn.getWriteSet(); Iterator writeIt = txnWriteDns.iterator(); Iterator readIt = readDns.iterator(); + + // If no write for any of the txns, then return + + if ( this.writeDns.size() == 0 || txnWriteDns.size() == 0 ) + { + return false; + } DnSet readDnSet; SearchScope readScope; Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/Transaction.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/Transaction.java?rev=1214089&r1=1214088&r2=1214089&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/Transaction.java (original) +++ directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/Transaction.java Wed Dec 14 08:07:39 2011 @@ -24,6 +24,7 @@ import java.util.List; import java.util.UUID; import org.apache.directory.server.core.api.partition.index.IndexEntry; +import org.apache.directory.server.core.api.txn.TxnHandle; import org.apache.directory.shared.ldap.model.entry.Entry; import org.apache.directory.shared.ldap.model.name.Dn; @@ -32,7 +33,7 @@ import org.apache.directory.shared.ldap. * * @author Apache Directory Project */ -/** Package protected */ interface Transaction +/** Package protected */ interface Transaction extends TxnHandle { /** Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/TxnManagerFactory.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/TxnManagerFactory.java?rev=1214089&r1=1214088&r2=1214089&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/TxnManagerFactory.java (original) +++ directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/TxnManagerFactory.java Wed Dec 14 08:07:39 2011 @@ -38,13 +38,15 @@ import java.io.IOException; public class TxnManagerFactory { /** The only txn manager */ - private static TxnManagerInternal txnManager; + private TxnManagerInternal txnManager; /** The only txn log manager */ - private static TxnLogManager txnLogManager; + private TxnLogManager txnLogManager; /** log suffix */ - private static String LOG_SUFFIX = "log"; + private String LOG_SUFFIX = "log"; + + private boolean inited; /** @@ -56,9 +58,9 @@ public class TxnManagerFactory * @param logFileSize max targer log file size for the log manager. * @throws IOException thrown if initialization fails. */ - public static void init( String logFolderPath, + public TxnManagerFactory( String logFolderPath, int logBufferSize, long logFileSize ) throws IOException - { + { Log log = new DefaultLog(); try @@ -72,27 +74,40 @@ public class TxnManagerFactory txnManager = new DefaultTxnManager(); - txnLogManager = new DefaultTxnLogManager(); - ( ( DefaultTxnLogManager )txnLogManager ).init( log, ( TxnManagerInternal ) txnManager ); + txnLogManager = new DefaultTxnLogManager( log, this ); ( ( DefaultTxnManager ) txnManager ).init( txnLogManager ); + + inited = true; } + public void uninit() + { + if ( inited == false ) + { + return; + } + + ( ( DefaultTxnManager ) txnManager ).uninit(); + ( (DefaultTxnLogManager) txnLogManager).uninit(); + inited = false; + } + - public static TxnManager txnManagerInstance() + public TxnManager txnManagerInstance() { return txnManager; } - public static TxnLogManager txnLogManagerInstance() + public TxnLogManager txnLogManagerInstance() { return txnLogManager; } - static TxnManagerInternal txnManagerInternalInstance() + TxnManagerInternal txnManagerInternalInstance() { return txnManager; } Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/DefaultTxnManagerTest.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/DefaultTxnManagerTest.java?rev=1214089&r1=1214088&r2=1214089&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/DefaultTxnManagerTest.java (original) +++ directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/DefaultTxnManagerTest.java Wed Dec 14 08:07:39 2011 @@ -20,6 +20,7 @@ package org.apache.directory.server.core.shared.txn; import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.IOException; import java.io.ObjectOutputStream; @@ -71,8 +72,8 @@ public class DefaultTxnManagerTest { try { - TxnManagerFactory.init( getLogFolder(), logBufferSize, logFileSize ); - txnManager = TxnManagerFactory.txnManagerInternalInstance(); + TxnManagerFactory txnManagerFactory = new TxnManagerFactory( getLogFolder(), logBufferSize, logFileSize ); + txnManager = txnManagerFactory.txnManagerInternalInstance(); } catch ( IOException e ) { @@ -85,6 +86,7 @@ public class DefaultTxnManagerTest @After public void teardown() throws IOException { + Utils.deleteDirectory( new File( getLogFolder() ) ); } Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/EntryUpdateMergeTest.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/EntryUpdateMergeTest.java?rev=1214089&r1=1214088&r2=1214089&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/EntryUpdateMergeTest.java (original) +++ directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/EntryUpdateMergeTest.java Wed Dec 14 08:07:39 2011 @@ -20,6 +20,7 @@ package org.apache.directory.server.core.shared.txn; +import java.io.File; import java.io.IOException; import java.util.TreeSet; import java.util.UUID; @@ -131,9 +132,9 @@ public class EntryUpdateMergeTest GN_AT = schemaManager.getAttributeType( "gn" ); // Init the txn manager - TxnManagerFactory.init( getLogFolder(), logBufferSize, logFileSize ); - txnManager = TxnManagerFactory.txnManagerInternalInstance(); - txnLogManager = TxnManagerFactory.txnLogManagerInstance(); + TxnManagerFactory txnManagerFactory = new TxnManagerFactory( getLogFolder(), logBufferSize, logFileSize ); + txnManager = txnManagerFactory.txnManagerInternalInstance(); + txnLogManager = txnManagerFactory.txnLogManagerInstance(); toUpdate = createEntry( updatedEntryId ); toAdd = createEntry( addedEntryId ); @@ -209,6 +210,8 @@ public class EntryUpdateMergeTest e.printStackTrace(); fail(); } + + Utils.deleteDirectory( new File( getLogFolder() ) ); } Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/IndexCursorWrapperTest.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/IndexCursorWrapperTest.java?rev=1214089&r1=1214088&r2=1214089&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/IndexCursorWrapperTest.java (original) +++ directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/IndexCursorWrapperTest.java Wed Dec 14 08:07:39 2011 @@ -20,6 +20,7 @@ package org.apache.directory.server.core.shared.txn; +import java.io.File; import java.io.IOException; import java.util.TreeSet; import java.util.UUID; @@ -118,9 +119,9 @@ public class IndexCursorWrapperTest dn = new Dn( "cn=Test", "ou=department" ); // Init the txn manager - TxnManagerFactory.init( getLogFolder(), logBufferSize, logFileSize ); - txnManager = TxnManagerFactory.txnManagerInternalInstance(); - txnLogManager = TxnManagerFactory.txnLogManagerInstance(); + TxnManagerFactory txnManagerFactory = new TxnManagerFactory( getLogFolder(), logBufferSize, logFileSize ); + txnManager = txnManagerFactory.txnManagerInternalInstance(); + txnLogManager = txnManagerFactory.txnLogManagerInstance(); // Prepare the to be wrapped cursor ForwardIndexEntry idxEntry; @@ -215,6 +216,8 @@ public class IndexCursorWrapperTest @After public void teardown() throws IOException { + Utils.deleteDirectory( new File( getLogFolder() ) ); + try { txnManager.commitTransaction(); Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/TxnConflicTest.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/TxnConflicTest.java?rev=1214089&r1=1214088&r2=1214089&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/TxnConflicTest.java (original) +++ directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/TxnConflicTest.java Wed Dec 14 08:07:39 2011 @@ -20,12 +20,14 @@ package org.apache.directory.server.core.shared.txn; +import java.io.File; import java.io.IOException; import org.apache.directory.server.core.api.txn.TxnLogManager; import org.apache.directory.server.core.api.log.InvalidLogException; import org.apache.directory.shared.ldap.model.message.SearchScope; import org.apache.directory.shared.ldap.model.name.Dn; +import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -74,9 +76,9 @@ public class TxnConflicTest try { // Init the txn manager - TxnManagerFactory.init( getLogFolder(), logBufferSize, logFileSize ); - txnManager = TxnManagerFactory.txnManagerInternalInstance(); - txnLogManager = TxnManagerFactory.txnLogManagerInstance(); + TxnManagerFactory txnManagerFactory = new TxnManagerFactory( getLogFolder(), logBufferSize, logFileSize ); + txnManager = txnManagerFactory.txnManagerInternalInstance(); + txnLogManager = txnManagerFactory.txnLogManagerInstance(); } catch ( Exception e ) { @@ -84,6 +86,12 @@ public class TxnConflicTest fail(); } } + + @After + public void teardown() throws IOException + { + Utils.deleteDirectory( new File( getLogFolder() ) ); + } @Test @@ -117,7 +125,7 @@ public class TxnConflicTest checkedTxn = ( ReadWriteTxn ) txnManager.getCurTxn(); conflicted = checkedTxn.hasConflict( firstTxn ); - assertTrue( conflicted == true ); + assertTrue( conflicted == false ); txnManager.commitTransaction(); txnManager.beginTransaction( false ); @@ -160,7 +168,7 @@ public class TxnConflicTest checkedTxn = ( ReadWriteTxn ) txnManager.getCurTxn(); conflicted = checkedTxn.hasConflict( firstTxn ); - assertTrue( conflicted == true ); + assertTrue( conflicted == false ); txnManager.commitTransaction(); txnManager.beginTransaction( false ); @@ -176,7 +184,7 @@ public class TxnConflicTest checkedTxn = ( ReadWriteTxn ) txnManager.getCurTxn(); conflicted = checkedTxn.hasConflict( firstTxn ); - assertTrue( conflicted == true ); + assertTrue( conflicted == false ); txnManager.commitTransaction(); txnManager.beginTransaction( false ); Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/TxnIndexCursorTest.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/TxnIndexCursorTest.java?rev=1214089&r1=1214088&r2=1214089&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/TxnIndexCursorTest.java (original) +++ directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/TxnIndexCursorTest.java Wed Dec 14 08:07:39 2011 @@ -20,6 +20,8 @@ package org.apache.directory.server.core.shared.txn; +import java.io.File; +import java.io.IOException; import java.util.TreeSet; import java.util.UUID; Added: directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/Utils.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/Utils.java?rev=1214089&view=auto ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/Utils.java (added) +++ directory/apacheds/branches/apacheds-txns/core-shared/src/test/java/org/apache/directory/server/core/shared/txn/Utils.java Wed Dec 14 08:07:39 2011 @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.directory.server.core.shared.txn; + +import java.io.File; + +public class Utils +{ + public static boolean deleteDirectory( File directory ) + { + + // System.out.println("removeDirectory " + directory); + + if ( directory == null ) + { + return false; + } + + if ( !directory.exists() ) + { + return true; + } + + if ( !directory.isDirectory() ) + { + return false; + } + + String[] list = directory.list(); + + // Some JVMs return null for File.list() when the + // directory is empty. + + if ( list != null ) + { + for ( int i = 0; i < list.length; i++ ) + { + File entry = new File( directory, list[i] ); + + if ( entry.isDirectory() ) + { + if ( !deleteDirectory( entry ) ) + { + return false; + } + } + else + { + if ( !entry.delete() ) + { + return false; + } + } + } + } + + return directory.delete(); + } +}