pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby.
8+ messages / 4 participants
[nested] [flat]

* BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby.
@ 2018-12-28 02:01 PG Bug reporting form <noreply@postgresql.org>
  2018-12-29 03:59 ` Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. Maxim Boguk <maxim.boguk@gmail.com>
  0 siblings, 1 reply; 8+ messages in thread

From: PG Bug reporting form @ 2018-12-28 02:01 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: lichuancheng@highgo.com

The following bug has been logged on the website:

Bug reference:      15567
Logged by:          movead
Email address:      lichuancheng@highgo.com
PostgreSQL version: 10.5
Operating system:   centos7
Description:        

[Problem description]
We use pg9.5.7 with replica and i find that if some damaged wal record
arrived at standby then the startup process on standby try to restart
walreceiver process but never sucess and log below Infinite cycle on
standby.If i try to restart database now,it sucess.
(I try it on pg10.5,the same result.)
-----------------------------------------------------------------------------------------------------------------
2018-12-15 10:38:00.302 CST,,,30928,,5c1422d5.78d0,2,,2018-12-15 05:38:29
CST,,0,FATAL,57P01,"terminating walreceiver process due to administrator
command",,,,,,,,,""
2018-12-15 10:38:00.302 CST,,,5546,,5c1276c1.15aa,8,,2018-12-13 23:12:01
CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
5A9/11E0A90",,,,,,,,,""
2018-12-15 10:38:00.302 CST,,,5546,,5c1276c1.15aa,9,,2018-12-13 23:12:01
CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
5A9/11E0A90",,,,,,,,,""
2018-12-15 10:38:00.302 CST,,,5546,,5c1276c1.15aa,10,,2018-12-13 23:12:01
CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
5A9/11E0A90",,,,,,,,,""
2018-12-15 10:38:05.308 CST,,,5546,,5c1276c1.15aa,11,,2018-12-13 23:12:01
CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
5A9/11E0A90",,,,,,,,,""
2018-12-15 10:38:10.314 CST,,,5546,,5c1276c1.15aa,12,,2018-12-13 23:12:01
CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
5A9/11E0A90",,,,,,,,,""
2018-12-15 10:38:15.319 CST,,,5546,,5c1276c1.15aa,13,,2018-12-13 23:12:01
CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
5A9/11E0A90",,,,,,,,,""
2018-12-15 10:38:20.325 CST,,,5546,,5c1276c1.15aa,14,,2018-12-13 23:12:01
CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
5A9/11E0A90",,,,,,,,,""
2018-12-15 10:38:25.331 CST,,,5546,,5c1276c1.15aa,15,,2018-12-13 23:12:01
CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
5A9/11E0A90",,,,,,,,,""
2018-12-15 10:38:30.336 CST,,,5546,,5c1276c1.15aa,16,,2018-12-13 23:12:01
CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
5A9/11E0A90",,,,,,,,,""
2018-12-15 10:38:35.342 CST,,,5546,,5c1276c1.15aa,17,,2018-12-13 23:12:01
CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
5A9/11E0A90",,,,,,,,,""
2018-12-15 10:38:40.348 CST,,,5546,,5c1276c1.15aa,18,,2018-12-13 23:12:01
CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
5A9/11E0A90",,,,,,,,,""
2018-12-15 10:38:45.353 CST,,,5546,,5c1276c1.15aa,19,,2018-12-13 23:12:01
CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
5A9/11E0A90",,,,,,,,,""
2018-12-15 10:38:50.359 CST,,,5546,,5c1276c1.15aa,20,,2018-12-13 23:12:01
CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
5A9/11E0A90",,,,,,,,,""
2018-12-15 10:38:55.364 CST,,,5546,,5c1276c1.15aa,21,,2018-12-13 23:12:01
CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
5A9/11E0A90",,,,,,,,,""
2018-12-15 10:39:00.370 CST,,,5546,,5c1276c1.15aa,22,,2018-12-13 23:12:01
CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
5A9/11E0A90",,,,,,,,,""
-----------------------------------------------------------------------------------------------------------------


[Code review]
I read the code about startup process and walreciver process.

When a damaged wal record arrived:
1.The startup process shutdown the walreciver process use function
ShutdownWalRcv().
2.The startup process start the walreciver process use funtion
RequestXLogStreaming() by signal PMSIGNAL_START_WALRECEIVER.
3.The startup process try to read wal record. 
	And now reciver process does not startup completely,so the startup process
read the damaged wal record another times.
	And startup process set walrcv->walRcvState = WALRCV_STOPPED use function
ShutdownWalRcv().
4.go to 2.
That's the infinite cycle.

[Question]
I wonder that if it is a bug or you just don't want restart walreciver
process.



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby.
  2018-12-28 02:01 BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. PG Bug reporting form <noreply@postgresql.org>
@ 2018-12-29 03:59 ` Maxim Boguk <maxim.boguk@gmail.com>
  2018-12-29 05:08   ` Re: Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. lichuancheng@highgo.com <lichuancheng@highgo.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Maxim Boguk @ 2018-12-29 03:59 UTC (permalink / raw)
  To: lichuancheng@highgo.com; pgsql-bugs@lists.postgresql.org

On Fri, Dec 28, 2018 at 8:10 PM PG Bug reporting form <
noreply@postgresql.org> wrote:

> The following bug has been logged on the website:
>
> Bug reference:      15567
> Logged by:          movead
> Email address:      lichuancheng@highgo.com
> PostgreSQL version: 10.5
> Operating system:   centos7
> Description:
>
> [Problem description]
> We use pg9.5.7 with replica and i find that if some damaged wal record
> arrived at standby then the startup process on standby try to restart
> walreceiver process but never sucess and log below Infinite cycle on
> standby.If i try to restart database now,it sucess.
> (I try it on pg10.5,the same result.)
>
> -----------------------------------------------------------------------------------------------------------------
> 2018-12-15 10:38:00.302 CST,,,30928,,5c1422d5.78d0,2,,2018-12-15 05:38:29
> CST,,0,FATAL,57P01,"terminating walreceiver process due to administrator
> command",,,,,,,,,""
> 2018-12-15 10:38:00.302 CST,,,5546,,5c1276c1.15aa,8,,2018-12-13 23:12:01
> CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
> 5A9/11E0A90",,,,,,,,,""
> 2018-12-15 10:38:00.302 CST,,,5546,,5c1276c1.15aa,9,,2018-12-13 23:12:01
> CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
> 5A9/11E0A90",,,,,,,,,""
> 2018-12-15 10:38:00.302 CST,,,5546,,5c1276c1.15aa,10,,2018-12-13 23:12:01
> CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
> 5A9/11E0A90",,,,,,,,,""
> 2018-12-15 10:38:05.308 CST,,,5546,,5c1276c1.15aa,11,,2018-12-13 23:12:01
> CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
> 5A9/11E0A90",,,,,,,,,""
> 2018-12-15 10:38:10.314 CST,,,5546,,5c1276c1.15aa,12,,2018-12-13 23:12:01
> CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
> 5A9/11E0A90",,,,,,,,,""
> 2018-12-15 10:38:15.319 CST,,,5546,,5c1276c1.15aa,13,,2018-12-13 23:12:01
> CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
> 5A9/11E0A90",,,,,,,,,""
> 2018-12-15 10:38:20.325 CST,,,5546,,5c1276c1.15aa,14,,2018-12-13 23:12:01
> CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
> 5A9/11E0A90",,,,,,,,,""
> 2018-12-15 10:38:25.331 CST,,,5546,,5c1276c1.15aa,15,,2018-12-13 23:12:01
> CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
> 5A9/11E0A90",,,,,,,,,""
> 2018-12-15 10:38:30.336 CST,,,5546,,5c1276c1.15aa,16,,2018-12-13 23:12:01
> CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
> 5A9/11E0A90",,,,,,,,,""
> 2018-12-15 10:38:35.342 CST,,,5546,,5c1276c1.15aa,17,,2018-12-13 23:12:01
> CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
> 5A9/11E0A90",,,,,,,,,""
> 2018-12-15 10:38:40.348 CST,,,5546,,5c1276c1.15aa,18,,2018-12-13 23:12:01
> CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
> 5A9/11E0A90",,,,,,,,,""
> 2018-12-15 10:38:45.353 CST,,,5546,,5c1276c1.15aa,19,,2018-12-13 23:12:01
> CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
> 5A9/11E0A90",,,,,,,,,""
> 2018-12-15 10:38:50.359 CST,,,5546,,5c1276c1.15aa,20,,2018-12-13 23:12:01
> CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
> 5A9/11E0A90",,,,,,,,,""
> 2018-12-15 10:38:55.364 CST,,,5546,,5c1276c1.15aa,21,,2018-12-13 23:12:01
> CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
> 5A9/11E0A90",,,,,,,,,""
> 2018-12-15 10:39:00.370 CST,,,5546,,5c1276c1.15aa,22,,2018-12-13 23:12:01
> CST,1/0,0,LOG,00000,"incorrect resource manager data checksum in record at
> 5A9/11E0A90",,,,,,,,,""
>
> -----------------------------------------------------------------------------------------------------------------
>
>
> [Code review]
> I read the code about startup process and walreciver process.
>
> When a damaged wal record arrived:
> 1.The startup process shutdown the walreciver process use function
> ShutdownWalRcv().
> 2.The startup process start the walreciver process use funtion
> RequestXLogStreaming() by signal PMSIGNAL_START_WALRECEIVER.
> 3.The startup process try to read wal record.
>         And now reciver process does not startup completely,so the startup
> process
> read the damaged wal record another times.
>         And startup process set walrcv->walRcvState = WALRCV_STOPPED use
> function
> ShutdownWalRcv().
> 4.go to 2.
> That's the infinite cycle.
>
> [Question]
> I wonder that if it is a bug or you just don't want restart walreciver
> process.
>
>
It look like the same issue as I reported in BUG #15151.
https://www.postgresql.org/message-id/flat/152353560977.31233.11406243320876395727%40wrigleys.postgr...
(unfortunately I didn't have time to explore it further then).

You have good description of what's going on under hood.


-- 
Maxim Boguk
Senior Postgresql DBA
https://dataegret.com/

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby.
  2018-12-28 02:01 BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. PG Bug reporting form <noreply@postgresql.org>
  2018-12-29 03:59 ` Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. Maxim Boguk <maxim.boguk@gmail.com>
