From: Kyle Kingsbury <aphyr@jepsen.io>
To: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Subject: Re: Potential G2-item cycles under serializable isolation
Date: Tue, 2 Jun 2020 12:18:52 -0400
Message-ID: <3150072e-13b8-7655-211b-17898f894e45@jepsen.io> (raw)
In-Reply-To: <CAH2-Wzm2F+pNUVeonrS3cZfttJDBmp0nMUiHYG4qAoGQO-rCvA@mail.gmail.com>
References: <db7b729d-0226-d162-a126-8a8ab2dc4443@jepsen.io>
<CAH2-WzkmEz0ax0AG_nc788uRSe_P_RTQwgkveY5VCjDy5y4eUw@mail.gmail.com>
<11bb3199-c685-1cec-63bb-f92848edbe10@jepsen.io>
<CAH2-Wzne1fr47aayESfDdfMvjiB+jSfW+xEWggdZuRYa8CL8Nw@mail.gmail.com>
<CAMotZ_w2-bdQms+rFa-DA_vH+y7A=ky0Gmwu9Y81LT=2ge5TtQ@mail.gmail.com>
<CAH2-WzkBwwDj38NvdiP4J3ia_POC68C1-FCtXvnDvnzwMASv5w@mail.gmail.com>
<54c6c503-b939-c4ce-0d54-4f998ac04168@jepsen.io>
<CAH2-Wzm2F+pNUVeonrS3cZfttJDBmp0nMUiHYG4qAoGQO-rCvA@mail.gmail.com>
OK! So I've designed a variant of this test which doesn't use ON CONFLICT.
Instead, we do a homebrew sort of upsert: we try to update the row in place by
primary key; if we see zero records updated, we insert a new row, and if *that*
fails due to the primary key conflict, we try the update again, under the theory
that since we now know a copy of the row exists, we should be able to update it.
https://github.com/jepsen-io/jepsen/blob/f47eb25ab32529a7b66f1dfdd3b5ef2fc84ed778/stolon/src/jepsen/...
This isn't bulletproof; even under SERIALIZABLE, Postgres will allow a
transaction to fail to update any rows, then fail to insert due to a primary key
conflict--but because the primary key conflict forces a transaction abort (or
rolling back to a savepoint, which negates the conflict), I think it's still
serializable. The isolation docs explain this, I think.
Unfortunately, I'm still seeing tons of G2-item cycles. Whatever this is, it's
not related to ON CONFLICT.
As a side note, I can confirm that Postgres repeatable read is definitely weaker
than repeatable read--at least as formalized by Adya et al. This makes sense if
you understand repeatable read to mean SI (after all, the SI paper says they're
incomparable!), but the Postgres docs seem to imply Postgres is strictly
*stronger* than the ANSI SQL spec, and I'm not convinced that's entirely true:
https://www.postgresql.org/docs/12/transaction-iso.html
> The table also shows that PostgreSQL's Repeatable Read implementation does
not allow phantom reads. Stricter behavior is permitted by the SQL standard...
> This is a stronger guarantee than is required by the SQL standard for this
isolation level...
I get the sense that the Postgres docs have already diverged from the ANSI SQL
standard a bit, since SQL 92 only defines three anomalies (P1, P2, P3), and
Postgres defines a fourth: "serialization anomaly".
This results in a sort of weird situation: on the one hand, it's true: we don't
(I think) observe P1 or P2 under Postgres Repeatable Read. On the other hand,
SQL 92 says that the difference between repeatable read and serializable is
*exactly* the prohibition of P3 ("phantom"). Even though all our operations are
performed by primary key, we can observe a distinct difference between Postgres
repeatable read and Postgres serializable.
I can see two ways to reconcile this--one being that Postgres chose the anomaly
interpretation of the SQL spec, and the result is... maybe internally
inconsistent? Or perhaps one of the operations in this workload actually *is* a
predicate operation--maybe by dint of relying on a uniqueness constraint?
I'm surprised the transaction isolation docs don't say something like "Postgres
repeatable read level means snapshot isolation, which is incomparable with SQL
repeatable read." Then it'd be obvious that Postgres repeatable read exhibits
G2-item! Weirdly, the term "snapshot isolation" doesn't show up on the page at all!
--Kyle
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: aphyr@jepsen.io
Subject: Re: Potential G2-item cycles under serializable isolation
In-Reply-To: <3150072e-13b8-7655-211b-17898f894e45@jepsen.io>
References: <db7b729d-0226-d162-a126-8a8ab2dc4443@jepsen.io> <CAH2-WzkmEz0ax0AG_nc788uRSe_P_RTQwgkveY5VCjDy5y4eUw@mail.gmail.com> <11bb3199-c685-1cec-63bb-f92848edbe10@jepsen.io> <CAH2-Wzne1fr47aayESfDdfMvjiB+jSfW+xEWggdZuRYa8CL8Nw@mail.gmail.com> <CAMotZ_w2-bdQms+rFa-DA_vH+y7A=ky0Gmwu9Y81LT=2ge5TtQ@mail.gmail.com> <CAH2-WzkBwwDj38NvdiP4J3ia_POC68C1-FCtXvnDvnzwMASv5w@mail.gmail.com> <54c6c503-b939-c4ce-0d54-4f998ac04168@jepsen.io> <CAH2-Wzm2F+pNUVeonrS3cZfttJDBmp0nMUiHYG4qAoGQO-rCvA@mail.gmail.com> <3150072e-13b8-7655-211b-17898f894e45@jepsen.io>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox