Refactor WaitLSNType enum to use a macro for type count
authorAlexander Korotkov <[email protected]>
Sun, 14 Dec 2025 15:18:32 +0000 (17:18 +0200)
committerAlexander Korotkov <[email protected]>
Sun, 14 Dec 2025 15:18:32 +0000 (17:18 +0200)
Change WAIT_LSN_TYPE_COUNT from an enum sentinel to a macro definition,
in a similar way to IOObject, IOContext, and BackendType enums.  Remove
explicit enum value assignments well.

Author: Xuneng Zhou <[email protected]>

src/backend/access/transam/xlogwait.c
src/include/access/xlogwait.h

index 84613fc39c7c25b317031f75a80f19d4ef7a08b0..6109381c0f0a8d6bcb7433afa84f94ce705a7388 100644 (file)
@@ -126,7 +126,7 @@ updateMinWaitedLSN(WaitLSNType lsnType)
    XLogRecPtr  minWaitedLSN = PG_UINT64_MAX;
    int         i = (int) lsnType;
 
-   Assert(i >= 0 && i < (int) WAIT_LSN_TYPE_COUNT);
+   Assert(i >= 0 && i < WAIT_LSN_TYPE_COUNT);
 
    if (!pairingheap_is_empty(&waitLSNState->waitersHeap[i]))
    {
@@ -147,7 +147,7 @@ addLSNWaiter(XLogRecPtr lsn, WaitLSNType lsnType)
    WaitLSNProcInfo *procInfo = &waitLSNState->procInfos[MyProcNumber];
    int         i = (int) lsnType;
 
-   Assert(i >= 0 && i < (int) WAIT_LSN_TYPE_COUNT);
+   Assert(i >= 0 && i < WAIT_LSN_TYPE_COUNT);
 
    LWLockAcquire(WaitLSNLock, LW_EXCLUSIVE);
 
@@ -172,7 +172,7 @@ deleteLSNWaiter(WaitLSNType lsnType)
    WaitLSNProcInfo *procInfo = &waitLSNState->procInfos[MyProcNumber];
    int         i = (int) lsnType;
 
-   Assert(i >= 0 && i < (int) WAIT_LSN_TYPE_COUNT);
+   Assert(i >= 0 && i < WAIT_LSN_TYPE_COUNT);
 
    LWLockAcquire(WaitLSNLock, LW_EXCLUSIVE);
 
@@ -213,7 +213,7 @@ wakeupWaiters(WaitLSNType lsnType, XLogRecPtr currentLSN)
    int         numWakeUpProcs;
    int         i = (int) lsnType;
 
-   Assert(i >= 0 && i < (int) WAIT_LSN_TYPE_COUNT);
+   Assert(i >= 0 && i < WAIT_LSN_TYPE_COUNT);
 
    do
    {
@@ -270,7 +270,7 @@ WaitLSNWakeup(WaitLSNType lsnType, XLogRecPtr currentLSN)
 {
    int         i = (int) lsnType;
 
-   Assert(i >= 0 && i < (int) WAIT_LSN_TYPE_COUNT);
+   Assert(i >= 0 && i < WAIT_LSN_TYPE_COUNT);
 
    /*
     * Fast path check.  Skip if currentLSN is InvalidXLogRecPtr, which means
index e607441d618770fd0996dcebc09f8a6418a23a79..3e8fcbd917786e097128ab05a7e57ed23dabe45d 100644 (file)
@@ -35,11 +35,12 @@ typedef enum
  */
 typedef enum WaitLSNType
 {
-   WAIT_LSN_TYPE_REPLAY = 0,   /* Waiting for replay on standby */
-   WAIT_LSN_TYPE_FLUSH = 1,    /* Waiting for flush on primary */
-   WAIT_LSN_TYPE_COUNT = 2
+   WAIT_LSN_TYPE_REPLAY,       /* Waiting for replay on standby */
+   WAIT_LSN_TYPE_FLUSH,        /* Waiting for flush on primary */
 } WaitLSNType;
 
+#define WAIT_LSN_TYPE_COUNT (WAIT_LSN_TYPE_FLUSH + 1)
+
 /*
  * WaitLSNProcInfo - the shared memory structure representing information
  * about the single process, which may wait for LSN operations.  An item of