修复btvacuumscan中有遍历扫描lastBlockVacuumed到lastBlockLocked生成btree vacuum xlog的问题

This commit is contained in:
arcoalien@qq.com
2024-07-18 09:05:05 +08:00
committed by cchen676
parent 2226a90858
commit f8d2bf261e

View File

@ -44,8 +44,6 @@ typedef struct {
IndexBulkDeleteCallback callback;
void *callback_state;
BTCycleId cycleid;
BlockNumber lastBlockVacuumed; /* highest blkno actually vacuumed */
BlockNumber lastBlockLocked; /* highest blkno we've cleanup-locked */
BlockNumber totFreePages; /* true total # of free pages */
MemoryContext pagedelcontext;
} BTVacState;
@ -828,8 +826,6 @@ static void btvacuumscan(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, In
vstate.callback = callback;
vstate.callback_state = callback_state;
vstate.cycleid = cycleid;
vstate.lastBlockVacuumed = BTREE_METAPAGE; /* Initialise at first block */
vstate.lastBlockLocked = BTREE_METAPAGE;
vstate.totFreePages = 0;
/* Create a temporary memory context to run _bt_pagedel in */
@ -882,33 +878,6 @@ static void btvacuumscan(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, In
}
}
/*
* If the WAL is replayed in hot standby, the replay process needs to get
* cleanup locks on all index leaf pages, just as we've been doing here.
* However, we won't issue any WAL records about pages that have no items
* to be deleted. For pages between pages we've vacuumed, the replay code
* will take locks under the direction of the lastBlockVacuumed fields in
* the XLOG_BTREE_VACUUM WAL records. To cover pages after the last one
* we vacuum, we need to issue a dummy XLOG_BTREE_VACUUM WAL record
* against the last leaf page in the index, if that one wasn't vacuumed.
*/
if (XLogStandbyInfoActive() && vstate.lastBlockVacuumed < vstate.lastBlockLocked && !SS_SINGLE_CLUSTER) {
Buffer buf;
/*
* The page should be valid, but we can't use _bt_getbuf() because we
* want to use a nondefault buffer access strategy. Since we aren't
* going to delete any items, getting cleanup lock again is probably
* overkill, but for consistency do that anyway.
*/
buf = ReadBufferExtended(rel, MAIN_FORKNUM, vstate.lastBlockLocked, RBM_NORMAL, info->strategy);
_bt_checkbuffer_valid(rel, buf);
LockBufferForCleanup(buf);
_bt_checkpage(rel, buf);
_bt_delitems_vacuum(rel, buf, NULL, 0, NULL, 0,vstate.lastBlockVacuumed);
_bt_relbuf(rel, buf);
}
MemoryContextDelete(vstate.pagedelcontext);
/* update statistics */
@ -1005,14 +974,6 @@ restart:
LockBuffer(buf, BUFFER_LOCK_UNLOCK);
LockBufferForCleanup(buf);
/*
* Remember highest leaf page number we've taken cleanup lock on; see
* notes in btvacuumscan
*/
if (blkno > vstate->lastBlockLocked) {
vstate->lastBlockLocked = blkno;
}
/*
* Check whether we need to recurse back to earlier pages. What we
* are concerned about is a page split that happened since we started
@ -1110,15 +1071,7 @@ restart:
Assert(num_dead_heap_tids >= Max(num_deletable, 1));
Assert(num_deletable > 0 || updatable > 0);
_bt_delitems_vacuum(rel, buf, deletable, num_deletable, updatable, num_updatable,
vstate->lastBlockVacuumed);
/*
* Remember highest leaf page number we've issued a
* XLOG_BTREE_VACUUM WAL record for.
*/
if (blkno > vstate->lastBlockVacuumed) {
vstate->lastBlockVacuumed = blkno;
}
0);
stats->tuples_removed += num_dead_heap_tids;
/* must recompute maxoff */