From: <tho...@us...> - 2010-11-18 17:10:24
|
Revision: 3960 http://bigdata.svn.sourceforge.net/bigdata/?rev=3960&view=rev Author: thompsonbry Date: 2010-11-18 17:10:17 +0000 (Thu, 18 Nov 2010) Log Message: ----------- Hacked in an intgration with the RWStore to make it aware of the #of active transactions. Modified Paths: -------------- branches/JOURNAL_HA_BRANCH/bigdata/src/java/com/bigdata/journal/Journal.java branches/JOURNAL_HA_BRANCH/bigdata/src/java/com/bigdata/rwstore/RWStore.java branches/JOURNAL_HA_BRANCH/bigdata/src/samples/com/bigdata/samples/btree/JournalReadOnlyTxExample.java Modified: branches/JOURNAL_HA_BRANCH/bigdata/src/java/com/bigdata/journal/Journal.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata/src/java/com/bigdata/journal/Journal.java 2010-11-18 16:50:22 UTC (rev 3959) +++ branches/JOURNAL_HA_BRANCH/bigdata/src/java/com/bigdata/journal/Journal.java 2010-11-18 17:10:17 UTC (rev 3960) @@ -237,8 +237,26 @@ protected AbstractLocalTransactionManager newLocalTransactionManager() { final JournalTransactionService abstractTransactionService = new JournalTransactionService( - properties, this).start(); + properties, this) { + + protected void activateTx(final TxState state) { + final IBufferStrategy bufferStrategy = Journal.this.getBufferStrategy(); + if(bufferStrategy instanceof RWStrategy) { + ((RWStrategy)bufferStrategy).getRWStore().activateTx(); + } + super.activateTx(state); + } + protected void deactivateTx(final TxState state) { + super.deactivateTx(state); + final IBufferStrategy bufferStrategy = Journal.this.getBufferStrategy(); + if(bufferStrategy instanceof RWStrategy) { + ((RWStrategy)bufferStrategy).getRWStore().deactivateTx(); + } + } + + }.start(); + return new AbstractLocalTransactionManager() { public AbstractTransactionService getTransactionService() { Modified: branches/JOURNAL_HA_BRANCH/bigdata/src/java/com/bigdata/rwstore/RWStore.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata/src/java/com/bigdata/rwstore/RWStore.java 2010-11-18 16:50:22 UTC (rev 3959) +++ branches/JOURNAL_HA_BRANCH/bigdata/src/java/com/bigdata/rwstore/RWStore.java 2010-11-18 17:10:17 UTC (rev 3960) @@ -444,6 +444,14 @@ // * the same txReleaseTime. // private static final int MAX_DEFERRED_FREE = 4094; // fits in 16k block private final long m_minReleaseAge; + + /** + * The #of open transactions (read-only or read-write). + * + * This is guarded by the {@link #m_allocationLock}. + */ + private int m_activeTxCount = 0; + private volatile long m_lastDeferredReleaseTime = 0L; // private final ArrayList<Integer> m_currentTxnFreeList = new ArrayList<Integer>(); private final PSOutputStream m_deferredFreeOut; @@ -1428,7 +1436,8 @@ * FIXME We need unit test when MIN_RELEASE_AGE is ZERO AND * there are open read-only transactions. */ - boolean alwaysDefer = m_minReleaseAge > 0L; + boolean alwaysDefer = m_minReleaseAge > 0L + || m_activeTxCount > 0; if (!alwaysDefer) alwaysDefer = context == null && !m_contexts.isEmpty(); if (alwaysDefer) @@ -4206,4 +4215,22 @@ return m_storageStats; } + public void activateTx() { + m_allocationLock.lock(); + try { + m_activeTxCount++; + } finally { + m_allocationLock.unlock(); + } + } + + public void deactivateTx() { + m_allocationLock.lock(); + try { + m_activeTxCount++; + } finally { + m_allocationLock.unlock(); + } + } + } Modified: branches/JOURNAL_HA_BRANCH/bigdata/src/samples/com/bigdata/samples/btree/JournalReadOnlyTxExample.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata/src/samples/com/bigdata/samples/btree/JournalReadOnlyTxExample.java 2010-11-18 16:50:22 UTC (rev 3959) +++ branches/JOURNAL_HA_BRANCH/bigdata/src/samples/com/bigdata/samples/btree/JournalReadOnlyTxExample.java 2010-11-18 17:10:17 UTC (rev 3960) @@ -183,10 +183,12 @@ // First, remove the existing tuples. removeWriteSet(unisolatedBTree); + store.commit(); + /* * Verify that the read-only view has not seen those changes. */ - { + if(false) { final BTree readOnlyBTree = (BTree) store.getIndex(name, tx2); verifyWriteSet1(readOnlyBTree); @@ -198,6 +200,8 @@ */ writeSet2(unisolatedBTree); + store.commit(); + /* * Verify that the read-only view has not seen those changes. * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |