My Project
replication.h
00001 /* Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software Foundation,
00014    51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
00015 
00016 #ifndef REPLICATION_H
00017 #define REPLICATION_H
00018 
00019 #include <mysql.h>
00020 
00021 typedef struct st_mysql MYSQL;
00022 
00023 #ifdef __cplusplus
00024 extern "C" {
00025 #endif
00026 
00030 enum Trans_flags {
00032   TRANS_IS_REAL_TRANS = 1
00033 };
00034 
00038 typedef struct Trans_param {
00039   uint32 server_id;
00040   uint32 flags;
00041 
00042   /*
00043     The latest binary log file name and position written by current
00044     transaction, if binary log is disabled or no log event has been
00045     written into binary log file by current transaction (events
00046     written into transaction log cache are not counted), these two
00047     member will be zero.
00048   */
00049   const char *log_file;
00050   my_off_t log_pos;
00051 } Trans_param;
00052 
00056 typedef struct Trans_observer {
00057   uint32 len;
00058 
00076   int (*after_commit)(Trans_param *param);
00077 
00095   int (*after_rollback)(Trans_param *param);
00096 } Trans_observer;
00097 
00101 enum Binlog_storage_flags {
00103   BINLOG_STORAGE_IS_SYNCED = 1
00104 };
00105 
00109 typedef struct Binlog_storage_param {
00110   uint32 server_id;
00111 } Binlog_storage_param;
00112 
00116 typedef struct Binlog_storage_observer {
00117   uint32 len;
00118 
00132   int (*after_flush)(Binlog_storage_param *param,
00133                      const char *log_file, my_off_t log_pos);
00134 } Binlog_storage_observer;
00135 
00139 typedef struct Binlog_transmit_param {
00140   uint32 server_id;
00141   uint32 flags;
00142   /* Let us keep 1-16 as output flags and 17-32 as input flags */
00143   static const uint32 F_OBSERVE= 1;
00144   static const uint32 F_DONT_OBSERVE= 2;
00145 
00146   void set_observe_flag() { flags|= F_OBSERVE; }
00147   void set_dont_observe_flag() { flags|= F_DONT_OBSERVE; }
00155   bool should_observe()
00156   {
00157     return (flags & F_OBSERVE) || !(flags & F_DONT_OBSERVE);
00158   }
00159 } Binlog_transmit_param;
00160 
00164 typedef struct Binlog_transmit_observer {
00165   uint32 len;
00166   
00178   int (*transmit_start)(Binlog_transmit_param *param,
00179                         const char *log_file, my_off_t log_pos);
00180 
00189   int (*transmit_stop)(Binlog_transmit_param *param);
00190 
00209   int (*reserve_header)(Binlog_transmit_param *param,
00210                         unsigned char *header,
00211                         unsigned long size,
00212                         unsigned long *len);
00213 
00226   int (*before_send_event)(Binlog_transmit_param *param,
00227                            unsigned char *packet, unsigned long len,
00228                            const char *log_file, my_off_t log_pos );
00229 
00246   int (*after_send_event)(Binlog_transmit_param *param,
00247                           const char *event_buf, unsigned long len,
00248                           const char *skipped_log_file, my_off_t skipped_log_pos);
00249 
00261   int (*after_reset_master)(Binlog_transmit_param *param);
00262 } Binlog_transmit_observer;
00263 
00267 enum Binlog_relay_IO_flags {
00269   BINLOG_RELAY_IS_SYNCED = 1
00270 };
00271 
00272 
00276 typedef struct Binlog_relay_IO_param {
00277   uint32 server_id;
00278 
00279   /* Master host, user and port */
00280   char *host;
00281   char *user;
00282   unsigned int port;
00283 
00284   char *master_log_name;
00285   my_off_t master_log_pos;
00286 
00287   MYSQL *mysql;                        /* the connection to master */
00288 } Binlog_relay_IO_param;
00289 
00293 typedef struct Binlog_relay_IO_observer {
00294   uint32 len;
00295 
00304   int (*thread_start)(Binlog_relay_IO_param *param);
00305 
00314   int (*thread_stop)(Binlog_relay_IO_param *param);
00315 
00328   int (*before_request_transmit)(Binlog_relay_IO_param *param, uint32 flags);
00329 
00342   int (*after_read_event)(Binlog_relay_IO_param *param,
00343                           const char *packet, unsigned long len,
00344                           const char **event_buf, unsigned long *event_len);
00345 
00357   int (*after_queue_event)(Binlog_relay_IO_param *param,
00358                            const char *event_buf, unsigned long event_len,
00359                            uint32 flags);
00360 
00369   int (*after_reset_slave)(Binlog_relay_IO_param *param);
00370 } Binlog_relay_IO_observer;
00371 
00372 
00382 int register_trans_observer(Trans_observer *observer, void *p);
00383 
00393 int unregister_trans_observer(Trans_observer *observer, void *p);
00394 
00404 int register_binlog_storage_observer(Binlog_storage_observer *observer, void *p);
00405 
00415 int unregister_binlog_storage_observer(Binlog_storage_observer *observer, void *p);
00416 
00426 int register_binlog_transmit_observer(Binlog_transmit_observer *observer, void *p);
00427 
00437 int unregister_binlog_transmit_observer(Binlog_transmit_observer *observer, void *p);
00438 
00448 int register_binlog_relay_io_observer(Binlog_relay_IO_observer *observer, void *p);
00449 
00459 int unregister_binlog_relay_io_observer(Binlog_relay_IO_observer *observer, void *p);
00460 
00478 void thd_enter_cond(MYSQL_THD thd, mysql_cond_t *cond, mysql_mutex_t *mutex,
00479                     const PSI_stage_info *stage, PSI_stage_info *old_stage,
00480                     const char *src_function, const char *src_file,
00481                     int src_line);
00482 
00483 #define THD_ENTER_COND(P1, P2, P3, P4, P5) \
00484   thd_enter_cond(P1, P2, P3, P4, P5, __func__, __FILE__, __LINE__)
00485 
00499 void thd_exit_cond(MYSQL_THD thd, const PSI_stage_info *stage,
00500                    const char *src_function, const char *src_file,
00501                    int src_line);
00502 
00503 #define THD_EXIT_COND(P1, P2) \
00504   thd_exit_cond(P1, P2, __func__, __FILE__, __LINE__)
00505 
00521 int get_user_var_int(const char *name,
00522                      long long int *value, int *null_value);
00523 
00539 int get_user_var_real(const char *name,
00540                       double *value, int *null_value);
00541 
00559 int get_user_var_str(const char *name,
00560                      char *value, unsigned long len,
00561                      unsigned int precision, int *null_value);
00562 
00563   
00564 
00565 #ifdef __cplusplus
00566 }
00567 #endif
00568 #endif /* REPLICATION_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines