Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit45e4067

Browse files
committed
Fix minor bug in logical-replication walsender shutdown
Logical walsender should exit when it catches up with sending WAL duringshutdown; but there was a rare corner case when it failed to because ofa race condition that puts it back to wait for more WAL instead -- butsince there wasn't any, it'd not shut down immediately. It would onlycontinue the shutdown when wal_sender_timeout terminates the sleep,which causes annoying waits during shutdown procedure. Restructure thecode so that we no longer forget to set WalSndCaughtUp in that case.This was an oversight in commitc6c3334.Backpatch all the way down to 9.4.Author: Craig Ringer, Álvaro HerreraDiscussion:https://postgr.es/m/CAMsr+YEuz4XwZX_QmnX_-2530XhyAmnK=zCmicEnq1vLr0aZ-g@mail.gmail.com
1 parent6737111 commit45e4067

File tree

1 file changed

+17
-28
lines changed

1 file changed

+17
-28
lines changed

‎src/backend/replication/walsender.c

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,6 @@ WalSndWaitForWal(XLogRecPtr loc)
12831283
intwakeEvents;
12841284
staticXLogRecPtrRecentFlushPtr=InvalidXLogRecPtr;
12851285

1286-
12871286
/*
12881287
* Fast path to avoid acquiring the spinlock in case we already know we
12891288
* have enough WAL available. This is particularly interesting if we're
@@ -2770,6 +2769,7 @@ XLogSendLogical(void)
27702769
{
27712770
XLogRecord*record;
27722771
char*errm;
2772+
XLogRecPtrflushPtr;
27732773

27742774
/*
27752775
* Don't know whether we've caught up yet. We'll set WalSndCaughtUp to
@@ -2786,11 +2786,13 @@ XLogSendLogical(void)
27862786
if (errm!=NULL)
27872787
elog(ERROR,"%s",errm);
27882788

2789+
/*
2790+
* We'll use the current flush point to determine whether we've caught up.
2791+
*/
2792+
flushPtr=GetFlushRecPtr();
2793+
27892794
if (record!=NULL)
27902795
{
2791-
/* XXX: Note that logical decoding cannot be used while in recovery */
2792-
XLogRecPtrflushPtr=GetFlushRecPtr();
2793-
27942796
/*
27952797
* Note the lack of any call to LagTrackerWrite() which is handled by
27962798
* WalSndUpdateProgress which is called by output plugin through
@@ -2799,32 +2801,19 @@ XLogSendLogical(void)
27992801
LogicalDecodingProcessRecord(logical_decoding_ctx,logical_decoding_ctx->reader);
28002802

28012803
sentPtr=logical_decoding_ctx->reader->EndRecPtr;
2802-
2803-
/*
2804-
* If we have sent a record that is at or beyond the flushed point, we
2805-
* have caught up.
2806-
*/
2807-
if (sentPtr >=flushPtr)
2808-
WalSndCaughtUp= true;
28092804
}
2810-
else
2811-
{
2812-
/*
2813-
* If the record we just wanted read is at or beyond the flushed
2814-
* point, then we're caught up.
2815-
*/
2816-
if (logical_decoding_ctx->reader->EndRecPtr >=GetFlushRecPtr())
2817-
{
2818-
WalSndCaughtUp= true;
28192805

2820-
/*
2821-
* Have WalSndLoop() terminate the connection in an orderly
2822-
* manner, after writing out all the pending data.
2823-
*/
2824-
if (got_STOPPING)
2825-
got_SIGUSR2= true;
2826-
}
2827-
}
2806+
/* Set flag if we're caught up. */
2807+
if (logical_decoding_ctx->reader->EndRecPtr >=flushPtr)
2808+
WalSndCaughtUp= true;
2809+
2810+
/*
2811+
* If we're caught up and have been requested to stop, have WalSndLoop()
2812+
* terminate the connection in an orderly manner, after writing out all
2813+
* the pending data.
2814+
*/
2815+
if (WalSndCaughtUp&&got_STOPPING)
2816+
got_SIGUSR2= true;
28282817

28292818
/* Update shared memory status */
28302819
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp