PostgreSQL Source Code  git master
pgstat_archiver.c File Reference
#include "postgres.h"
#include "utils/pgstat_internal.h"
#include "utils/timestamp.h"
Include dependency graph for pgstat_archiver.c:

Go to the source code of this file.

Functions

void pgstat_report_archiver (const char *xlog, bool failed)
 
PgStat_ArchiverStatspgstat_fetch_stat_archiver (void)
 
void pgstat_archiver_init_shmem_cb (void *stats)
 
void pgstat_archiver_reset_all_cb (TimestampTz ts)
 
void pgstat_archiver_snapshot_cb (void)
 

Function Documentation

◆ pgstat_archiver_init_shmem_cb()

void pgstat_archiver_init_shmem_cb ( void *  stats)

Definition at line 66 of file pgstat_archiver.c.

67 {
68  PgStatShared_Archiver *stats_shmem = (PgStatShared_Archiver *) stats;
69 
71 }
void LWLockInitialize(LWLock *lock, int tranche_id)
Definition: lwlock.c:707
@ LWTRANCHE_PGSTATS_DATA
Definition: lwlock.h:205

References PgStatShared_Archiver::lock, LWLockInitialize(), and LWTRANCHE_PGSTATS_DATA.

◆ pgstat_archiver_reset_all_cb()

void pgstat_archiver_reset_all_cb ( TimestampTz  ts)

Definition at line 74 of file pgstat_archiver.c.

75 {
77 
78  /* see explanation above PgStatShared_Archiver for the reset protocol */
79  LWLockAcquire(&stats_shmem->lock, LW_EXCLUSIVE);
81  &stats_shmem->stats,
82  sizeof(stats_shmem->stats),
83  &stats_shmem->changecount);
84  stats_shmem->stats.stat_reset_timestamp = ts;
85  LWLockRelease(&stats_shmem->lock);
86 }
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1168
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1781
@ LW_EXCLUSIVE
Definition: lwlock.h:114
PgStat_LocalState pgStatLocal
Definition: pgstat.c:212
static void pgstat_copy_changecounted_stats(void *dst, void *src, size_t len, uint32 *cc)
PgStat_ArchiverStats reset_offset
PgStat_ArchiverStats stats
TimestampTz stat_reset_timestamp
Definition: pgstat.h:282
PgStat_ShmemControl * shmem
PgStatShared_Archiver archiver

References PgStat_ShmemControl::archiver, PgStatShared_Archiver::changecount, PgStatShared_Archiver::lock, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), pgstat_copy_changecounted_stats(), pgStatLocal, PgStatShared_Archiver::reset_offset, PgStat_LocalState::shmem, PgStat_ArchiverStats::stat_reset_timestamp, and PgStatShared_Archiver::stats.

◆ pgstat_archiver_snapshot_cb()

void pgstat_archiver_snapshot_cb ( void  )

Definition at line 89 of file pgstat_archiver.c.

90 {
93  PgStat_ArchiverStats *reset_offset = &stats_shmem->reset_offset;
95 
97  &stats_shmem->stats,
98  sizeof(stats_shmem->stats),
99  &stats_shmem->changecount);
100 
101  LWLockAcquire(&stats_shmem->lock, LW_SHARED);
102  memcpy(&reset, reset_offset, sizeof(stats_shmem->stats));
103  LWLockRelease(&stats_shmem->lock);
104 
105  /* compensate by reset offsets */
106  if (stat_snap->archived_count == reset.archived_count)
107  {
108  stat_snap->last_archived_wal[0] = 0;
109  stat_snap->last_archived_timestamp = 0;
110  }
111  stat_snap->archived_count -= reset.archived_count;
112 
113  if (stat_snap->failed_count == reset.failed_count)
114  {
115  stat_snap->last_failed_wal[0] = 0;
116  stat_snap->last_failed_timestamp = 0;
117  }
118  stat_snap->failed_count -= reset.failed_count;
119 }
@ LW_SHARED
Definition: lwlock.h:115
void reset(void)
Definition: sql-declare.c:600
TimestampTz last_failed_timestamp
Definition: pgstat.h:281
TimestampTz last_archived_timestamp
Definition: pgstat.h:277
char last_failed_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:279
PgStat_Counter failed_count
Definition: pgstat.h:278
PgStat_Counter archived_count
Definition: pgstat.h:274
char last_archived_wal[MAX_XFN_CHARS+1]
Definition: pgstat.h:275
PgStat_Snapshot snapshot
PgStat_ArchiverStats archiver

References PgStat_ArchiverStats::archived_count, PgStat_ShmemControl::archiver, PgStat_Snapshot::archiver, PgStatShared_Archiver::changecount, PgStat_ArchiverStats::failed_count, PgStat_ArchiverStats::last_archived_timestamp, PgStat_ArchiverStats::last_archived_wal, PgStat_ArchiverStats::last_failed_timestamp, PgStat_ArchiverStats::last_failed_wal, PgStatShared_Archiver::lock, LW_SHARED, LWLockAcquire(), LWLockRelease(), pgstat_copy_changecounted_stats(), pgStatLocal, reset(), PgStatShared_Archiver::reset_offset, PgStat_LocalState::shmem, PgStat_LocalState::snapshot, and PgStatShared_Archiver::stats.

◆ pgstat_fetch_stat_archiver()

PgStat_ArchiverStats* pgstat_fetch_stat_archiver ( void  )

Definition at line 58 of file pgstat_archiver.c.

59 {
61 
63 }
void pgstat_snapshot_fixed(PgStat_Kind kind)
Definition: pgstat.c:1068
#define PGSTAT_KIND_ARCHIVER
Definition: pgstat.h:54

References PgStat_Snapshot::archiver, PGSTAT_KIND_ARCHIVER, pgstat_snapshot_fixed(), pgStatLocal, and PgStat_LocalState::snapshot.

Referenced by pg_stat_get_archiver().

◆ pgstat_report_archiver()

void pgstat_report_archiver ( const char *  xlog,
bool  failed 
)

Definition at line 28 of file pgstat_archiver.c.

29 {
32 
34 
35  if (failed)
36  {
37  ++stats_shmem->stats.failed_count;
38  memcpy(&stats_shmem->stats.last_failed_wal, xlog,
39  sizeof(stats_shmem->stats.last_failed_wal));
40  stats_shmem->stats.last_failed_timestamp = now;
41  }
42  else
43  {
44  ++stats_shmem->stats.archived_count;
45  memcpy(&stats_shmem->stats.last_archived_wal, xlog,
46  sizeof(stats_shmem->stats.last_archived_wal));
47  stats_shmem->stats.last_archived_timestamp = now;
48  }
49 
51 }
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1644
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1608
int64 TimestampTz
Definition: timestamp.h:39
static void pgstat_end_changecount_write(uint32 *cc)
static void pgstat_begin_changecount_write(uint32 *cc)

References PgStat_ArchiverStats::archived_count, PgStat_ShmemControl::archiver, PgStatShared_Archiver::changecount, PgStat_ArchiverStats::failed_count, GetCurrentTimestamp(), PgStat_ArchiverStats::last_archived_timestamp, PgStat_ArchiverStats::last_archived_wal, PgStat_ArchiverStats::last_failed_timestamp, PgStat_ArchiverStats::last_failed_wal, now(), pgstat_begin_changecount_write(), pgstat_end_changecount_write(), pgStatLocal, PgStat_LocalState::shmem, and PgStatShared_Archiver::stats.

Referenced by pgarch_ArchiverCopyLoop().