21 #define PGSTAT_ENTRY_REF_HASH_SIZE 128
33 #define SH_PREFIX pgstat_entry_ref_hash
34 #define SH_ELEMENT_TYPE PgStat_EntryRefHashEntry
35 #define SH_KEY_TYPE PgStat_HashKey
37 #define SH_HASH_KEY(tb, key) \
38 pgstat_hash_hash_key(&key, sizeof(PgStat_HashKey), NULL)
39 #define SH_EQUAL(tb, a, b) \
40 pgstat_cmp_hash_key(&a, &b, sizeof(PgStat_HashKey), NULL) == 0
41 #define SH_SCOPE static inline
154 char *p = (
char *) ctl;
276 shheader->
magic = 0xdeadbeef;
279 shhashent->
body = chunk;
377 Assert(entry_ref->shared_entry != NULL);
378 Assert(entry_ref->shared_stats != NULL);
380 Assert(entry_ref->shared_stats->magic == 0xdeadbeef);
409 Assert(create || created_entry == NULL);
417 if (created_entry != NULL)
418 *created_entry =
false;
437 Assert(entry_ref != NULL);
445 if (create && !shhashent)
460 if (created_entry != NULL)
461 *created_entry =
true;
485 if (shhashent->
dropped && create)
498 if (created_entry != NULL)
499 *created_entry =
true;
522 bool discard_pending)
524 if (entry_ref && entry_ref->
pending)
529 elog(
ERROR,
"releasing ref with pending data");
558 elog(
ERROR,
"could not find just referenced shared stats entry");
568 elog(
ERROR,
"entry ref vanished before deletion");
652 pgstat_entry_ref_hash_iterator
i;
674 if (entry_ref->
pending != NULL)
687 pgstat_entry_ref_hash_iterator
i;
700 if (match && !match(ent, match_data))
812 uint64 not_freed_count = 0;
853 if (not_freed_count > 0)
899 uint64 not_freed_count = 0;
912 if (not_freed_count > 0)
968 if (!do_reset(p, match_data))
1000 "PgStat Shared Ref",
1005 "PgStat Shared Ref Hash",
static uint32 pg_atomic_sub_fetch_u32(volatile pg_atomic_uint32 *ptr, int32 sub_)
static uint32 pg_atomic_fetch_sub_u32(volatile pg_atomic_uint32 *ptr, int32 sub_)
static void pg_atomic_init_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
static uint32 pg_atomic_fetch_add_u32(volatile pg_atomic_uint32 *ptr, int32 add_)
static uint64 pg_atomic_fetch_add_u64(volatile pg_atomic_uint64 *ptr, int64 add_)
static uint32 pg_atomic_read_u32(volatile pg_atomic_uint32 *ptr)
static void pg_atomic_init_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
static uint64 pg_atomic_read_u64(volatile pg_atomic_uint64 *ptr)
#define PG_USED_FOR_ASSERTS_ONLY
#define OidIsValid(objectId)
elog(ERROR, "%s: %s", p2, msg)
dsa_area * dsa_create_in_place(void *place, size_t size, int tranche_id, dsm_segment *segment)
void * dsa_get_address(dsa_area *area, dsa_pointer dp)
void dsa_set_size_limit(dsa_area *area, size_t limit)
void dsa_pin_mapping(dsa_area *area)
void dsa_detach(dsa_area *area)
dsa_area * dsa_attach_in_place(void *place, dsm_segment *segment)
void dsa_free(dsa_area *area, dsa_pointer dp)
size_t dsa_minimum_size(void)
void dsa_pin(dsa_area *area)
#define dsa_allocate0(area, size)
#define InvalidDsaPointer
void dshash_delete_entry(dshash_table *hash_table, void *entry)
void dshash_release_lock(dshash_table *hash_table, void *entry)
void dshash_detach(dshash_table *hash_table)
void dshash_seq_init(dshash_seq_status *status, dshash_table *hash_table, bool exclusive)
void * dshash_find(dshash_table *hash_table, const void *key, bool exclusive)
dshash_table_handle dshash_get_hash_table_handle(dshash_table *hash_table)
void dshash_seq_term(dshash_seq_status *status)
void * dshash_find_or_insert(dshash_table *hash_table, const void *key, bool *found)
dshash_table * dshash_attach(dsa_area *area, const dshash_parameters *params, dshash_table_handle handle, void *arg)
dshash_table * dshash_create(dsa_area *area, const dshash_parameters *params, void *arg)
void * dshash_seq_next(dshash_seq_status *status)
void dshash_delete_current(dshash_seq_status *status)
Assert(fmt[strlen(fmt) - 1] !='\n')
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
void LWLockRelease(LWLock *lock)
void LWLockInitialize(LWLock *lock, int tranche_id)
bool LWLockConditionalAcquire(LWLock *lock, LWLockMode mode)
void pfree(void *pointer)
MemoryContext TopMemoryContext
void * MemoryContextAlloc(MemoryContext context, Size size)
#define AllocSetContextCreate
#define ALLOCSET_SMALL_SIZES
#define BACKEND_NUM_TYPES
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
const PgStat_KindInfo * pgstat_get_kind_info(PgStat_Kind kind)
void pgstat_delete_pending_entry(PgStat_EntryRef *entry_ref)
PgStat_LocalState pgStatLocal
static uint32 pgstat_hash_hash_key(const void *d, size_t size, void *arg)
static int pgstat_cmp_hash_key(const void *a, const void *b, size_t size, void *arg)
static void * pgstat_get_entry_data(PgStat_Kind kind, PgStatShared_Common *entry)
#define pgstat_assert_is_up()
struct PgStat_HashKey PgStat_HashKey
static size_t pgstat_get_entry_len(PgStat_Kind kind)
static bool match_db(PgStat_EntryRefHashEntry *ent, Datum match_data)
static void pgstat_setup_memcxt(void)
void pgstat_reset_entries_of_kind(PgStat_Kind kind, TimestampTz ts)
void pgstat_request_entry_refs_gc(void)
static void pgstat_release_db_entry_refs(Oid dboid)
PgStatShared_Common * pgstat_init_entry(PgStat_Kind kind, PgStatShared_HashEntry *shhashent)
static Size pgstat_dsa_init_size(void)
static bool match_kind(PgStatShared_HashEntry *p, Datum match_data)
static MemoryContext pgStatEntryRefHashContext
void StatsShmemInit(void)
bool pgstat_lock_entry_shared(PgStat_EntryRef *entry_ref, bool nowait)
void pgstat_attach_shmem(void)
static void pgstat_free_entry(PgStatShared_HashEntry *shent, dshash_seq_status *hstat)
static int pgStatSharedRefAge
#define PGSTAT_ENTRY_REF_HASH_SIZE
static void shared_stat_reset_contents(PgStat_Kind kind, PgStatShared_Common *header, TimestampTz ts)
static void pgstat_setup_shared_refs(void)
static void pgstat_release_entry_ref(PgStat_HashKey key, PgStat_EntryRef *entry_ref, bool discard_pending)
static void pgstat_drop_database_and_contents(Oid dboid)
static PgStatShared_Common * pgstat_reinit_entry(PgStat_Kind kind, PgStatShared_HashEntry *shhashent)
static pgstat_entry_ref_hash_hash * pgStatEntryRefHash
void pgstat_reset_entry(PgStat_Kind kind, Oid dboid, Oid objoid, TimestampTz ts)
Size StatsShmemSize(void)
static void pgstat_acquire_entry_ref(PgStat_EntryRef *entry_ref, PgStatShared_HashEntry *shhashent, PgStatShared_Common *shheader)
static MemoryContext pgStatSharedRefContext
void pgstat_reset_matching_entries(bool(*do_reset)(PgStatShared_HashEntry *, Datum), Datum match_data, TimestampTz ts)
void pgstat_drop_all_entries(void)
static const dshash_parameters dsh_params
PgStat_EntryRef * pgstat_get_entry_ref(PgStat_Kind kind, Oid dboid, Oid objoid, bool create, bool *created_entry)
static bool pgstat_get_entry_ref_cached(PgStat_HashKey key, PgStat_EntryRef **entry_ref_p)
void pgstat_unlock_entry(PgStat_EntryRef *entry_ref)
static void pgstat_release_all_entry_refs(bool discard_pending)
struct PgStat_EntryRefHashEntry PgStat_EntryRefHashEntry
static void pgstat_release_matching_entry_refs(bool discard_pending, ReleaseMatchCB match, Datum match_data)
bool(* ReleaseMatchCB)(PgStat_EntryRefHashEntry *, Datum data)
bool pgstat_drop_entry(PgStat_Kind kind, Oid dboid, Oid objoid)
bool pgstat_lock_entry(PgStat_EntryRef *entry_ref, bool nowait)
static void pgstat_gc_entry_refs(void)
static bool pgstat_need_entry_refs_gc(void)
static bool pgstat_drop_entry_internal(PgStatShared_HashEntry *shent, dshash_seq_status *hstat)
void pgstat_detach_shmem(void)
PgStat_EntryRef * pgstat_get_entry_ref_locked(PgStat_Kind kind, Oid dboid, Oid objoid, bool nowait)
static Oid DatumGetObjectId(Datum X)
static Datum ObjectIdGetDatum(Oid X)
static Datum Int32GetDatum(int32 X)
static int32 DatumGetInt32(Datum X)
Size add_size(Size s1, Size s2)
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
pg_atomic_uint32 refcount
LWLock locks[BACKEND_NUM_TYPES]
PgStat_EntryRef * entry_ref
PgStatShared_Common * shared_stats
PgStatShared_HashEntry * shared_entry
void(* reset_timestamp_cb)(PgStatShared_Common *header, TimestampTz ts)
dshash_table * shared_hash
PgStat_ShmemControl * shmem
dshash_table_handle hash_handle
pg_atomic_uint64 gc_request_count
PgStatShared_Archiver archiver
PgStatShared_Checkpointer checkpointer
PgStatShared_BgWriter bgwriter