Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Fix traversing to the deleted GIN page via downlink
authorAlexander Korotkov <akorotkov@postgresql.org>
Tue, 19 Nov 2019 20:08:14 +0000 (23:08 +0300)
committerAlexander Korotkov <akorotkov@postgresql.org>
Tue, 19 Nov 2019 21:05:42 +0000 (00:05 +0300)
Current GIN code appears to don't handle traversing to the deleted page via
downlink.  This commit fixes that by stepping right from the delete page like
we do in nbtree.

This commit also fixes setting 'deleted' flag to the GIN pages.  Now other page
flags are not erased once page is deleted.  That helps to keep our assertions
true if we arrive deleted page via downlink.

Discussion: https://postgr.es/m/CAPpHfdvMvsw-NcE5bRS7R1BbvA4BxoDnVVjkXC5W0Czvy9LVrg%40mail.gmail.com
Author: Alexander Korotkov
Reviewed-by: Peter Geoghegan
Backpatch-through: 9.4

src/backend/access/gin/ginbtree.c
src/backend/access/gin/gindatapage.c
src/backend/access/gin/ginvacuum.c
src/backend/access/gin/ginxlog.c

index b02cb8ae58f5075ad7e712854b09dda3b02bbb6c..3b241931bbc17fc1f207600c3c01b18c152a0446 100644 (file)
@@ -179,13 +179,6 @@ ginStepRight(Buffer buffer, Relation index, int lockmode)
    if (isLeaf != GinPageIsLeaf(page) || isData != GinPageIsData(page))
        elog(ERROR, "right sibling of GIN page is of different type");
 
-   /*
-    * Given the proper lock sequence above, we should never land on a deleted
-    * page.
-    */
-   if (GinPageIsDeleted(page))
-       elog(ERROR, "right sibling of GIN page was deleted");
-
    return nextbuffer;
 }
 
index 62b2f43ac940a2ec77cf19ab7b0ba40dd9ab630c..dac0c459bed764cc32f698ad7260f6da94faa65b 100644 (file)
@@ -237,6 +237,9 @@ dataIsMoveRight(GinBtree btree, Page page)
    if (GinPageRightMost(page))
        return FALSE;
 
+   if (GinPageIsDeleted(page))
+       return TRUE;
+
    return (ginCompareItemPointers(&btree->itemptr, iptr) > 0) ? TRUE : FALSE;
 }
 
index ed4ecfd0b13993fadf6ada76d1d9dcbdebffc89c..729e3bac8f2138ccc9451947418b940517251694 100644 (file)
@@ -179,7 +179,7 @@ ginDeletePage(GinVacuumState *gvs, BlockNumber deleteBlkno, BlockNumber leftBlkn
     * we shouldn't change rightlink field to save workability of running
     * search scan
     */
-   GinPageGetOpaque(page)->flags = GIN_DELETED;
+   GinPageSetDeleted(page);
 
    MarkBufferDirty(pBuffer);
    MarkBufferDirty(lBuffer);
index b86990f3ac7af6fafeb7ba33d63cf131e4a78922..938ad7d1aadb23f03484bafd90654245bf12b0c0 100644 (file)
@@ -530,7 +530,7 @@ ginRedoDeletePage(XLogReaderState *record)
    {
        page = BufferGetPage(dbuffer);
        Assert(GinPageIsData(page));
-       GinPageGetOpaque(page)->flags = GIN_DELETED;
+       GinPageSetDeleted(page);
 
        /*
         * deleteXid field of ginxlogDeletePage was added during backpatching.