From: Tatsuo Ishii Date: Thu, 4 Sep 2025 05:59:26 +0000 (+0900) Subject: Fix query cache lock file handling. X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=9e03245757ce4fb638fc674da8025c0a33659b3a;p=pgpool2.git Fix query cache lock file handling. Query cache module creates a lock file under logdir for concurrency control. However, there were bugs in the handling: 1) Garbage file "QUERY_CACHE_LOCK_FILE" was created by pgpool main process. 2) The lock file was not removed upon pgpool shutdown. This commit fixes the bugs. Author: Tatsuo Ishii Reported-by: Bo Peng Reviewed-by: Bo Peng Backpatch-through: v4.4 --- diff --git a/src/main/pgpool_main.c b/src/main/pgpool_main.c index d74cf12b2..04624ff0a 100644 --- a/src/main/pgpool_main.c +++ b/src/main/pgpool_main.c @@ -5,7 +5,7 @@ * pgpool: a language independent connection pool server for PostgreSQL * written by Tatsuo Ishii * - * Copyright (c) 2003-2024 PgPool Global Development Group + * Copyright (c) 2003-2025 PgPool Global Development Group * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose and without fee is hereby @@ -303,8 +303,11 @@ PgpoolMain(bool discard_status, bool clear_memcache_oidmaps) */ volatile bool first = true; - /* For PostmasterRandom */ - gettimeofday(&random_start_time, NULL); + /* + * Query cache lock file path. This should be declared as "static" because + * the path is passed to be registered using on_proc_exit(). + */ + static char query_cache_lock_path[MAXPGPATH]; processState = INITIALIZING; @@ -510,23 +513,23 @@ PgpoolMain(bool discard_status, bool clear_memcache_oidmaps) } /* For query cache concurrency control */ - if (pool_config->memory_cache_enabled) + if (pool_config->memory_cache_enabled || pool_config->enable_shared_relcache) { - char path[1024]; - int lfd; + int lfd; - snprintf(path, sizeof(path), "%s/QUERY_CACHE_LOCK_FILE", pool_config->logdir); - lfd = open(path, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR); + snprintf(query_cache_lock_path, sizeof(query_cache_lock_path), + "%s/%s", pool_config->logdir, QUERY_CACHE_LOCK_FILE); + lfd = open(query_cache_lock_path, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR); if (lfd == -1) { ereport(FATAL, - (errmsg("Failed to open lock file for query cache \"%s\"", path), + (errmsg("Failed to open lock file for query cache \"%s\"", query_cache_lock_path), errdetail("%m"))); } close(lfd); /* Register file unlink at exit */ - on_proc_exit(FileUnlink, (Datum) path); + on_proc_exit(FileUnlink, (Datum) query_cache_lock_path); } /*