test_slru: Fix LWLock tranche allocation in EXEC_BACKEND builds.

Currently, test_slru's shmem_startup_hook unconditionally generates
new LWLock tranche IDs.  This is fine on non-EXEC_BACKEND builds,
where only the postmaster executes this hook, but on EXEC_BACKEND
builds, every backend executes it, too.  To fix, only generate the
tranche IDs in the postmaster process by checking the
IsUnderPostmaster variable.

This is arguably a bug fix and could be back-patched, but since the
damage is limited to some extra unused tranche IDs in a test
module, I'm not going to bother.

Reported-by: Sami Imseih <samimseih@gmail.com>
Reviewed-by: Sami Imseih <samimseih@gmail.com>
Discussion: https://postgr.es/m/CAA5RZ0vaAuonaf12CeDddQJu5xKL%2B6xVyS%2B_q1%2BcH%3D33JXV82w%40mail.gmail.com
master
Nathan Bossart 1 day ago
parent 81a61fde84
commit 530cfa8eb5
  1. 20
      src/test/modules/test_slru/test_slru.c

@ -219,8 +219,8 @@ test_slru_shmem_startup(void)
*/
const bool long_segment_names = true;
const char slru_dir_name[] = "pg_test_slru";
int test_tranche_id;
int test_buffer_tranche_id;
int test_tranche_id = -1;
int test_buffer_tranche_id = -1;
if (prev_shmem_startup_hook)
prev_shmem_startup_hook();
@ -231,10 +231,18 @@ test_slru_shmem_startup(void)
*/
(void) MakePGDirectory(slru_dir_name);
/* initialize the SLRU facility */
test_tranche_id = LWLockNewTrancheId("test_slru_tranche");
test_buffer_tranche_id = LWLockNewTrancheId("test_buffer_tranche");
/*
* Initialize the SLRU facility. In EXEC_BACKEND builds, the
* shmem_startup_hook is called in the postmaster and in each backend, but
* we only need to generate the LWLock tranches once. Note that these
* tranche ID variables are not used by SimpleLruInit() when
* IsUnderPostmaster is true.
*/
if (!IsUnderPostmaster)
{
test_tranche_id = LWLockNewTrancheId("test_slru_tranche");
test_buffer_tranche_id = LWLockNewTrancheId("test_buffer_tranche");
}
TestSlruCtl->PagePrecedes = test_slru_page_precedes_logically;
SimpleLruInit(TestSlruCtl, "TestSLRU",

Loading…
Cancel
Save