directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Emmanuel Lecharny <elecha...@gmail.com>
Subject A Q about the TxnManager.beginReadonlyTransaction() method
Date Sat, 07 Jan 2012 15:24:40 GMT
hi,

as i'm reviewing the txn code, I have a question regarding the 
TxnManager.beginReadonlyTransaction() method (this method is called when 
one do a beginTransaction(true)).

The code contains a do..while loop :

         ReadWriteTxn lastTxnToCheck = null;

         do
         {
             if ( lastTxnToCheck != null )
             {
                 lastTxnToCheck.getRefCount().decrementAndGet();
             }

             lastTxnToCheck = latestCommittedTxn.get(); // Step 1

             if ( lastTxnToCheck != null )
             {
                 lastTxnToCheck.getRefCount().getAndIncrement(); // Step 2
             }

         }
         while ( lastTxnToCheck != latestCommittedTxn.get() ); // Step 3

I'm not sure it's useful. AFAIU, the idea is to get the last commited 
ReadWriteTxn, and to use it as a starting point for the ReadOnlyTxn :

         // Determine start time
         long startTime;

         if ( lastTxnToCheck != null ) // Step 4
         {
             startTime = lastTxnToCheck.getCommitTime(); // Step 5
         }
         else
         {
             startTime = LogAnchor.UNKNOWN_LSN;
         }

Why are we doing a loop ? (note : the lastCommittedTxn is an 
AtomicReference which contains a dummyTxn when the TxnManager is 
initialized, so it's never null). The only reason I can foresee is that 
a new RWTxn can be started just after step 1, and changed the 
latestCommittedTxn before step 3, which is forst very unlikely, and 
second, doe snot protect us from another RWTxn to be started before we 
do step 5.

Last, not least, if we get out of the loop, the lastTxnToCheck variable 
will *always* be not null, so I don't understand teh check in step 4.

Am I missing something ?

-- 
Regards,
Cordialement,
Emmanuel L├ęcharny
www.iktek.com


Mime
View raw message