@ 2018-12-29 05:08   ` lichuancheng@highgo.com <lichuancheng@highgo.com>
  2019-01-03 09:50     ` BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. lichuancheng@highgo.com <lichuancheng@highgo.com>
  0 siblings, 1 reply; 8+ messages in thread

From: lichuancheng@highgo.com @ 2018-12-29 05:08 UTC (permalink / raw)
  To: Maxim Boguk <maxim.boguk@gmail.com>; pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>


>It look like the same issue as I reported in BUG #15151.
>https://www.postgresql.org/message-id/flat/152353560977.31233.11406243320876395727%40wrigleys.postgr...
>(unfortunately I didn't have time to explore it further then).

>You have good description of what's going on under hood.

Hi,I read the BUG #15151.
You have say that it does not help to restart slave.

But in 15567, either 'restart slave' or 'move the wal segment from master to slave' can make the slave nomal.

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby.
  2018-12-28 02:01 BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. PG Bug reporting form <noreply@postgresql.org>
  2018-12-29 03:59 ` Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. Maxim Boguk <maxim.boguk@gmail.com>
  2018-12-29 05:08   ` Re: Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. lichuancheng@highgo.com <lichuancheng@highgo.com>
@ 2019-01-03 09:50     ` lichuancheng@highgo.com <lichuancheng@highgo.com>
  2019-01-09 07:14       ` Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 8+ messages in thread

From: lichuancheng@highgo.com @ 2019-01-03 09:50 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>

hello

I have analysis of the causes of bug when report it.

>[Code review]
>I read the code about startup process and walreciver process.
>When a damaged wal record arrived:
>1.The startup process shutdown the walreciver process use function ShutdownWalRcv().
>2.The startup process start the walreciver process use funtion RequestXLogStreaming() by signal PMSIGNAL_START_WALRECEIVER.
>3.The startup process try to read wal record. 
> And now reciver process does not startup completely,so the startup process read the damaged wal record another times.
> And startup process set walrcv->walRcvState = WALRCV_STOPPED use function ShutdownWalRcv().
>4.go to 2.
>That's the infinite cycle.


And now i do a patch in mail attachment to solve the bug.  
I test it on pg10.5 and work well.

-----
movead


Attachments:

bug15567_lichuancheng_20190103.patch (application/octet-stream, 992B) download diff --git a/src/backend/replication/walreceiverfuncs.c b/src/backend/replication/walreceiverfuncs.c index 48e8498d62..5066688288 100644 --- a/src/backend/replication/walreceiverfuncs.c +++ b/src/backend/replication/walreceiverfuncs.c @@ -280,7 +280,26 @@ RequestXLogStreaming(TimeLineID tli, XLogRecPtr recptr, const char *conninfo, SpinLockRelease(&walrcv->mutex); if (launch) + { SendPostmasterSignal(PMSIGNAL_START_WALRECEIVER); + + for(;;) + { + /* + * Now we want to restart walreciver process and walrcv->walRcvState is WALRCV_STARTING. + * We should not go on startup process until walrcv->walRcvState changed to other value. + * + * And we do a loop here in case of there may be any delay during restart of walreciver process. + */ + if(WALRCV_STARTING != walrcv->walRcvState) + { + break; + } + + elog(LOG,"startup process is waiting for restart of walreciver process"); + pg_usleep(1000000L); + } + } else if (latch) SetLatch(latch); }
^ permalink raw reply [nested|flat] 8+ messages in thread

* Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby.
  2018-12-28 02:01 BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. PG Bug reporting form <noreply@postgresql.org>
  2018-12-29 03:59 ` Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. Maxim Boguk <maxim.boguk@gmail.com>
  2018-12-29 05:08   ` Re: Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. lichuancheng@highgo.com <lichuancheng@highgo.com>
  2019-01-03 09:50     ` BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. lichuancheng@highgo.com <lichuancheng@highgo.com>
@ 2019-01-09 07:14       ` Michael Paquier <michael@paquier.xyz>
  2019-01-09 08:28         ` Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. lichuancheng@highgo.com <lichuancheng@highgo.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Michael Paquier @ 2019-01-09 07:14 UTC (permalink / raw)
  To: lichuancheng@highgo.com <lichuancheng@highgo.com>; +Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>

On Thu, Jan 03, 2019 at 05:50:48PM +0800, lichuancheng@highgo.com wrote:
>> I read the code about startup process and walreciver process.
>> When a damaged wal record arrived:
>> 1.The startup process shutdown the walreciver process use function ShutdownWalRcv().
>> 2.The startup process start the walreciver process use funtion RequestXLogStreaming() by signal PMSIGNAL_START_WALRECEIVER.
>> 3.The startup process try to read wal record. 
>>  And now reciver process does not startup completely,so the startup process read the damaged wal record another times.
>>  And startup process set walrcv->walRcvState = WALRCV_STOPPED use function ShutdownWalRcv().
>> 4.go to 2.
>> That's the infinite cycle.
> 
> And now i do a patch in mail attachment to solve the bug.  
> I test it on pg10.5 and work well.

So the take of the patch is to make sure that the WAL receiver has
been correctly started if the startup process requested one before
trying to replay more WAL records.  Now it seems to me that you do not
close all the gaps here.  The WAL receiver could finish starting, but
still not have the time to stream up to the point where the startup
process could consume things safely.  The patch makes somewhat sure
that the gap is closed by applying a timeout of 1s, still in
environments with more latency it would make the failure still
happen.  Wouldn't it be better instead to make sure that the startup
process does not try to use once again the same record where the
failure happened before the WAL receiver confirms that it has flushed
something newer than the LSN position which was known as bad?

One problem may be that upon restart we reset receivedUpto, and that
visibly we may want to be more careful with its handling to avoid
successive failures so as the startup process does not bump
repeatitively into the same bogus record.  Looking at the code, the
computation looks quite safe though (I need to double-check to be 100%
sure), so isn't the origin of the problem just that the WAL segment
from the primary is corrupted, and that what gets streamed is broken
at its origin point, preventing the standby to move on?  You may want
to double-check that as well..

As a side note, the patch is incorrect for a couple of things though:
1) Formatting of comments and indentation.
2) Please be careful of whitespaces.
3) Usually no more than 72-80 characters per line.
4) Why a wait phase of 1s?
5) And much worse, the WAL receiver status cannot be looked at without
taking its mutex lock first, so this makes the logic look at something
which may be concurrently updated.  Oops.
6) Still the patch is incorrect per the reasons above ;)
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby.
  2018-12-28 02:01 BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. PG Bug reporting form <noreply@postgresql.org>
  2018-12-29 03:59 ` Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. Maxim Boguk <maxim.boguk@gmail.com>
  2018-12-29 05:08   ` Re: Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. lichuancheng@highgo.com <lichuancheng@highgo.com>
  2019-01-03 09:50     ` BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. lichuancheng@highgo.com <lichuancheng@highgo.com>
  2019-01-09 07:14       ` Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. Michael Paquier <michael@paquier.xyz>
@ 2019-01-09 08:28         ` lichuancheng@highgo.com <lichuancheng@highgo.com>
  2019-01-11 02:59           ` Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. lichuancheng@highgo.com <lichuancheng@highgo.com>
  0 siblings, 1 reply; 8+ messages in thread

From: lichuancheng@highgo.com @ 2019-01-09 08:28 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>


>So the take of the patch is to make sure that the WAL receiver has
>been correctly started if the startup process requested one before
>trying to replay more WAL records.  Now it seems to me that you do not
>close all the gaps here.  The WAL receiver could finish starting, but 
>still not have the time to stream up to the point where the startup 
>process could consume things safely.  The patch makes somewhat sure 
>that the gap is closed by applying a timeout of 1s, still in
>environments with more latency it would make the failure still
>happen.  Wouldn't it be better instead to make sure that the startup
>process does not try to use once again the same record where the
>failure happened before the WAL receiver confirms that it has flushed
>something newer than the LSN position which was known as bad?
 
>One problem may be that upon restart we reset receivedUpto, and that
>visibly we may want to be more careful with its handling to avoid
>successive failures so as the startup process does not bump
>repeatitively into the same bogus record.  Looking at the code, the
>computation looks quite safe though (I need to double-check to be 100%
>sure), so isn't the origin of the problem just that the WAL segment
>from the primary is corrupted, and that what gets streamed is broken
>at its origin point, preventing the standby to move on?  You may want
>to double-check that as well..

I known what you describe.
Nomally,when the reciver process restart,the code reset redo LSN to the start of the 
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 the reciver process. 
So the way to solve the problem  is give some time to reciver process to 
restart. As long as it restart sucessful,it will apply wal record at the start of the 
wal segment from master and the correct wal record will arrived. so i do not 
think what you say 'still in environments with 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,
it's well in master and other slave.

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

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

>6) Still the patch is incorrect per the reasons above ;)
I am new here, thanks for your explanation in side note.

-----
movead




^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby.
  2018-12-28 02:01 BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. PG Bug reporting form <noreply@postgresql.org>
  2018-12-29 03:59 ` Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. Maxim Boguk <maxim.boguk@gmail.com>
  2018-12-29 05:08   ` Re: Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. lichuancheng@highgo.com <lichuancheng@highgo.com>
  2019-01-03 09:50     ` BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. lichuancheng@highgo.com <lichuancheng@highgo.com>
  2019-01-09 07:14       ` Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. Michael Paquier <michael@paquier.xyz>
  2019-01-09 08:28         ` Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. lichuancheng@highgo.com <lichuancheng@highgo.com>
@ 2019-01-11 02:59           ` lichuancheng@highgo.com <lichuancheng@highgo.com>
  2019-03-11 06:52             ` Re: Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. lichuancheng@highgo.com <lichuancheng@highgo.com>
  0 siblings, 1 reply; 8+ messages in thread

From: lichuancheng@highgo.com @ 2019-01-11 02:59 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>


Thanks Michael Paquier for your explanation.
I have modified the patch  in mail attachment,wish your reply.


-----
movead



Attachments:

bug15567_lichuancheng_20190111.patch (application/octet-stream, 1.5K) download diff --git a/src/backend/replication/walreceiverfuncs.c b/src/backend/replication/walreceiverfuncs.c index 48e8498d62..c4785b5f59 100644 --- a/src/backend/replication/walreceiverfuncs.c +++ b/src/backend/replication/walreceiverfuncs.c @@ -280,7 +280,42 @@ RequestXLogStreaming(TimeLineID tli, XLogRecPtr recptr, const char *conninfo, SpinLockRelease(&walrcv->mutex); if (launch) + { SendPostmasterSignal(PMSIGNAL_START_WALRECEIVER); + + for (;;) + { + /* + * Now we want to restart walreciver process and walrcv->walRcvState is WALRCV_STARTING. + * We should not go on startup process until walrcv->walRcvState changed to other value. + * + * And we do a loop here in case of there may be any delay during restart of walreciver + * process. + */ + + SpinLockAcquire(&walrcv->mutex); + + if(WALRCV_STARTING != walrcv->walRcvState) + { + SpinLockRelease(&walrcv->mutex); + break; + } + + SpinLockRelease(&walrcv->mutex); + + elog(LOG,"startup process is waiting for restart of walreciver process"); + + /* + * The walreciver progress is restarting now, startup progress sleep 1s here to ensure + * the restarting, otherwise startup progress may shutdown the restarting in function + * WaitForWALToBecomeAvailable(). + * + * Infact 1s is enought for reciver process to restart. It is related to the slave + * only, noting with network. + */ + pg_usleep(1000000L); + } + } else if (latch) SetLatch(latch); }
^ permalink raw reply [nested|flat] 8+ messages in thread

* Re: Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby.
  2018-12-28 02:01 BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. PG Bug reporting form <noreply@postgresql.org>
  2018-12-29 03:59 ` Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. Maxim Boguk <maxim.boguk@gmail.com>
  2018-12-29 05:08   ` Re: Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. lichuancheng@highgo.com <lichuancheng@highgo.com>
  2019-01-03 09:50     ` BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. lichuancheng@highgo.com <lichuancheng@highgo.com>
  2019-01-09 07:14       ` Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. Michael Paquier <michael@paquier.xyz>
  2019-01-09 08:28         ` Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. lichuancheng@highgo.com <lichuancheng@highgo.com>
  2019-01-11 02:59           ` Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. lichuancheng@highgo.com <lichuancheng@highgo.com>
@ 2019-03-11 06:52             ` lichuancheng@highgo.com <lichuancheng@highgo.com>
  0 siblings, 0 replies; 8+ messages in thread

From: lichuancheng@highgo.com @ 2019-03-11 06:52 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>

hello

 A change to prevent dead-cycle by function 'HandleStartupProcInterrupts()'

-----
movead



Attachments:

bug15567_lichuancheng_20190225.patch (application/octet-stream, 1.6K) download diff --git a/src/backend/replication/walreceiverfuncs.c b/src/backend/replication/walreceiverfuncs.c index 48e8498d62..301babaaa1 100644 --- a/src/backend/replication/walreceiverfuncs.c +++ b/src/backend/replication/walreceiverfuncs.c @@ -280,7 +280,47 @@ RequestXLogStreaming(TimeLineID tli, XLogRecPtr recptr, const char *conninfo, SpinLockRelease(&walrcv->mutex); if (launch) + { SendPostmasterSignal(PMSIGNAL_START_WALRECEIVER); + + for (;;) + { + /* + * Now we want to restart walreciver process and walrcv->walRcvState is WALRCV_STARTING. + * We should not go on startup process until walrcv->walRcvState changed to other value. + * + * And we do a loop here in case of there may be any delay during restart of walreciver + * process. + */ + + SpinLockAcquire(&walrcv->mutex); + + if(WALRCV_STARTING != walrcv->walRcvState) + { + SpinLockRelease(&walrcv->mutex); + break; + } + + SpinLockRelease(&walrcv->mutex); + + /* + * This possibly-long loop needs to handle interrupts of startup + * process. + */ + HandleStartupProcInterrupts(); + + elog(LOG,"startup process is waiting for restart of walreciver process"); + + /* + * The walreciver progress is restarting now, startup progress sleep 1s here to ensure + * the restarting, otherwise startup progress may shutdown the restarting in function + * WaitForWALToBecomeAvailable(). + * + * Infact 1s is enought for reciver process to restart. It is related to the slave + * only, noting with network. + */ + pg_usleep(1000000L); + } + } else if (latch) SetLatch(latch); }
^ permalink raw reply [nested|flat] 8+ messages in thread


end of thread, other threads:[~2019-03-11 06:52 UTC | newest]

Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-12-28 02:01 BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. PG Bug reporting form <noreply@postgresql.org>
2018-12-29 03:59 ` Maxim Boguk <maxim.boguk@gmail.com>
2018-12-29 05:08   ` lichuancheng@highgo.com <lichuancheng@highgo.com>
2019-01-03 09:50     ` lichuancheng@highgo.com <lichuancheng@highgo.com>
2019-01-09 07:14       ` Michael Paquier <michael@paquier.xyz>
2019-01-09 08:28         ` lichuancheng@highgo.com <lichuancheng@highgo.com>
2019-01-11 02:59           ` lichuancheng@highgo.com <lichuancheng@highgo.com>
2019-03-11 06:52             ` lichuancheng@highgo.com <lichuancheng@highgo.com>

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