Skip to content

Commit a722252

Browse files
committed
Back-patch b1ffe3f into REL_13_STABLE.
This is a cherry pick of 4c8e00a from the 14 branch into the 13 branch. It avoids an assertion failure when ForwardSyncRequest() tries to allocate memory while trying to compact the queue, if run in a critical section. RelationTruncate() gained a critical section in 38c579b, and could fail in that way in the 13 branch. b1ffe3f originally fixed the same problem with TruncateMultiXact(), but for that case it only needed to go back as far as 14, where SLRUs started using the sync request queue. It also fixed a related deadlock risk that doesn't apply in this case (this case doesn't wait), but it might exist in theory and it doesn't hurt to keep the code the same as later branches. Author: Heikki Linnakangas <heikki.linnakangas@iki.fi> (original commit) Reviewed-by: Michael Paquier <michael@paquier.xyz> (in this new context) Reported-by: Yura Sokolov <y.sokolov@postgrespro.ru> Discussion: https://postgr.es/m/f98aaa79-80b5-47c9-832a-31416a3a528b%40postgrespro.ru
1 parent 417d41c commit a722252

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/backend/access/transam/xlog.c

+7
Original file line numberDiff line numberDiff line change
@@ -9139,6 +9139,12 @@ CreateCheckPoint(int flags)
91399139
{
91409140
do
91419141
{
9142+
/*
9143+
* Keep absorbing fsync requests while we wait. There could even
9144+
* be a deadlock if we don't, if the process that prevents the
9145+
* checkpoint is trying to add a request to the queue.
9146+
*/
9147+
AbsorbSyncRequests();
91429148
pg_usleep(10000L); /* wait for 10 msec */
91439149
} while (HaveVirtualXIDsDelayingChkpt(vxids, nvxids));
91449150
}
@@ -9151,6 +9157,7 @@ CreateCheckPoint(int flags)
91519157
{
91529158
do
91539159
{
9160+
AbsorbSyncRequests();
91549161
pg_usleep(10000L); /* wait for 10 msec */
91559162
} while (HaveVirtualXIDsDelayingChkptEnd(vxids, nvxids));
91569163
}

src/backend/postmaster/checkpointer.c

+4
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,10 @@ CompactCheckpointerRequestQueue(void)
11441144
/* must hold CheckpointerCommLock in exclusive mode */
11451145
Assert(LWLockHeldByMe(CheckpointerCommLock));
11461146

1147+
/* Avoid memory allocations in a critical section. */
1148+
if (CritSectionCount > 0)
1149+
return false;
1150+
11471151
/* Initialize skip_slot array */
11481152
skip_slot = palloc0(sizeof(bool) * CheckpointerShmem->num_requests);
11491153

0 commit comments

Comments
 (0)