Re: Connections hang indefinitely while taking a gin index's LWLock buffer_content lock
Peter Geoghegan <pg@bowt.ie>
From: Peter Geoghegan <pg@bowt.ie>
To: chjischj@163.com
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2018-11-07T23:18:55Z
Lists: pgsql-hackers
On Mon, Oct 29, 2018 at 12:04 PM chenhj <chjischj@163.com> wrote:
> #4 0x00000000007095ac in LWLockAcquire (lock=0x2aaab4009564, mode=LW_EXCLUSIVE) at lwlock.c:1233
> #5 0x0000000000490a32 in ginStepRight (buffer=6713826, index=<optimized out>, lockmode=lockmode@entry=2) at ginbtree.c:174
> #6 0x0000000000490c1c in ginFinishSplit (btree=btree@entry=0x7ffd81e4f950, stack=0x28eebf8, freestack=freestack@entry=1 '\001', buildStats=buildStats@entry=0x0) at ginbtree.c:701
> #7 0x0000000000491396 in ginInsertValue (btree=btree@entry=0x7ffd81e4f950, stack=<optimized out>, insertdata=insertdata@entry=0x7ffd81e4f940, buildStats=buildStats@entry=0x0)
> at ginbtree.c:773
> #8 0x000000000048fb42 in ginInsertItemPointers (index=<optimized out>, rootBlkno=rootBlkno@entry=644, items=items@entry=0x2916598, nitem=nitem@entry=353, buildStats=buildStats@entry=0x0)
> at gindatapage.c:1907
> #9 0x000000000048a9ea in ginEntryInsert (ginstate=ginstate@entry=0x28e7ef8, attnum=<optimized out>, key=42920440, category=<optimized out>, items=0x2916598, nitem=353,
> buildStats=buildStats@entry=0x0) at gininsert.c:214
> #10 0x0000000000496d94 in ginInsertCleanup (ginstate=ginstate@entry=0x28e7ef8, full_clean=full_clean@entry=0 '\000', fill_fsm=fill_fsm@entry=1 '\001',
> forceCleanup=forceCleanup@entry=0 '\000', stats=stats@entry=0x0) at ginfast.c:883
> #11 0x0000000000497727 in ginHeapTupleFastInsert (ginstate=ginstate@entry=0x28e7ef8, collector=collector@entry=0x7ffd81e4fe60) at ginfast.c:448
> #12 0x000000000048b209 in gininsert (index=<optimized out>, values=0x7ffd81e4ff40, isnull=0x7ffd81e50040 "", ht_ctid=0x280d98c, heapRel=<optimized out>, checkUnique=<optimized out>,
> indexInfo=0x28b5aa8) at gininsert.c:522
I want to point something out about the above inserter represented by
this stack trace. It deadlocks against VACUUM from within the
following ginEntryInsert() call:
/*
* While we left the page unlocked, more stuff might have gotten
* added to it. If so, process those entries immediately. There
* shouldn't be very many, so we don't worry about the fact that
* we're doing this with exclusive lock. Insertion algorithm
* guarantees that inserted row(s) will not continue on next page.
* NOTE: intentionally no vacuum_delay_point in this loop.
*/
if (PageGetMaxOffsetNumber(page) != maxoff)
{
ginInitBA(&accum);
processPendingPage(&accum, &datums, page, maxoff + 1);
ginBeginBAScan(&accum);
while ((list = ginGetBAEntry(&accum,
&attnum, &key, &category,
&nlist)) != NULL)
ginEntryInsert(ginstate, attnum, key, category, //
<--- deadlocks
list, nlist, NULL);
}
Clearly this particular call to ginEntryInsert() from within
ginInsertCleanup() is generally supposed to be a rare occurrence. It's
not surprising that it's hard for you to hit this issue.
BTW, I strongly doubt that disabling hugepages has fixed anything,
though it may have accidentally masked the problem. This is an issue
around the basic correctness of the locking protocols used by GIN.
--
Peter Geoghegan
Commits
-
Fix WAL format incompatibility introduced by backpatching of 52ac6cd2d0
- d1166af192ed 9.4.22 landed
- cda5f6575306 9.5.17 landed
- f8a69a68a087 9.6.13 landed
- e23d44016d51 10.8 landed
- 89f39736f484 11.3 landed
-
Fix wrong backpatching of ginRedoDeletePage() deadlock fix
- bf0e5a73be20 9.4.21 landed
-
Fix deadlock in GIN vacuum introduced by 218f51584d5
- fd83c83d0943 12.0 landed
- 2e3bd064e530 10.7 landed
- 9aa94d8536f8 11.2 landed
-
Prevent GIN deleted pages from being reclaimed too early
- 52ac6cd2d0cd 12.0 landed
- ad6ebcfcbb88 9.5.16 landed
- 1cf175c74f10 9.4.21 landed
- cd24b4eaece3 9.6.12 landed
- a0696d29551b 10.7 landed
- dd951dc34a2e 11.2 landed
-
Prevent deadlock in ginRedoDeletePage()
- c6ade7a8cd31 12.0 landed
- 19cf52e6cc33 9.4.21 landed
- f6c44e1b55c1 9.5.16 landed
- 865870374aff 10.7 landed
- 80d4d8d71d57 9.6.12 landed
- 225b5c9c480f 11.2 landed
-
Reduce page locking in GIN vacuum
- 218f51584d5a 10.0 cited
-
Fix race condition in GIN posting tree page deletion.
- ac4ab97ec05e 9.4.0 cited