LCOV - code coverage report
Current view: top level - src/backend/utils/activity - pgstat_subscription.c (source / functions) Hit Total Coverage
Test: PostgreSQL 16devel Lines: 27 28 96.4 %
Date: 2022-08-17 04:10:37 Functions: 6 6 100.0 %
Legend: Lines: hit not hit

          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-2022, 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
      27          80 : pgstat_report_subscription_error(Oid subid, bool is_apply_error)
      28             : {
      29             :     PgStat_EntryRef *entry_ref;
      30             :     PgStat_BackendSubEntry *pending;
      31             : 
      32          80 :     entry_ref = pgstat_prep_pending_entry(PGSTAT_KIND_SUBSCRIPTION,
      33             :                                           InvalidOid, subid, NULL);
      34          80 :     pending = entry_ref->pending;
      35             : 
      36          80 :     if (is_apply_error)
      37          66 :         pending->apply_error_count++;
      38             :     else
      39          14 :         pending->sync_error_count++;
      40          80 : }
      41             : 
      42             : /*
      43             :  * Report creating the subscription.
      44             :  *
      45             :  * Ensures that stats are dropped if transaction rolls back.
      46             :  */
      47             : void
      48         184 : pgstat_create_subscription(Oid subid)
      49             : {
      50         184 :     pgstat_create_transactional(PGSTAT_KIND_SUBSCRIPTION,
      51             :                                 InvalidOid, subid);
      52         184 : }
      53             : 
      54             : /*
      55             :  * Report dropping the subscription.
      56             :  *
      57             :  * Ensures that stats are dropped if transaction commits.
      58             :  */
      59             : void
      60          46 : pgstat_drop_subscription(Oid subid)
      61             : {
      62          46 :     pgstat_drop_transactional(PGSTAT_KIND_SUBSCRIPTION,
      63             :                               InvalidOid, subid);
      64          46 : }
      65             : 
      66             : /*
      67             :  * Support function for the SQL-callable pgstat* functions. Returns
      68             :  * the collected statistics for one subscription or NULL.
      69             :  */
      70             : PgStat_StatSubEntry *
      71          34 : pgstat_fetch_stat_subscription(Oid subid)
      72             : {
      73          34 :     return (PgStat_StatSubEntry *)
      74          34 :         pgstat_fetch_entry(PGSTAT_KIND_SUBSCRIPTION, InvalidOid, subid);
      75             : }
      76             : 
      77             : /*
      78             :  * Flush out pending stats for the entry
      79             :  *
      80             :  * If nowait is true, this function returns false if lock could not
      81             :  * immediately acquired, otherwise true is returned.
      82             :  */
      83             : bool
      84          80 : pgstat_subscription_flush_cb(PgStat_EntryRef *entry_ref, bool nowait)
      85             : {
      86             :     PgStat_BackendSubEntry *localent;
      87             :     PgStatShared_Subscription *shsubent;
      88             : 
      89          80 :     localent = (PgStat_BackendSubEntry *) entry_ref->pending;
      90          80 :     shsubent = (PgStatShared_Subscription *) entry_ref->shared_stats;
      91             : 
      92             :     /* localent always has non-zero content */
      93             : 
      94          80 :     if (!pgstat_lock_entry(entry_ref, nowait))
      95           0 :         return false;
      96             : 
      97             : #define SUB_ACC(fld) shsubent->stats.fld += localent->fld
      98          80 :     SUB_ACC(apply_error_count);
      99          80 :     SUB_ACC(sync_error_count);
     100             : #undef SUB_ACC
     101             : 
     102          80 :     pgstat_unlock_entry(entry_ref);
     103          80 :     return true;
     104             : }
     105             : 
     106             : void
     107          12 : pgstat_subscription_reset_timestamp_cb(PgStatShared_Common *header, TimestampTz ts)
     108             : {
     109          12 :     ((PgStatShared_Subscription *) header)->stats.stat_reset_timestamp = ts;
     110          12 : }

Generated by: LCOV version 1.14