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.
pull/5696/head
Onder Kalaci 2022-02-08 11:36:33 +01:00
parent cc129ebe11
commit 1e69f5ad5e
1 changed files with 9 additions and 1 deletions

View File

@ -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(&currentBackend->mutex);
continue;
}
Oid databaseId = currentBackend->databaseId;
int backendPid = ProcGlobal->allProcs[backendIndex].pid;
int backendPid = currentProc->pid;
initiatorNodeIdentifier = currentBackend->citusBackend.initiatorNodeIdentifier;
/*