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 <
[email protected]>
Reviewed-by: Bertrand Drouvot <[email protected]>
Reviewed-by: Chao Li <[email protected]>
Reviewed-by: wenhui qiu <[email protected]>
Discussion: https://postgr.es/m/
[email protected]
Backpatch-through: 18
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;
stats_shmem->stats.numcached += numcached;
stats_shmem->stats.numloaded += numloaded;
pgstat_end_changecount_write(&stats_shmem->changecount);
+
+ LWLockRelease(&stats_shmem->lock);
}
/*