PostgreSQL Source Code  git master
worker_internal.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * worker_internal.h
4  * Internal headers shared by logical replication workers.
5  *
6  * Portions Copyright (c) 2016-2021, PostgreSQL Global Development Group
7  *
8  * src/include/replication/worker_internal.h
9  *
10  *-------------------------------------------------------------------------
11  */
12 #ifndef WORKER_INTERNAL_H
13 #define WORKER_INTERNAL_H
14 
15 #include <signal.h>
16 
17 #include "access/xlogdefs.h"
19 #include "datatype/timestamp.h"
20 #include "storage/lock.h"
21 #include "storage/spin.h"
22 
23 
24 typedef struct LogicalRepWorker
25 {
26  /* Time at which this worker was launched. */
28 
29  /* Indicates if this slot is used or free. */
30  bool in_use;
31 
32  /* Increased every time the slot is taken by new worker. */
34 
35  /* Pointer to proc array. NULL if not running. */
37 
38  /* Database id to connect to. */
40 
41  /* User to use for connection (will be same as owner of subscription). */
43 
44  /* Subscription id for the worker. */
46 
47  /* Used for initial table synchronization. */
49  char relstate;
52 
53  /*
54  * Used to create the changes and subxact files for the streaming
55  * transactions. Upon the arrival of the first streaming transaction, the
56  * fileset will be initialized, and it will be deleted when the worker
57  * exits. Under this, separate buffiles would be created for each
58  * transaction which will be deleted after the transaction is finished.
59  */
61 
62  /* Stats. */
69 
70 /* Main memory context for apply worker. Permanent during worker lifetime. */
72 
73 /* libpqreceiver connection */
75 
76 /* Worker and subscription objects. */
79 
80 extern bool in_remote_transaction;
81 
82 extern void logicalrep_worker_attach(int slot);
84  bool only_running);
85 extern List *logicalrep_workers_find(Oid subid, bool only_running);
86 extern void logicalrep_worker_launch(Oid dbid, Oid subid, const char *subname,
87  Oid userid, Oid relid);
91 
93 
95  char *originname, int szorgname);
96 extern char *LogicalRepSyncTableStart(XLogRecPtr *origin_startpos);
97 
98 extern bool AllTablesyncsReady(void);
99 extern void UpdateTwoPhaseState(Oid suboid, char new_state);
100 
101 void process_syncing_tables(XLogRecPtr current_lsn);
102 void invalidate_syncing_table_states(Datum arg, int cacheid,
103  uint32 hashvalue);
104 
105 static inline bool
107 {
108  return OidIsValid(MyLogicalRepWorker->relid);
109 }
110 
111 #endif /* WORKER_INTERNAL_H */
int slock_t
Definition: s_lock.h:958
int64 TimestampTz
Definition: timestamp.h:39
int logicalrep_sync_worker_count(Oid subid)
Definition: launcher.c:664
LogicalRepWorker * logicalrep_worker_find(Oid subid, Oid relid, bool only_running)
Definition: launcher.c:215
Subscription * MySubscription
Definition: worker.c:247
TimestampTz last_send_time
XLogRecPtr last_lsn
void invalidate_syncing_table_states(Datum arg, int cacheid, uint32 hashvalue)
Definition: tablesync.c:268
bool AllTablesyncsReady(void)
Definition: tablesync.c:1230
struct LogicalRepWorker LogicalRepWorker
unsigned int Oid
Definition: postgres_ext.h:31
NameData subname
#define OidIsValid(objectId)
Definition: c.h:710
List * logicalrep_workers_find(Oid subid, bool only_running)
Definition: launcher.c:243
void logicalrep_worker_launch(Oid dbid, Oid subid, const char *subname, Oid userid, Oid relid)
Definition: launcher.c:266
XLogRecPtr relstate_lsn
void logicalrep_worker_wakeup(Oid subid, Oid relid)
Definition: launcher.c:534
FileSet * stream_fileset
unsigned short uint16
Definition: c.h:440
char * LogicalRepSyncTableStart(XLogRecPtr *origin_startpos)
Definition: tablesync.c:920
XLogRecPtr reply_lsn
static bool am_tablesync_worker(void)
void logicalrep_worker_wakeup_ptr(LogicalRepWorker *worker)
Definition: launcher.c:554
unsigned int uint32
Definition: c.h:441
MemoryContext ApplyContext
Definition: worker.c:240
uintptr_t Datum
Definition: postgres.h:411
void logicalrep_worker_stop(Oid subid, Oid relid)
Definition: launcher.c:437
void UpdateTwoPhaseState(Oid suboid, char new_state)
Definition: tablesync.c:1255
void process_syncing_tables(XLogRecPtr current_lsn)
Definition: tablesync.c:587
TimestampTz launch_time
TimestampTz last_recv_time
uint64 XLogRecPtr
Definition: xlogdefs.h:21
bool in_remote_transaction
Definition: worker.c:250
void * arg
void logicalrep_worker_attach(int slot)
Definition: launcher.c:565
void ReplicationOriginNameForTablesync(Oid suboid, Oid relid, char *originname, int szorgname)
Definition: tablesync.c:905
Definition: proc.h:121
Definition: pg_list.h:50
struct WalReceiverConn * LogRepWorkerWalRcvConn
Definition: worker.c:245
LogicalRepWorker * MyLogicalRepWorker
Definition: launcher.c:57
TimestampTz reply_time