diff options
author | unknown <knielsen@knielsen-hq.org> | 2012-11-05 15:01:49 +0100 |
---|---|---|
committer | unknown <knielsen@knielsen-hq.org> | 2012-11-05 15:01:49 +0100 |
commit | 03f28863e845976f899c8c35dab3add918f4a8f6 (patch) | |
tree | 47d17f08d260da4dcf982110415f1b63b1f311a4 /sql/log_event.h | |
parent | ab8e8f4b277c23e6989650e0590ec0a5fa03fb3a (diff) | |
download | mariadb-git-03f28863e845976f899c8c35dab3add918f4a8f6.tar.gz |
MDEV-26: Global transaction commit. Intermediate commit.
Now slave records GTID in mysql.rpl_slave_state when applying XID log event.
Diffstat (limited to 'sql/log_event.h')
-rw-r--r-- | sql/log_event.h | 86 |
1 files changed, 80 insertions, 6 deletions
diff --git a/sql/log_event.h b/sql/log_event.h index be809970c6d..04c818313a3 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -2953,18 +2953,92 @@ struct rpl_gtid }; -struct rpl_state +/* + Replication slave state. + + For every independent replication stream (identified by domain_id), this + remembers the last gtid applied on the slave within this domain. + + Since events are always committed in-order within a single domain, this is + sufficient to maintain the state of the replication slave. +*/ +struct rpl_slave_state { + /* Elements in the list of GTIDs kept for each domain_id. */ + struct list_element + { + struct list_element *next; + uint64 sub_id; + uint64 seq_no; + uint32 server_id; + }; + + /* Elements in the HASH that hold the state for one domain_id. */ + struct element + { + struct list_element *list; + uint64 last_sub_id; + uint32 domain_id; + + list_element *grab_list() { list_element *l= list; list= NULL; return l; } + void add (list_element *l) + { + l->next= list; + list= l; + if (last_sub_id < l->sub_id) + last_sub_id= l->sub_id; + } + }; + + /* Mapping from domain_id to its element. */ HASH hash; + /* Mutex protecting access to the state. */ + mysql_mutex_t LOCK_slave_state; + + bool inited; + bool loaded; - rpl_state(); - ~rpl_state(); + rpl_slave_state(); + ~rpl_slave_state(); + void init(); + void deinit(); ulong count() const { return hash.records; } - int update(const struct rpl_gtid *gtid); + int update(uint32 domain_id, uint32 server_id, uint64 sub_id, uint64 seq_no); + int record_gtid(THD *thd, const rpl_gtid *gtid, uint64 sub_id, + bool in_transaction); + uint64 next_subid(uint32 domain_id); + + void lock() { DBUG_ASSERT(inited); mysql_mutex_lock(&LOCK_slave_state); } + void unlock() { DBUG_ASSERT(inited); mysql_mutex_unlock(&LOCK_slave_state); } + + element *get_element(uint32 domain_id); }; -extern rpl_state global_rpl_gtid_state; + +/* + Binlog state. + This keeps the last GTID written to the binlog for every distinct + (domain_id, server_id) pair. + This will be logged at the start of the next binlog file as a + Gtid_list_log_event; this way, it is easy to find the binlog file + containing a gigen GTID, by simply scanning backwards from the newest + one until a lower seq_no is found in the Gtid_list_log_event at the + start of a binlog for the given domain_id and server_id. +*/ +struct rpl_binlog_state +{ + /* Mapping from (domain_id,server_id) to its GTID. */ + HASH hash; + /* Mutex protecting access to the state. */ + mysql_mutex_t LOCK_binlog_state; + + rpl_binlog_state(); + ~rpl_binlog_state(); + + ulong count() const { return hash.records; } + int update(const struct rpl_gtid *gtid); +}; /** @class Gtid_log_event @@ -3129,7 +3203,7 @@ public: static const uint element_size= 4+4+8; #ifdef MYSQL_SERVER - Gtid_list_log_event(rpl_state *gtid_set); + Gtid_list_log_event(rpl_binlog_state *gtid_set); #ifdef HAVE_REPLICATION void pack_info(THD *thd, Protocol *protocol); #endif |