LCOV - differential code coverage report
Current view: top level - src/backend/access/transam - rmgr.c (source / functions) Coverage Total Hit UBC GNC CBC DCB
Current: Differential Code Coverage HEAD vs 15 Lines: 84.4 % 45 38 7 1 37 1
Current Date: 2023-04-08 17:13:01 Functions: 80.0 % 5 4 1 1 3 1
Baseline: 15 Line coverage date bins:
Baseline Date: 2023-04-08 15:09:40 (120,180] days: 100.0 % 2 2 1 1
Legend: Lines: hit not hit (240..) days: 83.7 % 43 36 7 36
Function coverage date bins:
(120,180] days: 100.0 % 1 1 1
(240..) days: 75.0 % 4 3 1 3

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

Generated by: LCOV version v1.16-55-g56c0a2a