logical.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*-------------------------------------------------------------------------
  2. * logical.h
  3. * PostgreSQL logical decoding coordination
  4. *
  5. * Copyright (c) 2012-2016, PostgreSQL Global Development Group
  6. *
  7. *-------------------------------------------------------------------------
  8. */
  9. #ifndef LOGICAL_H
  10. #define LOGICAL_H
  11. #include "replication/slot.h"
  12. #include "access/xlog.h"
  13. #include "access/xlogreader.h"
  14. #include "replication/output_plugin.h"
  15. struct LogicalDecodingContext;
  16. typedef void (*LogicalOutputPluginWriterWrite) (
  17. struct LogicalDecodingContext *lr,
  18. XLogRecPtr Ptr,
  19. TransactionId xid,
  20. bool last_write
  21. );
  22. typedef LogicalOutputPluginWriterWrite LogicalOutputPluginWriterPrepareWrite;
  23. typedef struct LogicalDecodingContext
  24. {
  25. /* memory context this is all allocated in */
  26. MemoryContext context;
  27. /* infrastructure pieces */
  28. XLogReaderState *reader;
  29. ReplicationSlot *slot;
  30. struct ReorderBuffer *reorder;
  31. struct SnapBuild *snapshot_builder;
  32. OutputPluginCallbacks callbacks;
  33. OutputPluginOptions options;
  34. /*
  35. * User specified options
  36. */
  37. List *output_plugin_options;
  38. /*
  39. * User-Provided callback for writing/streaming out data.
  40. */
  41. LogicalOutputPluginWriterPrepareWrite prepare_write;
  42. LogicalOutputPluginWriterWrite write;
  43. /*
  44. * Output buffer.
  45. */
  46. StringInfo out;
  47. /*
  48. * Private data pointer of the output plugin.
  49. */
  50. void *output_plugin_private;
  51. /*
  52. * Private data pointer for the data writer.
  53. */
  54. void *output_writer_private;
  55. /*
  56. * State for writing output.
  57. */
  58. bool accept_writes;
  59. bool prepared_write;
  60. XLogRecPtr write_location;
  61. TransactionId write_xid;
  62. } LogicalDecodingContext;
  63. extern void CheckLogicalDecodingRequirements(void);
  64. extern LogicalDecodingContext *CreateInitDecodingContext(char *plugin,
  65. List *output_plugin_options,
  66. bool need_full_snapshot,
  67. XLogPageReadCB read_page,
  68. LogicalOutputPluginWriterPrepareWrite prepare_write,
  69. LogicalOutputPluginWriterWrite do_write);
  70. extern LogicalDecodingContext *CreateDecodingContext(
  71. XLogRecPtr start_lsn,
  72. List *output_plugin_options,
  73. XLogPageReadCB read_page,
  74. LogicalOutputPluginWriterPrepareWrite prepare_write,
  75. LogicalOutputPluginWriterWrite do_write);
  76. extern void DecodingContextFindStartpoint(LogicalDecodingContext *ctx);
  77. extern bool DecodingContextReady(LogicalDecodingContext *ctx);
  78. extern void FreeDecodingContext(LogicalDecodingContext *ctx);
  79. extern void LogicalIncreaseXminForSlot(XLogRecPtr lsn, TransactionId xmin);
  80. extern void LogicalIncreaseRestartDecodingForSlot(XLogRecPtr current_lsn,
  81. XLogRecPtr restart_lsn);
  82. extern void LogicalConfirmReceivedLocation(XLogRecPtr lsn);
  83. extern bool filter_by_origin_cb_wrapper(LogicalDecodingContext *ctx, RepOriginId origin_id);
  84. #endif