← Back to team overview

maria-developers team mailing list archive

Rev 2751: MWL#36: Add a mysqlbinlog option to change the used database in file:///home/psergey/dev/maria-5.1-wl36-r3/

 

At file:///home/psergey/dev/maria-5.1-wl36-r3/

------------------------------------------------------------
revno: 2751
revision-id: psergey@xxxxxxxxxxxx-20091024194339-tauuslposi16t7uv
parent: alexi1952@xxxxxxxxx-20091017061257-v142dpem8x7rrh35
committer: Sergey Petrunya <psergey@xxxxxxxxxxxx>
branch nick: maria-5.1-wl36-r3
timestamp: Sat 2009-10-24 23:43:39 +0400
message:
  MWL#36: Add a mysqlbinlog option to change the used database
  - Review fixes
=== modified file 'client/Makefile.am'
--- a/client/Makefile.am	2009-07-31 19:28:15 +0000
+++ b/client/Makefile.am	2009-10-24 19:43:39 +0000
@@ -107,7 +107,8 @@
 	rpl_utility.h rpl_tblmap.h rpl_tblmap.cc \
 	log_event.cc my_decimal.h my_decimal.cc \
 	log_event_old.h log_event_old.cc \
-	rpl_record_old.h rpl_record_old.cc
+	rpl_record_old.h rpl_record_old.cc \
+        sql_list.h rpl_filter.h sql_list.cc rpl_filter.cc
 strings_src=decimal.c
 
 link_sources:

=== modified file 'client/mysqlbinlog.cc'
--- a/client/mysqlbinlog.cc	2009-10-16 14:04:12 +0000
+++ b/client/mysqlbinlog.cc	2009-10-24 19:43:39 +0000
@@ -35,13 +35,10 @@
 #include "log_event.h"
 #include "sql_common.h"
 
-/* Needed for Rlp_filter */
-struct TABLE_LIST;
-
 /* Needed for Rpl_filter */
 CHARSET_INFO* system_charset_info= &my_charset_utf8_general_ci;
 
-#include "../sql/sql_string.h"  // needed for Rpl_filter
+#include "sql_string.h"  // needed for Rpl_filter
 #include "sql_list.h"           // needed for Rpl_filter
 #include "rpl_filter.h"
 
@@ -628,12 +625,13 @@
 
 
 /**
-  Prints "use <db>" statement when current db is to be changed.
+  Print "use <db>" statement when current db is to be changed.
 
   We have to control emiting USE statements according to rewrite-db options.
   We have to do it here (see process_event() below) and to suppress
   producing USE statements by corresponding log event print-functions.
 */
