directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Selcuk AYA <ayasel...@gmail.com>
Subject Re: A Q about the TxnManager.beginReadonlyTransaction() method
Date Sun, 08 Jan 2012 08:21:54 GMT
the checks are necessary so that the read only txn can be sure that
txns after its start time are not flushed to partitions. This is
explained in greater detail in the comments right above the code.

I added dummytxn later on so some of the null checks became
unnecessary but that is not a big deal.

On Sat, Jan 7, 2012 at 5:24 PM, Emmanuel Lecharny <elecharny@gmail.com> wrote:
> 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