logical.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*-------------------------------------------------------------------------
  2. * logical.h
  3. * PostgreSQL logical decoding coordination
  4. *
  5. * Copyright (c) 2012-2022, PostgreSQL Global Development Group
  6. *
  7. *-------------------------------------------------------------------------
  8. */
  9. #ifndef LOGICAL_H
  10. #define LOGICAL_H
  11. #include "access/xlog.h"
  12. #include "access/xlogreader.h"
  13. #include "replication/output_plugin.h"
  14. #include "replication/slot.h"
  15. struct LogicalDecodingContext;
  16. typedef void (*LogicalOutputPluginWriterWrite) (struct LogicalDecodingContext *lr,
  17. XLogRecPtr Ptr,
  18. TransactionId xid,
  19. bool last_write
  20. );
  21. typedef LogicalOutputPluginWriterWrite LogicalOutputPluginWriterPrepareWrite;
  22. typedef void (*LogicalOutputPluginWriterUpdateProgress) (struct LogicalDecodingContext *lr,
  23. XLogRecPtr Ptr,
  24. TransactionId xid,
  25. bool skipped_xact
  26. );
  27. typedef struct LogicalDecodingContext
  28. {
  29. /* memory context this is all allocated in */
  30. MemoryContext context;
  31. /* The associated replication slot */
  32. ReplicationSlot *slot;
  33. /* infrastructure pieces for decoding */
  34. XLogReaderState *reader;
  35. struct ReorderBuffer *reorder;
  36. struct SnapBuild *snapshot_builder;
  37. /*
  38. * Marks the logical decoding context as fast forward decoding one. Such a
  39. * context does not have plugin loaded so most of the following properties
  40. * are unused.
  41. */
  42. bool fast_forward;
  43. OutputPluginCallbacks callbacks;
  44. OutputPluginOptions options;
  45. /*
  46. * User specified options
  47. */
  48. List *output_plugin_options;
  49. /*
  50. * User-Provided callback for writing/streaming out data.
  51. */
  52. LogicalOutputPluginWriterPrepareWrite prepare_write;
  53. LogicalOutputPluginWriterWrite write;
  54. LogicalOutputPluginWriterUpdateProgress update_progress;
  55. /*
  56. * Output buffer.
  57. */
  58. StringInfo out;
  59. /*
  60. * Private data pointer of the output plugin.
  61. */
  62. void *output_plugin_private;
  63. /*
  64. * Private data pointer for the data writer.
  65. */
  66. void *output_writer_private;
  67. /*
  68. * Does the output plugin support streaming, and is it enabled?
  69. */
  70. bool streaming;
  71. /*
  72. * Does the output plugin support two-phase decoding, and is it enabled?
  73. */
  74. bool twophase;
  75. /*
  76. * Is two-phase option given by output plugin?
  77. *
  78. * This flag indicates that the plugin passed in the two-phase option as
  79. * part of the START_STREAMING command. We can't rely solely on the
  80. * twophase flag which only tells whether the plugin provided all the
  81. * necessary two-phase callbacks.
  82. */
  83. bool twophase_opt_given;
  84. /*
  85. * State for writing output.
  86. */
  87. bool accept_writes;
  88. bool prepared_write;
  89. XLogRecPtr write_location;
  90. TransactionId write_xid;
  91. /* Are we processing the end LSN of a transaction? */
  92. bool end_xact;
  93. } LogicalDecodingContext;
  94. extern void CheckLogicalDecodingRequirements(void);
  95. extern LogicalDecodingContext *CreateInitDecodingContext(const char *plugin,
  96. List *output_plugin_options,
  97. bool need_full_snapshot,
  98. XLogRecPtr restart_lsn,
  99. XLogReaderRoutine *xl_routine,
  100. LogicalOutputPluginWriterPrepareWrite prepare_write,
  101. LogicalOutputPluginWriterWrite do_write,
  102. LogicalOutputPluginWriterUpdateProgress update_progress);
  103. extern LogicalDecodingContext *CreateDecodingContext(XLogRecPtr start_lsn,
  104. List *output_plugin_options,
  105. bool fast_forward,
  106. XLogReaderRoutine *xl_routine,
  107. LogicalOutputPluginWriterPrepareWrite prepare_write,
  108. LogicalOutputPluginWriterWrite do_write,
  109. LogicalOutputPluginWriterUpdateProgress update_progress);
  110. extern void DecodingContextFindStartpoint(LogicalDecodingContext *ctx);
  111. extern bool DecodingContextReady(LogicalDecodingContext *ctx);
  112. extern void FreeDecodingContext(LogicalDecodingContext *ctx);
  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. extern bool filter_prepare_cb_wrapper(LogicalDecodingContext *ctx,
  118. TransactionId xid, const char *gid);
  119. extern bool filter_by_origin_cb_wrapper(LogicalDecodingContext *ctx, RepOriginId origin_id);
  120. extern void ResetLogicalStreamingState(void);
  121. extern void UpdateDecodingStats(LogicalDecodingContext *ctx);
  122. #endif