diff options
author | unknown <knielsen@knielsen-hq.org> | 2013-08-23 14:02:13 +0200 |
---|---|---|
committer | unknown <knielsen@knielsen-hq.org> | 2013-08-23 14:02:13 +0200 |
commit | f9c2b402f437a2278b04d971054fcacc57eb07aa (patch) | |
tree | 5e5beb8bd8ab697ca05f3c39ecb53fb85ee7f147 /sql/rpl_gtid.cc | |
parent | 62d358295bbf8df16da75dd109c463de796dabe0 (diff) | |
download | mariadb-git-f9c2b402f437a2278b04d971054fcacc57eb07aa.tar.gz |
MDEV-26: Global transaction ID.
Implement @@gtid_binlog_state. This is the internal state of the binlog
(most recent GTID logged for every domain_id and server_id). This allows
to save the state before RESET MASTER and restore it afterwards.
Diffstat (limited to 'sql/rpl_gtid.cc')
-rw-r--r-- | sql/rpl_gtid.cc | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/sql/rpl_gtid.cc b/sql/rpl_gtid.cc index 96dade4d390..62d2d6026ce 100644 --- a/sql/rpl_gtid.cc +++ b/sql/rpl_gtid.cc @@ -719,6 +719,45 @@ gtid_parser_helper(char **ptr, char *end, rpl_gtid *out_gtid) } +rpl_gtid * +gtid_parse_string_to_list(const char *str, size_t str_len, uint32 *out_len) +{ + char *p= const_cast<char *>(str); + char *end= p + str_len; + uint32 len= 0, alloc_len= 5; + rpl_gtid *list= NULL; + + for (;;) + { + rpl_gtid gtid; + + if (len >= (((uint32)1 << 28)-1) || gtid_parser_helper(&p, end, >id)) + { + my_free(list); + return NULL; + } + if ((!list || len >= alloc_len) && + !(list= + (rpl_gtid *)my_realloc(list, + (alloc_len= alloc_len*2) * sizeof(rpl_gtid), + MYF(MY_FREE_ON_ERROR|MY_ALLOW_ZERO_PTR)))) + return NULL; + list[len++]= gtid; + + if (p == end) + break; + if (*p != ',') + { + my_free(list); + return NULL; + } + ++p; + } + *out_len= len; + return list; +} + + /* Update the slave replication state with the GTID position obtained from master when connecting with old-style (filename,offset) position. @@ -1234,6 +1273,41 @@ rpl_binlog_state::append_pos(String *str) } +bool +rpl_binlog_state::append_state(String *str) +{ + uint32 i, j; + bool first= true; + + for (i= 0; i < hash.records; ++i) + { + element *e= (element *)my_hash_element(&hash, i); + if (!e->last_gtid) + { + DBUG_ASSERT(e->hash.records==0); + continue; + } + for (j= 0; j <= e->hash.records; ++j) + { + const rpl_gtid *gtid; + if (j < e->hash.records) + { + gtid= (rpl_gtid *)my_hash_element(&e->hash, j); + if (gtid == e->last_gtid) + continue; + } + else + gtid= e->last_gtid; + + if (rpl_slave_state_tostring_helper(str, gtid, &first)) + return true; + } + } + + return false; +} + + slave_connection_state::slave_connection_state() { my_hash_init(&hash, &my_charset_bin, 32, |