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

Commitbab9599

Browse files
committed
Fix race condition that lead to WALInsertLock deadlock with commit_delay.
If a call to WaitForXLogInsertionsToFinish() returned a value in the middleof a page, and another backend then started to insert a record to the samepage, and then you called WaitXLogInsertionsToFinish() again, the secondcall might return a smaller value than the first call. The problem was inGetXLogBuffer(), which always updated the insertingAt value to thebeginning of the requested page, not the actual requested location. Becauseof that, the second call might return a xlog pointer to the beginning ofthe page, while the first one returned a later position on the same page.XLogFlush() performs two calls to WaitXLogInsertionsToFinish() insuccession, and holds WALWriteLock on the second call, which can deadlockif the second call to WaitXLogInsertionsToFinish() blocks.Reported by Spiros Ioannou. Backpatch to 9.4, where the more scalableWALInsertLock mechanism, and this bug, was introduced.
1 parente39a3b2 commitbab9599

File tree

1 file changed

+24
-3
lines changed
  • src/backend/access/transam

1 file changed

+24
-3
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,11 +1839,32 @@ GetXLogBuffer(XLogRecPtr ptr)
18391839
endptr=XLogCtl->xlblocks[idx];
18401840
if (expectedEndPtr!=endptr)
18411841
{
1842+
XLogRecPtrinitializedUpto;
1843+
18421844
/*
1843-
* Let others know that we're finished inserting the record up to the
1844-
* page boundary.
1845+
* Before calling AdvanceXLInsertBuffer(), which can block, let others
1846+
* know how far we're finished with inserting the record.
1847+
*
1848+
* NB: If 'ptr' points to just after the page header, advertise a
1849+
* position at the beginning of the page rather than 'ptr' itself. If
1850+
* there are no other insertions running, someone might try to flush
1851+
* up to our advertised location. If we advertised a position after
1852+
* the page header, someone might try to flush the page header, even
1853+
* though page might actually not be initialized yet. As the first
1854+
* inserter on the page, we are effectively responsible for making
1855+
* sure that it's initialized, before we let insertingAt to move past
1856+
* the page header.
18451857
*/
1846-
WALInsertLockUpdateInsertingAt(expectedEndPtr-XLOG_BLCKSZ);
1858+
if (ptr %XLOG_BLCKSZ==SizeOfXLogShortPHD&&
1859+
ptr %XLOG_SEG_SIZE>XLOG_BLCKSZ)
1860+
initializedUpto=ptr-SizeOfXLogShortPHD;
1861+
elseif (ptr %XLOG_BLCKSZ==SizeOfXLogLongPHD&&
1862+
ptr %XLOG_SEG_SIZE<XLOG_BLCKSZ)
1863+
initializedUpto=ptr-SizeOfXLogLongPHD;
1864+
else
1865+
initializedUpto=ptr;
1866+
1867+
WALInsertLockUpdateInsertingAt(initializedUpto);
18471868

18481869
AdvanceXLInsertBuffer(ptr, false);
18491870
endptr=XLogCtl->xlblocks[idx];

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp