v2-0001-Add-get_logical_worker_type-to-retrieve-the-worke.patch
application/octet-stream
Filename: v2-0001-Add-get_logical_worker_type-to-retrieve-the-worke.patch
Type: application/octet-stream
Part: 0
Message:
Re: pgstat include expansion
Patch
Format: format-patch
Series: patch v2-0001
Subject: Add get_logical_worker_type() to retrieve the worker type
| File | + | − |
|---|---|---|
| src/backend/commands/functioncmds.c | 1 | 0 |
| src/backend/replication/logical/sequencesync.c | 1 | 2 |
| src/backend/replication/logical/tablesync.c | 1 | 2 |
| src/backend/replication/logical/worker.c | 2 | 4 |
| src/backend/storage/ipc/procsignal.c | 1 | 0 |
| src/backend/utils/activity/pgstat_subscription.c | 2 | 1 |
| src/include/pgstat.h | 1 | 3 |
| src/include/replication/worker_internal.h | 7 | 0 |
| src/test/modules/test_custom_stats/test_custom_var_stats.c | 1 | 0 |
From 540974fb9683166d37e37ed3852d6bccc43fd99b Mon Sep 17 00:00:00 2001
From: Nisha Moond <nisha.moond412@gmail.com>
Date: Wed, 18 Feb 2026 10:08:00 +0530
Subject: [PATCH v2] Add get_logical_worker_type() to retrieve the worker type
This patch resolves the logical worker type dependency in
pgstat.h by obtaining the current logical replication worker
type through get_logical_worker_type().
---
src/backend/commands/functioncmds.c | 1 +
src/backend/replication/logical/sequencesync.c | 3 +--
src/backend/replication/logical/tablesync.c | 3 +--
src/backend/replication/logical/worker.c | 6 ++----
src/backend/storage/ipc/procsignal.c | 1 +
src/backend/utils/activity/pgstat_subscription.c | 3 ++-
src/include/pgstat.h | 4 +---
src/include/replication/worker_internal.h | 7 +++++++
src/test/modules/test_custom_stats/test_custom_var_stats.c | 1 +
9 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index a516b037dea..242372b1e68 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -34,6 +34,7 @@
#include "access/htup_details.h"
#include "access/table.h"
+#include "access/xact.h"
#include "catalog/catalog.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
diff --git a/src/backend/replication/logical/sequencesync.c b/src/backend/replication/logical/sequencesync.c
index 165f909b3ba..9c92fddd624 100644
--- a/src/backend/replication/logical/sequencesync.c
+++ b/src/backend/replication/logical/sequencesync.c
@@ -750,8 +750,7 @@ start_sequence_sync(void)
* idle state.
*/
AbortOutOfAnyTransaction();
- pgstat_report_subscription_error(MySubscription->oid,
- WORKERTYPE_SEQUENCESYNC);
+ pgstat_report_subscription_error(MySubscription->oid);
PG_RE_THROW();
}
diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c
index 19a3c21a863..2f2f0121ecf 100644
--- a/src/backend/replication/logical/tablesync.c
+++ b/src/backend/replication/logical/tablesync.c
@@ -1527,8 +1527,7 @@ start_table_sync(XLogRecPtr *origin_startpos, char **slotname)
* idle state.
*/
AbortOutOfAnyTransaction();
- pgstat_report_subscription_error(MySubscription->oid,
- WORKERTYPE_TABLESYNC);
+ pgstat_report_subscription_error(MySubscription->oid);
PG_RE_THROW();
}
diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c
index 32725c48623..73daa4479e0 100644
--- a/src/backend/replication/logical/worker.c
+++ b/src/backend/replication/logical/worker.c
@@ -5606,8 +5606,7 @@ start_apply(XLogRecPtr origin_startpos)
* idle state.
*/
AbortOutOfAnyTransaction();
- pgstat_report_subscription_error(MySubscription->oid,
- MyLogicalRepWorker->type);
+ pgstat_report_subscription_error(MySubscription->oid);
PG_RE_THROW();
}
@@ -5960,8 +5959,7 @@ DisableSubscriptionAndExit(void)
* Report the worker failed during sequence synchronization, table
* synchronization, or apply.
*/
- pgstat_report_subscription_error(MyLogicalRepWorker->subid,
- MyLogicalRepWorker->type);
+ pgstat_report_subscription_error(MyLogicalRepWorker->subid);
/* Disable the subscription */
StartTransactionCommand();
diff --git a/src/backend/storage/ipc/procsignal.c b/src/backend/storage/ipc/procsignal.c
index 5d33559926a..7505c9d3a37 100644
--- a/src/backend/storage/ipc/procsignal.c
+++ b/src/backend/storage/ipc/procsignal.c
@@ -22,6 +22,7 @@
#include "miscadmin.h"
#include "pgstat.h"
#include "port/pg_bitutils.h"
+#include "replication/logicalctl.h"
#include "replication/logicalworker.h"
#include "replication/walsender.h"
#include "storage/condition_variable.h"
diff --git a/src/backend/utils/activity/pgstat_subscription.c b/src/backend/utils/activity/pgstat_subscription.c
index 500b1899188..3277cf88a4e 100644
--- a/src/backend/utils/activity/pgstat_subscription.c
+++ b/src/backend/utils/activity/pgstat_subscription.c
@@ -25,10 +25,11 @@
* Report a subscription error.
*/
void
-pgstat_report_subscription_error(Oid subid, LogicalRepWorkerType wtype)
+pgstat_report_subscription_error(Oid subid)
{
PgStat_EntryRef *entry_ref;
PgStat_BackendSubEntry *pending;
+ LogicalRepWorkerType wtype = get_logical_worker_type();
entry_ref = pgstat_prep_pending_entry(PGSTAT_KIND_SUBSCRIPTION,
InvalidOid, subid, NULL);
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index fff7ecc2533..9bb777c3d5a 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -16,7 +16,6 @@
#include "portability/instr_time.h"
#include "postmaster/pgarch.h" /* for MAX_XFN_CHARS */
#include "replication/conflict.h"
-#include "replication/worker_internal.h"
#include "utils/backend_progress.h" /* for backward compatibility */ /* IWYU pragma: export */
#include "utils/backend_status.h" /* for backward compatibility */ /* IWYU pragma: export */
#include "utils/pgstat_kind.h"
@@ -775,8 +774,7 @@ extern PgStat_SLRUStats *pgstat_fetch_slru(void);
* Functions in pgstat_subscription.c
*/
-extern void pgstat_report_subscription_error(Oid subid,
- LogicalRepWorkerType wtype);
+extern void pgstat_report_subscription_error(Oid subid);
extern void pgstat_report_subscription_conflict(Oid subid, ConflictType type);
extern void pgstat_create_subscription(Oid subid);
extern void pgstat_drop_subscription(Oid subid);
diff --git a/src/include/replication/worker_internal.h b/src/include/replication/worker_internal.h
index c1285fdd1bc..da5f938a065 100644
--- a/src/include/replication/worker_internal.h
+++ b/src/include/replication/worker_internal.h
@@ -392,4 +392,11 @@ am_parallel_apply_worker(void)
return isParallelApplyWorker(MyLogicalRepWorker);
}
+static inline LogicalRepWorkerType
+get_logical_worker_type(void)
+{
+ Assert(MyLogicalRepWorker->in_use);
+ return MyLogicalRepWorker->type;
+}
+
#endif /* WORKER_INTERNAL_H */
diff --git a/src/test/modules/test_custom_stats/test_custom_var_stats.c b/src/test/modules/test_custom_stats/test_custom_var_stats.c
index 64a8fe63cce..da28afbd929 100644
--- a/src/test/modules/test_custom_stats/test_custom_var_stats.c
+++ b/src/test/modules/test_custom_stats/test_custom_var_stats.c
@@ -12,6 +12,7 @@
*/
#include "postgres.h"
+#include "access/htup_details.h"
#include "common/hashfn.h"
#include "funcapi.h"
#include "storage/dsm_registry.h"
--
2.50.1 (Apple Git-155)