MWL#36: Add a mysqlbinlog option to change the used database.
Add Rpl_filter to mysqlbinlog.cc Note. Though within MWL#36 we are going to use only two Rpl_filter's methods (add_db_rewrite and get_rewrite_db), we look forward for MWL#40 where Rpl_filter is likely to be used to its more extent. Note. Within MWL#36 we will not use Rpl_filter for supporting --database option: this option allows to specify only one database what doesn't correlate with Rpl_filter::add_do_db() (using this method will either appear "artificial" or require changing --database semantics). To be discussed within MWL#40. To add Rpl_filter we need: 1. include sql_string.h There are two instances of sql_string.* files - in sql and in client directories. We need to use the ones from the sql dir. 2. include sql_list.h This requires to define a client version of sql_alloc() function. 3. include rpl_filter.h This requires a definition of system_charset_info variable. Besides, Rpl_filter::tables_ok() refers to a TABLE_LIST structure which encounts deep non-client dependencies and can't be used here as is. On the other hand, tables_ok() make use only few TABLE_LIST's members and none of them depends on specific server context. This allows to redefine TABLE_LIST in a client context so that tables_ok() becomes admissible (surely it's a kind of hack but (at least currently) it's better than #ifndef'ing this method in Rpl_filter definition). Also add Rpl_filter::rewrite_db_is_empty() method. This is needed to be able to check that --rewrite-db is not used jointly with --base64-output= always (this is not supported - at least currently).
This commit is contained in:
parent
ef5874d154
commit
c12c675d36
@ -35,6 +35,18 @@
|
|||||||
#include "log_event.h"
|
#include "log_event.h"
|
||||||
#include "sql_common.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_list.h" // needed for Rpl_filter
|
||||||
|
#include "rpl_filter.h"
|
||||||
|
|
||||||
|
Rpl_filter *binlog_filter;
|
||||||
|
|
||||||
#define BIN_LOG_HEADER_SIZE 4
|
#define BIN_LOG_HEADER_SIZE 4
|
||||||
#define PROBE_HEADER_LEN (EVENT_LEN_OFFSET+4)
|
#define PROBE_HEADER_LEN (EVENT_LEN_OFFSET+4)
|
||||||
|
|
||||||
@ -1986,6 +1998,8 @@ end:
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Used in sql_alloc(). Inited and freed in main() */
|
||||||
|
MEM_ROOT s_mem_root;
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
@ -1998,6 +2012,13 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
my_init_time(); // for time functions
|
my_init_time(); // for time functions
|
||||||
|
|
||||||
|
init_alloc_root(&s_mem_root, 16384, 0);
|
||||||
|
if (!(binlog_filter= new Rpl_filter))
|
||||||
|
{
|
||||||
|
error("Failed to create Rpl_filter");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
parse_args(&argc, (char***)&argv);
|
parse_args(&argc, (char***)&argv);
|
||||||
defaults_argv=argv;
|
defaults_argv=argv;
|
||||||
|
|
||||||
@ -2084,6 +2105,8 @@ int main(int argc, char** argv)
|
|||||||
if (result_file != stdout)
|
if (result_file != stdout)
|
||||||
my_fclose(result_file, MYF(0));
|
my_fclose(result_file, MYF(0));
|
||||||
cleanup();
|
cleanup();
|
||||||
|
delete binlog_filter;
|
||||||
|
free_root(&s_mem_root, MYF(0));
|
||||||
free_defaults(defaults_argv);
|
free_defaults(defaults_argv);
|
||||||
my_free_open_file_info();
|
my_free_open_file_info();
|
||||||
load_processor.destroy();
|
load_processor.destroy();
|
||||||
@ -2095,6 +2118,21 @@ int main(int argc, char** argv)
|
|||||||
DBUG_RETURN(retval == ERROR_STOP ? 1 : 0);
|
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)
|
||||||
|
{
|
||||||
|
return alloc_root(&s_mem_root, size);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
We must include this here as it's compiled with different options for
|
We must include this here as it's compiled with different options for
|
||||||
the server
|
the server
|
||||||
@ -2105,4 +2143,7 @@ int main(int argc, char** argv)
|
|||||||
#include "my_decimal.cc"
|
#include "my_decimal.cc"
|
||||||
#include "log_event.cc"
|
#include "log_event.cc"
|
||||||
#include "log_event_old.cc"
|
#include "log_event_old.cc"
|
||||||
|
#include "../sql/sql_string.cc"
|
||||||
|
#include "sql_list.cc"
|
||||||
|
#include "rpl_filter.cc"
|
||||||
|
|
||||||
|
@ -514,6 +514,13 @@ Rpl_filter::get_wild_ignore_table(String* str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
Rpl_filter::rewrite_db_is_empty()
|
||||||
|
{
|
||||||
|
return rewrite_db.is_empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
Rpl_filter::get_rewrite_db(const char* db, size_t *new_len)
|
Rpl_filter::get_rewrite_db(const char* db, size_t *new_len)
|
||||||
{
|
{
|
||||||
|
@ -69,6 +69,7 @@ public:
|
|||||||
void get_wild_do_table(String* str);
|
void get_wild_do_table(String* str);
|
||||||
void get_wild_ignore_table(String* str);
|
void get_wild_ignore_table(String* str);
|
||||||
|
|
||||||
|
bool rewrite_db_is_empty();
|
||||||
const char* get_rewrite_db(const char* db, size_t *new_len);
|
const char* get_rewrite_db(const char* db, size_t *new_len);
|
||||||
|
|
||||||
I_List<i_string>* get_do_db();
|
I_List<i_string>* get_do_db();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user