LCOV - differential code coverage report
Current view: top level - src/backend/utils/activity - pgstat_subscription.c (source / functions) Coverage Total Hit UIC GBC GIC GNC CBC ECB
Current: Differential Code Coverage HEAD vs 15 Lines: 96.7 % 30 29 1 1 13 2 13 16
Current Date: 2023-04-08 17:13:01 Functions: 100.0 % 6 6 5 1 5
Baseline: 15 Line coverage date bins:
Baseline Date: 2023-04-08 15:09:40 (180,240] days: 100.0 % 2 2 2
Legend: Lines: hit not hit (240..) days: 96.4 % 28 27 1 1 13 13 13
Function coverage date bins:
(240..) days: 60.0 % 10 6 5 1 4

 Age         Owner                  TLA  Line data    Source code
                                  1                 : /* -------------------------------------------------------------------------
                                  2                 :  *
                                  3                 :  * pgstat_subscription.c
                                  4                 :  *    Implementation of subscription statistics.
                                  5                 :  *
                                  6                 :  * This file contains the implementation of subscription statistics. It is kept
                                  7                 :  * separate from pgstat.c to enforce the line between the statistics access /
                                  8                 :  * storage implementation and the details about individual types of
                                  9                 :  * statistics.
                                 10                 :  *
                                 11                 :  * Copyright (c) 2001-2023, PostgreSQL Global Development Group
                                 12                 :  *
                                 13                 :  * IDENTIFICATION
                                 14                 :  *    src/backend/utils/activity/pgstat_subscription.c
                                 15                 :  * -------------------------------------------------------------------------
                                 16                 :  */
                                 17                 : 
                                 18                 : #include "postgres.h"
                                 19                 : 
                                 20                 : #include "utils/pgstat_internal.h"
                                 21                 : 
                                 22                 : 
                                 23                 : /*
                                 24                 :  * Report a subscription error.
                                 25                 :  */
                                 26                 : void
  384 andres                     27 CBC          53 : pgstat_report_subscription_error(Oid subid, bool is_apply_error)
                                 28                 : {
                                 29                 :     PgStat_EntryRef *entry_ref;
                                 30                 :     PgStat_BackendSubEntry *pending;
                                 31                 : 
  368                            32              53 :     entry_ref = pgstat_prep_pending_entry(PGSTAT_KIND_SUBSCRIPTION,
                                 33                 :                                           InvalidOid, subid, NULL);
                                 34              53 :     pending = entry_ref->pending;
                                 35                 : 
                                 36              53 :     if (is_apply_error)
                                 37              45 :         pending->apply_error_count++;
                                 38                 :     else
                                 39               8 :         pending->sync_error_count++;
  384                            40              53 : }
                                 41                 : 
                                 42                 : /*
                                 43                 :  * Report creating the subscription.
  368 andres                     44 ECB             :  */
                                 45                 : void
  368 andres                     46 GIC         107 : pgstat_create_subscription(Oid subid)
  368 andres                     47 ECB             : {
                                 48                 :     /* Ensures that stats are dropped if transaction rolls back */
  368 andres                     49 GIC         107 :     pgstat_create_transactional(PGSTAT_KIND_SUBSCRIPTION,
                                 50                 :                                 InvalidOid, subid);
                                 51                 : 
                                 52                 :     /* Create and initialize the subscription stats entry */
  185 andres                     53 GNC         107 :     pgstat_get_entry_ref(PGSTAT_KIND_SUBSCRIPTION, InvalidOid, subid,
                                 54                 :                          true, NULL);
                                 55             107 :     pgstat_reset_entry(PGSTAT_KIND_SUBSCRIPTION, InvalidOid, subid, 0);
  368 andres                     56 GIC         107 : }
  368 andres                     57 ECB             : 
                                 58                 : /*
                                 59                 :  * Report dropping the subscription.
                                 60                 :  *
                                 61                 :  * Ensures that stats are dropped if transaction commits.
                                 62                 :  */
                                 63                 : void
  368 andres                     64 GIC          34 : pgstat_drop_subscription(Oid subid)
                                 65                 : {
                                 66              34 :     pgstat_drop_transactional(PGSTAT_KIND_SUBSCRIPTION,
                                 67                 :                               InvalidOid, subid);
  384 andres                     68 CBC          34 : }
                                 69                 : 
  368 andres                     70 ECB             : /*
                                 71                 :  * Support function for the SQL-callable pgstat* functions. Returns
                                 72                 :  * the collected statistics for one subscription or NULL.
                                 73                 :  */
                                 74                 : PgStat_StatSubEntry *
  368 andres                     75 GIC          29 : pgstat_fetch_stat_subscription(Oid subid)
                                 76                 : {
                                 77              29 :     return (PgStat_StatSubEntry *)
                                 78              29 :         pgstat_fetch_entry(PGSTAT_KIND_SUBSCRIPTION, InvalidOid, subid);
  368 andres                     79 ECB             : }
                                 80                 : 
                                 81                 : /*
                                 82                 :  * Flush out pending stats for the entry
                                 83                 :  *
                                 84                 :  * If nowait is true, this function returns false if lock could not
                                 85                 :  * immediately acquired, otherwise true is returned.
                                 86                 :  */
                                 87                 : bool
  368 andres                     88 GIC          53 : pgstat_subscription_flush_cb(PgStat_EntryRef *entry_ref, bool nowait)
                                 89                 : {
                                 90                 :     PgStat_BackendSubEntry *localent;
                                 91                 :     PgStatShared_Subscription *shsubent;
  368 andres                     92 ECB             : 
  368 andres                     93 GIC          53 :     localent = (PgStat_BackendSubEntry *) entry_ref->pending;
                                 94              53 :     shsubent = (PgStatShared_Subscription *) entry_ref->shared_stats;
                                 95                 : 
                                 96                 :     /* localent always has non-zero content */
  368 andres                     97 ECB             : 
  368 andres                     98 CBC          53 :     if (!pgstat_lock_entry(entry_ref, nowait))
  368 andres                     99 UIC           0 :         return false;
                                100                 : 
                                101                 : #define SUB_ACC(fld) shsubent->stats.fld += localent->fld
  368 andres                    102 CBC          53 :     SUB_ACC(apply_error_count);
  368 andres                    103 GBC          53 :     SUB_ACC(sync_error_count);
                                104                 : #undef SUB_ACC
                                105                 : 
  368 andres                    106 CBC          53 :     pgstat_unlock_entry(entry_ref);
                                107              53 :     return true;
                                108                 : }
                                109                 : 
  368 andres                    110 ECB             : void
  368 andres                    111 CBC         119 : pgstat_subscription_reset_timestamp_cb(PgStatShared_Common *header, TimestampTz ts)
                                112                 : {
  368 andres                    113 GIC         119 :     ((PgStatShared_Subscription *) header)->stats.stat_reset_timestamp = ts;
                                114             119 : }
        

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