From: | Heikki Linnakangas <hlinnakangas(at)vmware(dot)com> |
---|---|
To: | PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org> |
Subject: | Re: Gin page deletion bug |
Date: | 2013-11-08 15:19:31 |
Message-ID: | 527D0103.4070802@vmware.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 07.11.2013 22:49, Heikki Linnakangas wrote:
> Gin page deletion fails to take into account that there might be a
> search in-flight to the page that is deleted. If the page is reused for
> something else, the search can get very confused.
>
> ...
>
> The regular b-tree code solves this by stamping deleted pages with the
> current XID, and only allowing them to be reused once that XID becomes
> old enough (< RecentGlobalXmin). Another approach might be to grab a
> cleanup-strength lock on the left and parent pages when deleting a page,
> and requiring search to keep the pin on the page its coming from, until
> it has locked the next page.
I came up with the attached fix. In a nutshell, when walking along a
right-link, the new page is locked before releasing the lock on the old
one. Also, never delete the leftmost branch of a posting tree. I believe
these changes are sufficient to fix the problem, because of the way the
posting tree is searched:
All searches on a posting tree are "full searches", scanning the whole
tree from left to right. Insertions do seek to the middle of the tree,
but they are locked out during vacuum by holding a cleanup lock on the
posting tree root (even without this patch). Thanks to this property, a
search cannot step on a page that's being deleted by following a
downlink, if we refrain from deleting the leftmost page on a level, as
searches only descend down the leftmost branch.
It would be nice to improve that in master - holding an exclusive lock
on the root page is pretty horrible - but this is a nice back-patchable
patch. I'm not worried about the loss of concurrency because we now have
to hold the lock on previous page when stepping to next page. In
searches, it's only a share-lock, and in insertions, it's very rare that
you have to step right.
The patch also adds some sanity checks to stepping right: the next page
should be of the same type as the current page, e.g stepping right
should not go from leaf to non-leaf or vice versa.
- Heikki
Attachment | Content-Type | Size |
---|---|---|
gin-fix-page-deletion-1.patch | text/x-diff | 10.0 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Alvaro Herrera | 2013-11-08 15:33:22 | Add CREATE support to event triggers |
Previous Message | Albe Laurenz | 2013-11-08 15:13:48 | Re: FDW: possible resjunk columns in AddForeignUpdateTargets |