From: Heikki Linnakangas <hlinnaka@iki.fi>
To: Thomas Munro <thomas.munro@enterprisedb.com>
To: const_sunny@126.com
Cc: PostgreSQL Bugs <pgsql-bugs@postgresql.org>
Subject: Re: BUG #14721: Assertion of synchronous replication
Date: Wed, 12 Jul 2017 15:45:48 +0300
Message-ID: <22a6cc48-0803-49d9-d1f3-dd5206f24c21@iki.fi> (raw)
In-Reply-To: <CAEepm=33AAJFu9CMPhCsnX-Zg6ZySrga_oAjRV0Dtgx2G03kpQ@mail.gmail.com>
References: <20170629023623.1480.26508@wrigleys.postgresql.org>
<CAEepm=3k=gTAn5=X_Qv=hWw9JnUxUMXCzBxTKPaHHXxKkF0+iw@mail.gmail.com>
<CAEepm=33AAJFu9CMPhCsnX-Zg6ZySrga_oAjRV0Dtgx2G03kpQ@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
On 06/29/2017 08:11 AM, Thomas Munro wrote:
> On Thu, Jun 29, 2017 at 4:27 PM, Thomas Munro
> <thomas.munro@enterprisedb.com> wrote:
>> /*
>> * Acquiring the lock is not needed, the latch ensures proper
>> * barriers. If it looks like we're done, we must really be done,
>> * because once walsender changes the state to SYNC_REP_WAIT_COMPLETE,
>> * it will never update it again, so we can't be seeing a stale value
>> * in that case.
>> */
>
> Yeah, counting on the latch for free barriers doesn't work if you
> happen to see SYNC_REP_WAIT_COMPLETE first time through the loop, or
> if you see it after a spurious signal woke you and then it's
> immediately set to SYNC_REP_WAIT_COMPLETE. In those cases, the
> following Assert statement is making an assertion about cache
> coherency that doesn't work even on a friendly TSO system.
Ah yes, that's clearly broken.
> Can you reproduce the problem with this experimental patch applied?
I was able to reproduce this, after adding some sleeps (see attached).
It must be pretty hard to hit it normally, or we would've gotten reports
earlier. Although it only really shows with assertions enabled, so that
could also be why.
In your patch, I think the pg_read_barrier() is only necessary, if
assertions are enabled. Then again, better safe than sorry, and at least
on my x86-64 machine with gcc, it doesn't actually change the produced
machine code at all.
I committed your patch and backported to 9.5, with some additional
comments. Thanks for the report Const!
- Heikki
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugsAttachments:reproduce-assert-failure.patch (text/x-diff, 592B) downloaddiff --git a/src/backend/replication/syncrep.c b/src/backend/replication/syncrep.cindex 6a28becdad..1f163e4176 100644--- a/src/backend/replication/syncrep.c+++ b/src/backend/replication/syncrep.c@@ -208,6 +208,8 @@ SyncRepWaitForLSN(XLogRecPtr lsn, bool commit)
new_status[len] = '\0'; /* truncate off " waiting ..." */
}
+ usleep(5000);+
/*
* Wait for specified LSN to be confirmed.
*
@@ -1027,6 +1029,8 @@ SyncRepWakeQueue(bool all, int mode)
*/
thisproc->syncRepState = SYNC_REP_WAIT_COMPLETE;
+ usleep(10000);+
/*
* Remove thisproc from queue.
*/
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: hlinnaka@iki.fi, thomas.munro@enterprisedb.com, const_sunny@126.com
Subject: Re: BUG #14721: Assertion of synchronous replication
In-Reply-To: <22a6cc48-0803-49d9-d1f3-dd5206f24c21@iki.fi>
References: <20170629023623.1480.26508@wrigleys.postgresql.org> <CAEepm=3k=gTAn5=X_Qv=hWw9JnUxUMXCzBxTKPaHHXxKkF0+iw@mail.gmail.com> <CAEepm=33AAJFu9CMPhCsnX-Zg6ZySrga_oAjRV0Dtgx2G03kpQ@mail.gmail.com> <22a6cc48-0803-49d9-d1f3-dd5206f24c21@iki.fi>
* 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