mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Refactor libpqwalreceiver
The whole walreceiver API is now wrapped into a struct, like most of our other loadable module APIs. The libpq connection is no longer a global variable in libpqwalreceiver. Instead, it is encapsulated into a struct that is passed around the functions. This allows multiple walreceivers to run at the same time. Add some rudimentary support for logical replication connections to libpqwalreceiver. These changes are mostly cosmetic and are going to be useful for the future logical replication patches. From: Petr Jelinek <petr@2ndquadrant.com>
This commit is contained in:
@@ -134,33 +134,64 @@ typedef struct
|
||||
|
||||
extern WalRcvData *WalRcv;
|
||||
|
||||
struct WalReceiverConn;
|
||||
typedef struct WalReceiverConn WalReceiverConn;
|
||||
|
||||
/* libpqwalreceiver hooks */
|
||||
typedef void (*walrcv_connect_type) (char *conninfo);
|
||||
extern PGDLLIMPORT walrcv_connect_type walrcv_connect;
|
||||
typedef WalReceiverConn *(*walrcv_connect_fn) (const char *conninfo, bool logical,
|
||||
const char *appname);
|
||||
typedef char *(*walrcv_get_conninfo_fn) (WalReceiverConn *conn);
|
||||
typedef char *(*walrcv_identify_system_fn) (WalReceiverConn *conn,
|
||||
TimeLineID *primary_tli);
|
||||
typedef void (*walrcv_readtimelinehistoryfile_fn) (WalReceiverConn *conn,
|
||||
TimeLineID tli,
|
||||
char **filename,
|
||||
char **content, int *size);
|
||||
typedef bool (*walrcv_startstreaming_fn) (WalReceiverConn *conn,
|
||||
TimeLineID tli,
|
||||
XLogRecPtr startpoint,
|
||||
const char *slotname);
|
||||
typedef void (*walrcv_endstreaming_fn) (WalReceiverConn *conn,
|
||||
TimeLineID *next_tli);
|
||||
typedef int (*walrcv_receive_fn) (WalReceiverConn *conn, char **buffer,
|
||||
pgsocket *wait_fd);
|
||||
typedef void (*walrcv_send_fn) (WalReceiverConn *conn, const char *buffer,
|
||||
int nbytes);
|
||||
typedef void (*walrcv_disconnect_fn) (WalReceiverConn *conn);
|
||||
|
||||
typedef char *(*walrcv_get_conninfo_type) (void);
|
||||
extern PGDLLIMPORT walrcv_get_conninfo_type walrcv_get_conninfo;
|
||||
typedef struct WalReceiverFunctionsType
|
||||
{
|
||||
walrcv_connect_fn connect;
|
||||
walrcv_get_conninfo_fn get_conninfo;
|
||||
walrcv_identify_system_fn identify_system;
|
||||
walrcv_readtimelinehistoryfile_fn readtimelinehistoryfile;
|
||||
walrcv_startstreaming_fn startstreaming;
|
||||
walrcv_endstreaming_fn endstreaming;
|
||||
walrcv_receive_fn receive;
|
||||
walrcv_send_fn send;
|
||||
walrcv_disconnect_fn disconnect;
|
||||
} WalReceiverFunctionsType;
|
||||
|
||||
typedef void (*walrcv_identify_system_type) (TimeLineID *primary_tli);
|
||||
extern PGDLLIMPORT walrcv_identify_system_type walrcv_identify_system;
|
||||
extern PGDLLIMPORT WalReceiverFunctionsType *WalReceiverFunctions;
|
||||
|
||||
typedef void (*walrcv_readtimelinehistoryfile_type) (TimeLineID tli, char **filename, char **content, int *size);
|
||||
extern PGDLLIMPORT walrcv_readtimelinehistoryfile_type walrcv_readtimelinehistoryfile;
|
||||
|
||||
typedef bool (*walrcv_startstreaming_type) (TimeLineID tli, XLogRecPtr startpoint, char *slotname);
|
||||
extern PGDLLIMPORT walrcv_startstreaming_type walrcv_startstreaming;
|
||||
|
||||
typedef void (*walrcv_endstreaming_type) (TimeLineID *next_tli);
|
||||
extern PGDLLIMPORT walrcv_endstreaming_type walrcv_endstreaming;
|
||||
|
||||
typedef int (*walrcv_receive_type) (char **buffer, pgsocket *wait_fd);
|
||||
extern PGDLLIMPORT walrcv_receive_type walrcv_receive;
|
||||
|
||||
typedef void (*walrcv_send_type) (const char *buffer, int nbytes);
|
||||
extern PGDLLIMPORT walrcv_send_type walrcv_send;
|
||||
|
||||
typedef void (*walrcv_disconnect_type) (void);
|
||||
extern PGDLLIMPORT walrcv_disconnect_type walrcv_disconnect;
|
||||
#define walrcv_connect(conninfo, logical, appname) \
|
||||
WalReceiverFunctions->connect(conninfo, logical, appname)
|
||||
#define walrcv_get_conninfo(conn) \
|
||||
WalReceiverFunctions->get_conninfo(conn)
|
||||
#define walrcv_identify_system(conn, primary_tli) \
|
||||
WalReceiverFunctions->identify_system(conn, primary_tli)
|
||||
#define walrcv_readtimelinehistoryfile(conn, tli, filename, content, size) \
|
||||
WalReceiverFunctions->readtimelinehistoryfile(conn, tli, filename, content, size)
|
||||
#define walrcv_startstreaming(conn, tli, startpoint, slotname) \
|
||||
WalReceiverFunctions->startstreaming(conn, tli, startpoint, slotname)
|
||||
#define walrcv_endstreaming(conn, next_tli) \
|
||||
WalReceiverFunctions->endstreaming(conn, next_tli)
|
||||
#define walrcv_receive(conn, buffer, wait_fd) \
|
||||
WalReceiverFunctions->receive(conn, buffer, wait_fd)
|
||||
#define walrcv_send(conn, buffer, nbytes) \
|
||||
WalReceiverFunctions->send(conn, buffer, nbytes)
|
||||
#define walrcv_disconnect(conn) \
|
||||
WalReceiverFunctions->disconnect(conn)
|
||||
|
||||
/* prototypes for functions in walreceiver.c */
|
||||
extern void WalReceiverMain(void) pg_attribute_noreturn();
|
||||
|
Reference in New Issue
Block a user