Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dVH1i-00076a-8R for pgsql-bugs@arkaria.postgresql.org; Wed, 12 Jul 2017 12:45:58 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dVH1h-0002Ju-RH for pgsql-bugs@arkaria.postgresql.org; Wed, 12 Jul 2017 12:45:57 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dVH1h-0002Jl-CF for pgsql-bugs@postgresql.org; Wed, 12 Jul 2017 12:45:57 +0000 Received: from mail-lf0-x244.google.com ([2a00:1450:4010:c07::244]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1dVH1c-0004bf-RA for pgsql-bugs@postgresql.org; Wed, 12 Jul 2017 12:45:56 +0000 Received: by mail-lf0-x244.google.com with SMTP id f28so2596485lfi.3 for ; Wed, 12 Jul 2017 05:45:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to; bh=l8yJt7xMCUDvVlYneH6Kn7bHk3i/M20Y1UOoMmZpzZ4=; b=cvh5zTSJ0FuHc99nGmqt9tc9jLsyXLY1yFfj1VlWG5IS3g9ygg9uhiuyvh5A0o9cWT aaTh3BFxykul+VTPDpWmnoNqrNDNbxd/Da0RQKzI7S3UszOOVcbGqFoS+19fJ5Mf1sAe zMQgolt9MpI7n2GRqV+KNCVcqEySxdDbDO660g+3vBJsH/ktEN7fZxg8JqBOM5J+ubZ1 NpD+GZjz4+bNUjUswUauCvGV41fV9HucFSeO9JZahfODopP1FDjsskMbEhysC3vO83nt YNWQCGY24/uqewqCufsSI4SEQfNYlVC4boMgCPkOcmsq5fdS3ENDbzZC2nnC7/hQyDvP jfAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:references:cc:from:message-id :date:user-agent:mime-version:in-reply-to; bh=l8yJt7xMCUDvVlYneH6Kn7bHk3i/M20Y1UOoMmZpzZ4=; b=NdkLbOrMDBkuDc7O3qrWutyHKtY8IWEcryBxCRpJszaxGV4N5JxONAgxffYb9phY7u LDjJQljRtMyoQyZHAy0kwCq7viPuLZuffLvZ8DW0DHg13zMuEbqqvZr4JWh/mJ/1Gupo /GBwLtkEeosDW8LQOQQKvB+SMd96WUAY1Yiv1V8cRnBwAyopvBfvje9/D7YBbUwxTpon CpK3v29+nGj8p7gi1C7MT1NPL1gnv7DY776zQuMyerAnH24JxeC6F9wjgAeRlPLlDUZ1 slcTK7BgsBUdWqkm85qEqeRNaMEZD4XFbvSRWX7lpsdOXHcmTVK8DKBRGTddJsgUDAxU YllQ== X-Gm-Message-State: AIVw1110pKk9mfawfmkiTr4iJOw1vJQrFCTnszrt6xAzZH52YgquKKTn /1VKRCcpaN0cfbM+ X-Received: by 10.25.196.194 with SMTP id u185mr1864345lff.88.1499863550403; Wed, 12 Jul 2017 05:45:50 -0700 (PDT) Received: from [192.168.1.99] (dsl-hkibng32-54fb4e-103.dhcp.inet.fi. [84.251.78.103]) by smtp.gmail.com with ESMTPSA id e79sm482759lji.25.2017.07.12.05.45.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Jul 2017 05:45:49 -0700 (PDT) Subject: Re: BUG #14721: Assertion of synchronous replication To: Thomas Munro , const_sunny@126.com References: <20170629023623.1480.26508@wrigleys.postgresql.org> Cc: PostgreSQL Bugs From: Heikki Linnakangas Message-ID: <22a6cc48-0803-49d9-d1f3-dd5206f24c21@iki.fi> Date: Wed, 12 Jul 2017 15:45:48 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------2E8995699EAB1D3D61F5D6C3" List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org This is a multi-part message in MIME format. --------------2E8995699EAB1D3D61F5D6C3 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 06/29/2017 08:11 AM, Thomas Munro wrote: > On Thu, Jun 29, 2017 at 4:27 PM, Thomas Munro > 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 --------------2E8995699EAB1D3D61F5D6C3 Content-Type: text/x-diff; name="reproduce-assert-failure.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="reproduce-assert-failure.patch" diff --git a/src/backend/replication/syncrep.c b/src/backend/replication/syncrep.c index 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. */ --------------2E8995699EAB1D3D61F5D6C3 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --------------2E8995699EAB1D3D61F5D6C3--