]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Avoid including worker_internal.h in pgstat.h.
authorAmit Kapila <akapila@postgresql.org>
Fri, 20 Feb 2026 03:56:33 +0000 (09:26 +0530)
committerAmit Kapila <akapila@postgresql.org>
Fri, 20 Feb 2026 03:56:33 +0000 (09:26 +0530)
pgstat.h is a widely included header. Including worker_internal.h there is
unnecessary and creates tight coupling. By refactoring
pgstat_report_subscription_error() to fetch the required
LogicalRepWorkerType internally rather than receiving it as an argument,
we can eliminate the need for the internal header.

Reported-by: Andres Freund <andres@anarazel.de>
Author: Nisha Moond <nisha.moond412@gmail.com>
Reviewed-by: vignesh C <vignesh21@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Discussion: https://postgr.es/m/aY-UE-4t7FiYgH3t@alap3.anarazel.de

src/backend/commands/functioncmds.c
src/backend/replication/logical/sequencesync.c
src/backend/replication/logical/tablesync.c
src/backend/replication/logical/worker.c
src/backend/storage/ipc/procsignal.c
src/backend/utils/activity/pgstat_subscription.c
src/include/pgstat.h
src/include/replication/worker_internal.h
src/test/modules/test_custom_stats/test_custom_var_stats.c

index a516b037dea7ea49834288c20725a1f73abaab78..242372b1e686eb854172e246467f52cb1c3043fd 100644 (file)
@@ -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"
index 165f909b3ba97b695c36a87c6c4cb8ae7f6b8b8e..9c92fddd624e7a25d0e264802db50deadca435c2 100644 (file)
@@ -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();
                }
index 19a3c21a86372b6c2cd40b7a5a2510f7a4e15270..2f2f0121ecfa1b363325c096d293cb304813bacd 100644 (file)
@@ -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();
                }
index adbdec49a0c6db5002933bbba5bec4a13146ec67..bae8c0113900617cddf412a68be56cf29ad8e40f 100644 (file)
@@ -5644,8 +5644,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();
                }
@@ -6000,8 +5999,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();
index 5d33559926a190c0e6a0a8fefe5ab1ef4c31d14f..7505c9d3a37a2251195cf7b7bea05d17137c52ef 100644 (file)
@@ -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"
index 500b189918881457997c4374bc90e904de8a6911..3277cf88a4eb7d30115c732ccc834dbce05d6905 100644 (file)
  * 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);
index fff7ecc2533298e0827f790b84d98416d3ada8a9..9bb777c3d5a828d59c2c523e8dfd787916e4d07b 100644 (file)
@@ -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);
index 33fb7f552b4107c31d854cac5f03ca02a9563c09..4ecbdcfadac3d24cd2f9894cf9bb5af5a854b173 100644 (file)
@@ -393,4 +393,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 */
index 64a8fe63cce88d0ad9ec326b0119e1e14f09dbef..da28afbd9291b3b118a06aaf9ec1f1c10300ee39 100644 (file)
@@ -12,6 +12,7 @@
  */
 #include "postgres.h"
 
+#include "access/htup_details.h"
 #include "common/hashfn.h"
 #include "funcapi.h"
 #include "storage/dsm_registry.h"