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