mirror of
https://github.com/postgres/postgres.git
synced 2025-12-21 05:21:08 +03:00
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
This commit is contained in:
@@ -219,8 +219,8 @@ test_slru_shmem_startup(void)
|
|||||||
*/
|
*/
|
||||||
const bool long_segment_names = true;
|
const bool long_segment_names = true;
|
||||||
const char slru_dir_name[] = "pg_test_slru";
|
const char slru_dir_name[] = "pg_test_slru";
|
||||||
int test_tranche_id;
|
int test_tranche_id = -1;
|
||||||
int test_buffer_tranche_id;
|
int test_buffer_tranche_id = -1;
|
||||||
|
|
||||||
if (prev_shmem_startup_hook)
|
if (prev_shmem_startup_hook)
|
||||||
prev_shmem_startup_hook();
|
prev_shmem_startup_hook();
|
||||||
@@ -231,10 +231,18 @@ test_slru_shmem_startup(void)
|
|||||||
*/
|
*/
|
||||||
(void) MakePGDirectory(slru_dir_name);
|
(void) MakePGDirectory(slru_dir_name);
|
||||||
|
|
||||||
/* initialize the SLRU facility */
|
/*
|
||||||
test_tranche_id = LWLockNewTrancheId("test_slru_tranche");
|
* Initialize the SLRU facility. In EXEC_BACKEND builds, the
|
||||||
|
* shmem_startup_hook is called in the postmaster and in each backend, but
|
||||||
test_buffer_tranche_id = LWLockNewTrancheId("test_buffer_tranche");
|
* 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;
|
TestSlruCtl->PagePrecedes = test_slru_page_precedes_logically;
|
||||||
SimpleLruInit(TestSlruCtl, "TestSLRU",
|
SimpleLruInit(TestSlruCtl, "TestSLRU",
|
||||||
|
|||||||
Reference in New Issue
Block a user