From 1e69f5ad5e60eb1ab35312e26376f10814ea0a61 Mon Sep 17 00:00:00 2001 From: Onder Kalaci Date: Tue, 8 Feb 2022 11:36:33 +0100 Subject: [PATCH] Skip Postgres' parallel workers while getting Citus backends Due to Postgres' parallel queries, we sometime have duplicate entries in citus_worker_stat_activity with global_pid = 0: ``` select cp.query, pp.leader_pid, pp.pid, cp.global_pid FROM citus_worker_stat_activity cp JOIN pg_stat_activity pp USING(pid) where pp.query NOT ilike '%dump%' and pp.query NOT ilike '%prepare%'; query | leader_pid | pid | global_pid ------------------------------------------------------------------------------------------+------------+-------+-------------- SELECT count(*) AS count FROM public.test_102009 test WHERE (a OPERATOR(pg_catalog.=) 1) | | 83475 | 110000083474 SELECT count(*) AS count FROM public.test_102009 test WHERE (a OPERATOR(pg_catalog.=) 1) | 83475 | 83503 | 0 SELECT count(*) AS count FROM public.test_102009 test WHERE (a OPERATOR(pg_catalog.=) 1) | 83475 ``` With this commit, we prevent those. --- src/backend/distributed/transaction/backend_data.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/backend/distributed/transaction/backend_data.c b/src/backend/distributed/transaction/backend_data.c index 5713412d7..5f7980c1d 100644 --- a/src/backend/distributed/transaction/backend_data.c +++ b/src/backend/distributed/transaction/backend_data.c @@ -406,8 +406,16 @@ StoreAllActiveTransactions(Tuplestorestate *tupleStore, TupleDesc tupleDescripto continue; } + PGPROC *currentProc = &ProcGlobal->allProcs[backendIndex]; + if (currentProc->lockGroupLeader != NULL) + { + /* we skip Postgres' parallel workers as it is enough to show the leader */ + SpinLockRelease(¤tBackend->mutex); + continue; + } + Oid databaseId = currentBackend->databaseId; - int backendPid = ProcGlobal->allProcs[backendIndex].pid; + int backendPid = currentProc->pid; initiatorNodeIdentifier = currentBackend->citusBackend.initiatorNodeIdentifier; /*