Re: Assertion failing in master, predicate.c

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Mark Dilger <hornschnorter(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Martijn van Oosterhout <kleptog(at)gmail(dot)com>
Subject: Re: Assertion failing in master, predicate.c
Date: 2019-11-24 22:21:48
Message-ID: 25565.1574634108@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I wrote:
> * Given that the idea is to ignore already-committed entries, it makes
> sense that if LISTEN is called inside a serializable transaction block
> then the cutoff ought to be the transaction's snapshot. Otherwise we'd
> be dropping notifications from transactions that the calling session
> can't have seen the effects of. That defeats the whole point.

> * This says that not only is it okay to use a serializable snapshot
> as the reference, but we *should* do so; that is, it's actually wrong
> to use GetLatestSnapshot here, we should use GetTransactionSnapshot.
> There's not going to be any real difference in read-committed mode,
> but in repeatable-read or serializable mode we are risking dropping
> events that it'd be better to send to the client.

> I'm disinclined to make such a change in the back branches, but it'd
> be reasonable to do so in HEAD.

I spent some time working on this, but then realized that the idea
has a fatal problem. We cannot guarantee receipt of all notifications
since the transaction snapshot, because if our session isn't yet
listening, there's nothing to stop other transactions from trimming
away notify queue entries as soon as all the already-listening sessions
have read them.

One could imagine changing the queue-trimming rules to avoid this,
but I think it's pointless. The right way to use LISTEN is to be
sure you commit it before inspecting database state, and that's
independent of isolation level.

I'd written some documentation and comment changes around this,
claiming falsely that Repeatable Read or Serializable isolation
would now let you make more assumptions about the timing of the
first received notification. I'll get rid of those claims and
just commit the docs changes --- it seems worthwhile to clarify
what is and isn't safe use of LISTEN. But the code should be
left as-is, I'm thinking.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2019-11-24 23:33:25 Re: TAP tests aren't using the magic words for Windows file access
Previous Message Thomas Munro 2019-11-24 20:29:25 Re: Minor white space typo in documentation