Skip to content

Commit e174f69

Browse files
committed
Add some assertions in syncrep.c
A couple of routines assume that the LWLock SyncRepLock needs to be taken, so add a couple of assertions to be sure of that. Also, when waiting for a given LSN at transaction commit, the code implied that the syncrep queue cleanup happens while holding interrupts, but the code never checked after that. Author: Michael Paquier Reviewed-by: Fujii Masao, Kyotaro Horiguchi, Dongming Liu Discussion: https://postgr.es/m/a0806273-8bbb-43b3-bbe1-c45a58f6ae21.lingce.ldm@alibaba-inc.com
1 parent 2034519 commit e174f69

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/backend/replication/syncrep.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ SyncRepWaitForLSN(XLogRecPtr lsn, bool commit)
149149
const char *old_status;
150150
int mode;
151151

152+
/*
153+
* This should be called while holding interrupts during a transaction
154+
* commit to prevent the follow-up shared memory queue cleanups to be
155+
* influenced by external interruptions.
156+
*/
157+
Assert(InterruptHoldoffCount > 0);
158+
152159
/* Cap the level for anything other than commit to remote flush only. */
153160
if (commit)
154161
mode = SyncRepWaitMode;
@@ -516,6 +523,8 @@ SyncRepReleaseWaiters(void)
516523
/*
517524
* Calculate the synced Write, Flush and Apply positions among sync standbys.
518525
*
526+
* The caller must hold SyncRepLock.
527+
*
519528
* Return false if the number of sync standbys is less than
520529
* synchronous_standby_names specifies. Otherwise return true and
521530
* store the positions into *writePtr, *flushPtr and *applyPtr.
@@ -529,6 +538,8 @@ SyncRepGetSyncRecPtr(XLogRecPtr *writePtr, XLogRecPtr *flushPtr,
529538
{
530539
List *sync_standbys;
531540

541+
Assert(LWLockHeldByMe(SyncRepLock));
542+
532543
*writePtr = InvalidXLogRecPtr;
533544
*flushPtr = InvalidXLogRecPtr;
534545
*applyPtr = InvalidXLogRecPtr;
@@ -688,6 +699,8 @@ cmp_lsn(const void *a, const void *b)
688699
List *
689700
SyncRepGetSyncStandbys(bool *am_sync)
690701
{
702+
Assert(LWLockHeldByMe(SyncRepLock));
703+
691704
/* Set default result */
692705
if (am_sync != NULL)
693706
*am_sync = false;
@@ -992,7 +1005,7 @@ SyncRepGetStandbyPriority(void)
9921005
* Pass all = true to wake whole queue; otherwise, just wake up to
9931006
* the walsender's LSN.
9941007
*
995-
* Must hold SyncRepLock.
1008+
* The caller must hold SyncRepLock in exclusive mode.
9961009
*/
9971010
static int
9981011
SyncRepWakeQueue(bool all, int mode)
@@ -1003,6 +1016,7 @@ SyncRepWakeQueue(bool all, int mode)
10031016
int numprocs = 0;
10041017

10051018
Assert(mode >= 0 && mode < NUM_SYNC_REP_WAIT_MODE);
1019+
Assert(LWLockHeldByMeInMode(SyncRepLock, LW_EXCLUSIVE));
10061020
Assert(SyncRepQueueIsOrderedByLSN(mode));
10071021

10081022
proc = (PGPROC *) SHMQueueNext(&(WalSndCtl->SyncRepQueue[mode]),

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy