summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2025-09-30 09:02:35 +0900
committerMichael Paquier <michael@paquier.xyz>2025-09-30 09:02:35 +0900
commitb5f898944d1226f8daeb0bda58098f645582c80f (patch)
treeae6c41fa85e4a0a5cfce6e20ff2ffdc1d07d804e
parentd024160fffc8065b9b007c6be1b5f907eb2122c9 (diff)
injection_points: Add proper locking when reporting fixed-variable statsorigin/REL_18_STABLE
Contrary to its siblings for the archiver, the bgwriter and the checkpointer stats, pgstat_report_inj_fixed() can be called concurrently. This was causing an assertion failure, while messing up with the stats. This code is aimed at being a template for extension developers, so it is not a critical issue, but let's be correct. This module has also been useful for some benchmarking, at least for me, and that was how I have discovered this issue. Oversight in f68cd847fa40. Author: Michael Paquier <michael@paquier.xyz> Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Reviewed-by: wenhui qiu <qiuwenhuifx@gmail.com> Discussion: https://postgr.es/m/aNnXbAXHPFUWPIz2@paquier.xyz Backpatch-through: 18
-rw-r--r--src/test/modules/injection_points/injection_stats_fixed.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/test/modules/injection_points/injection_stats_fixed.c b/src/test/modules/injection_points/injection_stats_fixed.c
index bc54c79d190..74c35fcbfa7 100644
--- a/src/test/modules/injection_points/injection_stats_fixed.c
+++ b/src/test/modules/injection_points/injection_stats_fixed.c
@@ -152,6 +152,8 @@ pgstat_report_inj_fixed(uint32 numattach,
stats_shmem = pgstat_get_custom_shmem_data(PGSTAT_KIND_INJECTION_FIXED);
+ LWLockAcquire(&stats_shmem->lock, LW_EXCLUSIVE);
+
pgstat_begin_changecount_write(&stats_shmem->changecount);
stats_shmem->stats.numattach += numattach;
stats_shmem->stats.numdetach += numdetach;
@@ -159,6 +161,8 @@ pgstat_report_inj_fixed(uint32 numattach,
stats_shmem->stats.numcached += numcached;
stats_shmem->stats.numloaded += numloaded;
pgstat_end_changecount_write(&stats_shmem->changecount);
+
+ LWLockRelease(&stats_shmem->lock);
}
/*