LCOV - code coverage report
Current view: top level - src/test/modules/injection_points - regress_injection.c (source / functions) Coverage Total Hit
Test: PostgreSQL 20devel Lines: 92.3 % 26 24
Test Date: 2026-11-25 14:16:11 Functions: 100.0 % 3 3
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 35.0 % 20 7

             Branch data     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
      37                 :           8 : logicalrep_relation_redirect(const char *name, const void *private_data,
      38                 :             :                              void *arg)
      39                 :             : {
      40                 :           8 :     LogicalRepRelation *rel = (LogicalRepRelation *) arg;
      41                 :           8 :     char       *target = pstrdup((const char *) private_data);
      42                 :           8 :     char       *sep = strchr(target, '.');
      43                 :             : 
      44         [ -  + ]:           8 :     if (sep == NULL)
      45         [ #  # ]:           0 :         elog(ERROR, "malformed target relation \"%s\"", target);
      46                 :             : 
      47                 :           8 :     *sep = '\0';
      48                 :           8 :     rel->nspname = target;
      49                 :           8 :     rel->relname = sep + 1;
      50                 :           8 : }
      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                 :             :  */
      67                 :          90 : 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                 :             : 
      80   [ +  -  -  +  :          12 :     if (rel != NULL && !rel->rd_rel->relisshared && autovacuum_start_daemon)
                   -  - ]
      81         [ #  # ]:           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                 :             :      */
      91                 :          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