roaldm153 opened a new pull request, #1934:
URL: https://github.com/apache/cloudberry/pull/1934
### What does this PR do?
Adds a signal-based runtime query-state facility to the `gp_stats_collector`
extension. It lets a session inspect the live execution state of another
running backend on demand - walking its active plan tree across the QD and all
QEs - without waiting for the query to finish, pushing batches to the UDS(unix
domain socket).
New SQL API (extension v1.2, schema `gpsc`):
- `gpsc.pg_query_state(pid, trace_id)` - fan out a poll to the query running
on `pid`; each participating backend walks its plan tree and logs a per-node
snapshot.
- `gpsc.pg_query_state_backends(pid)` - list the `(segid, pid)` QE backends
taking part in that query.
- `cbdb_mpp_query_state(gpsc.gp_segment_pid[], trace_id)` - QE-side dispatch
target.
The extension embeds the `pg_query_state` signal layer, which depends on
three PostgreSQL core changes folded directly into the tree (configure enables
the extension by default, so the tree must build without a manual patch step):
- custom `ProcSignal` handlers (`procsignal.c/.h`, `postgres.c`);
- end-of-node instrumentation flag readable mid-run (`instrument.c/.h`);
- runtime `EXPLAIN` entry points (`explain.c/.h`).
### Type of Change
- [ ] Bug fix (non-breaking change)
- [x] New feature (non-breaking change)
- [ ] Breaking change (fix or feature with breaking changes)
- [ ] Documentation update
### Breaking Changes
None. Core changes are additive (new signal reasons, a new Instrumentation
field, new runtime-EXPLAIN paths); existing behavior is unchanged.
### Test Plan
- [x] Unit tests added/updated
- [x] Integration tests added/updated
- [x] Passed `make installcheck`
- pg_regress (`gpcontrib/gp_stats_collector/test`): catalog contract
(function/type registration, exec location) and input-validation errors.
- isolation2 (`gpcontrib/gp_stats_collector/test/isolation2`), multi-session:
- `gpsc_pqs_backends` - idle backend yields an empty list;
- `gpsc_pqs_running` - happy path: poll a query suspended on the QEs via a
fault injector;
- `gpsc_pqs_perms` - permission gate (non-owner non-superuser denied);
- `gpsc_pqs_disabled` - `STAT_DISABLED` reports no backends;
- `gpsc_pqs_seg_count` - one backend per primary segment.
- `gpsc-crash-test` - parallel tracing on `make installcheck-parallel`, core
dumps checking
- A dedicated CI workflow builds Cloudberry with the extension across
ubuntu22.04/rocky8/rocky9 and runs the pg_regress, isolation2, and core
regression suites.
### Impact
**Performance:**
No steady-state cost. Work happens only when a poll is issued: one signal
fan-out plus a bounded shared-memory round-trip; the shmem lock is held only
around the request, not during dispatch.
**User-facing changes:**
New `gpsc.pg_query_state*` functions and the `pg_query_state.enable` GUC.
Functions are granted to PUBLIC; access is gated in C so a caller may poll a
backend only if it is a superuser or owns the target query.
**Dependencies:**
None.
### Checklist
- [x] Followed contribution guide
- [x] Added/updated documentation
- [x] Reviewed code for security implications
- [x] Requested review from cloudberry committers
### Additional Context
The signal layer under `src/pg_query_state/` is derived from
[pg_query_state](https://github.com/postgrespro/pg_query_state) (PostgreSQL
License). Derived files carry dual license headers (ASF + `Portions Copyright
Postgres Professional`) and the root `LICENSE` records a PostgreSQL-License
notice for it. Happy to provide provenance details for IP clearance.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]