From 6723a79bec8bc4a437bb595af21962a5d411fa77 Mon Sep 17 00:00:00 2001 From: Konstantin Knizhnik Date: Tue, 19 Sep 2023 21:55:36 +0300 Subject: [PATCH] Do not handle lfc_change_limit in processes not haing PGPROC structure (#5332) ## Problem See https://neondb.slack.com/archives/C05L7D1JAUS/p1693775881474019 ## Summary of changes Do not perform local file cache resizing in processes having no PGPROC ## Checklist before requesting a review - [ ] I have performed a self-review of my code. - [ ] If it is a core feature, I have added thorough tests. - [ ] Do we need to implement analytics? if so did you add the relevant metrics to the dashboard? - [ ] If this PR requires public announcement, mark it with /release-notes label and add several sentences in this section. ## Checklist before merging - [ ] Do not forget to reformat commit message to not include the above checklist --------- Co-authored-by: Konstantin Knizhnik --- pgxn/neon/file_cache.c | 3 +- test_runner/regress/test_lfc_resize.py | 44 ++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 test_runner/regress/test_lfc_resize.py diff --git a/pgxn/neon/file_cache.c b/pgxn/neon/file_cache.c index 6e5c0e0f38..4be75e1dad 100644 --- a/pgxn/neon/file_cache.c +++ b/pgxn/neon/file_cache.c @@ -222,8 +222,9 @@ lfc_change_limit_hook(int newval, void *extra) /* * Stats collector detach shared memory, so we should not try to access shared memory here. * Parallel workers first assign default value (0), so not perform truncation in parallel workers. + * The Postmaster can handle SIGHUP and it has access to shared memory (UsedShmemSegAddr != NULL), but has no PGPROC. */ - if (!lfc_ctl || !UsedShmemSegAddr || IsParallelWorker()) + if (!lfc_ctl || !MyProc || !UsedShmemSegAddr || IsParallelWorker()) return; /* Open cache file if not done yet */ diff --git a/test_runner/regress/test_lfc_resize.py b/test_runner/regress/test_lfc_resize.py new file mode 100644 index 0000000000..5c68a63d06 --- /dev/null +++ b/test_runner/regress/test_lfc_resize.py @@ -0,0 +1,44 @@ +import threading +import time + +import pytest +from fixtures.log_helper import log +from fixtures.neon_fixtures import NeonEnv, PgBin + + +# +# Test branching, when a transaction is in prepared state +# +@pytest.mark.timeout(600) +def test_lfc_resize(neon_simple_env: NeonEnv, pg_bin: PgBin): + env = neon_simple_env + env.neon_cli.create_branch("test_lfc_resize", "empty") + endpoint = env.endpoints.create_start( + "test_lfc_resize", + config_lines=[ + "neon.file_cache_path='file.cache'", + "neon.max_file_cache_size=1GB", + "neon.file_cache_size_limit=1GB", + ], + ) + n_resize = 10 + scale = 10 + log.info("postgres is running on 'test_lfc_resize' branch") + + def run_pgbench(connstr: str): + log.info(f"Start a pgbench workload on pg {connstr}") + pg_bin.run_capture(["pgbench", "-i", f"-s{scale}", connstr]) + pg_bin.run_capture(["pgbench", "-c4", f"-T{n_resize}", "-Mprepared", connstr]) + + thread = threading.Thread(target=run_pgbench, args=(endpoint.connstr(),), daemon=True) + thread.start() + + conn = endpoint.connect() + cur = conn.cursor() + + for i in range(n_resize): + cur.execute(f"alter system set neon.file_cache_size_limit='{i*10}MB'") + cur.execute("select pg_reload_conf()") + time.sleep(1) + + thread.join()