Skip to content

Commit fcd8d25

Browse files
committed
amcheck: editorialize variable name & comment.
No exclusive lock is taken anymore...
1 parent 56018bf commit fcd8d25

File tree

1 file changed

+38
-39
lines changed

1 file changed

+38
-39
lines changed

contrib/amcheck/verify_nbtree.c

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ typedef struct BtreeCheckState
5555

5656
/* B-Tree Index Relation */
5757
Relation rel;
58-
/* ExclusiveLock held? */
59-
bool exclusivelylocked;
58+
/* ShareLock held on heap/index, rather than AccessShareLock? */
59+
bool readonly;
6060
/* Per-page context */
6161
MemoryContext targetcontext;
6262
/* Buffer access strategy */
@@ -94,7 +94,7 @@ PG_FUNCTION_INFO_V1(bt_index_parent_check);
9494

9595
static void bt_index_check_internal(Oid indrelid, bool parentcheck);
9696
static inline void btree_index_checkable(Relation rel);
97-
static void bt_check_every_level(Relation rel, bool exclusivelylocked);
97+
static void bt_check_every_level(Relation rel, bool readonly);
9898
static BtreeLevel bt_check_level_from_leftmost(BtreeCheckState *state,
9999
BtreeLevel level);
100100
static void bt_target_page_check(BtreeCheckState *state);
@@ -256,23 +256,23 @@ btree_index_checkable(Relation rel)
256256
* logical order, verifying invariants as it goes.
257257
*
258258
* It is the caller's responsibility to acquire appropriate heavyweight lock on
259-
* the index relation, and advise us if extra checks are safe when an
260-
* ExclusiveLock is held.
259+
* the index relation, and advise us if extra checks are safe when a ShareLock
260+
* is held.
261261
*
262-
* An ExclusiveLock is generally assumed to prevent any kind of physical
262+
* A ShareLock is generally assumed to prevent any kind of physical
263263
* modification to the index structure, including modifications that VACUUM may
264264
* make. This does not include setting of the LP_DEAD bit by concurrent index
265265
* scans, although that is just metadata that is not able to directly affect
266266
* any check performed here. Any concurrent process that might act on the
267267
* LP_DEAD bit being set (recycle space) requires a heavyweight lock that
268-
* cannot be held while we hold an ExclusiveLock. (Besides, even if that could
268+
* cannot be held while we hold a ShareLock. (Besides, even if that could
269269
* happen, the ad-hoc recycling when a page might otherwise split is performed
270270
* per-page, and requires an exclusive buffer lock, which wouldn't cause us
271271
* trouble. _bt_delitems_vacuum() may only delete leaf items, and so the extra
272272
* parent/child check cannot be affected.)
273273
*/
274274
static void
275-
bt_check_every_level(Relation rel, bool exclusivelylocked)
275+
bt_check_every_level(Relation rel, bool readonly)
276276
{
277277
BtreeCheckState *state;
278278
Page metapage;
@@ -291,7 +291,7 @@ bt_check_every_level(Relation rel, bool exclusivelylocked)
291291
*/
292292
state = palloc(sizeof(BtreeCheckState));
293293
state->rel = rel;
294-
state->exclusivelylocked = exclusivelylocked;
294+
state->readonly = readonly;
295295
/* Create context for page */
296296
state->targetcontext = AllocSetContextCreate(CurrentMemoryContext,
297297
"amcheck context",
@@ -353,7 +353,7 @@ bt_check_every_level(Relation rel, bool exclusivelylocked)
353353

354354
/*
355355
* Given a left-most block at some level, move right, verifying each page
356-
* individually (with more verification across pages for "exclusivelylocked"
356+
* individually (with more verification across pages for "readonly"
357357
* callers). Caller should pass the true root page as the leftmost initially,
358358
* working their way down by passing what is returned for the last call here
359359
* until level 0 (leaf page level) was reached.
@@ -428,7 +428,7 @@ bt_check_level_from_leftmost(BtreeCheckState *state, BtreeLevel level)
428428
* locking, check that the first valid page meets caller's
429429
* expectations.
430430
*/
431-
if (state->exclusivelylocked)
431+
if (state->readonly)
432432
{
433433
if (!P_LEFTMOST(opaque))
434434
ereport(ERROR,
@@ -482,7 +482,7 @@ bt_check_level_from_leftmost(BtreeCheckState *state, BtreeLevel level)
482482
*/
483483
}
484484

485-
if (state->exclusivelylocked && opaque->btpo_prev != leftcurrent)
485+
if (state->readonly && opaque->btpo_prev != leftcurrent)
486486
ereport(ERROR,
487487
(errcode(ERRCODE_INDEX_CORRUPTED),
488488
errmsg("left link/right link pair in index \"%s\" not in agreement",
@@ -541,7 +541,7 @@ bt_check_level_from_leftmost(BtreeCheckState *state, BtreeLevel level)
541541
* "real" data item on the page to the right (if such a first item is
542542
* available).
543543
*
544-
* Furthermore, when state passed shows ExclusiveLock held, and target page is
544+
* Furthermore, when state passed shows ShareLock held, and target page is
545545
* internal page, function also checks:
546546
*
547547
* - That all child pages respect downlinks lower bound.
@@ -597,8 +597,8 @@ bt_target_page_check(BtreeCheckState *state)
597597
* page items.
598598
*
599599
* We prefer to check all items against high key rather than checking
600-
* just the first and trusting that the operator class obeys the
601-
* transitive law (which implies that all subsequent items also
600+
* just the last and trusting that the operator class obeys the
601+
* transitive law (which implies that all previous items also
602602
* respected the high key invariant if they pass the item order
603603
* check).
604604
*
@@ -705,21 +705,20 @@ bt_target_page_check(BtreeCheckState *state)
705705
{
706706
/*
707707
* As explained at length in bt_right_page_check_scankey(),
708-
* there is a known !exclusivelylocked race that could account
709-
* for apparent violation of invariant, which we must check
710-
* for before actually proceeding with raising error. Our
711-
* canary condition is that target page was deleted.
708+
* there is a known !readonly race that could account for
709+
* apparent violation of invariant, which we must check for
710+
* before actually proceeding with raising error. Our canary
711+
* condition is that target page was deleted.
712712
*/
713-
if (!state->exclusivelylocked)
713+
if (!state->readonly)
714714
{
715715
/* Get fresh copy of target page */
716716
state->target = palloc_btree_page(state, state->targetblock);
717717
/* Note that we deliberately do not update target LSN */
718718
topaque = (BTPageOpaque) PageGetSpecialPointer(state->target);
719719

720720
/*
721-
* All !exclusivelylocked checks now performed; just
722-
* return
721+
* All !readonly checks now performed; just return
723722
*/
724723
if (P_IGNORE(topaque))
725724
return;
@@ -740,11 +739,11 @@ bt_target_page_check(BtreeCheckState *state)
740739
* * Downlink check *
741740
*
742741
* Additional check of child items iff this is an internal page and
743-
* caller holds an ExclusiveLock. This happens for every downlink
744-
* (item) in target excluding the negative-infinity downlink (again,
745-
* this is because it has no useful value to compare).
742+
* caller holds a ShareLock. This happens for every downlink (item)
743+
* in target excluding the negative-infinity downlink (again, this is
744+
* because it has no useful value to compare).
746745
*/
747-
if (!P_ISLEAF(topaque) && state->exclusivelylocked)
746+
if (!P_ISLEAF(topaque) && state->readonly)
748747
{
749748
BlockNumber childblock = ItemPointerGetBlockNumber(&(itup->t_tid));
750749

@@ -766,7 +765,7 @@ bt_target_page_check(BtreeCheckState *state)
766765
* with different parent page). If no such valid item is available, return
767766
* NULL instead.
768767
*
769-
* Note that !exclusivelylocked callers must reverify that target page has not
768+
* Note that !readonly callers must reverify that target page has not
770769
* been concurrently deleted.
771770
*/
772771
static ScanKey
@@ -833,14 +832,14 @@ bt_right_page_check_scankey(BtreeCheckState *state)
833832
}
834833

835834
/*
836-
* No ExclusiveLock held case -- why it's safe to proceed.
835+
* No ShareLock held case -- why it's safe to proceed.
837836
*
838837
* Problem:
839838
*
840839
* We must avoid false positive reports of corruption when caller treats
841840
* item returned here as an upper bound on target's last item. In
842841
* general, false positives are disallowed. Avoiding them here when
843-
* caller is !exclusivelylocked is subtle.
842+
* caller is !readonly is subtle.
844843
*
845844
* A concurrent page deletion by VACUUM of the target page can result in
846845
* the insertion of items on to this right sibling page that would
@@ -892,7 +891,7 @@ bt_right_page_check_scankey(BtreeCheckState *state)
892891
*
893892
* Top level tree walk caller moves on to next page (makes it the new
894893
* target) following recovery from this race. (cf. The rationale for
895-
* child/downlink verification needing an ExclusiveLock within
894+
* child/downlink verification needing a ShareLock within
896895
* bt_downlink_check(), where page deletion is also the main source of
897896
* trouble.)
898897
*
@@ -984,7 +983,7 @@ bt_downlink_check(BtreeCheckState *state, BlockNumber childblock,
984983
BTPageOpaque copaque;
985984

986985
/*
987-
* Caller must have ExclusiveLock on target relation, because of
986+
* Caller must have ShareLock on target relation, because of
988987
* considerations around page deletion by VACUUM.
989988
*
990989
* NB: In general, page deletion deletes the right sibling's downlink, not
@@ -994,8 +993,8 @@ bt_downlink_check(BtreeCheckState *state, BlockNumber childblock,
994993
* page's rightmost child unless it is the last child page, and we intend
995994
* to also delete the parent itself.)
996995
*
997-
* If this verification happened without an ExclusiveLock, the following
998-
* race condition could cause false positives:
996+
* If this verification happened without a ShareLock, the following race
997+
* condition could cause false positives:
999998
*
1000999
* In general, concurrent page deletion might occur, including deletion of
10011000
* the left sibling of the child page that is examined here. If such a
@@ -1009,19 +1008,19 @@ bt_downlink_check(BtreeCheckState *state, BlockNumber childblock,
10091008
* part of deletion's first phase.)
10101009
*
10111010
* Note that while the cross-page-same-level last item check uses a trick
1012-
* that allows it to perform verification for !exclusivelylocked callers,
1013-
* a similar trick seems difficult here. The trick that that other check
1014-
* uses is, in essence, to lock down race conditions to those that occur
1015-
* due to concurrent page deletion of the target; that's a race that can
1016-
* be reliably detected before actually reporting corruption.
1011+
* that allows it to perform verification for !readonly callers, a similar
1012+
* trick seems difficult here. The trick that that other check uses is,
1013+
* in essence, to lock down race conditions to those that occur due to
1014+
* concurrent page deletion of the target; that's a race that can be
1015+
* reliably detected before actually reporting corruption.
10171016
*
10181017
* On the other hand, we'd need to lock down race conditions involving
10191018
* deletion of child's left page, for long enough to read the child page
10201019
* into memory (in other words, a scheme with concurrently held buffer
10211020
* locks on both child and left-of-child pages). That's unacceptable for
10221021
* amcheck functions on general principle, though.
10231022
*/
1024-
Assert(state->exclusivelylocked);
1023+
Assert(state->readonly);
10251024

10261025
/*
10271026
* Verify child page has the downlink key from target page (its parent) as

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy