summaryrefslogtreecommitdiff
path: root/src/include/replication/worker_internal.h
diff options
context:
space:
mode:
authorAmit Kapila <akapila@postgresql.org>2023-08-14 08:38:03 +0530
committerAmit Kapila <akapila@postgresql.org>2023-08-14 08:38:03 +0530
commit2a8b40e3681921943a2989fd4ec6cdbf8766566c (patch)
treea5c55ec41deb79663ab7b9585f63bd6b1dcd3ad7 /src/include/replication/worker_internal.h
parent3d8d217450a63638825167c17ed791122f376176 (diff)
Simplify determining logical replication worker types.
We deduce a LogicalRepWorker's type from the values of several different fields ('relid' and 'leader_pid') whenever logic needs to know it. In fact, the logical replication worker type is already known at the time of launching the LogicalRepWorker and it never changes for the lifetime of that process. Instead of deducing the type, it is simpler to just store it one time, and access it directly thereafter. Author: Peter Smith Reviewed-by: Amit Kapila, Bharath Rupireddy Discussion: http://postgr.es/m/CAHut+PttPSuP0yoZ=9zLDXKqTJ=d0bhxwKaEaNcaym1XqcvDEg@mail.gmail.com
Diffstat (limited to 'src/include/replication/worker_internal.h')
-rw-r--r--src/include/replication/worker_internal.h22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/include/replication/worker_internal.h b/src/include/replication/worker_internal.h
index 672a7117c0c..a428663859b 100644
--- a/src/include/replication/worker_internal.h
+++ b/src/include/replication/worker_internal.h
@@ -27,9 +27,20 @@
#include "storage/shm_toc.h"
#include "storage/spin.h"
+/* Different types of worker */
+typedef enum LogicalRepWorkerType
+{
+ WORKERTYPE_UNKNOWN = 0,
+ WORKERTYPE_TABLESYNC,
+ WORKERTYPE_APPLY,
+ WORKERTYPE_PARALLEL_APPLY
+} LogicalRepWorkerType;
typedef struct LogicalRepWorker
{
+ /* What type of worker is this? */
+ LogicalRepWorkerType type;
+
/* Time at which this worker was launched. */
TimestampTz launch_time;
@@ -232,7 +243,8 @@ extern void logicalrep_worker_attach(int slot);
extern LogicalRepWorker *logicalrep_worker_find(Oid subid, Oid relid,
bool only_running);
extern List *logicalrep_workers_find(Oid subid, bool only_running);
-extern bool logicalrep_worker_launch(Oid dbid, Oid subid, const char *subname,
+extern bool logicalrep_worker_launch(LogicalRepWorkerType wtype,
+ Oid dbid, Oid subid, const char *subname,
Oid userid, Oid relid,
dsm_handle subworker_dsm);
extern void logicalrep_worker_stop(Oid subid, Oid relid);
@@ -315,19 +327,19 @@ extern void pa_decr_and_wait_stream_block(void);
extern void pa_xact_finish(ParallelApplyWorkerInfo *winfo,
XLogRecPtr remote_lsn);
-#define isParallelApplyWorker(worker) ((worker)->leader_pid != InvalidPid)
+#define isParallelApplyWorker(worker) ((worker)->type == WORKERTYPE_PARALLEL_APPLY)
+#define isTablesyncWorker(worker) ((worker)->type == WORKERTYPE_TABLESYNC)
static inline bool
am_tablesync_worker(void)
{
- return OidIsValid(MyLogicalRepWorker->relid);
+ return isTablesyncWorker(MyLogicalRepWorker);
}
static inline bool
am_leader_apply_worker(void)
{
- return (!am_tablesync_worker() &&
- !isParallelApplyWorker(MyLogicalRepWorker));
+ return (MyLogicalRepWorker->type == WORKERTYPE_APPLY);
}
static inline bool