2017-01-19 12:00:00 -05:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
*
|
|
|
|
|
* worker_internal.h
|
|
|
|
|
* Internal headers shared by logical replication workers.
|
|
|
|
|
*
|
2018-01-02 23:30:12 -05:00
|
|
|
* Portions Copyright (c) 2016-2018, PostgreSQL Global Development Group
|
2017-01-19 12:00:00 -05:00
|
|
|
*
|
|
|
|
|
* src/include/replication/worker_internal.h
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
#ifndef WORKER_INTERNAL_H
|
|
|
|
|
#define WORKER_INTERNAL_H
|
|
|
|
|
|
2017-04-13 21:47:24 -04:00
|
|
|
#include <signal.h>
|
|
|
|
|
|
2017-01-21 15:49:53 -05:00
|
|
|
#include "access/xlogdefs.h"
|
2017-01-19 12:00:00 -05:00
|
|
|
#include "catalog/pg_subscription.h"
|
2017-01-21 15:49:53 -05:00
|
|
|
#include "datatype/timestamp.h"
|
2017-01-19 12:00:00 -05:00
|
|
|
#include "storage/lock.h"
|
|
|
|
|
|
|
|
|
|
typedef struct LogicalRepWorker
|
|
|
|
|
{
|
2017-04-26 10:43:04 -04:00
|
|
|
/* Time at which this worker was launched. */
|
2017-05-17 16:31:56 -04:00
|
|
|
TimestampTz launch_time;
|
2017-04-26 10:43:04 -04:00
|
|
|
|
|
|
|
|
/* Indicates if this slot is used or free. */
|
2017-05-17 16:31:56 -04:00
|
|
|
bool in_use;
|
2017-04-26 10:43:04 -04:00
|
|
|
|
|
|
|
|
/* Increased everytime the slot is taken by new worker. */
|
2017-05-17 16:31:56 -04:00
|
|
|
uint16 generation;
|
2017-04-26 10:43:04 -04:00
|
|
|
|
2017-01-19 12:00:00 -05:00
|
|
|
/* Pointer to proc array. NULL if not running. */
|
2017-05-17 16:31:56 -04:00
|
|
|
PGPROC *proc;
|
2017-01-19 12:00:00 -05:00
|
|
|
|
|
|
|
|
/* Database id to connect to. */
|
2017-05-17 16:31:56 -04:00
|
|
|
Oid dbid;
|
2017-01-19 12:00:00 -05:00
|
|
|
|
|
|
|
|
/* User to use for connection (will be same as owner of subscription). */
|
2017-05-17 16:31:56 -04:00
|
|
|
Oid userid;
|
2017-01-19 12:00:00 -05:00
|
|
|
|
|
|
|
|
/* Subscription id for the worker. */
|
2017-05-17 16:31:56 -04:00
|
|
|
Oid subid;
|
2017-01-19 12:00:00 -05:00
|
|
|
|
|
|
|
|
/* Used for initial table synchronization. */
|
2017-05-17 16:31:56 -04:00
|
|
|
Oid relid;
|
|
|
|
|
char relstate;
|
2017-03-23 08:36:36 -04:00
|
|
|
XLogRecPtr relstate_lsn;
|
|
|
|
|
slock_t relmutex;
|
2017-01-19 12:00:00 -05:00
|
|
|
|
|
|
|
|
/* Stats. */
|
|
|
|
|
XLogRecPtr last_lsn;
|
2017-05-17 16:31:56 -04:00
|
|
|
TimestampTz last_send_time;
|
|
|
|
|
TimestampTz last_recv_time;
|
2017-01-19 12:00:00 -05:00
|
|
|
XLogRecPtr reply_lsn;
|
2017-05-17 16:31:56 -04:00
|
|
|
TimestampTz reply_time;
|
2017-01-19 12:00:00 -05:00
|
|
|
} LogicalRepWorker;
|
|
|
|
|
|
2017-05-09 14:40:42 -04:00
|
|
|
/* Main memory context for apply worker. Permanent during worker lifetime. */
|
2017-05-17 16:31:56 -04:00
|
|
|
extern MemoryContext ApplyContext;
|
2017-03-23 08:36:36 -04:00
|
|
|
|
2017-01-19 12:00:00 -05:00
|
|
|
/* libpqreceiver connection */
|
2017-05-17 16:31:56 -04:00
|
|
|
extern struct WalReceiverConn *wrconn;
|
2017-01-19 12:00:00 -05:00
|
|
|
|
|
|
|
|
/* Worker and subscription objects. */
|
2017-05-17 16:31:56 -04:00
|
|
|
extern Subscription *MySubscription;
|
|
|
|
|
extern LogicalRepWorker *MyLogicalRepWorker;
|
2017-01-19 12:00:00 -05:00
|
|
|
|
2017-05-17 16:31:56 -04:00
|
|
|
extern bool in_remote_transaction;
|
2017-01-19 12:00:00 -05:00
|
|
|
|
|
|
|
|
extern void logicalrep_worker_attach(int slot);
|
2017-03-23 08:36:36 -04:00
|
|
|
extern LogicalRepWorker *logicalrep_worker_find(Oid subid, Oid relid,
|
2017-05-17 16:31:56 -04:00
|
|
|
bool only_running);
|
2017-08-04 21:14:35 -04:00
|
|
|
extern List *logicalrep_workers_find(Oid subid, bool only_running);
|
2017-03-23 08:36:36 -04:00
|
|
|
extern void logicalrep_worker_launch(Oid dbid, Oid subid, const char *subname,
|
2017-05-17 16:31:56 -04:00
|
|
|
Oid userid, Oid relid);
|
2017-03-23 08:36:36 -04:00
|
|
|
extern void logicalrep_worker_stop(Oid subid, Oid relid);
|
2017-08-04 21:14:35 -04:00
|
|
|
extern void logicalrep_worker_stop_at_commit(Oid subid, Oid relid);
|
2017-03-23 08:36:36 -04:00
|
|
|
extern void logicalrep_worker_wakeup(Oid subid, Oid relid);
|
|
|
|
|
extern void logicalrep_worker_wakeup_ptr(LogicalRepWorker *worker);
|
|
|
|
|
|
2017-05-17 16:31:56 -04:00
|
|
|
extern int logicalrep_sync_worker_count(Oid subid);
|
2017-01-19 12:00:00 -05:00
|
|
|
|
2017-03-23 08:36:36 -04:00
|
|
|
extern char *LogicalRepSyncTableStart(XLogRecPtr *origin_startpos);
|
2017-05-17 16:31:56 -04:00
|
|
|
void process_syncing_tables(XLogRecPtr current_lsn);
|
2017-03-23 08:36:36 -04:00
|
|
|
void invalidate_syncing_table_states(Datum arg, int cacheid,
|
2017-05-17 16:31:56 -04:00
|
|
|
uint32 hashvalue);
|
2017-03-23 08:36:36 -04:00
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
|
am_tablesync_worker(void)
|
|
|
|
|
{
|
|
|
|
|
return OidIsValid(MyLogicalRepWorker->relid);
|
|
|
|
|
}
|
2017-01-19 12:00:00 -05:00
|
|
|
|
Phase 2 of pgindent updates.
Change pg_bsd_indent to follow upstream rules for placement of comments
to the right of code, and remove pgindent hack that caused comments
following #endif to not obey the general rule.
Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using
the published version of pg_bsd_indent, but a hacked-up version that
tried to minimize the amount of movement of comments to the right of
code. The situation of interest is where such a comment has to be
moved to the right of its default placement at column 33 because there's
code there. BSD indent has always moved right in units of tab stops
in such cases --- but in the previous incarnation, indent was working
in 8-space tab stops, while now it knows we use 4-space tabs. So the
net result is that in about half the cases, such comments are placed
one tab stop left of before. This is better all around: it leaves
more room on the line for comment text, and it means that in such
cases the comment uniformly starts at the next 4-space tab stop after
the code, rather than sometimes one and sometimes two tabs after.
Also, ensure that comments following #endif are indented the same
as comments following other preprocessor commands such as #else.
That inconsistency turns out to have been self-inflicted damage
from a poorly-thought-through post-indent "fixup" in pgindent.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 15:18:54 -04:00
|
|
|
#endif /* WORKER_INTERNAL_H */
|