2
0

mariadb_rpl.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /* Copyright (C) 2018 MariaDB Corporation AB
  2. This library is free software; you can redistribute it and/or
  3. modify it under the terms of the GNU Library General Public
  4. License as published by the Free Software Foundation; either
  5. version 2 of the License, or (at your option) any later version.
  6. This library is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9. Library General Public License for more details.
  10. You should have received a copy of the GNU Library General Public
  11. License along with this library; if not, write to the Free
  12. Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  13. MA 02111-1301, USA */
  14. #ifndef _mariadb_rpl_h_
  15. #define _mariadb_rpl_h_
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. #include <stdint.h>
  20. #define MARIADB_RPL_VERSION 0x0001
  21. #define MARIADB_RPL_REQUIRED_VERSION 0x0001
  22. /* Protocol flags */
  23. #define MARIADB_RPL_BINLOG_DUMP_NON_BLOCK 1
  24. #define MARIADB_RPL_BINLOG_SEND_ANNOTATE_ROWS 2
  25. #define MARIADB_RPL_IGNORE_HEARTBEAT (1 << 17)
  26. #define EVENT_HEADER_OFS 20
  27. #define FL_GROUP_COMMIT_ID 2
  28. #define FL_STMT_END 1
  29. #define LOG_EVENT_ARTIFICIAL_F 0x20
  30. /* Options */
  31. enum mariadb_rpl_option {
  32. MARIADB_RPL_FILENAME, /* Filename and length */
  33. MARIADB_RPL_START, /* Start position */
  34. MARIADB_RPL_SERVER_ID, /* Server ID */
  35. MARIADB_RPL_FLAGS, /* Protocol flags */
  36. MARIADB_RPL_GTID_CALLBACK, /* GTID callback function */
  37. MARIADB_RPL_GTID_DATA, /* GTID data */
  38. MARIADB_RPL_BUFFER
  39. };
  40. /* Event types: From MariaDB Server sql/log_event.h */
  41. enum mariadb_rpl_event {
  42. UNKNOWN_EVENT= 0,
  43. START_EVENT_V3= 1,
  44. QUERY_EVENT= 2,
  45. STOP_EVENT= 3,
  46. ROTATE_EVENT= 4,
  47. INTVAR_EVENT= 5,
  48. LOAD_EVENT= 6,
  49. SLAVE_EVENT= 7,
  50. CREATE_FILE_EVENT= 8,
  51. APPEND_BLOCK_EVENT= 9,
  52. EXEC_LOAD_EVENT= 10,
  53. DELETE_FILE_EVENT= 11,
  54. NEW_LOAD_EVENT= 12,
  55. RAND_EVENT= 13,
  56. USER_VAR_EVENT= 14,
  57. FORMAT_DESCRIPTION_EVENT= 15,
  58. XID_EVENT= 16,
  59. BEGIN_LOAD_QUERY_EVENT= 17,
  60. EXECUTE_LOAD_QUERY_EVENT= 18,
  61. TABLE_MAP_EVENT = 19,
  62. PRE_GA_WRITE_ROWS_EVENT = 20, /* deprecated */
  63. PRE_GA_UPDATE_ROWS_EVENT = 21, /* deprecated */
  64. PRE_GA_DELETE_ROWS_EVENT = 22, /* deprecated */
  65. WRITE_ROWS_EVENT_V1 = 23,
  66. UPDATE_ROWS_EVENT_V1 = 24,
  67. DELETE_ROWS_EVENT_V1 = 25,
  68. INCIDENT_EVENT= 26,
  69. HEARTBEAT_LOG_EVENT= 27,
  70. IGNORABLE_LOG_EVENT= 28,
  71. ROWS_QUERY_LOG_EVENT= 29,
  72. WRITE_ROWS_EVENT = 30,
  73. UPDATE_ROWS_EVENT = 31,
  74. DELETE_ROWS_EVENT = 32,
  75. GTID_LOG_EVENT= 33,
  76. ANONYMOUS_GTID_LOG_EVENT= 34,
  77. PREVIOUS_GTIDS_LOG_EVENT= 35,
  78. TRANSACTION_CONTEXT_EVENT= 36,
  79. VIEW_CHANGE_EVENT= 37,
  80. XA_PREPARE_LOG_EVENT= 38,
  81. /*
  82. Add new events here - right above this comment!
  83. Existing events (except ENUM_END_EVENT) should never change their numbers
  84. */
  85. /* New MySQL/Sun events are to be added right above this comment */
  86. MYSQL_EVENTS_END,
  87. MARIA_EVENTS_BEGIN= 160,
  88. ANNOTATE_ROWS_EVENT= 160,
  89. BINLOG_CHECKPOINT_EVENT= 161,
  90. GTID_EVENT= 162,
  91. GTID_LIST_EVENT= 163,
  92. START_ENCRYPTION_EVENT= 164,
  93. QUERY_COMPRESSED_EVENT = 165,
  94. WRITE_ROWS_COMPRESSED_EVENT_V1 = 166,
  95. UPDATE_ROWS_COMPRESSED_EVENT_V1 = 167,
  96. DELETE_ROWS_COMPRESSED_EVENT_V1 = 168,
  97. WRITE_ROWS_COMPRESSED_EVENT = 169,
  98. UPDATE_ROWS_COMPRESSED_EVENT = 170,
  99. DELETE_ROWS_COMPRESSED_EVENT = 171,
  100. /* Add new MariaDB events here - right above this comment! */
  101. ENUM_END_EVENT /* end marker */
  102. };
  103. typedef struct {
  104. char *str;
  105. size_t length;
  106. } MARIADB_STRING;
  107. enum mariadb_row_event_type {
  108. WRITE_ROWS= 0,
  109. UPDATE_ROWS= 1,
  110. DELETE_ROWS= 2
  111. };
  112. /* Global transaction id */
  113. typedef struct st_mariadb_gtid {
  114. unsigned int domain_id;
  115. unsigned int server_id;
  116. unsigned long long sequence_nr;
  117. } MARIADB_GTID;
  118. /* Generic replication handle */
  119. typedef struct st_mariadb_rpl {
  120. unsigned int version;
  121. MYSQL *mysql;
  122. char *filename;
  123. uint32_t filename_length;
  124. unsigned char *buffer;
  125. unsigned long buffer_size;
  126. uint32_t server_id;
  127. unsigned long start_position;
  128. uint32_t flags;
  129. uint8_t fd_header_len; /* header len from last format description event */
  130. uint8_t use_checksum;
  131. } MARIADB_RPL;
  132. /* Event header */
  133. struct st_mariadb_rpl_rotate_event {
  134. unsigned long long position;
  135. MARIADB_STRING filename;
  136. };
  137. struct st_mariadb_rpl_query_event {
  138. uint32_t thread_id;
  139. uint32_t seconds;
  140. MARIADB_STRING database;
  141. uint32_t errornr;
  142. MARIADB_STRING status;
  143. MARIADB_STRING statement;
  144. };
  145. struct st_mariadb_rpl_gtid_list_event {
  146. uint32_t gtid_cnt;
  147. MARIADB_GTID *gtid;
  148. };
  149. struct st_mariadb_rpl_format_description_event
  150. {
  151. uint16_t format;
  152. char *server_version;
  153. uint32_t timestamp;
  154. uint8_t header_len;
  155. };
  156. struct st_mariadb_rpl_checkpoint_event {
  157. MARIADB_STRING filename;
  158. };
  159. struct st_mariadb_rpl_xid_event {
  160. uint64_t transaction_nr;
  161. };
  162. struct st_mariadb_rpl_gtid_event {
  163. uint64_t sequence_nr;
  164. uint32_t domain_id;
  165. uint8_t flags;
  166. uint64_t commit_id;
  167. };
  168. struct st_mariadb_rpl_annotate_rows_event {
  169. MARIADB_STRING statement;
  170. };
  171. struct st_mariadb_rpl_table_map_event {
  172. unsigned long long table_id;
  173. MARIADB_STRING database;
  174. MARIADB_STRING table;
  175. unsigned int column_count;
  176. MARIADB_STRING column_types;
  177. MARIADB_STRING metadata;
  178. char *null_indicator;
  179. };
  180. struct st_mariadb_rpl_rand_event {
  181. unsigned long long first_seed;
  182. unsigned long long second_seed;
  183. };
  184. struct st_mariadb_rpl_encryption_event {
  185. char scheme;
  186. unsigned int key_version;
  187. char *nonce;
  188. };
  189. struct st_mariadb_rpl_intvar_event {
  190. char type;
  191. unsigned long long value;
  192. };
  193. struct st_mariadb_rpl_uservar_event {
  194. MARIADB_STRING name;
  195. uint8_t is_null;
  196. uint8_t type;
  197. uint32_t charset_nr;
  198. MARIADB_STRING value;
  199. uint8_t flags;
  200. };
  201. struct st_mariadb_rpl_rows_event {
  202. enum mariadb_row_event_type type;
  203. uint64_t table_id;
  204. uint16_t flags;
  205. uint32_t column_count;
  206. char *column_bitmap;
  207. char *column_update_bitmap;
  208. size_t row_data_size;
  209. void *row_data;
  210. size_t extra_data_size;
  211. void *extra_data;
  212. };
  213. struct st_mariadb_rpl_heartbeat_event {
  214. uint32_t timestamp;
  215. uint32_t next_position;
  216. uint8_t type;
  217. uint16_t flags;
  218. };
  219. typedef struct st_mariadb_rpl_event
  220. {
  221. /* common header */
  222. MA_MEM_ROOT memroot;
  223. unsigned int checksum;
  224. char ok;
  225. enum mariadb_rpl_event event_type;
  226. unsigned int timestamp;
  227. unsigned int server_id;
  228. unsigned int event_length;
  229. unsigned int next_event_pos;
  230. unsigned short flags;
  231. /****************/
  232. union {
  233. struct st_mariadb_rpl_rotate_event rotate;
  234. struct st_mariadb_rpl_query_event query;
  235. struct st_mariadb_rpl_format_description_event format_description;
  236. struct st_mariadb_rpl_gtid_list_event gtid_list;
  237. struct st_mariadb_rpl_checkpoint_event checkpoint;
  238. struct st_mariadb_rpl_xid_event xid;
  239. struct st_mariadb_rpl_gtid_event gtid;
  240. struct st_mariadb_rpl_annotate_rows_event annotate_rows;
  241. struct st_mariadb_rpl_table_map_event table_map;
  242. struct st_mariadb_rpl_rand_event rand;
  243. struct st_mariadb_rpl_encryption_event encryption;
  244. struct st_mariadb_rpl_intvar_event intvar;
  245. struct st_mariadb_rpl_uservar_event uservar;
  246. struct st_mariadb_rpl_rows_event rows;
  247. struct st_mariadb_rpl_heartbeat_event heartbeat;
  248. } event;
  249. } MARIADB_RPL_EVENT;
  250. #define mariadb_rpl_init(a) mariadb_rpl_init_ex((a), MARIADB_RPL_VERSION)
  251. /* Function prototypes */
  252. MARIADB_RPL * STDCALL mariadb_rpl_init_ex(MYSQL *mysql, unsigned int version);
  253. int mariadb_rpl_optionsv(MARIADB_RPL *rpl, enum mariadb_rpl_option, ...);
  254. int mariadb_rpl_get_optionsv(MARIADB_RPL *rpl, enum mariadb_rpl_option, ...);
  255. int STDCALL mariadb_rpl_open(MARIADB_RPL *rpl);
  256. void STDCALL mariadb_rpl_close(MARIADB_RPL *rpl);
  257. MARIADB_RPL_EVENT * STDCALL mariadb_rpl_fetch(MARIADB_RPL *rpl, MARIADB_RPL_EVENT *event);
  258. void STDCALL mariadb_free_rpl_event(MARIADB_RPL_EVENT *event);
  259. #ifdef __cplusplus
  260. }
  261. #endif
  262. #endif