From 5396ef46268685d051177ab972925c3d8cb2818a Mon Sep 17 00:00:00 2001 From: Leonid Borchuk Date: Tue, 1 Dec 2026 17:35:45 +0300 Subject: [PATCH 1/2] Derive Cloudberry session waiting fields from wait events Replace hardcoded false/empty waiting metadata with wait_event_type presence and its normalized wait class. Existing session API fields now report lock waits consistently with wait events and blocker information. Leave the GP6 query unchanged. Fixes apache/cloudberry-command-center#39 --- internal/gp/stat_activity/lister.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/gp/stat_activity/lister.go b/internal/gp/stat_activity/lister.go index 78503e04..dd222ffc 100644 --- a/internal/gp/stat_activity/lister.go +++ b/internal/gp/stat_activity/lister.go @@ -107,13 +107,13 @@ from xact_start AS XactStart, query_start AS QueryStart, state_change AS StateChange, - false as waiting, + (wait_event_type IS NOT NULL) AS waiting, state, backend_type AS BackendType, backend_xid AS BackendXid, backend_xmin AS backendXmin, query, - '' as WaitingReason, + lower(COALESCE(wait_event_type, '')) AS WaitingReason, rsgid, rsgname, 0 as rsgqueueduration, From 74435224eb16b27cddddaee17727582cc3fbe252 Mon Sep 17 00:00:00 2001 From: Dianjin Wang Date: Wed, 2 Dec 2026 11:27:42 +0800 Subject: [PATCH 2/2] Count only real waits as waiting sessions On Cloudberry every session reports a wait event: idle clients wait on Client/ClientRead and background processes on Activity/*. Deriving "waiting" from wait_event_type IS NOT NULL therefore marked every idle session as waiting with reason "client". Count only lock, resource group, resource queue and synchronous replication waits, and map them to the GP6 waiting_reason values (lock, resgroup, resqueue, replication) that GetStatus expects. Treat resource queue waits as "waiting" in GetStatus, like resource group waits, and cover the status mapping with a unit test. Assisted-by: Claude Code --- internal/gp/sessions.go | 2 +- internal/gp/sessions_test.go | 24 ++++++++++++++++++++++++ internal/gp/stat_activity/lister.go | 18 ++++++++++++++++-- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/internal/gp/sessions.go b/internal/gp/sessions.go index d18b3cfd..4df52a74 100644 --- a/internal/gp/sessions.go +++ b/internal/gp/sessions.go @@ -229,7 +229,7 @@ func GetStatus(blockSessID *int, waiting *bool, reason *string) string { return "blocked" } if reason != nil { - if waiting != nil && *waiting && *reason == "resgroup" { + if waiting != nil && *waiting && (*reason == "resgroup" || *reason == "resqueue") { return "waiting" } if waiting != nil && *waiting && *reason == "replication" { diff --git a/internal/gp/sessions_test.go b/internal/gp/sessions_test.go index 234f2b4a..471c925f 100644 --- a/internal/gp/sessions_test.go +++ b/internal/gp/sessions_test.go @@ -958,3 +958,27 @@ func TestSessionDescriptionsUseCoordinatorHost(t *testing.T) { assert.Equal(t, host, query.Hostname) } } + +func TestGetStatusFromWaitingReason(t *testing.T) { + blocker := 7 + for _, tc := range []struct { + name string + blocker *int + waiting bool + reason string + want string + }{ + {name: "blocked by session", blocker: &blocker, want: "blocked"}, + {name: "lock wait", waiting: true, reason: "lock", want: "blocked"}, + {name: "resource group wait", waiting: true, reason: "resgroup", want: "waiting"}, + {name: "resource queue wait", waiting: true, reason: "resqueue", want: "waiting"}, + {name: "replication wait", waiting: true, reason: "replication", want: "waiting"}, + {name: "idle client", reason: "", want: ""}, + {name: "reason without waiting", reason: "lock", want: ""}, + } { + t.Run(tc.name, func(t *testing.T) { + waiting, reason := tc.waiting, tc.reason + assert.Equal(t, tc.want, GetStatus(tc.blocker, &waiting, &reason)) + }) + } +} diff --git a/internal/gp/stat_activity/lister.go b/internal/gp/stat_activity/lister.go index dd222ffc..08a0d760 100644 --- a/internal/gp/stat_activity/lister.go +++ b/internal/gp/stat_activity/lister.go @@ -107,13 +107,27 @@ from xact_start AS XactStart, query_start AS QueryStart, state_change AS StateChange, - (wait_event_type IS NOT NULL) AS waiting, + -- Only lock, resource management and synchronous + -- replication waits count. Idle clients (Client) and + -- background processes (Activity) always report a wait + -- event and must not show up as waiting. + (wait_event_type IN ('Lock', 'ResourceGroup', 'ResourceQueue', 'Replication') + OR (wait_event_type = 'IPC' AND wait_event = 'SyncRep')) AS waiting, state, backend_type AS BackendType, backend_xid AS BackendXid, backend_xmin AS backendXmin, query, - lower(COALESCE(wait_event_type, '')) AS WaitingReason, + -- Same vocabulary as waiting_reason on GP6. + CASE + WHEN wait_event_type = 'ResourceQueue' + OR (wait_event_type = 'Lock' AND wait_event = 'resource queue') THEN 'resqueue' + WHEN wait_event_type = 'Lock' THEN 'lock' + WHEN wait_event_type = 'ResourceGroup' THEN 'resgroup' + WHEN wait_event_type = 'Replication' + OR (wait_event_type = 'IPC' AND wait_event = 'SyncRep') THEN 'replication' + ELSE '' + END AS WaitingReason, rsgid, rsgname, 0 as rsgqueueduration,