Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gh9Cx-0007nm-FE for pgsql-bugs@arkaria.postgresql.org; Wed, 09 Jan 2019 08:27:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gh9Cv-0003H0-Ub for pgsql-bugs@arkaria.postgresql.org; Wed, 09 Jan 2019 08:27:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gh9Cv-0003Gt-O0 for pgsql-bugs@lists.postgresql.org; Wed, 09 Jan 2019 08:27:25 +0000 Received: from [124.133.18.218] (helo=EX02.highgo.com) by magus.postgresql.org with esmtps (TLS1.0:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gh9Cr-0000pu-Cl for pgsql-bugs@lists.postgresql.org; Wed, 09 Jan 2019 08:27:25 +0000 Received: from MM7W91005DUDZZI (192.168.100.145) by EX02.highgo.com (192.168.110.195) with Microsoft SMTP Server (TLS) id 15.0.847.32; Wed, 9 Jan 2019 16:35:41 +0800 Date: Wed, 9 Jan 2019 16:28:51 +0800 From: "lichuancheng@highgo.com" To: Michael Paquier CC: "pgsql-bugs@lists.postgresql.org" Subject: Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. References: <15567-a9ff747c5e7c031c@postgresql.org>, , <2018122913081786371813@highgo.com>, <2019010317504815140834@highgo.com>, <20190109071411.GA23045@paquier.xyz> X-Priority: 3 X-Has-Attach: no X-Mailer: Foxmail 7, 2, 7, 26[cn] MIME-Version: 1.0 Message-ID: <2019010916285112831844@highgo.com> Content-Type: multipart/alternative; boundary="----=_001_NextPart425866801107_=----" X-Originating-IP: [192.168.100.145] X-ClientProxiedBy: EX02.highgo.com (192.168.110.195) To EX02.highgo.com (192.168.110.195) X-Host-Lookup-Failed: Reverse DNS lookup failed for 124.133.18.218 (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_001_NextPart425866801107_=---- Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: base64 DQo+U28gdGhlIHRha2Ugb2YgdGhlIHBhdGNoIGlzIHRvIG1ha2Ugc3VyZSB0aGF0IHRoZSBXQUwg cmVjZWl2ZXIgaGFzDQo+YmVlbiBjb3JyZWN0bHkgc3RhcnRlZCBpZiB0aGUgc3RhcnR1cCBwcm9j ZXNzIHJlcXVlc3RlZCBvbmUgYmVmb3JlDQo+dHJ5aW5nIHRvIHJlcGxheSBtb3JlIFdBTCByZWNv cmRzLiAgTm93IGl0IHNlZW1zIHRvIG1lIHRoYXQgeW91IGRvIG5vdA0KPmNsb3NlIGFsbCB0aGUg Z2FwcyBoZXJlLiAgVGhlIFdBTCByZWNlaXZlciBjb3VsZCBmaW5pc2ggc3RhcnRpbmcsIGJ1dCAN Cj5zdGlsbCBub3QgaGF2ZSB0aGUgdGltZSB0byBzdHJlYW0gdXAgdG8gdGhlIHBvaW50IHdoZXJl IHRoZSBzdGFydHVwIA0KPnByb2Nlc3MgY291bGQgY29uc3VtZSB0aGluZ3Mgc2FmZWx5LiAgVGhl IHBhdGNoIG1ha2VzIHNvbWV3aGF0IHN1cmUgDQo+dGhhdCB0aGUgZ2FwIGlzIGNsb3NlZCBieSBh cHBseWluZyBhIHRpbWVvdXQgb2YgMXMsIHN0aWxsIGluDQo+ZW52aXJvbm1lbnRzIHdpdGggbW9y ZSBsYXRlbmN5IGl0IHdvdWxkIG1ha2UgdGhlIGZhaWx1cmUgc3RpbGwNCj5oYXBwZW4uICBXb3Vs ZG4ndCBpdCBiZSBiZXR0ZXIgaW5zdGVhZCB0byBtYWtlIHN1cmUgdGhhdCB0aGUgc3RhcnR1cA0K PnByb2Nl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hZA0K DQoNCg== ------=_001_NextPart425866801107_=---- Content-Type: text/html; charset="ISO-8859-1" Content-Transfer-Encoding: quoted-printable =0A

=0A
>So the take of the= patch is to make sure that the WAL receiver has
=0A
= >been correctly started if the startup process requested one bef= ore
=0A>trying to replay more WAL records.  Now it seems= to me that you do not
=0A>close all the gaps here. = ; The WAL receiver could finish starting, but=0A
>still = not have the time to stream up to the point where the startup=0A>process could consume things safely.  The patch makes somew= hat sure=0A
>that the gap is closed by applying a timeout of= 1s, still in
=0A
>environments with more latency it would mak= e the failure still
=0A
>happen.  Wouldn't it be better i= nstead to make sure that the startup
=0A
>process does not try= to use once again the same record where the
=0A
>failure happ= ened before the WAL receiver confirms that it has flushed
=0A
>= ;something newer than the LSN position which was known as bad?
=0A =0A
>One problem may be that upon restart we reset re= ceivedUpto, and that
=0A
>visibly we may want to be more caref= ul with its handling to avoid
=0A
>successive failures so as t= he startup process does not bump
=0A
>repeatitively into the s= ame bogus record.  Looking at the code, the
=0A
>computat= ion looks quite safe though (I need to double-check to be 100%
=0A>sure), so isn't the origin of the problem just that the WAL segment<= /div>=0A
>from the primary is corrupted, and that what gets streame= d is broken
=0A
>at its origin point, preventing the standby t= o move on?  You may want
=0A
>to double-check that as wel= l..

I known what you describe.
Nomally,= when the reciver process restart,the code reset redo LSN to the start of t= he 
wal segment. But now the question is that the= reciver process can not restart
sucessful,so correct wal record nerver arrived. so the startup process is in a
infinite cycle to start and end t= he reciver process. 
So the way to = solve the problem  is give some time to reciver proc= ess to 
restart. As long as it restart sucessfu= l,it will apply wal record at the start of the 
wal segment from master and the correct wal record will arriv= ed. so i do not 
think what you say 'still&n= bsp;in environments w= ith more latency = ;it would make the 
failure still happen' is right.So i think the patch can solve the problem after
 modify as  side note=  blow.

I have= make sure that the the broken wal record is broked during stream,<= /div>
it's well in master and other slave.

<= /div>=0A
 
=0A
>As a side note, the patch is incorrec= t for a couple of things though:
=0A
>1) Formatting of comment= s and indentation.
=0A
>2) Please be careful of whitespaces.=0A
>3) Usually no more than 72-80 characters per line.
= =0A
>4) Why a wait phase of 1s?
I think 1s is enought for= reciver process to restart. Maybe it need a discuss.

= =0A
>5) And much worse, the WAL receiver status cannot be looked at= without
=0A
>taking its mutex lock first, so this makes the l= ogic look at something
=0A
>which may be concurrently updated.=   Oops.
I am sorry.

=0A
>6) Stil= l the patch is incorrect per the reasons above ;)
I am new here,= thanks for your explanation in side note<= span style=3D"background-color: rgba(0, 0, 0, 0); font-size: 10.5pt; line-= height: 1.5;">.

-----
movea= d


=0A
------=_001_NextPart425866801107_=------