LCOV - differential code coverage report
Current view: top level - src/backend/access/transam - rmgr.c (source / functions) Coverage Total Hit UBC CBC
Current: Differential Code Coverage 16@8cea358b128 vs 17@8cea358b128 Lines: 84.4 % 45 38 7 38
Current Date: 2024-04-14 14:21:10 Functions: 80.0 % 5 4 1 4
Baseline: 16@8cea358b128 Branches: 58.7 % 46 27 19 27
Baseline Date: 2024-04-14 14:21:09 Line coverage date bins:
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed (240..) days: 84.4 % 45 38 7 38
Function coverage date bins:
(240..) days: 80.0 % 5 4 1 4
Branch coverage date bins:
(240..) days: 58.7 % 46 27 19 27

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*
                                  2                 :                :  * rmgr.c
                                  3                 :                :  *
                                  4                 :                :  * Resource managers definition
                                  5                 :                :  *
                                  6                 :                :  * src/backend/access/transam/rmgr.c
                                  7                 :                :  */
                                  8                 :                : #include "postgres.h"
                                  9                 :                : 
                                 10                 :                : #include "access/rmgr.h"
                                 11                 :                : #include "access/xlog_internal.h"
                                 12                 :                : #include "fmgr.h"
                                 13                 :                : #include "funcapi.h"
                                 14                 :                : #include "miscadmin.h"
                                 15                 :                : #include "nodes/execnodes.h"
                                 16                 :                : #include "utils/builtins.h"
                                 17                 :                : #include "utils/fmgrprotos.h"
                                 18                 :                : #include "utils/tuplestore.h"
                                 19                 :                : 
                                 20                 :                : /* includes needed for "access/rmgrlist.h" */
                                 21                 :                : /* IWYU pragma: begin_keep */
                                 22                 :                : #include "access/brin_xlog.h"
                                 23                 :                : #include "access/clog.h"
                                 24                 :                : #include "access/commit_ts.h"
                                 25                 :                : #include "access/generic_xlog.h"
                                 26                 :                : #include "access/ginxlog.h"
                                 27                 :                : #include "access/gistxlog.h"
                                 28                 :                : #include "access/hash_xlog.h"
                                 29                 :                : #include "access/heapam_xlog.h"
                                 30                 :                : #include "access/multixact.h"
                                 31                 :                : #include "access/nbtxlog.h"
                                 32                 :                : #include "access/spgxlog.h"
                                 33                 :                : #include "access/xact.h"
                                 34                 :                : #include "catalog/storage_xlog.h"
                                 35                 :                : #include "commands/dbcommands_xlog.h"
                                 36                 :                : #include "commands/sequence.h"
                                 37                 :                : #include "commands/tablespace.h"
                                 38                 :                : #include "replication/decode.h"
                                 39                 :                : #include "replication/message.h"
                                 40                 :                : #include "replication/origin.h"
                                 41                 :                : #include "storage/standby.h"
                                 42                 :                : #include "utils/relmapper.h"
                                 43                 :                : /* IWYU pragma: end_keep */
                                 44                 :                : 
                                 45                 :                : 
                                 46                 :                : /* must be kept in sync with RmgrData definition in xlog_internal.h */
                                 47                 :                : #define PG_RMGR(symname,name,redo,desc,identify,startup,cleanup,mask,decode) \
                                 48                 :                :     { name, redo, desc, identify, startup, cleanup, mask, decode },
                                 49                 :                : 
                                 50                 :                : RmgrData    RmgrTable[RM_MAX_ID + 1] = {
                                 51                 :                : #include "access/rmgrlist.h"
                                 52                 :                : };
                                 53                 :                : 
                                 54                 :                : /*
                                 55                 :                :  * Start up all resource managers.
                                 56                 :                :  */
                                 57                 :                : void
  739 jdavis@postgresql.or       58                 :CBC         232 : RmgrStartup(void)
                                 59                 :                : {
                                 60         [ +  + ]:          59624 :     for (int rmid = 0; rmid <= RM_MAX_ID; rmid++)
                                 61                 :                :     {
                                 62         [ +  + ]:          59392 :         if (!RmgrIdExists(rmid))
                                 63                 :          54288 :             continue;
                                 64                 :                : 
                                 65         [ +  + ]:           5104 :         if (RmgrTable[rmid].rm_startup != NULL)
                                 66                 :            928 :             RmgrTable[rmid].rm_startup();
                                 67                 :                :     }
                                 68                 :            232 : }
                                 69                 :                : 
                                 70                 :                : /*
                                 71                 :                :  * Clean up all resource managers.
                                 72                 :                :  */
                                 73                 :                : void
                                 74                 :            140 : RmgrCleanup(void)
                                 75                 :                : {
                                 76         [ +  + ]:          35980 :     for (int rmid = 0; rmid <= RM_MAX_ID; rmid++)
                                 77                 :                :     {
                                 78         [ +  + ]:          35840 :         if (!RmgrIdExists(rmid))
                                 79                 :          32760 :             continue;
                                 80                 :                : 
                                 81         [ +  + ]:           3080 :         if (RmgrTable[rmid].rm_cleanup != NULL)
                                 82                 :            560 :             RmgrTable[rmid].rm_cleanup();
                                 83                 :                :     }
                                 84                 :            140 : }
                                 85                 :                : 
                                 86                 :                : /*
                                 87                 :                :  * Emit ERROR when we encounter a record with an RmgrId we don't
                                 88                 :                :  * recognize.
                                 89                 :                :  */
                                 90                 :                : void
  739 jdavis@postgresql.or       91                 :UBC           0 : RmgrNotFound(RmgrId rmid)
                                 92                 :                : {
                                 93         [ #  # ]:              0 :     ereport(ERROR, (errmsg("resource manager with ID %d not registered", rmid),
                                 94                 :                :                     errhint("Include the extension module that implements this resource manager in shared_preload_libraries.")));
                                 95                 :                : }
                                 96                 :                : 
                                 97                 :                : /*
                                 98                 :                :  * Register a new custom WAL resource manager.
                                 99                 :                :  *
                                100                 :                :  * Resource manager IDs must be globally unique across all extensions. Refer
                                101                 :                :  * to https://wiki.postgresql.org/wiki/CustomWALResourceManagers to reserve a
                                102                 :                :  * unique RmgrId for your extension, to avoid conflicts with other extension
                                103                 :                :  * developers. During development, use RM_EXPERIMENTAL_ID to avoid needlessly
                                104                 :                :  * reserving a new ID.
                                105                 :                :  */
                                106                 :                : void
  516 jdavis@postgresql.or      107                 :CBC           1 : RegisterCustomRmgr(RmgrId rmid, const RmgrData *rmgr)
                                108                 :                : {
  739                           109   [ +  -  -  + ]:              1 :     if (rmgr->rm_name == NULL || strlen(rmgr->rm_name) == 0)
  739 jdavis@postgresql.or      110         [ #  # ]:UBC           0 :         ereport(ERROR, (errmsg("custom resource manager name is invalid"),
                                111                 :                :                         errhint("Provide a non-empty name for the custom resource manager.")));
                                112                 :                : 
  738 jdavis@postgresql.or      113         [ -  + ]:CBC           1 :     if (!RmgrIdIsCustom(rmid))
  739 jdavis@postgresql.or      114         [ #  # ]:UBC           0 :         ereport(ERROR, (errmsg("custom resource manager ID %d is out of range", rmid),
                                115                 :                :                         errhint("Provide a custom resource manager ID between %d and %d.",
                                116                 :                :                                 RM_MIN_CUSTOM_ID, RM_MAX_CUSTOM_ID)));
                                117                 :                : 
  739 jdavis@postgresql.or      118         [ -  + ]:CBC           1 :     if (!process_shared_preload_libraries_in_progress)
  739 jdavis@postgresql.or      119         [ #  # ]:UBC           0 :         ereport(ERROR,
                                120                 :                :                 (errmsg("failed to register custom resource manager \"%s\" with ID %d", rmgr->rm_name, rmid),
                                121                 :                :                  errdetail("Custom resource manager must be registered while initializing modules in shared_preload_libraries.")));
                                122                 :                : 
  739 jdavis@postgresql.or      123         [ -  + ]:CBC           1 :     if (RmgrTable[rmid].rm_name != NULL)
  739 jdavis@postgresql.or      124         [ #  # ]:UBC           0 :         ereport(ERROR,
                                125                 :                :                 (errmsg("failed to register custom resource manager \"%s\" with ID %d", rmgr->rm_name, rmid),
                                126                 :                :                  errdetail("Custom resource manager \"%s\" already registered with the same ID.",
                                127                 :                :                            RmgrTable[rmid].rm_name)));
                                128                 :                : 
                                129                 :                :     /* check for existing rmgr with the same name */
  739 jdavis@postgresql.or      130         [ +  + ]:CBC         257 :     for (int existing_rmid = 0; existing_rmid <= RM_MAX_ID; existing_rmid++)
                                131                 :                :     {
                                132         [ +  + ]:            256 :         if (!RmgrIdExists(existing_rmid))
                                133                 :            234 :             continue;
                                134                 :                : 
                                135         [ -  + ]:             22 :         if (!pg_strcasecmp(RmgrTable[existing_rmid].rm_name, rmgr->rm_name))
  739 jdavis@postgresql.or      136         [ #  # ]:UBC           0 :             ereport(ERROR,
                                137                 :                :                     (errmsg("failed to register custom resource manager \"%s\" with ID %d", rmgr->rm_name, rmid),
                                138                 :                :                      errdetail("Existing resource manager with ID %d has the same name.", existing_rmid)));
                                139                 :                :     }
                                140                 :                : 
                                141                 :                :     /* register it */
  739 jdavis@postgresql.or      142                 :CBC           1 :     RmgrTable[rmid] = *rmgr;
                                143         [ +  - ]:              1 :     ereport(LOG,
                                144                 :                :             (errmsg("registered custom resource manager \"%s\" with ID %d",
                                145                 :                :                     rmgr->rm_name, rmid)));
                                146                 :              1 : }
                                147                 :                : 
                                148                 :                : /* SQL SRF showing loaded resource managers */
                                149                 :                : Datum
                                150                 :              1 : pg_get_wal_resource_managers(PG_FUNCTION_ARGS)
                                151                 :                : {
                                152                 :                : #define PG_GET_RESOURCE_MANAGERS_COLS 3
                                153                 :              1 :     ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
                                154                 :                :     Datum       values[PG_GET_RESOURCE_MANAGERS_COLS];
                                155                 :              1 :     bool        nulls[PG_GET_RESOURCE_MANAGERS_COLS] = {0};
                                156                 :                : 
  544 michael@paquier.xyz       157                 :              1 :     InitMaterializedSRF(fcinfo, 0);
                                158                 :                : 
  739 jdavis@postgresql.or      159         [ +  + ]:            257 :     for (int rmid = 0; rmid <= RM_MAX_ID; rmid++)
                                160                 :                :     {
                                161         [ +  + ]:            256 :         if (!RmgrIdExists(rmid))
                                162                 :            233 :             continue;
                                163                 :             23 :         values[0] = Int32GetDatum(rmid);
                                164                 :             23 :         values[1] = CStringGetTextDatum(GetRmgr(rmid).rm_name);
  738                           165                 :             23 :         values[2] = BoolGetDatum(RmgrIdIsBuiltin(rmid));
  739                           166                 :             23 :         tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
                                167                 :                :     }
                                168                 :                : 
                                169                 :              1 :     return (Datum) 0;
                                170                 :                : }
        

Generated by: LCOV version 2.1-beta2-3-g6141622