LCOV - differential code coverage report
Current view: top level - src/test/modules/test_wait_lsn - test_wait_lsn.c (source / functions) Coverage Total Hit UBC CBC
Current: f76c13edadc2b319036e0d238703ed56bb23f934 vs 9e17d25e79d4756be08b4a5521b4b58450217137 Lines: 92.3 % 39 36 3 36
Current Date: 2026-09-20 14:13:17 +0900 Functions: 100.0 % 6 6 6
Baseline: lcov-20260920-baseline Branches: 55.0 % 20 11 9 11
Baseline Date: 2026-09-20 14:13:13 +0900 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(30,360] days: 92.3 % 39 36 3 36
Function coverage date bins:
(30,360] days: 100.0 % 6 6 6
Branch coverage date bins:
(30,360] days: 55.0 % 20 11 9 11

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*--------------------------------------------------------------------------
                                  2                 :                :  *
                                  3                 :                :  * test_wait_lsn.c
                                  4                 :                :  *      Test support for WAIT FOR LSN.
                                  5                 :                :  *
                                  6                 :                :  * Copyright (c) 2026, PostgreSQL Global Development Group
                                  7                 :                :  *
                                  8                 :                :  * IDENTIFICATION
                                  9                 :                :  *      src/test/modules/test_wait_lsn/test_wait_lsn.c
                                 10                 :                :  *
                                 11                 :                :  * -------------------------------------------------------------------------
                                 12                 :                :  */
                                 13                 :                : #include "postgres.h"
                                 14                 :                : 
                                 15                 :                : #include "access/xlogwait.h"
                                 16                 :                : #include "fmgr.h"
                                 17                 :                : #include "storage/lwlock.h"
                                 18                 :                : #include "storage/proc.h"
                                 19                 :                : #include "storage/procarray.h"
                                 20                 :                : #include "utils/builtins.h"
                                 21                 :                : #include "utils/pg_lsn.h"
                                 22                 :                : 
   33 akorotkov@postgresql       23                 :CBC           7 : PG_MODULE_MAGIC;
                                 24                 :                : 
                                 25                 :              3 : PG_FUNCTION_INFO_V1(test_wait_lsn_wakeup);
                                 26                 :              6 : PG_FUNCTION_INFO_V1(test_wait_lsn_waiter_is_registered);
                                 27                 :                : 
                                 28                 :                : static WaitLSNType
                                 29                 :              5 : parse_wait_lsn_type(text *mode_text)
                                 30                 :                : {
                                 31                 :              5 :     char       *mode = text_to_cstring(mode_text);
                                 32                 :                :     WaitLSNType lsn_type;
                                 33                 :                : 
                                 34         [ -  + ]:              5 :     if (pg_strcasecmp(mode, "standby_replay") == 0)
   33 akorotkov@postgresql       35                 :UBC           0 :         lsn_type = WAIT_LSN_TYPE_STANDBY_REPLAY;
   33 akorotkov@postgresql       36         [ +  + ]:CBC           5 :     else if (pg_strcasecmp(mode, "standby_write") == 0)
                                 37                 :              3 :         lsn_type = WAIT_LSN_TYPE_STANDBY_WRITE;
                                 38         [ -  + ]:              2 :     else if (pg_strcasecmp(mode, "standby_flush") == 0)
   33 akorotkov@postgresql       39                 :UBC           0 :         lsn_type = WAIT_LSN_TYPE_STANDBY_FLUSH;
   33 akorotkov@postgresql       40         [ +  - ]:CBC           2 :     else if (pg_strcasecmp(mode, "primary_flush") == 0)
                                 41                 :              2 :         lsn_type = WAIT_LSN_TYPE_PRIMARY_FLUSH;
                                 42                 :                :     else
   33 akorotkov@postgresql       43         [ #  # ]:UBC           0 :         ereport(ERROR,
                                 44                 :                :                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                 45                 :                :                  errmsg("unrecognized WAIT FOR LSN mode \"%s\"", mode)));
                                 46                 :                : 
   33 akorotkov@postgresql       47                 :CBC           5 :     pfree(mode);
                                 48                 :              5 :     return lsn_type;
                                 49                 :                : }
                                 50                 :                : 
                                 51                 :                : /*
                                 52                 :                :  * Wake all waiters of the supplied type through the supplied LSN without
                                 53                 :                :  * advancing the underlying WAL position.
                                 54                 :                :  */
                                 55                 :                : Datum
                                 56                 :              1 : test_wait_lsn_wakeup(PG_FUNCTION_ARGS)
                                 57                 :                : {
                                 58                 :              1 :     WaitLSNType lsn_type = parse_wait_lsn_type(PG_GETARG_TEXT_PP(0));
                                 59                 :              1 :     XLogRecPtr  upto_lsn = PG_GETARG_LSN(1);
                                 60                 :                : 
                                 61                 :              1 :     WaitLSNWakeup(lsn_type, upto_lsn);
                                 62                 :                : 
                                 63                 :              1 :     PG_RETURN_VOID();
                                 64                 :                : }
                                 65                 :                : 
                                 66                 :                : /*
                                 67                 :                :  * Check whether the backend with the supplied PID is registered for the
                                 68                 :                :  * supplied mode and target.  ProcArrayLock stabilizes the PID mapping, while
                                 69                 :                :  * WaitLSNLock protects the registration state.
                                 70                 :                :  */
                                 71                 :                : Datum
                                 72                 :              4 : test_wait_lsn_waiter_is_registered(PG_FUNCTION_ARGS)
                                 73                 :                : {
                                 74                 :              4 :     int         pid = PG_GETARG_INT32(0);
                                 75                 :              4 :     WaitLSNType lsn_type = parse_wait_lsn_type(PG_GETARG_TEXT_PP(1));
                                 76                 :              4 :     XLogRecPtr  target_lsn = PG_GETARG_LSN(2);
                                 77                 :              4 :     bool        registered = false;
                                 78                 :                :     PGPROC     *proc;
                                 79                 :                : 
                                 80                 :              4 :     LWLockAcquire(ProcArrayLock, LW_SHARED);
                                 81                 :              4 :     proc = BackendPidGetProcWithLock(pid);
                                 82                 :                : 
                                 83         [ +  - ]:              4 :     if (proc != NULL)
                                 84                 :                :     {
                                 85                 :              4 :         ProcNumber  procno = GetNumberFromPGProc(proc);
                                 86                 :              4 :         WaitLSNProcInfo *proc_info = &waitLSNState->procInfos[procno];
                                 87                 :                : 
                                 88                 :              4 :         LWLockAcquire(WaitLSNLock, LW_SHARED);
                                 89                 :             11 :         registered = proc_info->inHeap &&
                                 90         [ +  - ]:              3 :             proc_info->procno == procno &&
                                 91   [ +  +  +  - ]:             10 :             proc_info->lsnType == lsn_type &&
                                 92         [ +  - ]:              3 :             proc_info->waitLSN == target_lsn;
                                 93                 :              4 :         LWLockRelease(WaitLSNLock);
                                 94                 :                :     }
                                 95                 :                : 
                                 96                 :              4 :     LWLockRelease(ProcArrayLock);
                                 97                 :                : 
                                 98                 :              4 :     PG_RETURN_BOOL(registered);
                                 99                 :                : }
        

Generated by: LCOV version 2.0-1