1 /*------------------------------------------------------------------------- 2 * logical.h 3 * PostgreSQL logical decoding coordination 4 * 5 * Copyright (c) 2012-2020, PostgreSQL Global Development Group 6 * 7 *------------------------------------------------------------------------- 8 */ 9 #ifndef LOGICAL_H 10 #define LOGICAL_H 11 12 #include "access/xlog.h" 13 #include "access/xlogreader.h" 14 #include "replication/output_plugin.h" 15 #include "replication/slot.h" 16 17 struct LogicalDecodingContext; 18 19 typedef void (*LogicalOutputPluginWriterWrite) (struct LogicalDecodingContext *lr, 20 XLogRecPtr Ptr, 21 TransactionId xid, 22 bool last_write 23 ); 24 25 typedef LogicalOutputPluginWriterWrite LogicalOutputPluginWriterPrepareWrite; 26 27 typedef void (*LogicalOutputPluginWriterUpdateProgress) (struct LogicalDecodingContext *lr, 28 XLogRecPtr Ptr, 29 TransactionId xid 30 ); 31 32 typedef struct LogicalDecodingContext 33 { 34 /* memory context this is all allocated in */ 35 MemoryContext context; 36 37 /* The associated replication slot */ 38 ReplicationSlot *slot; 39 40 /* infrastructure pieces for decoding */ 41 XLogReaderState *reader; 42 struct ReorderBuffer *reorder; 43 struct SnapBuild *snapshot_builder; 44 45 /* 46 * Marks the logical decoding context as fast forward decoding one. Such a 47 * context does not have plugin loaded so most of the following properties 48 * are unused. 49 */ 50 bool fast_forward; 51 52 OutputPluginCallbacks callbacks; 53 OutputPluginOptions options; 54 55 /* 56 * User specified options 57 */ 58 List *output_plugin_options; 59 60 /* 61 * User-Provided callback for writing/streaming out data. 62 */ 63 LogicalOutputPluginWriterPrepareWrite prepare_write; 64 LogicalOutputPluginWriterWrite write; 65 LogicalOutputPluginWriterUpdateProgress update_progress; 66 67 /* 68 * Output buffer. 69 */ 70 StringInfo out; 71 72 /* 73 * Private data pointer of the output plugin. 74 */ 75 void *output_plugin_private; 76 77 /* 78 * Private data pointer for the data writer. 79 */ 80 void *output_writer_private; 81 82 /* 83 * State for writing output. 84 */ 85 bool accept_writes; 86 bool prepared_write; 87 XLogRecPtr write_location; 88 TransactionId write_xid; 89 } LogicalDecodingContext; 90 91 92 extern void CheckLogicalDecodingRequirements(void); 93 94 extern LogicalDecodingContext *CreateInitDecodingContext(char *plugin, 95 List *output_plugin_options, 96 bool need_full_snapshot, 97 XLogRecPtr restart_lsn, 98 XLogReaderRoutine *xl_routine, 99 LogicalOutputPluginWriterPrepareWrite prepare_write, 100 LogicalOutputPluginWriterWrite do_write, 101 LogicalOutputPluginWriterUpdateProgress update_progress); 102 extern LogicalDecodingContext *CreateDecodingContext(XLogRecPtr start_lsn, 103 List *output_plugin_options, 104 bool fast_forward, 105 XLogReaderRoutine *xl_routine, 106 LogicalOutputPluginWriterPrepareWrite prepare_write, 107 LogicalOutputPluginWriterWrite do_write, 108 LogicalOutputPluginWriterUpdateProgress update_progress); 109 extern void DecodingContextFindStartpoint(LogicalDecodingContext *ctx); 110 extern bool DecodingContextReady(LogicalDecodingContext *ctx); 111 extern void FreeDecodingContext(LogicalDecodingContext *ctx); 112 113 extern void LogicalIncreaseXminForSlot(XLogRecPtr lsn, TransactionId xmin); 114 extern void LogicalIncreaseRestartDecodingForSlot(XLogRecPtr current_lsn, 115 XLogRecPtr restart_lsn); 116 extern void LogicalConfirmReceivedLocation(XLogRecPtr lsn); 117 118 extern bool filter_by_origin_cb_wrapper(LogicalDecodingContext *ctx, RepOriginId origin_id); 119 120 #endif 121