RE: Re: Strangeness in xid allocation / snapshot setup

From: "Mikheev, Vadim" <vmikheev(at)SECTORBASE(dot)COM>
To: "'Tom Lane'" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: RE: Re: Strangeness in xid allocation / snapshot setup
Date: 2001-07-12 17:11:02
Message-ID: 3705826352029646A3E91C53F7189E320166C4@sectorbase2.sectorbase.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> > You forget about Tx Old! The point is that changes made by
> > Tx Old *over* Tx New' changes effectively make those Tx New'
> > changes *visible* to Tx S!
>
> Yes, but what's that got to do with the order of operations in
> GetSnapshotData? The scenario you describe can occur anyway.

Try to describe it step by step.

> Only if Tx Old is running in Read Committed mode, of course.
> But if it is, then it's capable of deciding to update a row updated
> by Tx New. Whether Tx S's xmax value is before or after Tx New's ID
> is not going to change the behavior of Tx Old.

1. I consider particular case when Tx S' xmax is before Tx New' ID.
1.1 For this case acquiring SInval lock before ReadNewTransactionId()
changes behavior of Tx Old: it postpones change of Tx Old'
(and Tx New') MyProc->xid in xact.c:CommitTransaction(), so Tx S
will see Tx Old as running, ie Tx Old' changes will be invisible
to Tx S on the base of analyzing MyProc.xid-s, just like Tx New'
changes will be invisible on the base of analyzing next Tx ID.
2. If you can find examples when current code is not able to provide
consistent snapshot of running (out of interest) transactions
let's think how to fix code. Untill then my example shows why
we cannot move SInval lock request after ReadNewTransactionId().

> I'd still like to change GetSnapshotData to read the nextXid before
> it acquires SInvalLock, though. If we did that, it'd be safe to make
> GetNewTransactionId be
>
> SpinAcquire(XidGenLockId);
> xid = nextXid++;
> SpinAcquire(SInvalLockId);
> MyProc->xid = xid;
> SpinRelease(SInvalLockId);
> SpinRelease(XidGenLockId);
>
> which is really necessary if you want to avoid assuming that
> TransactionIds can be fetched and stored atomically.

To avoid that assumption one should add per MyProc spinlock.

Vadim

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2001-07-12 17:24:17 Re: Re: Strangeness in xid allocation / snapshot setup
Previous Message Bruce Momjian 2001-07-12 17:09:10 Re: Prefixing libpq error message with function names