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-2022, 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/fileset.h"
21 #include "storage/lock.h"
22 #include "storage/spin.h"
23 
24 
25 typedef struct LogicalRepWorker
26 {
27  /* Time at which this worker was launched. */
29 
30  /* Indicates if this slot is used or free. */
31  bool in_use;
32 
33  /* Increased every time the slot is taken by new worker. */
35 
36  /* Pointer to proc array. NULL if not running. */
38 
39  /* Database id to connect to. */
41 
42  /* User to use for connection (will be same as owner of subscription). */
44 
45  /* Subscription id for the worker. */
47 
48  /* Used for initial table synchronization. */
50  char relstate;
53 
54  /*
55  * Used to create the changes and subxact files for the streaming
56  * transactions. Upon the arrival of the first streaming transaction, the
57  * fileset will be initialized, and it will be deleted when the worker
58  * exits. Under this, separate buffiles would be created for each
59  * transaction which will be deleted after the transaction is finished.
60  */
62 
63  /* Stats. */
70 
71 /* Main memory context for apply worker. Permanent during worker lifetime. */
73 
74 /* libpqreceiver connection */
76 
77 /* Worker and subscription objects. */
80 
82 
83 extern void logicalrep_worker_attach(int slot);
84 extern LogicalRepWorker *logicalrep_worker_find(Oid subid, Oid relid,
85  bool only_running);
86 extern List *logicalrep_workers_find(Oid subid, bool only_running);
87 extern void logicalrep_worker_launch(Oid dbid, Oid subid, const char *subname,
88  Oid userid, Oid relid);
89 extern void logicalrep_worker_stop(Oid subid, Oid relid);
90 extern void logicalrep_worker_wakeup(Oid subid, Oid relid);
92 
93 extern int logicalrep_sync_worker_count(Oid subid);
94 
95 extern void ReplicationOriginNameForTablesync(Oid suboid, Oid relid,
96  char *originname, int szorgname);
97 extern char *LogicalRepSyncTableStart(XLogRecPtr *origin_startpos);
98 
99 extern bool AllTablesyncsReady(void);
100 extern void UpdateTwoPhaseState(Oid suboid, char new_state);
101 
102 extern void process_syncing_tables(XLogRecPtr current_lsn);
103 extern void invalidate_syncing_table_states(Datum arg, int cacheid,
104  uint32 hashvalue);
105 
106 static inline bool
108 {
110 }
111 
112 #endif /* WORKER_INTERNAL_H */
unsigned short uint16
Definition: c.h:440
unsigned int uint32
Definition: c.h:441
#define PGDLLIMPORT
Definition: c.h:1331
#define OidIsValid(objectId)
Definition: c.h:710
int64 TimestampTz
Definition: timestamp.h:39
void * arg
NameData subname
uintptr_t Datum
Definition: postgres.h:411
unsigned int Oid
Definition: postgres_ext.h:31
int slock_t
Definition: s_lock.h:975
Definition: pg_list.h:51
XLogRecPtr relstate_lsn
TimestampTz last_recv_time
TimestampTz launch_time
TimestampTz reply_time
FileSet * stream_fileset
XLogRecPtr reply_lsn
XLogRecPtr last_lsn
TimestampTz last_send_time
Definition: proc.h:160
bool AllTablesyncsReady(void)
Definition: tablesync.c:1515
LogicalRepWorker * logicalrep_worker_find(Oid subid, Oid relid, bool only_running)
Definition: launcher.c:214
PGDLLIMPORT bool in_remote_transaction
Definition: worker.c:256
void logicalrep_worker_wakeup_ptr(LogicalRepWorker *worker)
Definition: launcher.c:553
void invalidate_syncing_table_states(Datum arg, int cacheid, uint32 hashvalue)
Definition: tablesync.c:271
PGDLLIMPORT LogicalRepWorker * MyLogicalRepWorker
Definition: launcher.c:58
void logicalrep_worker_attach(int slot)
Definition: launcher.c:564
void ReplicationOriginNameForTablesync(Oid suboid, Oid relid, char *originname, int szorgname)
Definition: tablesync.c:1164
void logicalrep_worker_launch(Oid dbid, Oid subid, const char *subname, Oid userid, Oid relid)
Definition: launcher.c:265
List * logicalrep_workers_find(Oid subid, bool only_running)
Definition: launcher.c:242
void process_syncing_tables(XLogRecPtr current_lsn)
Definition: tablesync.c:590
char * LogicalRepSyncTableStart(XLogRecPtr *origin_startpos)
Definition: tablesync.c:1179
PGDLLIMPORT struct WalReceiverConn * LogRepWorkerWalRcvConn
Definition: worker.c:251
void logicalrep_worker_wakeup(Oid subid, Oid relid)
Definition: launcher.c:533
void logicalrep_worker_stop(Oid subid, Oid relid)
Definition: launcher.c:436
struct LogicalRepWorker LogicalRepWorker
static bool am_tablesync_worker(void)
PGDLLIMPORT Subscription * MySubscription
Definition: worker.c:253
int logicalrep_sync_worker_count(Oid subid)
Definition: launcher.c:663
void UpdateTwoPhaseState(Oid suboid, char new_state)
Definition: tablesync.c:1540
PGDLLIMPORT MemoryContext ApplyContext
Definition: worker.c:246
uint64 XLogRecPtr
Definition: xlogdefs.h:21