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