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

Commit80d4d8d

Browse files
committed
Prevent deadlock in ginRedoDeletePage()
On standby ginRedoDeletePage() can work concurrently with read-only queries.Those queries can traverse posting tree in two ways.1) Using rightlinks by ginStepRight(), which locks the next page before unlocking its left sibling.2) Using downlinks by ginFindLeafPage(), which locks at most one page at time.Original lock order was: page, parent, left sibling. That lock order candeadlock with ginStepRight(). In order to prevent deadlock this commit changeslock order to: left sibling, page, parent. Note, that position of parent inlocking order seems insignificant, because we only lock one page at time whiletraversing downlinks.Reported-by: Chen HuajunDiagnosed-by: Chen Huajun, Peter Geoghegan, Andrey BorodinDiscussion:https://postgr.es/m/31a702a.14dd.166c1366ac1.Coremail.chjischj%40163.comAuthor: Alexander KorotkovBackpatch-through: 9.4
1 parent12cb7ea commit80d4d8d

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

‎src/backend/access/gin/ginxlog.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,19 @@ ginRedoDeletePage(XLogReaderState *record)
511511
Bufferlbuffer;
512512
Pagepage;
513513

514+
/*
515+
* Lock left page first in order to prevent possible deadlock with
516+
* ginStepRight().
517+
*/
518+
if (XLogReadBufferForRedo(record,2,&lbuffer)==BLK_NEEDS_REDO)
519+
{
520+
page=BufferGetPage(lbuffer);
521+
Assert(GinPageIsData(page));
522+
GinPageGetOpaque(page)->rightlink=data->rightLink;
523+
PageSetLSN(page,lsn);
524+
MarkBufferDirty(lbuffer);
525+
}
526+
514527
if (XLogReadBufferForRedo(record,0,&dbuffer)==BLK_NEEDS_REDO)
515528
{
516529
page=BufferGetPage(dbuffer);
@@ -530,15 +543,6 @@ ginRedoDeletePage(XLogReaderState *record)
530543
MarkBufferDirty(pbuffer);
531544
}
532545

533-
if (XLogReadBufferForRedo(record,2,&lbuffer)==BLK_NEEDS_REDO)
534-
{
535-
page=BufferGetPage(lbuffer);
536-
Assert(GinPageIsData(page));
537-
GinPageGetOpaque(page)->rightlink=data->rightLink;
538-
PageSetLSN(page,lsn);
539-
MarkBufferDirty(lbuffer);
540-
}
541-
542546
if (BufferIsValid(lbuffer))
543547
UnlockReleaseBuffer(lbuffer);
544548
if (BufferIsValid(pbuffer))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp