issue: nbtpage.c,_bt_pagedel may get wrong result - Mailing list pgsql-bugs

From Pengfei Wang
Subject issue: nbtpage.c,_bt_pagedel may get wrong result
Date
Msg-id CALsf3S3YU43Km==Faya5MPugPo=GE4-akae8oj6pgw_xEh_cEA@mail.gmail.com
Whole thread Raw
Responses Re: issue: nbtpage.c,_bt_pagedel may get wrong result  (Heikki Linnakangas <hlinnaka@iki.fi>)
List pgsql-bugs
# issue
/*
* To avoid deadlocks, we'd better drop the leaf page lock
* before going further.
*/
_bt_unlockbuf(rel, leafbuf);

/*
* Check that the left sibling of leafbuf (if any) is not
* marked with INCOMPLETE_SPLIT flag before proceeding
*/
Assert(leafblkno == scanblkno);
if (_bt_leftsib_splitflag(rel, leftsib, leafblkno))
{
    ReleaseBuffer(leafbuf);
    return;
}
After unlocking leaf, but before call _bt_leftsib_splitflag, leftsib may be already split, and leafbuf's current left sibling is in INCOMPLETE_SPLIT status.

# how to fix
In function _bt_leftsib_splitflag, after lock leftsib, we should lock leafbuf again, then recheck if leafbuf's leftsib is still leftsib, if check passed, keep lock on leafbuf.
--
Regards
Wang Pengfei

pgsql-bugs by date:

Previous
From: Waka Ranai
Date:
Subject: Re: Bug report - pg_upgrade tool seems to have a race condition when trying to delete a pg_wal file
Next
From: Heikki Linnakangas
Date:
Subject: Re: issue: nbtpage.c,_bt_pagedel may get wrong result