修复备机读组获取快照死锁问题Offering: openGaussDevMore detail: standby read

Match-id-06894f7e495d72c5763653105cbd2c8eee989c81
This commit is contained in:
openGaussDev
2024-08-06 14:45:33 +08:00
committed by yanghao
parent f9b5322111
commit f5d45bdf68
3 changed files with 27 additions and 1 deletions

View File

@ -4764,6 +4764,29 @@ int GetThreadBufferLeakNum(void)
return refCountErrors;
}
bool CheckForBufferPin(void)
{
PrivateRefCountEntry *res = NULL;
for (int i = 0; i < REFCOUNT_ARRAY_ENTRIES; i++) {
res = &t_thrd.storage_cxt.PrivateRefCountArray[i];
if (res->buffer != InvalidBuffer) {
return true;
}
}
if (t_thrd.storage_cxt.PrivateRefCountOverflowed) {
HASH_SEQ_STATUS hstat;
hash_seq_init(&hstat, t_thrd.storage_cxt.PrivateRefCountHash);
while ((res = (PrivateRefCountEntry *)hash_seq_search(&hstat)) != NULL) {
hash_seq_term(&hstat);
return true;
}
}
return false;
}
/*
* CheckForBufferLeaks - ensure this backend holds no buffer pins
*

View File

@ -2120,6 +2120,8 @@ RETRY:
bool retry_get = false;
uint64 retry_count = 0;
const static uint64 WAIT_COUNT = 0x7FFFF;
bool get_snapshot_by_self = CheckForBufferPin() || forHSFeedBack;
/* reset xmin before acquiring lwlock, in case blocking redo */
t_thrd.pgxact->xmin = InvalidTransactionId;
RETRY_GET:
@ -2184,7 +2186,7 @@ RETRY_GET:
goto RETRY_GET;
}
#ifndef ENABLE_MULTIPLE_NODES
} else if (forHSFeedBack) {
} else if (get_snapshot_by_self) {
LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
if ((t_thrd.xact_cxt.ShmemVariableCache->standbyXmin
<= t_thrd.xact_cxt.ShmemVariableCache->standbyRedoCleanupXmin)

View File

@ -410,6 +410,7 @@ extern void RangeForgetBuffer(RelFileNode node, ForkNumber forkNum, BlockNumber
extern void DropSegRelNodeSharedBuffer(RelFileNode node, ForkNumber forkNum);
extern int GetThreadBufferLeakNum(void);
extern bool CheckForBufferPin(void);
extern void flush_all_buffers(Relation rel, Oid db_id, HTAB *hashtbl = NULL);
/* in localbuf.c */
extern void ForgetLocalBuffer(RelFileNode rnode, ForkNumber forkNum, BlockNumber blockNum);