pgpool2.git / summary / log / commit / refs
commit 09cd631edb0f962403a503ff02bdbea739de40e8
Author: Tatsuo Ishii <ishii@postgresql.org>
Date: Thu Sep 04 05:59:26 2025 +0000
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 <ishii@postgresql.org>
Reported-by: Bo Peng <pengbo@sraoss.co.jp>
Reviewed-by: Bo Peng <pengbo@sraoss.co.jp>
Backpatch-through: v4.4
src/main/pgpool_main.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/src/main/pgpool_main.c b/src/main/pgpool_main.c
index 40376b2f8..c73296665 100644
--- a/src/main/pgpool_main.c
+++ b/src/main/pgpool_main.c
@@ -306,6 +306,12 @@ PgpoolMain(bool discard_status, bool clear_memcache_oidmaps)
*/
volatile bool first = true;
+ /*
+ * 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;
/*
@@ -512,23 +518,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;
- 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);
}
/*
@@ -1652,14 +1658,14 @@ failover(void)
*/
if (failover_context.request_details & REQ_DETAIL_PROMOTE)
{
- promote_node = failover_context.node_id_set[0]; /* requested node */
+ promote_node = failover_context.node_id_set[0]; /* requested node */
for (i = 0; i < failover_context.node_count; i++)
{
failover_context.node_id_set[i] = REAL_PRIMARY_NODE_ID;
}
}
- node_id = failover_context.node_id_set[0]; /* set target node id */
+ node_id = failover_context.node_id_set[0]; /* set target node id */
/* failback request? */
if (failover_context.reqkind == NODE_UP_REQUEST)
[parent: b9e7b4245896]