output_plugin.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*-------------------------------------------------------------------------
  2. * output_plugin.h
  3. * PostgreSQL Logical Decode Plugin Interface
  4. *
  5. * Copyright (c) 2012-2016, PostgreSQL Global Development Group
  6. *
  7. *-------------------------------------------------------------------------
  8. */
  9. #ifndef OUTPUT_PLUGIN_H
  10. #define OUTPUT_PLUGIN_H
  11. #include "replication/reorderbuffer.h"
  12. struct LogicalDecodingContext;
  13. struct OutputPluginCallbacks;
  14. typedef enum OutputPluginOutputType
  15. {
  16. OUTPUT_PLUGIN_BINARY_OUTPUT,
  17. OUTPUT_PLUGIN_TEXTUAL_OUTPUT
  18. } OutputPluginOutputType;
  19. /*
  20. * Options set by the output plugin, in the startup callback.
  21. */
  22. typedef struct OutputPluginOptions
  23. {
  24. OutputPluginOutputType output_type;
  25. } OutputPluginOptions;
  26. /*
  27. * Type of the shared library symbol _PG_output_plugin_init that is looked up
  28. * when loading an output plugin shared library.
  29. */
  30. typedef void (*LogicalOutputPluginInit) (struct OutputPluginCallbacks *cb);
  31. /*
  32. * Callback that gets called in a user-defined plugin. ctx->private_data can
  33. * be set to some private data.
  34. *
  35. * "is_init" will be set to "true" if the decoding slot just got defined. When
  36. * the same slot is used from there one, it will be "false".
  37. */
  38. typedef void (*LogicalDecodeStartupCB) (struct LogicalDecodingContext *ctx,
  39. OutputPluginOptions *options,
  40. bool is_init);
  41. /*
  42. * Callback called for every (explicit or implicit) BEGIN of a successful
  43. * transaction.
  44. */
  45. typedef void (*LogicalDecodeBeginCB) (struct LogicalDecodingContext *ctx,
  46. ReorderBufferTXN *txn);
  47. /*
  48. * Callback for every individual change in a successful transaction.
  49. */
  50. typedef void (*LogicalDecodeChangeCB) (struct LogicalDecodingContext *ctx,
  51. ReorderBufferTXN *txn,
  52. Relation relation,
  53. ReorderBufferChange *change);
  54. /*
  55. * Called for every (explicit or implicit) COMMIT of a successful transaction.
  56. */
  57. typedef void (*LogicalDecodeCommitCB) (struct LogicalDecodingContext *ctx,
  58. ReorderBufferTXN *txn,
  59. XLogRecPtr commit_lsn);
  60. /*
  61. * Called for the generic logical decoding messages.
  62. */
  63. typedef void (*LogicalDecodeMessageCB) (struct LogicalDecodingContext *ctx,
  64. ReorderBufferTXN *txn,
  65. XLogRecPtr message_lsn,
  66. bool transactional,
  67. const char *prefix,
  68. Size message_size,
  69. const char *message);
  70. /*
  71. * Filter changes by origin.
  72. */
  73. typedef bool (*LogicalDecodeFilterByOriginCB) (struct LogicalDecodingContext *ctx,
  74. RepOriginId origin_id);
  75. /*
  76. * Called to shutdown an output plugin.
  77. */
  78. typedef void (*LogicalDecodeShutdownCB) (struct LogicalDecodingContext *ctx);
  79. /*
  80. * Output plugin callbacks
  81. */
  82. typedef struct OutputPluginCallbacks
  83. {
  84. LogicalDecodeStartupCB startup_cb;
  85. LogicalDecodeBeginCB begin_cb;
  86. LogicalDecodeChangeCB change_cb;
  87. LogicalDecodeCommitCB commit_cb;
  88. LogicalDecodeMessageCB message_cb;
  89. LogicalDecodeFilterByOriginCB filter_by_origin_cb;
  90. LogicalDecodeShutdownCB shutdown_cb;
  91. } OutputPluginCallbacks;
  92. /* Functions in replication/logical/logical.c */
  93. extern void OutputPluginPrepareWrite(struct LogicalDecodingContext *ctx, bool last_write);
  94. extern void OutputPluginWrite(struct LogicalDecodingContext *ctx, bool last_write);
  95. #endif /* OUTPUT_PLUGIN_H */