Re: Is cachedFetchXidStatus provably valid?

Lists: pgsql-hackers
From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Is cachedFetchXidStatus provably valid?
Date: 2012-06-13 17:22:36
Message-ID: CAHyXU0xTrwnFU0MaZ1EsgRihD_f5V9FE2W=Bf2kfgxVpcnCK8Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

It's probably an academic concern, but what happens if a backend saves
off cachedFetchXidStatus and then sleeps for a very long time. During
that time an xid wraparound happens and the backend wakes up and
happens to read another unhinted tuple with the same xid and a
different commit status. This is obviously incredibly unlikely, but
shouldn't cachedFetchXid be cleared at some appropriate point --
perhaps end of transaction?

merlin


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Is cachedFetchXidStatus provably valid?
Date: 2012-06-13 20:55:45
Message-ID: 16415.1339620945@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Merlin Moncure <mmoncure(at)gmail(dot)com> writes:
> It's probably an academic concern, but what happens if a backend saves
> off cachedFetchXidStatus and then sleeps for a very long time. During
> that time an xid wraparound happens and the backend wakes up and
> happens to read another unhinted tuple with the same xid and a
> different commit status. This is obviously incredibly unlikely, but
> shouldn't cachedFetchXid be cleared at some appropriate point --
> perhaps end of transaction?

Well, aside from what the odds might be of hitting the case if you did
manage to sleep through an XID wraparound, I think it's impossible for a
backend to sleep that long, because of cache inval signals. (Or, to
put it differently, a backend has typically got a whole lot of XIDs
cached within tuples in its syscaches. cachedFetchXidStatus is the
least of its worries if it fails to engage in cache inval activity.)

If we had a multiple-entry cache in place of the single-entry cache,
I think this would be a more realistic concern. You'd need some way to
flush old entries from that cache, rather than being able to expect
that the single entry would get overwritten with newer values anytime
something happened.

regards, tom lane


From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Is cachedFetchXidStatus provably valid?
Date: 2012-06-13 21:46:21
Message-ID: CAHyXU0zDoX9ubYrmesxBfuTsw208oyWadiUPBO4xJteyLmg00Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Jun 13, 2012 at 3:55 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Merlin Moncure <mmoncure(at)gmail(dot)com> writes:
>> It's probably an academic concern, but what happens if a backend saves
>> off cachedFetchXidStatus and then sleeps for a very long time.  During
>> that time an xid wraparound happens and the backend wakes up and
>> happens to read another unhinted tuple with the same xid and a
>> different commit status.  This is obviously incredibly unlikely, but
>> shouldn't cachedFetchXid be cleared at some appropriate point --
>> perhaps end of transaction?
>
> Well, aside from what the odds might be of hitting the case if you did
> manage to sleep through an XID wraparound, I think it's impossible for a
> backend to sleep that long, because of cache inval signals.  (Or, to
> put it differently, a backend has typically got a whole lot of XIDs
> cached within tuples in its syscaches.  cachedFetchXidStatus is the
> least of its worries if it fails to engage in cache inval activity.)
>
> If we had a multiple-entry cache in place of the single-entry cache,
> I think this would be a more realistic concern.  You'd need some way to
> flush old entries from that cache, rather than being able to expect
> that the single entry would get overwritten with newer values anytime
> something happened.

Right -- thanks for that -- I figured as much.

merlin