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

Commite174f69

Browse files
committed
Add some assertions in syncrep.c
A couple of routines assume that the LWLock SyncRepLock needs to betaken, so add a couple of assertions to be sure of that. Also, whenwaiting for a given LSN at transaction commit, the code implied that thesyncrep queue cleanup happens while holding interrupts, but the codenever checked after that.Author: Michael PaquierReviewed-by: Fujii Masao, Kyotaro Horiguchi, Dongming LiuDiscussion:https://postgr.es/m/a0806273-8bbb-43b3-bbe1-c45a58f6ae21.lingce.ldm@alibaba-inc.com
1 parent2034519 commite174f69

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
constchar*old_status;
150150
intmode;
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-
*Musthold SyncRepLock.
1008+
*The caller musthold SyncRepLock in exclusive mode.
9961009
*/
9971010
staticint
9981011
SyncRepWakeQueue(boolall,intmode)
@@ -1003,6 +1016,7 @@ SyncRepWakeQueue(bool all, int mode)
10031016
intnumprocs=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)

[8]ページ先頭

©2009-2025 Movatter.jp