optimize undo recycle

This commit is contained in:
sundechao
2024-06-06 14:30:04 +08:00
committed by yaoxin
parent 90553578b3
commit e9e338af79
4 changed files with 20 additions and 7 deletions

View File

@ -2002,7 +2002,7 @@ static bool vacuum_rel(Oid relid, VacuumStmt* vacstmt, bool do_toast)
Relation parent_rel = try_relation_open(relationid, NoLock); Relation parent_rel = try_relation_open(relationid, NoLock);
if (parent_rel != NULL) { if (parent_rel != NULL) {
if (RelationIsUstoreFormat(parent_rel) && parent_rel->rd_rel->relhasindex) { if (RelationIsUstoreFormat(parent_rel) && parent_rel->rd_rel->relhasindex) {
lmodePartTable = ShareLock; lmodePartTable = ExclusiveLock;
} }
relation_close(parent_rel, NoLock); relation_close(parent_rel, NoLock);
} }

View File

@ -2774,7 +2774,7 @@ void ForbidOutUsersToSetInnerOptions(List *userOptions)
void ForbidUserToSetDefinedIndexOptions(Relation rel, List *options) void ForbidUserToSetDefinedIndexOptions(Relation rel, List *options)
{ {
/* the following option must be in tab[] of default_reloptions(). */ /* the following option must be in tab[] of default_reloptions(). */
static const char *unchangedOpt[] = {"crossbucket", "storage_type"}; static const char *unchangedOpt[] = {"crossbucket", "storage_type", "index_txntype"};
int firstInvalidOpt = -1; int firstInvalidOpt = -1;
if (FindInvalidOption(options, unchangedOpt, lengthof(unchangedOpt), &firstInvalidOpt)) { if (FindInvalidOption(options, unchangedOpt, lengthof(unchangedOpt), &firstInvalidOpt)) {

View File

@ -397,7 +397,7 @@ TransactionId exrto_calculate_recycle_xmin_for_undo()
/* /*
* If there is no backend read threads, set read oldest lsn to snapshot lsn. * If there is no backend read threads, set read oldest lsn to snapshot lsn.
*/ */
if ((oldest_xmin == InvalidTransactionId) && (extreme_rto::g_dispatcher != NULL)) { if (extreme_rto::g_dispatcher != NULL) {
ExrtoSnapshot exrto_snapshot = NULL; ExrtoSnapshot exrto_snapshot = NULL;
exrto_snapshot = g_instance.comm_cxt.predo_cxt.exrto_snapshot; exrto_snapshot = g_instance.comm_cxt.predo_cxt.exrto_snapshot;
(void)LWLockAcquire(ExrtoSnapshotLock, LW_SHARED); (void)LWLockAcquire(ExrtoSnapshotLock, LW_SHARED);
@ -419,5 +419,9 @@ TransactionId exrto_calculate_recycle_xmin_for_undo()
if (oldest_xmin == InvalidTransactionId) { if (oldest_xmin == InvalidTransactionId) {
return snapshot_xmin; return snapshot_xmin;
} }
if (TransactionIdPrecedes(snapshot_xmin, oldest_xmin)) {
return snapshot_xmin;
}
return oldest_xmin; return oldest_xmin;
} }

View File

@ -270,7 +270,7 @@ void AdvanceFrozenXid(UndoZone *zone, TransactionId *oldestFozenXid,
} }
bool RecycleUndoSpace(UndoZone *zone, TransactionId recycleXmin, TransactionId frozenXid, bool RecycleUndoSpace(UndoZone *zone, TransactionId recycleXmin, TransactionId frozenXid,
TransactionId *oldestRecycleXid, TransactionId forceRecycleXid) TransactionId *oldestRecycleXid, TransactionId forceRecycleXid, TransactionId oldestXmin)
{ {
UndoSlotPtr recycle = zone->GetRecycleTSlotPtr(); UndoSlotPtr recycle = zone->GetRecycleTSlotPtr();
UndoSlotPtr allocate = zone->GetAllocateTSlotPtr(); UndoSlotPtr allocate = zone->GetAllocateTSlotPtr();
@ -360,9 +360,18 @@ bool RecycleUndoSpace(UndoZone *zone, TransactionId recycleXmin, TransactionId f
break; break;
} }
ereport(LOG, (errmodule(MOD_UNDO), errmsg(UNDOFORMAT("ForceRecycle: slot=%lu, slotxid=%lu, " ereport(LOG, (errmodule(MOD_UNDO), errmsg(UNDOFORMAT("ForceRecycle: slot=%lu, slotxid=%lu, "
"recyclexid=%lu, recycleXmin=%lu, startptr=%lu, endptr=%lu."), recycle, slot->XactId(), "recyclexid=%lu, recycleXmin=%lu, startptr=%lu, endptr=%lu, "
"glovalRecycleXid=%lu, globalFrozenXid=%lu, oldestXmin=%lu, "
"undoTotalSize=%u, undo_space_limit_size=%d, "
"metasize=%ld, g_force_recycle_size=%d."), recycle, slot->XactId(),
forceRecycleXid, recycleXmin, UNDO_PTR_GET_OFFSET(slot->StartUndoPtr()), forceRecycleXid, recycleXmin, UNDO_PTR_GET_OFFSET(slot->StartUndoPtr()),
UNDO_PTR_GET_OFFSET(slot->EndUndoPtr())))); UNDO_PTR_GET_OFFSET(slot->EndUndoPtr()),
pg_atomic_read_u64(&g_instance.undo_cxt.globalRecycleXid),
pg_atomic_read_u64(&g_instance.undo_cxt.globalFrozenXid),
oldestXmin,
pg_atomic_read_u32(&g_instance.undo_cxt.undoTotalSize),
u_sess->attr.attr_storage.undo_space_limit_size,
(int64)g_instance.undo_cxt.undoMetaSize, g_forceRecycleSize)));
forceRecycle = true; forceRecycle = true;
} }
#ifdef DEBUG_UHEAP #ifdef DEBUG_UHEAP
@ -921,7 +930,7 @@ void UndoRecycleMain()
UNDOFORMAT("oldestFrozenXidInUndo: oldestFrozenXidInUndo=%lu, frozenXid=%lu" UNDOFORMAT("oldestFrozenXidInUndo: oldestFrozenXidInUndo=%lu, frozenXid=%lu"
" before RecycleUndoSpace"), " before RecycleUndoSpace"),
oldestFrozenXidInUndo, frozenXid))); oldestFrozenXidInUndo, frozenXid)));
if (RecycleUndoSpace(zone, recycleXmin, frozenXid, &recycleXid, forceRecycleXid)) { if (RecycleUndoSpace(zone, recycleXmin, frozenXid, &recycleXid, forceRecycleXid, oldestXmin)) {
recycled = true; recycled = true;
} }
isAnyZoneUsed = true; isAnyZoneUsed = true;