+
 void print_use_stmt(PRINT_EVENT_INFO* pinfo, const char* db, size_t db_len)
 {
   // pinfo->db is the current db.
@@ -1021,14 +1019,16 @@
   retval= ERROR_STOP;
 end:
   rec_count++;
+  
   /*
-    Destroy the log_event object. If reading from a remote host,
-    set the temp_buf to NULL so that memory isn't freed twice.
+    Destroy the log_event object. 
+    MariaDB MWL#36: mainline does this:
+      If reading from a remote host,
+      set the temp_buf to NULL so that memory isn't freed twice.
+    We no longer do that, we use Rpl_filter::event_owns_temp_buf instead.
   */
   if (ev)
   {
-    if (remote_opt)
-      ev->temp_buf= 0;
     if (destroy_evt) /* destroy it later if not set (ignored table map) */
       delete ev;
   }
@@ -1385,6 +1385,7 @@
     break;
   case OPT_REWRITE_DB:    // db_from->db_to
   {
+    /* See also handling of OPT_REPLICATE_REWRITE_DB in sql/mysqld.cc */
     char* ptr;
     char* key= argument;  // db-from
     char* val;            // db-to
@@ -1395,20 +1396,22 @@
 
     // Where val begins
     if (!(ptr= strstr(argument, "->")))
-    { sql_print_error("Bad syntax in rewrite-db: missing '->'!\n");
+    {
+      sql_print_error("Bad syntax in rewrite-db: missing '->'!\n");
       return 1;
     }
     val= ptr + 2;
     while (*val && my_isspace(&my_charset_latin1, *val))
       val++;
 
-    // Write /0 and skip blanks at the end of key
+    // Write \0 and skip blanks at the end of key
     *ptr-- = 0;
     while (my_isspace(&my_charset_latin1, *ptr) && ptr > argument)
       *ptr-- = 0;
 
     if (!*key)
-    { sql_print_error("Bad syntax in rewrite-db: empty db-from!\n");
+    {
+      sql_print_error("Bad syntax in rewrite-db: empty db-from!\n");
       return 1;
     }
 
@@ -1419,7 +1422,8 @@
     *ptr= 0;
 
     if (!*val)
-    { sql_print_error("Bad syntax in rewrite-db: empty db-to!\n");
+    {
+      sql_print_error("Bad syntax in rewrite-db: empty db-to!\n");
       return 1;
     }
 
@@ -1691,7 +1695,7 @@
       If reading from a remote host, ensure the temp_buf for the
       Log_event class is pointing to the incoming stream.
     */
-    ev->register_temp_buf((char *) net->read_pos + 1);
+    ev->register_temp_buf((char *) net->read_pos + 1, FALSE);
 
     Log_event_type type= ev->get_type_code();
     if (glob_description_event->binlog_version >= 3 ||
@@ -2211,15 +2215,6 @@
   DBUG_RETURN(retval == ERROR_STOP ? 1 : 0);
 }
 
-/* Redefinition for Rpl_filter::tables_ok() */
-struct TABLE_LIST
-{
-  TABLE_LIST() {}
-  TABLE_LIST *next_global, **prev_global;
-  bool  updating;
-  char* db;
-  char* table_name;
-};
 
 void *sql_alloc(size_t size)
 {
@@ -2236,7 +2231,7 @@
 #include "my_decimal.cc"
 #include "log_event.cc"
 #include "log_event_old.cc"
-#include "../sql/sql_string.cc"
+#include "sql_string.cc"
 #include "sql_list.cc"
 #include "rpl_filter.cc"
 

=== modified file 'client/sql_string.h'
--- a/client/sql_string.h	2007-03-08 03:27:41 +0000
+++ b/client/sql_string.h	2009-10-24 19:43:39 +0000
@@ -15,6 +15,9 @@
 
 /* This file is originally from the mysql distribution. Coded by monty */
 
+#ifndef CLIENT_SQL_STRING_H
+#define CLIENT_SQL_STRING_H
+
 #ifdef USE_PRAGMA_INTERFACE
 #pragma interface			/* gcc class implementation */
 #endif
@@ -353,3 +356,5 @@
     return (s->alloced && Ptr >= s->Ptr && Ptr < s->Ptr + s->str_length);
   }
 };
+
+#endif 

=== modified file 'sql/log_event.cc'
--- a/sql/log_event.cc	2009-10-16 11:58:16 +0000
+++ b/sql/log_event.cc	2009-10-24 19:43:39 +0000
@@ -1121,7 +1121,7 @@
     goto err;
   }
   if ((res= read_log_event(buf, data_len, &error, description_event)))
-    res->register_temp_buf(buf);
+    res->register_temp_buf(buf, TRUE);
 
 err:
   UNLOCK_MUTEX;
@@ -8007,16 +8007,26 @@
 
 
 #ifdef MYSQL_CLIENT
+
 /*
-  Reset db name. This function assumes that temp_buf member contains event
-  representation taken from a binary log. It resets m_dbnam and m_dblen and
-  rewrites temp_buf with new db name.
-  On success returns 0, on failure return non-zero value.
+  Rewrite database name for the event to name specified by new_db
+  SYNOPSIS
+    new_db   Database name to change to
+    new_len  Length
+    desc     Event describing binlog that we're writing to.
+
+  DESCRIPTION
+    Reset db name. This function assumes that temp_buf member contains event
+    representation taken from a binary log. It resets m_dbnam and m_dblen and
+    rewrites temp_buf with new db name.
+
+  RETURN 
+    0     - Success
+    other - Error
 */
-int Table_map_log_event::rewrite_db(
-  const char* new_db,
-  size_t new_len,
-  const Format_description_log_event* desc)
+
+int Table_map_log_event::rewrite_db(const char* new_db, size_t new_len,
+                                    const Format_description_log_event* desc)
 {
   DBUG_ENTER("Table_map_log_event::rewrite_db");
   DBUG_ASSERT(temp_buf);
@@ -8039,8 +8049,9 @@
 
   if (!new_temp_buf)
   {
-    sql_print_error("Table_map_log_event::rewrite_dbname: "
-      "failed to allocate new temp_buf (%d bytes required)", event_new_len);
+    sql_print_error("Table_map_log_event::rewrite_db: "
+                    "failed to allocate new temp_buf (%d bytes required)",
+                    event_new_len);
     DBUG_RETURN(-1);
   }
 
@@ -8065,7 +8076,7 @@
 
   // Reregister temp buf
   free_temp_buf();
-  register_temp_buf(new_temp_buf);
+  register_temp_buf(new_temp_buf, TRUE);
 
   // Reset m_dbnam and m_dblen members
   m_dblen= new_len;
@@ -8083,9 +8094,9 @@
 
   if (!m_memory)
   {
-    sql_print_error("Table_map_log_event::rewrite_dbname: "
-      "failed to allocate new m_memory (%d + %d + %d bytes required)",
-      m_dblen + 1, m_tbllen + 1, m_colcnt);
+    sql_print_error("Table_map_log_event::rewrite_db: "
+                    "failed to allocate new m_memory (%d + %d + %d bytes required)",
+                    m_dblen + 1, m_tbllen + 1, m_colcnt);
     DBUG_RETURN(-1);
   }
 

=== modified file 'sql/log_event.h'
--- a/sql/log_event.h	2009-10-16 11:58:16 +0000
+++ b/sql/log_event.h	2009-10-24 19:43:39 +0000
@@ -873,6 +873,13 @@
      event's type, and its content is distributed in the event-specific fields.
   */
   char *temp_buf;
+  
+  /*
+    TRUE <=> this event 'owns' temp_buf and should call my_free() when done
+    with it
+  */
+  bool event_owns_temp_buf;
+
   /*
     Timestamp on the master(for debugging and replication of
     NOW()/TIMESTAMP).  It is important for queries and LOAD DATA
@@ -1014,12 +1021,17 @@
   Log_event(const char* buf, const Format_description_log_event
             *description_event);
   virtual ~Log_event() { free_temp_buf();}
-  void register_temp_buf(char* buf) { temp_buf = buf; }
+  void register_temp_buf(char* buf, bool must_free) 
+  { 
+    temp_buf= buf; 
+    event_owns_temp_buf= must_free;
+  }
   void free_temp_buf()
   {
     if (temp_buf)
     {
-      my_free(temp_buf, MYF(0));
+      if (event_owns_temp_buf)
+        my_free(temp_buf, MYF(0));
       temp_buf = 0;
     }
   }

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2009-10-07 13:07:10 +0000
+++ b/sql/mysqld.cc	2009-10-24 19:43:39 +0000
@@ -8188,6 +8188,7 @@
   }
   case (int)OPT_REPLICATE_REWRITE_DB:
   {
+    /* See also OPT_REWRITE_DB handling in client/mysqlbinlog.cc */
     char* key = argument,*p, *val;
 
     if (!(p= strstr(argument, "->")))

=== modified file 'sql/rpl_filter.cc'
--- a/sql/rpl_filter.cc	2009-10-16 13:28:13 +0000
+++ b/sql/rpl_filter.cc	2009-10-24 19:43:39 +0000
@@ -45,6 +45,7 @@
 }
 
 
+#ifndef MYSQL_CLIENT
 /*
   Returns true if table should be logged/replicated 
 
@@ -129,6 +130,7 @@
               !do_table_inited && !wild_do_table_inited);
 }
 
+#endif
 
 /*
   Checks whether a db matches some do_db and ignore_db rules

=== modified file 'sql/rpl_filter.h'
--- a/sql/rpl_filter.h	2009-10-16 13:28:13 +0000
+++ b/sql/rpl_filter.h	2009-10-24 19:43:39 +0000
@@ -42,7 +42,9 @@
  
   /* Checks - returns true if ok to replicate/log */
 
-  bool tables_ok(const char* db, TABLE_LIST* tables);
+#ifndef MYSQL_CLIENT
+  bool tables_ok(const char* db, TABLE_LIST *tables);
+#endif 
   bool db_ok(const char* db);
   bool db_ok_with_wild_table(const char *db);
 

=== modified file 'sql/sql_string.cc'
--- a/sql/sql_string.cc	2009-10-17 06:12:57 +0000
+++ b/sql/sql_string.cc	2009-10-24 19:43:39 +0000
@@ -28,6 +28,9 @@
 #endif
 #include "sql_string.h"
 
+#ifdef MYSQL_CLIENT
+#error Attempt to use server-side sql_string on client. Use client/sql_string.cc
+#endif 
 /*****************************************************************************
 ** String functions
 *****************************************************************************/

=== modified file 'sql/sql_string.h'
--- a/sql/sql_string.h	2009-10-16 11:20:09 +0000
+++ b/sql/sql_string.h	2009-10-24 19:43:39 +0000
@@ -25,6 +25,10 @@
 #define NOT_FIXED_DEC			31
 #endif
 
+#ifdef MYSQL_CLIENT
+#error Attempt to use server-side sql_string on client. Use client/sql_string.h
+#endif 
+
 class String;
 int sortcmp(const String *a,const String *b, CHARSET_INFO *cs);
 String *copy_if_not_alloced(String *a,String *b,uint32 arg_length);