aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFujii Masao <fujii@postgresql.org>2020-02-06 14:43:21 +0900
committerFujii Masao <fujii@postgresql.org>2020-02-06 14:43:21 +0900
commit3ccc66dac65e12b8f19d0766b00feabd55433854 (patch)
tree20e8062a3f1985f75dccc7c68aca87737e0e4bd0
parentb025f32e0b5d7668daec9bfa957edf3599f4baa8 (diff)
downloadpostgresql-3ccc66dac65e12b8f19d0766b00feabd55433854.tar.gz
postgresql-3ccc66dac65e12b8f19d0766b00feabd55433854.zip
Fix bug in LWLock statistics mechanism.
Previously PostgreSQL built with -DLWLOCK_STATS could report more than one LWLock statistics entries for the same backend process and the same LWLock. This is strange and only one statistics should be output in that case, instead. The cause of this issue is that the key variable used for LWLock stats hash table was not fully initialized. The key consists of two fields and they were initialized. But the following 4 bytes allocated in the key variable for the alignment was not initialized. So even if the same key was specified, hash_search(HASH_ENTER) could not find the existing entry for that key and created new one. This commit fixes this issue by initializing the key variable with zero. As the side effect of this commit, the volume of LWLock statistics output would be reduced very much. Back-patch to v10, where commit 3761fe3c20 introduced the issue. Author: Fujii Masao Reviewed-by: Julien Rouhaud, Kyotaro Horiguchi Discussion: https://postgr.es/m/26359edb-798a-568f-d93a-6aafac49752d@oss.nttdata.com
-rw-r--r--src/backend/storage/lmgr/lwlock.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index d07ce609d48..4c14e51c67f 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -310,6 +310,7 @@ get_lwlock_stats_entry(LWLock *lock)
return &lwlock_stats_dummy;
/* Fetch or create the entry. */
+ MemSet(&key, 0, sizeof(key));
key.tranche = lock->tranche;
key.instance = lock;
lwstats = hash_search(lwlock_stats_htab, &key, HASH_ENTER, &found);