Locks release order in LogStandbySnapshot

Поиск
Список
Период
Сортировка
От Japin Li
Тема Locks release order in LogStandbySnapshot
Дата
Msg-id MEYP282MB1669F81EB43FF064E348BFCEB63E9@MEYP282MB1669.AUSP282.PROD.OUTLOOK.COM
обсуждение исходный текст
Ответы Re: Locks release order in LogStandbySnapshot  (Andres Freund <andres@anarazel.de>)
Список pgsql-hackers
Hi, hackers

GetRunningTransactionData requires holding both ProcArrayLock and
XidGenLock (in that order).  Then LogStandbySnapshot releases those
locks in that order.  However, to reduce the frequency of having to
wait for XidGenLock while holding ProcArrayLock, ProcArrayAdd releases
them in reversed acquisition order.

The comments of LogStandbySnapshot says:

> GetRunningTransactionData() acquired ProcArrayLock, we must release it.
> For Hot Standby this can be done before inserting the WAL record
> because ProcArrayApplyRecoveryInfo() rechecks the commit status using
> the clog. For logical decoding, though, the lock can't be released
> early because the clog might be "in the future" from the POV of the
> historic snapshot. This would allow for situations where we're waiting
> for the end of a transaction listed in the xl_running_xacts record
> which, according to the WAL, has committed before the xl_running_xacts
> record. Fortunately this routine isn't executed frequently, and it's
> only a shared lock.

This comment is only for ProcArrayLock, not for XidGenLock. IIUC,
LogCurrentRunningXacts doesn't need holding XidGenLock, right?

Does there any sense to release them in reversed acquisition order in
LogStandbySnapshot like ProcArrayRemove?

-- 
Regrads,
Japin Li.
ChengDu WenWu Information Technology Co.,Ltd.

diff --git a/src/backend/storage/ipc/standby.c b/src/backend/storage/ipc/standby.c
index 7db86f7885..28d1c152bf 100644
--- a/src/backend/storage/ipc/standby.c
+++ b/src/backend/storage/ipc/standby.c
@@ -1283,6 +1283,9 @@ LogStandbySnapshot(void)
      */
     running = GetRunningTransactionData();
 
+    /* GetRunningTransactionData() acquired XidGenLock, we must release it */
+    LWLockRelease(XidGenLock);
+
     /*
      * GetRunningTransactionData() acquired ProcArrayLock, we must release it.
      * For Hot Standby this can be done before inserting the WAL record
@@ -1304,9 +1307,6 @@ LogStandbySnapshot(void)
     if (wal_level >= WAL_LEVEL_LOGICAL)
         LWLockRelease(ProcArrayLock);
 
-    /* GetRunningTransactionData() acquired XidGenLock, we must release it */
-    LWLockRelease(XidGenLock);
-
     return recptr;
 }


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Andres Freund
Дата:
Сообщение: Re: Asynchronous and "direct" IO support for PostgreSQL.
Следующее
От: Andres Freund
Дата:
Сообщение: Re: Locks release order in LogStandbySnapshot