@@ -213,39 +213,163 @@ typedef struct WalRcvExecResult
213
213
TupleDesc tupledesc ;
214
214
} WalRcvExecResult ;
215
215
216
- /* libpqwalreceiver hooks */
217
- typedef WalReceiverConn * (* walrcv_connect_fn ) (const char * conninfo , bool logical ,
216
+ /* WAL receiver - libpqwalreceiver hooks */
217
+
218
+ /*
219
+ * walrcv_connect_fn
220
+ *
221
+ * Establish connection to a cluster. 'logical' is true if the
222
+ * connection is logical, and false if the connection is physical.
223
+ * 'appname' is a name associated to the connection, to use for example
224
+ * with fallback_application_name or application_name. Returns the
225
+ * details about the connection established, as defined by
226
+ * WalReceiverConn for each WAL receiver module. On error, NULL is
227
+ * returned with 'err' including the error generated.
228
+ */
229
+ typedef WalReceiverConn * (* walrcv_connect_fn ) (const char * conninfo ,
230
+ bool logical ,
218
231
const char * appname ,
219
232
char * * err );
233
+
234
+ /*
235
+ * walrcv_check_conninfo_fn
236
+ *
237
+ * Parse and validate the connection string given as of 'conninfo'.
238
+ */
220
239
typedef void (* walrcv_check_conninfo_fn ) (const char * conninfo );
240
+
241
+ /*
242
+ * walrcv_get_conninfo_fn
243
+ *
244
+ * Returns a user-displayable conninfo string. Note that any
245
+ * security-sensitive fields should be obfuscated.
246
+ */
221
247
typedef char * (* walrcv_get_conninfo_fn ) (WalReceiverConn * conn );
248
+
249
+ /*
250
+ * walrcv_get_senderinfo_fn
251
+ *
252
+ * Provide information of the WAL sender this WAL receiver is connected
253
+ * to, as of 'sender_host' for the host of the sender and 'sender_port'
254
+ * for its port.
255
+ */
222
256
typedef void (* walrcv_get_senderinfo_fn ) (WalReceiverConn * conn ,
223
257
char * * sender_host ,
224
258
int * sender_port );
259
+
260
+ /*
261
+ * walrcv_identify_system_fn
262
+ *
263
+ * Run IDENTIFY_SYSTEM on the cluster connected to and validate the
264
+ * identity of the cluster. Returns the system ID of the cluster
265
+ * connected to. 'primary_tli' is the timeline ID of the sender.
266
+ */
225
267
typedef char * (* walrcv_identify_system_fn ) (WalReceiverConn * conn ,
226
268
TimeLineID * primary_tli );
269
+
270
+ /*
271
+ * walrcv_server_version_fn
272
+ *
273
+ * Returns the version number of the cluster connected to.
274
+ */
227
275
typedef int (* walrcv_server_version_fn ) (WalReceiverConn * conn );
276
+
277
+ /*
278
+ * walrcv_readtimelinehistoryfile_fn
279
+ *
280
+ * Fetch from cluster the timeline history file for timeline 'tli'.
281
+ * Returns the name of the timeline history file as of 'filename', its
282
+ * contents as of 'content' and its 'size'.
283
+ */
228
284
typedef void (* walrcv_readtimelinehistoryfile_fn ) (WalReceiverConn * conn ,
229
285
TimeLineID tli ,
230
286
char * * filename ,
231
- char * * content , int * size );
287
+ char * * content ,
288
+ int * size );
289
+
290
+ /*
291
+ * walrcv_startstreaming_fn
292
+ *
293
+ * Start streaming WAL data from given streaming options. Returns true
294
+ * if the connection has switched successfully to copy-both mode and false
295
+ * if the server received the command and executed it successfully, but
296
+ * didn't switch to copy-mode.
297
+ */
232
298
typedef bool (* walrcv_startstreaming_fn ) (WalReceiverConn * conn ,
233
299
const WalRcvStreamOptions * options );
300
+
301
+ /*
302
+ * walrcv_endstreaming_fn
303
+ *
304
+ * Stop streaming of WAL data. Returns the next timeline ID of the cluster
305
+ * connected to in 'next_tli', or 0 if there was no report.
306
+ */
234
307
typedef void (* walrcv_endstreaming_fn ) (WalReceiverConn * conn ,
235
308
TimeLineID * next_tli );
236
- typedef int (* walrcv_receive_fn ) (WalReceiverConn * conn , char * * buffer ,
309
+
310
+ /*
311
+ * walrcv_receive_fn
312
+ *
313
+ * Receive a message available from the WAL stream. 'buffer' is a pointer
314
+ * to a buffer holding the message received. Returns the length of the data,
315
+ * 0 if no data is available yet ('wait_fd' is a socket descriptor which can
316
+ * be waited on before a retry), and -1 if the cluster ended the COPY.
317
+ */
318
+ typedef int (* walrcv_receive_fn ) (WalReceiverConn * conn ,
319
+ char * * buffer ,
237
320
pgsocket * wait_fd );
238
- typedef void (* walrcv_send_fn ) (WalReceiverConn * conn , const char * buffer ,
321
+
322
+ /*
323
+ * walrcv_send_fn
324
+ *
325
+ * Send a message of size 'nbytes' to the WAL stream with 'buffer' as
326
+ * contents.
327
+ */
328
+ typedef void (* walrcv_send_fn ) (WalReceiverConn * conn ,
329
+ const char * buffer ,
239
330
int nbytes );
331
+
332
+ /*
333
+ * walrcv_create_slot_fn
334
+ *
335
+ * Create a new replication slot named 'slotname'. 'temporary' defines
336
+ * if the slot is temporary. 'snapshot_action' defines the behavior wanted
337
+ * for an exported snapshot (see replication protocol for more details).
338
+ * 'lsn' includes the LSN position at which the created slot became
339
+ * consistent. Returns the name of the exported snapshot for a logical
340
+ * slot, or NULL for a physical slot.
341
+ */
240
342
typedef char * (* walrcv_create_slot_fn ) (WalReceiverConn * conn ,
241
- const char * slotname , bool temporary ,
343
+ const char * slotname ,
344
+ bool temporary ,
242
345
CRSSnapshotAction snapshot_action ,
243
346
XLogRecPtr * lsn );
347
+
348
+ /*
349
+ * walrcv_get_backend_pid_fn
350
+ *
351
+ * Returns the PID of the remote backend process.
352
+ */
244
353
typedef pid_t (* walrcv_get_backend_pid_fn ) (WalReceiverConn * conn );
354
+
355
+ /*
356
+ * walrcv_exec_fn
357
+ *
358
+ * Send generic queries (and commands) to the remote cluster. 'nRetTypes'
359
+ * is the expected number of returned attributes, and 'retTypes' an array
360
+ * including their type OIDs. Returns the status of the execution and
361
+ * tuples if any.
362
+ */
245
363
typedef WalRcvExecResult * (* walrcv_exec_fn ) (WalReceiverConn * conn ,
246
364
const char * query ,
247
365
const int nRetTypes ,
248
366
const Oid * retTypes );
367
+
368
+ /*
369
+ * walrcv_disconnect_fn
370
+ *
371
+ * Disconnect with the cluster.
372
+ */
249
373
typedef void (* walrcv_disconnect_fn ) (WalReceiverConn * conn );
250
374
251
375
typedef struct WalReceiverFunctionsType
0 commit comments