• Heikki Linnakangas's avatar
    Make the handling of interrupted B-tree page splits more robust. · 40dae7ec
    Heikki Linnakangas authored
    Splitting a page consists of two separate steps: splitting the child page,
    and inserting the downlink for the new right page to the parent. Previously,
    we handled the case that you crash in between those steps with a cleanup
    routine after the WAL recovery had finished, which finished the incomplete
    split. However, that doesn't help if the page split is interrupted but the
    database doesn't crash, so that you don't perform WAL recovery. That could
    happen for example if you run out of disk space.
    
    Remove the end-of-recovery cleanup step. Instead, when a page is split, the
    left page is marked with a new INCOMPLETE_SPLIT flag, and when the downlink
    is inserted to the parent, the flag is cleared again. If an insertion sees
    a page with the flag set, it knows that the split was interrupted for some
    reason, and inserts the missing downlink before proceeding.
    
    I used the same approach to fix GIN and GiST split algorithms earlier. This
    was the last WAL cleanup routine, so we could get rid of that whole
    machinery now, but I'll leave that for a separate patch.
    
    Reviewed by Peter Geoghegan.
    40dae7ec
nbtxlog.c 32.4 KB