[Commits] Rev 3462: MDEV-26: Global transaction ID. in http://bazaar.launchpad.net/~maria-captains/maria/10.0

knielsen at knielsen-hq.org knielsen at knielsen-hq.org
Tue Feb 26 18:25:08 EET 2013


At http://bazaar.launchpad.net/~maria-captains/maria/10.0

------------------------------------------------------------
revno: 3462
revision-id: knielsen at knielsen-hq.org-20130226162507-uw2rk1igqzbo95rm
parent: knielsen at knielsen-hq.org-20130225170330-scqav24yhkfrqxh4
committer: knielsen at knielsen-hq.org
branch nick: work-10.0-mdev26
timestamp: Tue 2013-02-26 17:25:07 +0100
message:
  MDEV-26: Global transaction ID.
  
  Remove the two-component form of GTID with implicit domain_id=0, as it
  is likely to cause more confusion than help.
  
  Give a better error for CHANGE MASTER ... MASTER_GTID_POS='gtid,gitd,...'
  when two specified GTIDs have conflicting domain_id.
=== modified file 'sql/log_event.cc'
--- a/sql/log_event.cc	2013-02-22 11:31:55 +0000
+++ b/sql/log_event.cc	2013-02-26 16:25:07 +0000
@@ -6401,7 +6401,7 @@ rpl_slave_state::next_subid(uint32 domai
 
 static
 bool
-rpl_slave_state_tostring_helper(String *dest, rpl_gtid *gtid, bool *first)
+rpl_slave_state_tostring_helper(String *dest, const rpl_gtid *gtid, bool *first)
 {
   if (*first)
     *first= false;
@@ -6531,20 +6531,7 @@ gtid_parser_helper(char **ptr, char *end
   p= q+1;
   q= end;
   v2= (uint64)my_strtoll10(p, &q, &err);
-  if (err != 0)
-    return 1;
-  if (q == end || *q != '-')
-  {
-    /* Short form SERVERID-SEQNO, domain_id=0 implied. */
-    out_gtid->domain_id= 0;
-    out_gtid->server_id= v1;
-    out_gtid->seq_no= v2;
-    *ptr= q;
-    return 0;
-  }
-
-  /* Long form DOMAINID-SERVERID-SEQNO. */
-  if (v2 > (uint32)0xffffffff)
+  if (err != 0 || v2 > (uint32)0xffffffff || q == end || *q != '-')
     return 1;
   p= q+1;
   q= end;
@@ -6795,10 +6782,8 @@ rpl_binlog_state::read_from_iocache(IO_C
 {
   /* 10-digit - 10-digit - 20-digit \n \0 */
   char buf[10+1+10+1+20+1+1];
-  char *p, *q, *end;
-  int err;
+  char *p, *end;
   rpl_gtid gtid;
-  uint64 v;
 
   reset();
   for (;;)
@@ -6806,21 +6791,10 @@ rpl_binlog_state::read_from_iocache(IO_C
     size_t res= my_b_gets(src, buf, sizeof(buf));
     if (!res)
       break;
+    p= buf;
     end= buf + res;
-    p= end;
-    v= (uint64)my_strtoll10(buf, &p, &err);
-    if (err != 0 || v > (uint32)0xffffffff || *p++ != '-')
-      return 1;
-    gtid.domain_id= (uint32)v;
-    q= end;
-    v= (uint64)my_strtoll10(p, &q, &err);
-    if (err != 0 || v > (uint32)0xffffffff || *q++ != '-')
-      return 1;
-    gtid.server_id= (uint32)v;
-    gtid.seq_no= (uint64)my_strtoll10(q, &end, &err);
-    if (err != 0)
+    if (gtid_parser_helper(&p, end, &gtid))
       return 1;
-
     if (update(&gtid))
       return 1;
   }
@@ -6866,6 +6840,7 @@ slave_connection_state::load(char *slave
   char *p, *end;
   uchar *rec;
   rpl_gtid *gtid;
+  const rpl_gtid *gtid2;
 
   my_hash_reset(&hash);
   p= slave_request;
@@ -6873,18 +6848,39 @@ slave_connection_state::load(char *slave
   for (;;)
   {
     if (!(rec= (uchar *)my_malloc(sizeof(*gtid), MYF(MY_WME))))
+    {
+      my_error(ER_OUTOFMEMORY, MYF(0), sizeof(*gtid));
       return 1;
+    }
     gtid= (rpl_gtid *)rec;
-    if (gtid_parser_helper(&p, end, gtid) ||
-        my_hash_insert(&hash, rec))
+    if (gtid_parser_helper(&p, end, gtid))
+    {
+      my_free(rec);
+      my_error(ER_INCORRECT_GTID_STATE, MYF(0));
+      return 1;
+    }
+    if ((gtid2= (const rpl_gtid *)
+         my_hash_search(&hash, (const uchar *)(&gtid->domain_id), 0)))
     {
+      my_error(ER_DUPLICATE_GTID_DOMAIN, MYF(0), gtid->domain_id,
+               gtid->server_id, (ulonglong)gtid->seq_no, gtid2->domain_id,
+               gtid2->server_id, (ulonglong)gtid2->seq_no, gtid->domain_id);
       my_free(rec);
       return 1;
     }
+    if (my_hash_insert(&hash, rec))
+    {
+      my_free(rec);
+      my_error(ER_OUT_OF_RESOURCES, MYF(0));
+      return 1;
+    }
     if (p == end)
       break;                                         /* Finished. */
     if (*p != ',')
+    {
+      my_error(ER_INCORRECT_GTID_STATE, MYF(0));
       return 1;
+    }
     ++p;
   }
 
@@ -6957,20 +6953,14 @@ int
 slave_connection_state::to_string(String *out_str)
 {
   uint32 i;
+  bool first;
 
   out_str->length(0);
+  first= true;
   for (i= 0; i < hash.records; ++i)
   {
     const rpl_gtid *gtid= (const rpl_gtid *)my_hash_element(&hash, i);
-    if (i && out_str->append(","))
-      return 1;
-    if (gtid->domain_id &&
-        (out_str->append_ulonglong(gtid->domain_id) ||
-         out_str->append("-")))
-      return 1;
-    if (out_str->append_ulonglong(gtid->server_id) ||
-        out_str->append("-") ||
-        out_str->append_ulonglong(gtid->seq_no))
+    if (rpl_slave_state_tostring_helper(out_str, gtid, &first))
       return 1;
   }
   return 0;
@@ -7085,11 +7075,8 @@ Gtid_log_event::pack_info(THD *thd, Prot
   char buf[6+5+10+1+10+1+20+1];
   char *p;
   p = strmov(buf, (flags2 & FL_STANDALONE ? "GTID " : "BEGIN GTID "));
-  if (domain_id)
-  {
-    p= longlong10_to_str(domain_id, p, 10);
-    *p++= '-';
-  }
+  p= longlong10_to_str(domain_id, p, 10);
+  *p++= '-';
   p= longlong10_to_str(server_id, p, 10);
   *p++= '-';
   p= longlong10_to_str(seq_no, p, 10);
@@ -7171,12 +7158,7 @@ Gtid_log_event::print(FILE *file, PRINT_
   print_header(&cache, print_event_info, FALSE);
   longlong10_to_str(seq_no, buf, 10);
   if (!print_event_info->short_form)
-  {
-    my_b_printf(&cache, "\tGTID ");
-    if (domain_id)
-      my_b_printf(&cache, "%u-", domain_id);
-    my_b_printf(&cache, "%u-%s", server_id, buf);
-  }
+    my_b_printf(&cache, "\tGTID %u-%u-%s", domain_id, server_id, buf);
   my_b_printf(&cache, "\n");
 
   if (!print_event_info->domain_id_printed ||
@@ -7355,19 +7337,13 @@ Gtid_list_log_event::pack_info(THD *thd,
   char buf_mem[1024];
   String buf(buf_mem, sizeof(buf_mem), system_charset_info);
   uint32 i;
+  bool first;
 
   buf.length(0);
   buf.append(STRING_WITH_LEN("["));
+  first= true;
   for (i= 0; i < count; ++i)
-  {
-    if (i)
-      buf.append(STRING_WITH_LEN(", "));
-    buf.append_ulonglong((ulonglong)list[i].domain_id);
-    buf.append(STRING_WITH_LEN("-"));
-    buf.append_ulonglong((ulonglong)list[i].server_id);
-    buf.append(STRING_WITH_LEN("-"));
-    buf.append_ulonglong(list[i].seq_no);
-  }
+    rpl_slave_state_tostring_helper(&buf, &list[i], &first);
   buf.append(STRING_WITH_LEN("]"));
 
   protocol->store(&buf);
@@ -7389,9 +7365,9 @@ Gtid_list_log_event::print(FILE *file, P
     print_header(&cache, print_event_info, FALSE);
     for (i= 0; i < count; ++i)
     {
-      my_b_printf(&cache, "%u-", list[i].domain_id);
       longlong10_to_str(list[i].seq_no, buf, 10);
-      my_b_printf(&cache, "%u-%s", list[i].server_id, buf);
+      my_b_printf(&cache, "%u-%u-%s", list[i].domain_id,
+                  list[i].server_id, buf);
       if (i < count-1)
         my_b_printf(&cache, "\n# ");
       else

=== modified file 'sql/share/errmsg-utf8.txt'
--- a/sql/share/errmsg-utf8.txt	2013-02-15 16:06:01 +0000
+++ b/sql/share/errmsg-utf8.txt	2013-02-26 16:25:07 +0000
@@ -6604,3 +6604,5 @@ ER_INCORRECT_GTID_STATE
         eng "Could not parse GTID list for MASTER_GTID_POS"
 ER_CANNOT_UPDATE_GTID_STATE
         eng "Could not update replication slave gtid state"
+ER_DUPLICATE_GTID_DOMAIN
+        eng "GTID %u-%u-%llu and %u-%u-%llu conflict (duplicate domain id %u)"

=== modified file 'sql/sql_repl.cc'
--- a/sql/sql_repl.cc	2013-02-22 11:31:55 +0000
+++ b/sql/sql_repl.cc	2013-02-26 16:25:07 +0000
@@ -2262,7 +2262,6 @@ bool change_master(THD* thd, Master_info
     if (tmp_slave_state.load(lex_mi->gtid_pos_str.str,
                              lex_mi->gtid_pos_str.length))
     {
-      my_error(ER_INCORRECT_GTID_STATE, MYF(0));
       ret= TRUE;
       goto err;
     }
@@ -3074,7 +3073,7 @@ rpl_load_gtid_slave_state(THD *thd)
     sub_id= (ulonglong)table->field[1]->val_int();
     server_id= (ulonglong)table->field[2]->val_int();
     seq_no= (ulonglong)table->field[3]->val_int();
-    DBUG_PRINT("info", ("Read slave state row: %u:%u-%lu sub_id=%lu\n",
+    DBUG_PRINT("info", ("Read slave state row: %u-%u-%lu sub_id=%lu\n",
                         (unsigned)domain_id, (unsigned)server_id,
                         (ulong)seq_no, (ulong)sub_id));
     if ((rec= my_hash_search(&hash, (const uchar *)&domain_id, 0)))



More information about the commits mailing list