Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 34dae90

Browse files
committed
Fix amcheck for page checks concurrent to replay of btree page deletion
amcheck expects at least hikey to always exist on leaf page even if it is deleted page. But replica reinitializes page during replay of page deletion, causing deleted page to have no items. Thus, replay of page deletion can cause an error in concurrent amcheck run. This commit relaxes amcheck expectation making it tolerate deleted page with no items. Reported-by: Konstantin Knizhnik Discussion: https://postgr.es/m/CAPpHfdt_OTyQpXaPJcWzV2N-LNeNJseNB-K_A66qG%3DL518VTFw%40mail.gmail.com Author: Alexander Korotkov Reviewed-by: Peter Geoghegan Backpatch-through: 11
1 parent e8abf58 commit 34dae90

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

contrib/amcheck/verify_nbtree.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -2864,7 +2864,11 @@ 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.
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.
28682872
*
28692873
* This is correct when pages are half-dead, since internal pages are
28702874
* never half-dead, and leaf pages must have a high key when half-dead
@@ -2884,13 +2888,13 @@ palloc_btree_page(BtreeCheckState *state, BlockNumber blocknum)
28842888
blocknum, RelationGetRelationName(state->rel),
28852889
MaxIndexTuplesPerPage)));
28862890

2887-
if (!P_ISLEAF(opaque) && maxoffset < P_FIRSTDATAKEY(opaque))
2891+
if (!P_ISLEAF(opaque) && !P_ISDELETED(opaque) && maxoffset < P_FIRSTDATAKEY(opaque))
28882892
ereport(ERROR,
28892893
(errcode(ERRCODE_INDEX_CORRUPTED),
28902894
errmsg("internal block %u in index \"%s\" lacks high key and/or at least one downlink",
28912895
blocknum, RelationGetRelationName(state->rel))));
28922896

2893-
if (P_ISLEAF(opaque) && !P_RIGHTMOST(opaque) && maxoffset < P_HIKEY)
2897+
if (P_ISLEAF(opaque) && !P_ISDELETED(opaque) && !P_RIGHTMOST(opaque) && maxoffset < P_HIKEY)
28942898
ereport(ERROR,
28952899
(errcode(ERRCODE_INDEX_CORRUPTED),
28962900
errmsg("non-rightmost leaf block %u in index \"%s\" lacks high key item",

0 commit comments

Comments
 (0)