Skip to content

Commit f47b5e1

Browse files
committed
Remove btree page items after page unlink
Currently, page unlink leaves remaining items "as is", but replay of corresponding WAL-record re-initializes page leaving it with no items. For the sake of consistency, this commit makes primary delete all the items during page unlink as well. Thanks to this change, we now don't mask contents of deleted btree page for WAL consistency checking. Discussion: https://postgr.es/m/CAPpHfdt_OTyQpXaPJcWzV2N-LNeNJseNB-K_A66qG%3DL518VTFw%40mail.gmail.com Author: Alexander Korotkov Reviewed-by: Peter Geoghegan
1 parent 0f76294 commit f47b5e1

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

contrib/amcheck/verify_nbtree.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -2864,11 +2864,8 @@ palloc_btree_page(BtreeCheckState *state, BlockNumber blocknum)
28642864
* As noted at the beginning of _bt_binsrch(), an internal page must have
28652865
* children, since there must always be a negative infinity downlink
28662866
* (there may also be a highkey). In the case of non-rightmost leaf
2867-
* pages, there must be at least a highkey. Deleted pages on replica
2868-
* might contain no items, because page unlink re-initializes
2869-
* page-to-be-deleted. Deleted pages with no items might be on primary
2870-
* too due to preceding recovery, but on primary new deletions can't
2871-
* happen concurrently to amcheck.
2867+
* pages, there must be at least a highkey. The exceptions are deleted
2868+
* pages, which contain no items.
28722869
*
28732870
* This is correct when pages are half-dead, since internal pages are
28742871
* never half-dead, and leaf pages must have a high key when half-dead

src/backend/access/nbtree/nbtpage.c

+9
Original file line numberDiff line numberDiff line change
@@ -2058,6 +2058,7 @@ _bt_unlink_halfdead_page(Relation rel, Buffer leafbuf, BlockNumber scanblkno,
20582058
BTMetaPageData *metad = NULL;
20592059
ItemId itemid;
20602060
Page page;
2061+
PageHeader header;
20612062
BTPageOpaque opaque;
20622063
bool rightsib_is_rightmost;
20632064
int targetlevel;
@@ -2327,6 +2328,14 @@ _bt_unlink_halfdead_page(Relation rel, Buffer leafbuf, BlockNumber scanblkno,
23272328
opaque->btpo_flags |= BTP_DELETED;
23282329
opaque->btpo.xact = ReadNewTransactionId();
23292330

2331+
/*
2332+
* Remove the remaining tuples on the page. This keeps things simple for
2333+
* WAL consistency checking.
2334+
*/
2335+
header = (PageHeader) page;
2336+
header->pd_lower = SizeOfPageHeaderData;
2337+
header->pd_upper = header->pd_special;
2338+
23302339
/* And update the metapage, if needed */
23312340
if (BufferIsValid(metabuf))
23322341
{

src/backend/access/nbtree/nbtxlog.c

+1-9
Original file line numberDiff line numberDiff line change
@@ -1051,15 +1051,7 @@ btree_mask(char *pagedata, BlockNumber blkno)
10511051

10521052
maskopaq = (BTPageOpaque) PageGetSpecialPointer(page);
10531053

1054-
if (P_ISDELETED(maskopaq))
1055-
{
1056-
/*
1057-
* Mask page content on a DELETED page since it will be re-initialized
1058-
* during replay. See btree_xlog_unlink_page() for details.
1059-
*/
1060-
mask_page_content(page);
1061-
}
1062-
else if (P_ISLEAF(maskopaq))
1054+
if (P_ISLEAF(maskopaq))
10631055
{
10641056
/*
10651057
* In btree leaf pages, it is possible to modify the LP_FLAGS without

0 commit comments

Comments
 (0)