LCOV - differential code coverage report
Current view: top level - src/test/modules/injection_points - regress_injection.c (source / functions) Coverage Total Hit UBC CBC
Current: 4b3c9325757dfd8f2312e9f1a8decf4431f344ae vs e87b024bfb8dd55e3049b1b6e6ab4e810cf1abc8 Lines: 92.3 % 26 24 2 24
Current Date: 2026-11-28 16:48:44 +0900 Functions: 100.0 % 3 3 3
Baseline: lcov-20261128-baseline Branches: 35.0 % 20 7 13 7
Baseline Date: 2026-11-28 16:48:48 +0900 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(7,30] days: 90.0 % 10 9 1 9
(30,360] days: 100.0 % 1 1 1
(360..) days: 93.3 % 15 14 1 14
Function coverage date bins:
(7,30] days: 100.0 % 1 1 1
(360..) days: 100.0 % 2 2 2
Branch coverage date bins:
(7,30] days: 25.0 % 4 1 3 1
(30,360] days: 33.3 % 6 2 4 2
(360..) days: 40.0 % 10 4 6 4

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*--------------------------------------------------------------------------
                                  2                 :                :  *
                                  3                 :                :  * regress_injection.c
                                  4                 :                :  *      Functions supporting test-specific subject matter.
                                  5                 :                :  *
                                  6                 :                :  * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
                                  7                 :                :  * Portions Copyright (c) 1994, Regents of the University of California
                                  8                 :                :  *
                                  9                 :                :  * IDENTIFICATION
                                 10                 :                :  *      src/test/modules/injection_points/regress_injection.c
                                 11                 :                :  *
                                 12                 :                :  * -------------------------------------------------------------------------
                                 13                 :                :  */
                                 14                 :                : 
                                 15                 :                : #include "postgres.h"
                                 16                 :                : 
                                 17                 :                : #include "access/table.h"
                                 18                 :                : #include "fmgr.h"
                                 19                 :                : #include "miscadmin.h"
                                 20                 :                : #include "postmaster/autovacuum.h"
                                 21                 :                : #include "replication/logicalproto.h"
                                 22                 :                : #include "storage/procarray.h"
                                 23                 :                : #include "utils/rel.h"
                                 24                 :                : #include "utils/xid8.h"
                                 25                 :                : 
                                 26                 :                : extern PGDLLEXPORT void logicalrep_relation_redirect(const char *name,
                                 27                 :                :                                                      const void *private_data,
                                 28                 :                :                                                      void *arg);
                                 29                 :                : 
                                 30                 :                : /*
                                 31                 :                :  * Pretend that the publisher asked for a different target relation than it
                                 32                 :                :  * really did, so that relations which must never be replication targets can
                                 33                 :                :  * be reached.  The private data is the new qualified name, as
                                 34                 :                :  * "nspname.relname".
                                 35                 :                :  */
                                 36                 :                : void
   19 msawada@postgresql.o       37                 :CBC           4 : logicalrep_relation_redirect(const char *name, const void *private_data,
                                 38                 :                :                              void *arg)
                                 39                 :                : {
                                 40                 :              4 :     LogicalRepRelation *rel = (LogicalRepRelation *) arg;
                                 41                 :              4 :     char       *target = pstrdup((const char *) private_data);
                                 42                 :              4 :     char       *sep = strchr(target, '.');
                                 43                 :                : 
                                 44         [ -  + ]:              4 :     if (sep == NULL)
   19 msawada@postgresql.o       45         [ #  # ]:UBC           0 :         elog(ERROR, "malformed target relation \"%s\"", target);
                                 46                 :                : 
   19 msawada@postgresql.o       47                 :CBC           4 :     *sep = '\0';
                                 48                 :              4 :     rel->nspname = target;
                                 49                 :              4 :     rel->relname = sep + 1;
                                 50                 :              4 : }
                                 51                 :                : 
                                 52                 :                : /*
                                 53                 :                :  * removable_cutoff - for syscache-update-pruned.spec
                                 54                 :                :  *
                                 55                 :                :  * Wrapper around GetOldestNonRemovableTransactionId().  In general, this can
                                 56                 :                :  * move backward.  runningcheck=false isolation tests can reasonably prevent
                                 57                 :                :  * that.  For the causes of backward movement, see
                                 58                 :                :  * postgr.es/m/CAEze2Wj%2BV0kTx86xB_YbyaqTr5hnE_igdWAwuhSyjXBYscf5-Q%40mail.gmail.com
                                 59                 :                :  * and the header comment for ComputeXidHorizons().  One can assume this
                                 60                 :                :  * doesn't move backward if one (a) passes a shared catalog as the argument
                                 61                 :                :  * and (b) arranges for concurrent activity not to reach AbortTransaction().
                                 62                 :                :  * Non-runningcheck tests can control most concurrent activity, except
                                 63                 :                :  * autovacuum and the isolationtester control connection.  AbortTransaction()
                                 64                 :                :  * in those would justify test failure.  Seeing autoanalyze can allocate an
                                 65                 :                :  * XID in any database, (a) ensures we'll consistently not ignore those XIDs.
                                 66                 :                :  */
  672 noah@leadboat.com          67                 :             89 : PG_FUNCTION_INFO_V1(removable_cutoff);
                                 68                 :                : Datum
                                 69                 :             12 : removable_cutoff(PG_FUNCTION_ARGS)
                                 70                 :                : {
                                 71                 :             12 :     Relation    rel = NULL;
                                 72                 :                :     TransactionId xid;
                                 73                 :                :     FullTransactionId next_fxid_before,
                                 74                 :                :                 next_fxid;
                                 75                 :                : 
                                 76                 :                :     /* could take other relkinds callee takes, but we've not yet needed it */
                                 77         [ +  - ]:             12 :     if (!PG_ARGISNULL(0))
                                 78                 :             12 :         rel = table_open(PG_GETARG_OID(0), AccessShareLock);
                                 79                 :                : 
  316 heikki.linnakangas@i       80   [ +  -  -  +  :             12 :     if (rel != NULL && !rel->rd_rel->relisshared && autovacuum_start_daemon)
                                              -  - ]
  598 noah@leadboat.com          81         [ #  # ]:UBC           0 :         elog(WARNING,
                                 82                 :                :              "removable_cutoff(non-shared-rel) can move backward under autovacuum=on");
                                 83                 :                : 
                                 84                 :                :     /*
                                 85                 :                :      * No lock or snapshot necessarily prevents oldestXid from advancing past
                                 86                 :                :      * "xid" while this function runs.  That concerns us only in that we must
                                 87                 :                :      * not ascribe "xid" to the wrong epoch.  (That may never arise in
                                 88                 :                :      * isolation testing, but let's set a good example.)  As a crude solution,
                                 89                 :                :      * retry until nextXid doesn't change.
                                 90                 :                :      */
  672 noah@leadboat.com          91                 :CBC          12 :     next_fxid = ReadNextFullTransactionId();
                                 92                 :                :     do
                                 93                 :                :     {
                                 94         [ -  + ]:             12 :         CHECK_FOR_INTERRUPTS();
                                 95                 :             12 :         next_fxid_before = next_fxid;
                                 96                 :             12 :         xid = GetOldestNonRemovableTransactionId(rel);
                                 97                 :             12 :         next_fxid = ReadNextFullTransactionId();
                                 98         [ -  + ]:             12 :     } while (!FullTransactionIdEquals(next_fxid, next_fxid_before));
                                 99                 :                : 
                                100         [ +  - ]:             12 :     if (rel)
                                101                 :             12 :         table_close(rel, AccessShareLock);
                                102                 :                : 
                                103                 :             12 :     PG_RETURN_FULLTRANSACTIONID(FullTransactionIdFromAllowableAt(next_fxid,
                                104                 :                :                                                                  xid));
                                105                 :                : }
        

Generated by: LCOV version 2.0-1