From 2e4ccf1b4508cc337bb4d0afff1e32a049d549fc Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 6 Apr 2025 11:37:09 -0400 Subject: [PATCH] Use "(void)" to mark pgstat_lock_entry(..., false) calls. This should silence Coverity's complaints about the result being sometimes ignored. I'm inclined to think that these routines are simply misdesigned, because sometimes it's okay to ignore the result and sometimes it isn't, and we have no way to enforce the latter. But for now I just added a comment. --- src/backend/utils/activity/pgstat.c | 2 +- src/backend/utils/activity/pgstat_database.c | 2 +- src/backend/utils/activity/pgstat_shmem.c | 11 ++++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/backend/utils/activity/pgstat.c b/src/backend/utils/activity/pgstat.c index 0005021f644..21bdff106a9 100644 --- a/src/backend/utils/activity/pgstat.c +++ b/src/backend/utils/activity/pgstat.c @@ -1019,7 +1019,7 @@ pgstat_fetch_entry(PgStat_Kind kind, Oid dboid, uint64 objid) stats_data = MemoryContextAlloc(pgStatLocal.snapshot.context, kind_info->shared_data_len); - pgstat_lock_entry_shared(entry_ref, false); + (void) pgstat_lock_entry_shared(entry_ref, false); memcpy(stats_data, pgstat_get_entry_data(kind, entry_ref->shared_stats), kind_info->shared_data_len); diff --git a/src/backend/utils/activity/pgstat_database.c b/src/backend/utils/activity/pgstat_database.c index fbaf8364117..52d82d25352 100644 --- a/src/backend/utils/activity/pgstat_database.c +++ b/src/backend/utils/activity/pgstat_database.c @@ -195,7 +195,7 @@ pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount) return; } - pgstat_lock_entry(entry_ref, false); + (void) pgstat_lock_entry(entry_ref, false); sharedent = (PgStatShared_Database *) entry_ref->shared_stats; sharedent->stats.checksum_failures += failurecount; diff --git a/src/backend/utils/activity/pgstat_shmem.c b/src/backend/utils/activity/pgstat_shmem.c index 5cd24303755..2e33293b000 100644 --- a/src/backend/utils/activity/pgstat_shmem.c +++ b/src/backend/utils/activity/pgstat_shmem.c @@ -643,6 +643,13 @@ pgstat_release_entry_ref(PgStat_HashKey key, PgStat_EntryRef *entry_ref, pfree(entry_ref); } +/* + * Acquire exclusive lock on the entry. + * + * If nowait is true, it's just a conditional acquire, and the result + * *must* be checked to verify success. + * If nowait is false, waits as necessary, always returning true. + */ bool pgstat_lock_entry(PgStat_EntryRef *entry_ref, bool nowait) { @@ -656,8 +663,10 @@ pgstat_lock_entry(PgStat_EntryRef *entry_ref, bool nowait) } /* + * Acquire shared lock on the entry. + * * Separate from pgstat_lock_entry() as most callers will need to lock - * exclusively. + * exclusively. The wait semantics are identical. */ bool pgstat_lock_entry_shared(PgStat_EntryRef *entry_ref, bool nowait)