Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jg9d1-00087b-8f for pgsql-bugs@arkaria.postgresql.org; Tue, 02 Jun 2020 16:19:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jg9cy-0002Iw-O7 for pgsql-bugs@arkaria.postgresql.org; Tue, 02 Jun 2020 16:19:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jg9cy-0002Ip-Cd for pgsql-bugs@lists.postgresql.org; Tue, 02 Jun 2020 16:19:00 +0000 Received: from mail-qt1-x842.google.com ([2607:f8b0:4864:20::842]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jg9cv-0005v8-8w for pgsql-bugs@lists.postgresql.org; Tue, 02 Jun 2020 16:18:59 +0000 Received: by mail-qt1-x842.google.com with SMTP id e16so11132676qtg.0 for ; Tue, 02 Jun 2020 09:18:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jepsen-io.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=IdrXfehZIc0Ev88uD3n8xiMl9NLX9hkHEoOh3sYSV+A=; b=WRnCmi4L5ciBSva27vdVWDPOPHAoc2IwycOf+U6r6AJRXrufUN/QkWlMDxv4j3xgrR KhVcgLQ/xUEQ8/LsNXSXEhYbh2T1bPxhq+tyFNLWNouIuRYqZikyklsGS2+RvTXpzz9U 8o4E5YthwIlAgJMl/Y+BJ1vomhpH+/nOi0nCefJIgS/L3z8YHtpNmXuJ4Xn/CNpkriw4 I7ustJ8vLR0nB4xR87rOAROFmet4qfSollzkVLtpO70OKioK50vYaDq9toeOCJ8VFFQE bCWZ+QqpESvMeZ8Xt3AbHLI5HmS1+XIUiN3WsNkwu4EgqOMmoI+OScobG4f5EbJRVM2L wduw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=IdrXfehZIc0Ev88uD3n8xiMl9NLX9hkHEoOh3sYSV+A=; b=oQ1BJC42xgkAlxtWykMP0gWcYB0TzRW/gJx1feCIVGVwY1fglZOkCQeIlWbY+va/Hc FztGGvYTwSlkWvhrQ2Vh1RFSu6jkhW9M265hI+6xa8XlleZAhr8SpklkesAyiabd0vKt VOWw3X2uOVHU/B3fab1ULiOo97sFsk4rUAlL9vuIqNxMQZJhQlsrTTUX9uS0IS0b6bf2 Ab37+K+6hPb9tvkN1fkRDaWwl/8rPXsDeRwnfXa4k44+N7Xo+IwUy+YH1GZ2u6q8ZFsx CRaRq+2nTcS7IiaFZ4dKgfi20IQ5vadT4h3VNyHeFgljb3jKwbd1d92Zu9FFYqSiKT5l WfUg== X-Gm-Message-State: AOAM533uYcBuBXwUGdsTR4tiVy9bA2uNZxh9/xRevN85+sgwnWDwOKcV gTka+1JZbTrOgoP4jGWVCt0Cefqnmvc= X-Google-Smtp-Source: ABdhPJxzBk204izXJ++MQXz8Naq6uiNS2NsjwIWS3te0UbR6gw+d3RMeMpr0SicbYUNQn8B0h4jHHg== X-Received: by 2002:ac8:6b43:: with SMTP id x3mr26604849qts.321.1591114734616; Tue, 02 Jun 2020 09:18:54 -0700 (PDT) Received: from ?IPv6:2600:2b00:9454:400:2b41:90a6:b4e0:34c8? ([2600:2b00:9454:400:2b41:90a6:b4e0:34c8]) by smtp.gmail.com with ESMTPSA id u25sm3032147qtc.11.2020.06.02.09.18.53 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 02 Jun 2020 09:18:53 -0700 (PDT) Subject: Re: Potential G2-item cycles under serializable isolation To: PostgreSQL mailing lists References: <11bb3199-c685-1cec-63bb-f92848edbe10@jepsen.io> <54c6c503-b939-c4ce-0d54-4f998ac04168@jepsen.io> From: Kyle Kingsbury Message-ID: <3150072e-13b8-7655-211b-17898f894e45@jepsen.io> Date: Tue, 2 Jun 2020 12:18:52 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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/stolon/append.clj#L31-L108 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