Reformat blr.h

By oversight was not reformatted when the source was.
This commit is contained in:
Johan Wikman
2016-03-17 17:06:23 +02:00
parent 5070b81473
commit f551099af9

View File

@ -24,17 +24,17 @@
* @verbatim * @verbatim
* Revision History * Revision History
* *
* Date Who Description * Date Who Description
* 02/04/14 Mark Riddoch Initial implementation * 02/04/14 Mark Riddoch Initial implementation
* 25/05/15 Massimiliano Pinto Added BLRM_SLAVE_STOPPED state * 25/05/15 Massimiliano Pinto Added BLRM_SLAVE_STOPPED state
* 05/06/15 Massimiliano Pinto Addition of m_errno, m_errmsg fields * 05/06/15 Massimiliano Pinto Addition of m_errno, m_errmsg fields
* 08/06/15 Massimiliano Pinto Modification of MYSQL_ERROR_CODE and MYSQL_ERROR_MSG * 08/06/15 Massimiliano Pinto Modification of MYSQL_ERROR_CODE and MYSQL_ERROR_MSG
* 11/05/15 Massimiliano Pinto Added mariadb10_compat to master and slave structs * 11/05/15 Massimiliano Pinto Added mariadb10_compat to master and slave structs
* 12/06/15 Massimiliano Pinto Added mariadb10 new events * 12/06/15 Massimiliano Pinto Added mariadb10 new events
* 23/06/15 Massimiliano Pinto Addition of MASTER_SERVER_CFG struct * 23/06/15 Massimiliano Pinto Addition of MASTER_SERVER_CFG struct
* 24/06/15 Massimiliano Pinto Added BLRM_UNCONFIGURED state * 24/06/15 Massimiliano Pinto Added BLRM_UNCONFIGURED state
* 05/08/15 Massimiliano Pinto Initial implementation of transaction safety * 05/08/15 Massimiliano Pinto Initial implementation of transaction safety
* 23/10/15 Markus Makela Added current_safe_event * 23/10/15 Markus Makela Added current_safe_event
* *
* @endverbatim * @endverbatim
*/ */
@ -46,158 +46,158 @@
#include <zlib.h> #include <zlib.h>
#include <mysql_client_server_protocol.h> #include <mysql_client_server_protocol.h>
#define BINLOG_FNAMELEN 255 #define BINLOG_FNAMELEN 255
#define BLR_PROTOCOL "MySQLBackend" #define BLR_PROTOCOL "MySQLBackend"
#define BINLOG_MAGIC { 0xfe, 0x62, 0x69, 0x6e } #define BINLOG_MAGIC { 0xfe, 0x62, 0x69, 0x6e }
#define BINLOG_MAGIC_SIZE 4 #define BINLOG_MAGIC_SIZE 4
#define BINLOG_NAMEFMT "%s.%06d" #define BINLOG_NAMEFMT "%s.%06d"
#define BINLOG_NAME_ROOT "mysql-bin" #define BINLOG_NAME_ROOT "mysql-bin"
#define BINLOG_EVENT_HDR_LEN 19 #define BINLOG_EVENT_HDR_LEN 19
/** /**
* Binlog event types * Binlog event types
*/ */
#define START_EVENT_V3 0x01 #define START_EVENT_V3 0x01
#define QUERY_EVENT 0x02 #define QUERY_EVENT 0x02
#define STOP_EVENT 0x03 #define STOP_EVENT 0x03
#define ROTATE_EVENT 0x04 #define ROTATE_EVENT 0x04
#define INTVAR_EVENT 0x05 #define INTVAR_EVENT 0x05
#define LOAD_EVENT 0x06 #define LOAD_EVENT 0x06
#define SLAVE_EVENT 0x07 #define SLAVE_EVENT 0x07
#define CREATE_FILE_EVENT 0x08 #define CREATE_FILE_EVENT 0x08
#define APPEND_BLOCK_EVENT 0x09 #define APPEND_BLOCK_EVENT 0x09
#define EXEC_LOAD_EVENT 0x0A #define EXEC_LOAD_EVENT 0x0A
#define DELETE_FILE_EVENT 0x0B #define DELETE_FILE_EVENT 0x0B
#define NEW_LOAD_EVENT 0x0C #define NEW_LOAD_EVENT 0x0C
#define RAND_EVENT 0x0D #define RAND_EVENT 0x0D
#define USER_VAR_EVENT 0x0E #define USER_VAR_EVENT 0x0E
#define FORMAT_DESCRIPTION_EVENT 0x0F #define FORMAT_DESCRIPTION_EVENT 0x0F
#define XID_EVENT 0x10 #define XID_EVENT 0x10
#define BEGIN_LOAD_QUERY_EVENT 0x11 #define BEGIN_LOAD_QUERY_EVENT 0x11
#define EXECUTE_LOAD_QUERY_EVENT 0x12 #define EXECUTE_LOAD_QUERY_EVENT 0x12
#define TABLE_MAP_EVENT 0x13 #define TABLE_MAP_EVENT 0x13
#define WRITE_ROWS_EVENTv0 0x14 #define WRITE_ROWS_EVENTv0 0x14
#define UPDATE_ROWS_EVENTv0 0x15 #define UPDATE_ROWS_EVENTv0 0x15
#define DELETE_ROWS_EVENTv0 0x16 #define DELETE_ROWS_EVENTv0 0x16
#define WRITE_ROWS_EVENTv1 0x17 #define WRITE_ROWS_EVENTv1 0x17
#define UPDATE_ROWS_EVENTv1 0x18 #define UPDATE_ROWS_EVENTv1 0x18
#define DELETE_ROWS_EVENTv1 0x19 #define DELETE_ROWS_EVENTv1 0x19
#define INCIDENT_EVENT 0x1A #define INCIDENT_EVENT 0x1A
#define HEARTBEAT_EVENT 0x1B #define HEARTBEAT_EVENT 0x1B
#define IGNORABLE_EVENT 0x1C #define IGNORABLE_EVENT 0x1C
#define ROWS_QUERY_EVENT 0x1D #define ROWS_QUERY_EVENT 0x1D
#define WRITE_ROWS_EVENTv2 0x1E #define WRITE_ROWS_EVENTv2 0x1E
#define UPDATE_ROWS_EVENTv2 0x1F #define UPDATE_ROWS_EVENTv2 0x1F
#define DELETE_ROWS_EVENTv2 0x20 #define DELETE_ROWS_EVENTv2 0x20
#define GTID_EVENT 0x21 #define GTID_EVENT 0x21
#define ANONYMOUS_GTID_EVENT 0x22 #define ANONYMOUS_GTID_EVENT 0x22
#define PREVIOUS_GTIDS_EVENT 0x23 #define PREVIOUS_GTIDS_EVENT 0x23
#define MAX_EVENT_TYPE 0x23 #define MAX_EVENT_TYPE 0x23
/* New MariaDB event numbers start from 0xa0 */ /* New MariaDB event numbers start from 0xa0 */
#define MARIADB_NEW_EVENTS_BEGIN 0xa0 #define MARIADB_NEW_EVENTS_BEGIN 0xa0
#define MARIADB_ANNOTATE_ROWS_EVENT 0xa0 #define MARIADB_ANNOTATE_ROWS_EVENT 0xa0
/* New MariaDB 10 event numbers start from here */ /* New MariaDB 10 event numbers start from here */
#define MARIADB10_BINLOG_CHECKPOINT_EVENT 0xa1 #define MARIADB10_BINLOG_CHECKPOINT_EVENT 0xa1
#define MARIADB10_GTID_EVENT 0xa2 #define MARIADB10_GTID_EVENT 0xa2
#define MARIADB10_GTID_GTID_LIST_EVENT 0xa3 #define MARIADB10_GTID_GTID_LIST_EVENT 0xa3
#define MAX_EVENT_TYPE_MARIADB10 0xa3 #define MAX_EVENT_TYPE_MARIADB10 0xa3
/* Maximum event type so far */ /* Maximum event type so far */
#define MAX_EVENT_TYPE_END MAX_EVENT_TYPE_MARIADB10 #define MAX_EVENT_TYPE_END MAX_EVENT_TYPE_MARIADB10
/** /**
* Binlog event flags * Binlog event flags
*/ */
#define LOG_EVENT_BINLOG_IN_USE_F 0x0001 #define LOG_EVENT_BINLOG_IN_USE_F 0x0001
#define LOG_EVENT_FORCED_ROTATE_F 0x0002 #define LOG_EVENT_FORCED_ROTATE_F 0x0002
#define LOG_EVENT_THREAD_SPECIFIC_F 0x0004 #define LOG_EVENT_THREAD_SPECIFIC_F 0x0004
#define LOG_EVENT_SUPPRESS_USE_F 0x0008 #define LOG_EVENT_SUPPRESS_USE_F 0x0008
#define LOG_EVENT_UPDATE_TABLE_MAP_VERSION_F 0x0010 #define LOG_EVENT_UPDATE_TABLE_MAP_VERSION_F 0x0010
#define LOG_EVENT_ARTIFICIAL_F 0x0020 #define LOG_EVENT_ARTIFICIAL_F 0x0020
#define LOG_EVENT_RELAY_LOG_F 0x0040 #define LOG_EVENT_RELAY_LOG_F 0x0040
#define LOG_EVENT_IGNORABLE_F 0x0080 #define LOG_EVENT_IGNORABLE_F 0x0080
#define LOG_EVENT_NO_FILTER_F 0x0100 #define LOG_EVENT_NO_FILTER_F 0x0100
#define LOG_EVENT_MTS_ISOLATE_F 0x0200 #define LOG_EVENT_MTS_ISOLATE_F 0x0200
/** /**
* How often to call the binlog status function (seconds) * How often to call the binlog status function (seconds)
*/ */
#define BLR_STATS_FREQ 60 #define BLR_STATS_FREQ 60
#define BLR_NSTATS_MINUTES 30 #define BLR_NSTATS_MINUTES 30
/** /**
* High and Low water marks for the slave dcb. These values can be overriden * High and Low water marks for the slave dcb. These values can be overriden
* by the router options highwater and lowwater. * by the router options highwater and lowwater.
*/ */
#define DEF_LOW_WATER 1000 #define DEF_LOW_WATER 1000
#define DEF_HIGH_WATER 10000 #define DEF_HIGH_WATER 10000
/** /**
* Default burst sizes for slave catchup * Default burst sizes for slave catchup
*/ */
#define DEF_SHORT_BURST 15 #define DEF_SHORT_BURST 15
#define DEF_LONG_BURST 500 #define DEF_LONG_BURST 500
#define DEF_BURST_SIZE 1024000 /* 1 Mb */ #define DEF_BURST_SIZE 1024000 /* 1 Mb */
/** /**
* master reconnect backoff constants * master reconnect backoff constants
* BLR_MASTER_BACKOFF_TIME The increments of the back off time (seconds) * BLR_MASTER_BACKOFF_TIME The increments of the back off time (seconds)
* BLR_MAX_BACKOFF Maximum number of increments to backoff to * BLR_MAX_BACKOFF Maximum number of increments to backoff to
*/ */
#define BLR_MASTER_BACKOFF_TIME 10 #define BLR_MASTER_BACKOFF_TIME 10
#define BLR_MAX_BACKOFF 60 #define BLR_MAX_BACKOFF 60
/* max size for error message returned to client */ /* max size for error message returned to client */
#define BINLOG_ERROR_MSG_LEN 385 #define BINLOG_ERROR_MSG_LEN 385
/* network latency extra wait tme for heartbeat check */ /* network latency extra wait tme for heartbeat check */
#define BLR_NET_LATENCY_WAIT_TIME 1 #define BLR_NET_LATENCY_WAIT_TIME 1
/* default heartbeat interval in seconds */ /* default heartbeat interval in seconds */
#define BLR_HEARTBEAT_DEFAULT_INTERVAL 300 #define BLR_HEARTBEAT_DEFAULT_INTERVAL 300
/* strings and numbers in SQL replies */ /* strings and numbers in SQL replies */
#define BLR_TYPE_STRING 0xf #define BLR_TYPE_STRING 0xf
#define BLR_TYPE_INT 0x03 #define BLR_TYPE_INT 0x03
/* string len for COM_STATISTICS output */ /* string len for COM_STATISTICS output */
#define BLRM_COM_STATISTICS_SIZE 1000 #define BLRM_COM_STATISTICS_SIZE 1000
/* string len for strerror_r message */ /* string len for strerror_r message */
#define BLRM_STRERROR_R_MSG_SIZE 128 #define BLRM_STRERROR_R_MSG_SIZE 128
/* string len for task message name */ /* string len for task message name */
#define BLRM_TASK_NAME_LEN 80 #define BLRM_TASK_NAME_LEN 80
/* string len for temp binlog filename */ /* string len for temp binlog filename */
#define BLRM_BINLOG_NAME_STR_LEN 80 #define BLRM_BINLOG_NAME_STR_LEN 80
/* string len for temp binlog filename */ /* string len for temp binlog filename */
#define BLRM_SET_HEARTBEAT_QUERY_LEN 80 #define BLRM_SET_HEARTBEAT_QUERY_LEN 80
/* string len for master registration query */ /* string len for master registration query */
#define BLRM_MASTER_REGITRATION_QUERY_LEN 255 #define BLRM_MASTER_REGITRATION_QUERY_LEN 255
/* Read Binlog position states */ /* Read Binlog position states */
#define SLAVE_POS_READ_OK 0x00 #define SLAVE_POS_READ_OK 0x00
#define SLAVE_POS_READ_ERR 0xff #define SLAVE_POS_READ_ERR 0xff
#define SLAVE_POS_READ_UNSAFE 0xfe #define SLAVE_POS_READ_UNSAFE 0xfe
#define SLAVE_POS_BAD_FD 0xfd #define SLAVE_POS_BAD_FD 0xfd
#define SLAVE_POS_BEYOND_EOF 0xfc #define SLAVE_POS_BEYOND_EOF 0xfc
/** /**
* Some useful macros for examining the MySQL Response packets * Some useful macros for examining the MySQL Response packets
*/ */
#define MYSQL_RESPONSE_OK(buf) (*((uint8_t *)GWBUF_DATA(buf) + 4) == 0x00) #define MYSQL_RESPONSE_OK(buf) (*((uint8_t *)GWBUF_DATA(buf) + 4) == 0x00)
#define MYSQL_RESPONSE_EOF(buf) (*((uint8_t *)GWBUF_DATA(buf) + 4) == 0xfe) #define MYSQL_RESPONSE_EOF(buf) (*((uint8_t *)GWBUF_DATA(buf) + 4) == 0xfe)
#define MYSQL_RESPONSE_ERR(buf) (*((uint8_t *)GWBUF_DATA(buf) + 4) == 0xff) #define MYSQL_RESPONSE_ERR(buf) (*((uint8_t *)GWBUF_DATA(buf) + 4) == 0xff)
#define MYSQL_ERROR_CODE(buf) ((uint8_t *)GWBUF_DATA(buf) + 5) #define MYSQL_ERROR_CODE(buf) ((uint8_t *)GWBUF_DATA(buf) + 5)
#define MYSQL_ERROR_MSG(buf) ((uint8_t *)GWBUF_DATA(buf) + 7) #define MYSQL_ERROR_MSG(buf) ((uint8_t *)GWBUF_DATA(buf) + 7)
#define MYSQL_COMMAND(buf) (*((uint8_t *)GWBUF_DATA(buf) + 4)) #define MYSQL_COMMAND(buf) (*((uint8_t *)GWBUF_DATA(buf) + 4))
/** Possible states of an event sent by the master */ /** Possible states of an event sent by the master */
enum blr_event_state enum blr_event_state
@ -211,139 +211,147 @@ enum blr_event_state
}; };
/* Master Server configuration struct */ /* Master Server configuration struct */
typedef struct master_server_config { typedef struct master_server_config
char *host; {
unsigned short port; char *host;
char logfile[BINLOG_FNAMELEN+1]; unsigned short port;
uint64_t pos; char logfile[BINLOG_FNAMELEN+1];
uint64_t safe_pos; uint64_t pos;
char *user; uint64_t safe_pos;
char *password; char *user;
char *filestem; char *password;
char *filestem;
} MASTER_SERVER_CFG; } MASTER_SERVER_CFG;
/* Config struct for CHANGE MASTER TO options */ /* Config struct for CHANGE MASTER TO options */
typedef struct change_master_options { typedef struct change_master_options
char *host; {
char *port; char *host;
char *binlog_file; char *port;
char *binlog_pos; char *binlog_file;
char *user; char *binlog_pos;
char *password; char *user;
char *password;
} CHANGE_MASTER_OPTIONS; } CHANGE_MASTER_OPTIONS;
/** /**
* Packet header for replication messages * Packet header for replication messages
*/ */
typedef struct rep_header { typedef struct rep_header
int payload_len; /*< Payload length (24 bits) */ {
uint8_t seqno; /*< Response sequence number */ int payload_len; /*< Payload length (24 bits) */
uint8_t ok; /*< OK Byte from packet */ uint8_t seqno; /*< Response sequence number */
uint32_t timestamp; /*< Timestamp - start of binlog record */ uint8_t ok; /*< OK Byte from packet */
uint8_t event_type; /*< Binlog event type */ uint32_t timestamp; /*< Timestamp - start of binlog record */
uint32_t serverid; /*< Server id of master */ uint8_t event_type; /*< Binlog event type */
uint32_t event_size; /*< Size of header, post-header and body */ uint32_t serverid; /*< Server id of master */
uint32_t next_pos; /*< Position of next event */ uint32_t event_size; /*< Size of header, post-header and body */
uint16_t flags; /*< Event flags */ uint32_t next_pos; /*< Position of next event */
uint16_t flags; /*< Event flags */
} REP_HEADER; } REP_HEADER;
/** /**
* The binlog record structure. This contains the actual packet read from the binlog * The binlog record structure. This contains the actual packet read from the binlog
* file. * file.
*/ */
typedef struct { typedef struct
unsigned long position; /*< binlog record position for this cache entry */ {
GWBUF *pkt; /*< The packet received from the master */ unsigned long position; /*< binlog record position for this cache entry */
REP_HEADER hdr; /*< The packet header */ GWBUF *pkt; /*< The packet received from the master */
REP_HEADER hdr; /*< The packet header */
} BLCACHE_RECORD; } BLCACHE_RECORD;
/** /**
* The binlog cache. A cache exists for each file that hold cached bin log records. * The binlog cache. A cache exists for each file that hold cached bin log records.
* Caches will be used for all files being read by more than 1 slave. * Caches will be used for all files being read by more than 1 slave.
*/ */
typedef struct { typedef struct
BLCACHE_RECORD **records; /*< The actual binlog records */ {
int current; /*< The next record that will be inserted */ BLCACHE_RECORD **records; /*< The actual binlog records */
int cnt; /*< The number of records in the cache */ int current; /*< The next record that will be inserted */
SPINLOCK lock; /*< The spinlock for the cache */ int cnt; /*< The number of records in the cache */
SPINLOCK lock; /*< The spinlock for the cache */
} BLCACHE; } BLCACHE;
typedef struct blfile { typedef struct blfile
char binlogname[BINLOG_FNAMELEN+1]; /*< Name of the binlog file */ {
int fd; /*< Actual file descriptor */ char binlogname[BINLOG_FNAMELEN+1]; /*< Name of the binlog file */
int refcnt; /*< Reference count for file */ int fd; /*< Actual file descriptor */
BLCACHE *cache; /*< Record cache for this file */ int refcnt; /*< Reference count for file */
SPINLOCK lock; /*< The file lock */ BLCACHE *cache; /*< Record cache for this file */
struct blfile *next; /*< Next file in list */ SPINLOCK lock; /*< The file lock */
struct blfile *next; /*< Next file in list */
} BLFILE; } BLFILE;
/** /**
* Slave statistics * Slave statistics
*/ */
typedef struct { typedef struct
int n_events; /*< Number of events sent */ {
unsigned long n_bytes; /*< Number of bytes sent */ int n_events; /*< Number of events sent */
int n_bursts; /*< Number of bursts sent */ unsigned long n_bytes; /*< Number of bytes sent */
int n_requests; /*< Number of requests received */ int n_bursts; /*< Number of bursts sent */
int n_flows; /*< Number of flow control restarts */ int n_requests; /*< Number of requests received */
int n_queries; /*< Number of SQL queries */ int n_flows; /*< Number of flow control restarts */
int n_upd; int n_queries; /*< Number of SQL queries */
int n_cb; int n_upd;
int n_cbna; int n_cb;
int n_dcb; int n_cbna;
int n_above; int n_dcb;
int n_failed_read; int n_above;
int n_overrun; int n_failed_read;
int n_caughtup; int n_overrun;
int n_actions[3]; int n_caughtup;
uint64_t lastsample; int n_actions[3];
int minno; uint64_t lastsample;
int minavgs[BLR_NSTATS_MINUTES]; int minno;
int minavgs[BLR_NSTATS_MINUTES];
} SLAVE_STATS; } SLAVE_STATS;
/** /**
* The client session structure used within this router. This represents * The client session structure used within this router. This represents
* the slaves that are replicating binlogs from MaxScale. * the slaves that are replicating binlogs from MaxScale.
*/ */
typedef struct router_slave { typedef struct router_slave
{
#if defined(SS_DEBUG) #if defined(SS_DEBUG)
skygw_chk_t rses_chk_top; skygw_chk_t rses_chk_top;
#endif #endif
DCB *dcb; /*< The slave server DCB */ DCB *dcb; /*< The slave server DCB */
int state; /*< The state of this slave */ int state; /*< The state of this slave */
uint32_t binlog_pos; /*< Binlog position for this slave */ uint32_t binlog_pos; /*< Binlog position for this slave */
char binlogfile[BINLOG_FNAMELEN+1]; char binlogfile[BINLOG_FNAMELEN+1];
/*< Current binlog file for this slave */ /*< Current binlog file for this slave */
char *uuid; /*< Slave UUID */ char *uuid; /*< Slave UUID */
#ifdef BLFILE_IN_SLAVE #ifdef BLFILE_IN_SLAVE
BLFILE *file; /*< Currently open binlog file */ BLFILE *file; /*< Currently open binlog file */
#endif #endif
int serverid; /*< Server-id of the slave */ int serverid; /*< Server-id of the slave */
char *hostname; /*< Hostname of the slave, if known */ char *hostname; /*< Hostname of the slave, if known */
char *user; /*< Username if given */ char *user; /*< Username if given */
char *passwd; /*< Password if given */ char *passwd; /*< Password if given */
short port; /*< MySQL port */ short port; /*< MySQL port */
int nocrc; /*< Disable CRC */ int nocrc; /*< Disable CRC */
int overrun; int overrun;
uint32_t rank; /*< Replication rank */ uint32_t rank; /*< Replication rank */
uint8_t seqno; /*< Replication dump sequence no */ uint8_t seqno; /*< Replication dump sequence no */
uint32_t lastEventTimestamp;/*< Last event timestamp sent */ uint32_t lastEventTimestamp;/*< Last event timestamp sent */
SPINLOCK catch_lock; /*< Event catchup lock */ SPINLOCK catch_lock; /*< Event catchup lock */
unsigned int cstate; /*< Catch up state */ unsigned int cstate; /*< Catch up state */
bool mariadb10_compat;/*< MariaDB 10.0 compatibility */ bool mariadb10_compat;/*< MariaDB 10.0 compatibility */
SPINLOCK rses_lock; /*< Protects rses_deleted */ SPINLOCK rses_lock; /*< Protects rses_deleted */
pthread_t pthread; pthread_t pthread;
struct router_instance struct router_instance
*router; /*< Pointer to the owning router */ *router; /*< Pointer to the owning router */
struct router_slave *next; struct router_slave *next;
SLAVE_STATS stats; /*< Slave statistics */ SLAVE_STATS stats; /*< Slave statistics */
time_t connect_time; /*< Connect time of slave */ time_t connect_time; /*< Connect time of slave */
char *warning_msg; /*< Warning message */ char *warning_msg; /*< Warning message */
int heartbeat; /*< Heartbeat in seconds */ int heartbeat; /*< Heartbeat in seconds */
uint8_t lastEventReceived; /*< Last event received */ uint8_t lastEventReceived; /*< Last event received */
time_t lastReply; /*< Last event sent */ time_t lastReply; /*< Last event sent */
#if defined(SS_DEBUG) #if defined(SS_DEBUG)
skygw_chk_t rses_chk_tail; skygw_chk_t rses_chk_tail;
#endif #endif
} ROUTER_SLAVE; } ROUTER_SLAVE;
@ -351,215 +359,224 @@ typedef struct router_slave {
/** /**
* The statistics for this router instance * The statistics for this router instance
*/ */
typedef struct { typedef struct
int n_slaves; /*< Number slave sessions created */ {
int n_reads; /*< Number of record reads */ int n_slaves; /*< Number slave sessions created */
uint64_t n_binlogs; /*< Number of binlog records from master */ int n_reads; /*< Number of record reads */
uint64_t n_binlogs_ses; /*< Number of binlog records from master */ uint64_t n_binlogs; /*< Number of binlog records from master */
uint64_t n_binlog_errors;/*< Number of binlog records from master */ uint64_t n_binlogs_ses; /*< Number of binlog records from master */
uint64_t n_rotates; /*< Number of binlog rotate events */ uint64_t n_binlog_errors;/*< Number of binlog records from master */
uint64_t n_cachehits; /*< Number of hits on the binlog cache */ uint64_t n_rotates; /*< Number of binlog rotate events */
uint64_t n_cachemisses; /*< Number of misses on the binlog cache */ uint64_t n_cachehits; /*< Number of hits on the binlog cache */
int n_registered; /*< Number of registered slaves */ uint64_t n_cachemisses; /*< Number of misses on the binlog cache */
int n_masterstarts; /*< Number of times connection restarted */ int n_registered; /*< Number of registered slaves */
int n_delayedreconnects; int n_masterstarts; /*< Number of times connection restarted */
int n_residuals; /*< Number of times residual data was buffered */ int n_delayedreconnects;
int n_heartbeats; /*< Number of heartbeat messages */ int n_residuals; /*< Number of times residual data was buffered */
time_t lastReply; int n_heartbeats; /*< Number of heartbeat messages */
uint64_t n_fakeevents; /*< Fake events not written to disk */ time_t lastReply;
uint64_t n_artificial; /*< Artificial events not written to disk */ uint64_t n_fakeevents; /*< Fake events not written to disk */
int n_badcrc; /*< No. of bad CRC's from master */ uint64_t n_artificial; /*< Artificial events not written to disk */
uint64_t events[MAX_EVENT_TYPE_END + 1]; /*< Per event counters */ int n_badcrc; /*< No. of bad CRC's from master */
uint64_t lastsample; uint64_t events[MAX_EVENT_TYPE_END + 1]; /*< Per event counters */
int minno; uint64_t lastsample;
int minavgs[BLR_NSTATS_MINUTES]; int minno;
int minavgs[BLR_NSTATS_MINUTES];
} ROUTER_STATS; } ROUTER_STATS;
/** /**
* Saved responses from the master that will be forwarded to slaves * Saved responses from the master that will be forwarded to slaves
*/ */
typedef struct { typedef struct
GWBUF *server_id; /*< Master server id */ {
GWBUF *heartbeat; /*< Heartbeat period */ GWBUF *server_id; /*< Master server id */
GWBUF *chksum1; /*< Binlog checksum 1st response */ GWBUF *heartbeat; /*< Heartbeat period */
GWBUF *chksum2; /*< Binlog checksum 2nd response */ GWBUF *chksum1; /*< Binlog checksum 1st response */
GWBUF *gtid_mode; /*< GTID Mode response */ GWBUF *chksum2; /*< Binlog checksum 2nd response */
GWBUF *uuid; /*< Master UUID */ GWBUF *gtid_mode; /*< GTID Mode response */
GWBUF *setslaveuuid; /*< Set Slave UUID */ GWBUF *uuid; /*< Master UUID */
GWBUF *setnames; /*< Set NAMES latin1 */ GWBUF *setslaveuuid; /*< Set Slave UUID */
GWBUF *utf8; /*< Set NAMES utf8 */ GWBUF *setnames; /*< Set NAMES latin1 */
GWBUF *select1; /*< select 1 */ GWBUF *utf8; /*< Set NAMES utf8 */
GWBUF *selectver; /*< select version() */ GWBUF *select1; /*< select 1 */
GWBUF *selectvercom; /*< select @@version_comment */ GWBUF *selectver; /*< select version() */
GWBUF *selecthostname;/*< select @@hostname */ GWBUF *selectvercom; /*< select @@version_comment */
GWBUF *map; /*< select @@max_allowed_packet */ GWBUF *selecthostname;/*< select @@hostname */
GWBUF *mariadb10; /*< set @mariadb_slave_capability */ GWBUF *map; /*< select @@max_allowed_packet */
uint8_t *fde_event; /*< Format Description Event */ GWBUF *mariadb10; /*< set @mariadb_slave_capability */
int fde_len; /*< Length of fde_event */ uint8_t *fde_event; /*< Format Description Event */
int fde_len; /*< Length of fde_event */
} MASTER_RESPONSES; } MASTER_RESPONSES;
/** /**
* The per instance data for the router. * The per instance data for the router.
*/ */
typedef struct router_instance { typedef struct router_instance
SERVICE *service; /*< Pointer to the service using this router */ {
ROUTER_SLAVE *slaves; /*< Link list of all the slave connections */ SERVICE *service; /*< Pointer to the service using this router */
SPINLOCK lock; /*< Spinlock for the instance data */ ROUTER_SLAVE *slaves; /*< Link list of all the slave connections */
char *uuid; /*< UUID for the router to use w/master */ SPINLOCK lock; /*< Spinlock for the instance data */
int masterid; /*< Set ID of the master, sent to slaves */ char *uuid; /*< UUID for the router to use w/master */
int serverid; /*< ID for the router to use w/master */ int masterid; /*< Set ID of the master, sent to slaves */
int initbinlog; /*< Initial binlog file number */ int serverid; /*< ID for the router to use w/master */
char *user; /*< User name to use with master */ int initbinlog; /*< Initial binlog file number */
char *password; /*< Password to use with master */ char *user; /*< User name to use with master */
char *fileroot; /*< Root of binlog filename */ char *password; /*< Password to use with master */
bool master_chksum; /*< Does the master provide checksums */ char *fileroot; /*< Root of binlog filename */
bool mariadb10_compat; /*< MariaDB 10.0 compatibility */ bool master_chksum; /*< Does the master provide checksums */
char *master_uuid; /*< Set UUID of the master, sent to slaves */ bool mariadb10_compat; /*< MariaDB 10.0 compatibility */
DCB *master; /*< DCB for master connection */ char *master_uuid; /*< Set UUID of the master, sent to slaves */
DCB *client; /*< DCB for dummy client */ DCB *master; /*< DCB for master connection */
SESSION *session; /*< Fake session for master connection */ DCB *client; /*< DCB for dummy client */
unsigned int master_state; /*< State of the master FSM */ SESSION *session; /*< Fake session for master connection */
uint8_t lastEventReceived; /*< Last even received */ unsigned int master_state; /*< State of the master FSM */
uint32_t lastEventTimestamp; /*< Timestamp from last event */ uint8_t lastEventReceived; /*< Last even received */
GWBUF *residual; /*< Any residual binlog event */ uint32_t lastEventTimestamp; /*< Timestamp from last event */
MASTER_RESPONSES saved_master; /*< Saved master responses */ GWBUF *residual; /*< Any residual binlog event */
char *binlogdir; /*< The directory with the binlog files */ MASTER_RESPONSES saved_master; /*< Saved master responses */
SPINLOCK binlog_lock; /*< Lock to control update of the binlog position */ char *binlogdir; /*< The directory with the binlog files */
int trx_safe; /*< Detect and handle partial transactions */ SPINLOCK binlog_lock; /*< Lock to control update of the binlog position */
int pending_transaction; /*< Pending transaction */ int trx_safe; /*< Detect and handle partial transactions */
enum blr_event_state master_event_state; /*< Packet read state */ int pending_transaction; /*< Pending transaction */
uint32_t stored_checksum; /*< The current value of the checksum */ enum blr_event_state master_event_state; /*< Packet read state */
uint8_t partial_checksum[MYSQL_CHECKSUM_LEN]; /*< The partial value of the checksum uint32_t stored_checksum; /*< The current value of the checksum */
* received from the master */ uint8_t partial_checksum[MYSQL_CHECKSUM_LEN]; /*< The partial value of the checksum
uint8_t partial_checksum_bytes; /*< How many bytes of the checksum we have read */ * received from the master */
uint64_t checksum_size; /*< Data size for the checksum */ uint8_t partial_checksum_bytes; /*< How many bytes of the checksum we have read */
REP_HEADER stored_header; /*< Relication header of the event the master is sending */ uint64_t checksum_size; /*< Data size for the checksum */
uint64_t last_safe_pos; /* last committed transaction */ REP_HEADER stored_header; /*< Relication header of the event the master is sending */
char binlog_name[BINLOG_FNAMELEN+1]; uint64_t last_safe_pos; /* last committed transaction */
/*< Name of the current binlog file */ char binlog_name[BINLOG_FNAMELEN+1];
uint64_t binlog_position; /*< Name of the current binlog file */
/*< last committed transaction position */ uint64_t binlog_position;
uint64_t current_pos; /*< last committed transaction position */
/*< Current binlog position */ uint64_t current_pos;
int binlog_fd; /*< File descriptor of the binlog /*< Current binlog position */
* file being written int binlog_fd; /*< File descriptor of the binlog
*/ * file being written
uint64_t last_written; /*< Position of the last write operation */ */
uint64_t last_event_pos; /*< Position of last event written */ uint64_t last_written; /*< Position of the last write operation */
uint64_t current_safe_event; uint64_t last_event_pos; /*< Position of last event written */
/*< Position of the latest safe event being sent to slaves */ uint64_t current_safe_event;
char prevbinlog[BINLOG_FNAMELEN+1]; /*< Position of the latest safe event being sent to slaves */
int rotating; /*< Rotation in progress flag */ char prevbinlog[BINLOG_FNAMELEN+1];
BLFILE *files; /*< Files used by the slaves */ int rotating; /*< Rotation in progress flag */
SPINLOCK fileslock; /*< Lock for the files queue above */ BLFILE *files; /*< Files used by the slaves */
unsigned int low_water; /*< Low water mark for client DCB */ SPINLOCK fileslock; /*< Lock for the files queue above */
unsigned int high_water; /*< High water mark for client DCB */ unsigned int low_water; /*< Low water mark for client DCB */
unsigned int short_burst; /*< Short burst for slave catchup */ unsigned int high_water; /*< High water mark for client DCB */
unsigned int long_burst; /*< Long burst for slave catchup */ unsigned int short_burst; /*< Short burst for slave catchup */
unsigned long burst_size; /*< Maximum size of burst to send */ unsigned int long_burst; /*< Long burst for slave catchup */
unsigned long heartbeat; /*< Configured heartbeat value */ unsigned long burst_size; /*< Maximum size of burst to send */
ROUTER_STATS stats; /*< Statistics for this router */ unsigned long heartbeat; /*< Configured heartbeat value */
int active_logs; ROUTER_STATS stats; /*< Statistics for this router */
int reconnect_pending; int active_logs;
int retry_backoff; int reconnect_pending;
time_t connect_time; int retry_backoff;
int handling_threads; time_t connect_time;
unsigned long m_errno; /*< master response mysql errno */ int handling_threads;
char *m_errmsg; /*< master response mysql error message */ unsigned long m_errno; /*< master response mysql errno */
char *set_master_version; /*< Send custom Version to slaves */ char *m_errmsg; /*< master response mysql error message */
char *set_master_hostname; /*< Send custom Hostname to slaves */ char *set_master_version; /*< Send custom Version to slaves */
char *set_master_uuid; /*< Send custom Master UUID to slaves */ char *set_master_hostname; /*< Send custom Hostname to slaves */
char *set_master_server_id; /*< Send custom Master server_id to slaves */ char *set_master_uuid; /*< Send custom Master UUID to slaves */
int send_slave_heartbeat; /*< Enable sending heartbeat to slaves */ char *set_master_server_id; /*< Send custom Master server_id to slaves */
struct router_instance *next; int send_slave_heartbeat; /*< Enable sending heartbeat to slaves */
struct router_instance *next;
} ROUTER_INSTANCE; } ROUTER_INSTANCE;
/** /**
* State machine for the master to MaxScale replication * State machine for the master to MaxScale replication
*/ */
#define BLRM_UNCONFIGURED 0x0000 #define BLRM_UNCONFIGURED 0x0000
#define BLRM_UNCONNECTED 0x0001 #define BLRM_UNCONNECTED 0x0001
#define BLRM_CONNECTING 0x0002 #define BLRM_CONNECTING 0x0002
#define BLRM_AUTHENTICATED 0x0003 #define BLRM_AUTHENTICATED 0x0003
#define BLRM_TIMESTAMP 0x0004 #define BLRM_TIMESTAMP 0x0004
#define BLRM_SERVERID 0x0005 #define BLRM_SERVERID 0x0005
#define BLRM_HBPERIOD 0x0006 #define BLRM_HBPERIOD 0x0006
#define BLRM_CHKSUM1 0x0007 #define BLRM_CHKSUM1 0x0007
#define BLRM_CHKSUM2 0x0008 #define BLRM_CHKSUM2 0x0008
#define BLRM_GTIDMODE 0x0009 #define BLRM_GTIDMODE 0x0009
#define BLRM_MUUID 0x000A #define BLRM_MUUID 0x000A
#define BLRM_SUUID 0x000B #define BLRM_SUUID 0x000B
#define BLRM_LATIN1 0x000C #define BLRM_LATIN1 0x000C
#define BLRM_UTF8 0x000D #define BLRM_UTF8 0x000D
#define BLRM_SELECT1 0x000E #define BLRM_SELECT1 0x000E
#define BLRM_SELECTVER 0x000F #define BLRM_SELECTVER 0x000F
#define BLRM_SELECTVERCOM 0x0010 #define BLRM_SELECTVERCOM 0x0010
#define BLRM_SELECTHOSTNAME 0x0011 #define BLRM_SELECTHOSTNAME 0x0011
#define BLRM_MAP 0x0012 #define BLRM_MAP 0x0012
#define BLRM_REGISTER 0x0013 #define BLRM_REGISTER 0x0013
#define BLRM_BINLOGDUMP 0x0014 #define BLRM_BINLOGDUMP 0x0014
#define BLRM_SLAVE_STOPPED 0x0015 #define BLRM_SLAVE_STOPPED 0x0015
#define BLRM_MARIADB10 0x0016 #define BLRM_MARIADB10 0x0016
#define BLRM_MAXSTATE 0x0016 #define BLRM_MAXSTATE 0x0016
static char *blrm_states[] = { "Unconfigured", "Unconnected", "Connecting", "Authenticated", "Timestamp retrieval", static char *blrm_states[] =
"Server ID retrieval", "HeartBeat Period setup", "binlog checksum config", {
"binlog checksum rerieval", "GTID Mode retrieval", "Master UUID retrieval", "Unconfigured", "Unconnected", "Connecting", "Authenticated", "Timestamp retrieval",
"Set Slave UUID", "Set Names latin1", "Set Names utf8", "select 1", "Server ID retrieval", "HeartBeat Period setup", "binlog checksum config",
"select version()", "select @@version_comment", "select @@hostname", "binlog checksum rerieval", "GTID Mode retrieval", "Master UUID retrieval",
"select @@max_allowed_packet", "Register slave", "Binlog Dump", "Slave stopped", "Set MariaDB slave capability" }; "Set Slave UUID", "Set Names latin1", "Set Names utf8", "select 1",
"select version()", "select @@version_comment", "select @@hostname",
"select @@max_allowed_packet", "Register slave", "Binlog Dump", "Slave stopped",
"Set MariaDB slave capability"
};
#define BLRS_CREATED 0x0000 #define BLRS_CREATED 0x0000
#define BLRS_UNREGISTERED 0x0001 #define BLRS_UNREGISTERED 0x0001
#define BLRS_REGISTERED 0x0002 #define BLRS_REGISTERED 0x0002
#define BLRS_DUMPING 0x0003 #define BLRS_DUMPING 0x0003
#define BLRS_ERRORED 0x0004 #define BLRS_ERRORED 0x0004
#define BLRS_MAXSTATE 0x0004 #define BLRS_MAXSTATE 0x0004
static char *blrs_states[] = { "Created", "Unregistered", "Registered", static char *blrs_states[] =
"Sending binlogs", "Errored" }; {
"Created", "Unregistered", "Registered", "Sending binlogs", "Errored"
};
/** /**
* Slave catch-up status * Slave catch-up status
*/ */
#define CS_UPTODATE 0x0004 #define CS_UPTODATE 0x0004
#define CS_EXPECTCB 0x0008 #define CS_EXPECTCB 0x0008
#define CS_DIST 0x0010 #define CS_DIST 0x0010
#define CS_DISTLATCH 0x0020 #define CS_DISTLATCH 0x0020
#define CS_THRDWAIT 0x0040 #define CS_THRDWAIT 0x0040
#define CS_BUSY 0x0100 #define CS_BUSY 0x0100
#define CS_HOLD 0x0200 #define CS_HOLD 0x0200
/** /**
* MySQL protocol OpCodes needed for replication * MySQL protocol OpCodes needed for replication
*/ */
#define COM_QUIT 0x01 #define COM_QUIT 0x01
#define COM_QUERY 0x03 #define COM_QUERY 0x03
#define COM_STATISTICS 0x09 #define COM_STATISTICS 0x09
#define COM_PING 0x0e #define COM_PING 0x0e
#define COM_REGISTER_SLAVE 0x15 #define COM_REGISTER_SLAVE 0x15
#define COM_BINLOG_DUMP 0x12 #define COM_BINLOG_DUMP 0x12
/** /**
* Macros to extract common fields * Macros to extract common fields
*/ */
#define INLINE_EXTRACT 1 /* Set to 0 for debug purposes */ #define INLINE_EXTRACT 1 /* Set to 0 for debug purposes */
#if INLINE_EXTRACT #if INLINE_EXTRACT
#define EXTRACT16(x) (*(uint8_t *)(x) | (*((uint8_t *)(x) + 1) << 8)) #define EXTRACT16(x) (*(uint8_t *)(x) | (*((uint8_t *)(x) + 1) << 8))
#define EXTRACT24(x) (*(uint8_t *)(x) | \ #define EXTRACT24(x) (*(uint8_t *)(x) | \
(*((uint8_t *)(x) + 1) << 8) | \ (*((uint8_t *)(x) + 1) << 8) | \
(*((uint8_t *)(x) + 2) << 16)) (*((uint8_t *)(x) + 2) << 16))
#define EXTRACT32(x) (*(uint8_t *)(x) | \ #define EXTRACT32(x) (*(uint8_t *)(x) | \
(*((uint8_t *)(x) + 1) << 8) | \ (*((uint8_t *)(x) + 1) << 8) | \
(*((uint8_t *)(x) + 2) << 16) | \ (*((uint8_t *)(x) + 2) << 16) | \
(*((uint8_t *)(x) + 3) << 24)) (*((uint8_t *)(x) + 3) << 24))
#else #else
#define EXTRACT16(x) extract_field((x), 16) #define EXTRACT16(x) extract_field((x), 16)
#define EXTRACT24(x) extract_field((x), 24) #define EXTRACT24(x) extract_field((x), 24)
#define EXTRACT32(x) extract_field((x), 32) #define EXTRACT32(x) extract_field((x), 32)
#endif #endif
/* /*