Re: XMIN semantic at peril ?

From: Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: XMIN semantic at peril ?
Date: 2007-10-18 21:20:12
Message-ID: 20071018212012.GH15485@merkur.hilbert.loc
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Oct 11, 2007 at 12:03:47PM -0400, Tom Lane wrote:

> > If in the meantime another writer changed the data we
> > originally read we would detect that by xmin having changed
> > hence no row to be updated. So, yes, there is a *tiny*
> > failure condition:
>
> Hmm. I think the failure condition is not what you are thinking: in
> your example, you'd correctly conclude that some other transaction
> modified the row.
Not really, notice:

- original XMIN read, transaction is closed
- a loooong time passes:
- original row gets frozen, XMIN changed to FrozenTransactionId
- XMIN wraps
- original XMIN is *reused* on the *exact same* original row by
another concurrent writer without changing the primary key
- the original row is written back to the database
with "... where xmin = original_xmin and pk = original_pk ..."

Now the update succeeds, although the data DID change !

This is a worst-case failure but should be *very* rare.

> The problem case is
>
> - read (a rather old) row including XMIN
> - VACUUM comes along and decides to set XMIN = FrozenTransactionId
> - update row with "... where pk = ... and XMIN = old_xmin_from_read"
> - update fails, when there is no need to fail
>
> As long as the failure is "soft", ie, you recover reasonably, this
> shouldn't be a big problem. But it's certainly not a scenario you
> should dismiss as not credible because of timescales.
Very true. I documented this in our code and set up a TODO
item to switch to a AFTER-trigger updated non-system oplock
column.

Thanks,
Karsten
--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Laurent ROCHE 2007-10-18 21:26:43 Re : Abbreviation list
Previous Message Laurent ROCHE 2007-10-18 21:16:36 Re : Re : pg_dump SERIAL and SEQUENCE