1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

MWL#36: Add a mysqlbinlog option to change the used database

- Review fixes

client/Makefile.am:
  - Make it build on Linux
client/mysqlbinlog.cc:
  - Coding style fixes
  - Better/more comments
  - Use client/sql_string.*, not server's sql/sql_string.*.
  - Don't declare a dummy TABLE_LIST structure in the client.
client/sql_string.h:
  - Use client/sql_string.*, not server's sql/sql_string.*.
sql/log_event.cc:
  = Fix coding style
  = Introduce Log_event::event_owns_temp_buf which tells whether Log_event::temp_buf is 'owned' by the Log_event object and should be my_free'd on return. 
  This is needed because rewrite_db() needs to dispose of the buffer, and 
  - when mysqlbinlog is reading directly from binlog file, the buffer 
    should be freed
  - when mysqlbinlog is reading from a server, the buffer is a part of network
    buffer and shouldn't be freed.
sql/log_event.h:
  Introduce Log_event::event_owns_temp_buf which tells whether Log_event::temp_buf is 'owned' by the Log_event object and should be my_free'd on return. 
  This is needed because rewrite_db() needs to dispose of the buffer, and 
  - when mysqlbinlog is reading directly from binlog file, the buffer 
    should be freed
  - when mysqlbinlog is reading from a server, the buffer is a part of network
    buffer and shouldn't be freed.
sql/mysqld.cc:
  - Better/more comments
sql/rpl_filter.cc:
  - #ifdef-out Rpl_filter::tables_ok from the client. This allows not 
    to define dummy TABLE_LIST on the client
sql/rpl_filter.h:
  - #ifdef-out Rpl_filter::tables_ok from the client. This allows not 
    to define dummy TABLE_LIST on the client
sql/sql_string.cc:
  - Use client/sql_string.*, not server's sql/sql_string.*.
sql/sql_string.h:
  - Use client/sql_string.*, not server's sql/sql_string.*.
This commit is contained in:
Sergey Petrunya
2009-10-24 23:43:39 +04:00
parent 3ea974ad2f
commit b027072e01
10 changed files with 79 additions and 43 deletions

View File

@ -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 @@ static bool shall_skip_database(const char *log_dbname)
/**
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 @@ err:
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 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
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 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
// 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 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
*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 @@ static Exit_status dump_remote_log_entries(PRINT_EVENT_INFO *print_event_info,
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 @@ int main(int argc, char** argv)
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 @@ void *sql_alloc(size_t size)
#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"