laptop commit, syncing with the repostitory. Fixed some bad bugs in replication

parent f325f5fc
...@@ -13,8 +13,8 @@ C_WARNINGS="$GLOBAL_WARNINGS -Wunused" ...@@ -13,8 +13,8 @@ C_WARNINGS="$GLOBAL_WARNINGS -Wunused"
CC_WARNINGS="$GLOBAL_WARNINGS -Woverloaded-virtual -Wextern-inline -Wsign-promo -Wreorder -Wctor-dtor-privacy -Wnon-virtual-dtor" CC_WARNINGS="$GLOBAL_WARNINGS -Woverloaded-virtual -Wextern-inline -Wsign-promo -Wreorder -Wctor-dtor-privacy -Wnon-virtual-dtor"
CFLAGS="-DFORCE_INIT_OF_VARS -O2 -mpentiumpro $C_WARNINGS" CXX=gcc \ CFLAGS="-DEXTRA_DEBUG -DFORCE_INIT_OF_VARS -O2 -mpentiumpro $C_WARNINGS" CXX=gcc \
CXXFLAGS="-DFORCE_INIT_OF_VARS -O2 -mpentiumpro -felide-constructors -fno-exceptions -fno-rtti $CC_WARNINGS" \ CXXFLAGS="-DEXTRA_DEBUG -DFORCE_INIT_OF_VARS -O2 -mpentiumpro -felide-constructors -fno-exceptions -fno-rtti $CC_WARNINGS" \
./configure --prefix=/usr/local/mysql --enable-assembler --with-mysqld-ldflags=-all-static --disable-shared --with-extra-charsets=complex --with-debug=full \ ./configure --prefix=/usr/local/mysql --enable-assembler --with-mysqld-ldflags=-all-static --disable-shared --with-extra-charsets=complex --with-debug=full \
--with-berkeley-db=/usr/local/BerkeleyDB --with-berkeley-db=/usr/local/BerkeleyDB
make make
sasha@mysql.sashanet.com sasha@laptop.slkc.uswest.net
sasha@work.mysql.com
tim@threads.polyesthetic.msg
...@@ -48,7 +48,7 @@ noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \ ...@@ -48,7 +48,7 @@ noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \
opt_range.h opt_ft.h \ opt_range.h opt_ft.h \
sql_select.h structs.h table.h sql_udf.h hash_filo.h\ sql_select.h structs.h table.h sql_udf.h hash_filo.h\
lex.h lex_symbol.h sql_acl.h sql_crypt.h md5.h \ lex.h lex_symbol.h sql_acl.h sql_crypt.h md5.h \
log_event.h mini_client.h sql_repl.h log_event.h mini_client.h sql_repl.h slave.h
mysqld_SOURCES = sql_lex.cc \ mysqld_SOURCES = sql_lex.cc \
item.cc item_sum.cc item_buff.cc item_func.cc \ item.cc item_sum.cc item_buff.cc item_func.cc \
item_cmpfunc.cc item_strfunc.cc item_timefunc.cc \ item_cmpfunc.cc item_strfunc.cc item_timefunc.cc \
......
...@@ -93,7 +93,7 @@ public: ...@@ -93,7 +93,7 @@ public:
// if mutex is 0, the read will proceed without mutex // if mutex is 0, the read will proceed without mutex
static Log_event* read_log_event(FILE* file, pthread_mutex_t* log_lock); static Log_event* read_log_event(FILE* file, pthread_mutex_t* log_lock);
static Log_event* read_log_event(const char* buf, int max_buf); static Log_event* read_log_event(const char* buf, int event_len);
#ifndef MYSQL_CLIENT #ifndef MYSQL_CLIENT
static int read_log_event(FILE* file, String* packet, static int read_log_event(FILE* file, String* packet,
...@@ -133,7 +133,7 @@ public: ...@@ -133,7 +133,7 @@ public:
#endif #endif
Query_log_event(FILE* file, time_t when, uint32 server_id); Query_log_event(FILE* file, time_t when, uint32 server_id);
Query_log_event(const char* buf, int max_buf); Query_log_event(const char* buf, int event_len);
~Query_log_event() ~Query_log_event()
{ {
if (data_buf) if (data_buf)
...@@ -273,7 +273,7 @@ public: ...@@ -273,7 +273,7 @@ public:
#endif #endif
Load_log_event(FILE* file, time_t when, uint32 server_id); Load_log_event(FILE* file, time_t when, uint32 server_id);
Load_log_event(const char* buf, int max_buf); Load_log_event(const char* buf, int event_len);
~Load_log_event() ~Load_log_event()
{ {
if (data_buf) if (data_buf)
...@@ -398,7 +398,7 @@ public: ...@@ -398,7 +398,7 @@ public:
{} {}
Rotate_log_event(FILE* file, time_t when, uint32 server_id) ; Rotate_log_event(FILE* file, time_t when, uint32 server_id) ;
Rotate_log_event(const char* buf, int max_buf); Rotate_log_event(const char* buf, int event_len);
~Rotate_log_event() ~Rotate_log_event()
{ {
if (alloced) if (alloced)
......
...@@ -205,19 +205,6 @@ inline THD *_current_thd(void) ...@@ -205,19 +205,6 @@ inline THD *_current_thd(void)
#include "sql_class.h" #include "sql_class.h"
#include "opt_range.h" #include "opt_range.h"
int mysql_table_dump(THD* thd, char* db, char* tbl_name, int fd = -1);
// if fd is -1, dump to NET
int fetch_nx_table(THD* thd, MASTER_INFO* mi);
// retrieve non-exitent table from master
// the caller must set thd->last_nx_table and thd->last_nx_db first
int show_master_info(THD* thd);
int show_binlog_info(THD* thd);
int db_ok(const char* db, I_List<i_string> &do_list,
I_List<i_string> &ignore_list );
// check to see if the database is ok to operate on with respect to the
// do and ignore lists - used in replication
void mysql_create_db(THD *thd, char *db, uint create_info); void mysql_create_db(THD *thd, char *db, uint create_info);
void mysql_binlog_send(THD* thd, char* log_ident, ulong pos, ushort flags); void mysql_binlog_send(THD* thd, char* log_ident, ulong pos, ushort flags);
...@@ -522,7 +509,6 @@ int lock_table_name(THD *thd, TABLE_LIST *table_list); ...@@ -522,7 +509,6 @@ int lock_table_name(THD *thd, TABLE_LIST *table_list);
void unlock_table_name(THD *thd, TABLE_LIST *table_list); void unlock_table_name(THD *thd, TABLE_LIST *table_list);
bool wait_for_locked_table_names(THD *thd, TABLE_LIST *table_list); bool wait_for_locked_table_names(THD *thd, TABLE_LIST *table_list);
extern int flush_master_info(MASTER_INFO* mi);
/* old unireg functions */ /* old unireg functions */
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <mysql.h> #include <mysql.h>
#include <m_ctype.h> #include <m_ctype.h>
#include "sql_acl.h" #include "sql_acl.h"
#include "slave.h"
#ifdef HAVE_BERKELEY_DB #ifdef HAVE_BERKELEY_DB
#include "ha_berkeley.h" #include "ha_berkeley.h"
#endif #endif
...@@ -179,7 +180,6 @@ static char *opt_ssl_capath = 0; ...@@ -179,7 +180,6 @@ static char *opt_ssl_capath = 0;
static VioSSLAcceptorFd* ssl_acceptor_fd = 0; static VioSSLAcceptorFd* ssl_acceptor_fd = 0;
#endif /* HAVE_OPENSSL */ #endif /* HAVE_OPENSSL */
extern bool slave_running;
I_List <i_string_pair> replicate_rewrite_db; I_List <i_string_pair> replicate_rewrite_db;
I_List<i_string> replicate_do_db, replicate_ignore_db; I_List<i_string> replicate_do_db, replicate_ignore_db;
...@@ -2229,7 +2229,8 @@ enum options { ...@@ -2229,7 +2229,8 @@ enum options {
OPT_BINLOG_IGNORE_DB, OPT_WANT_CORE, OPT_BINLOG_IGNORE_DB, OPT_WANT_CORE,
OPT_SKIP_CONCURRENT_INSERT, OPT_MEMLOCK, OPT_MYISAM_RECOVER, OPT_SKIP_CONCURRENT_INSERT, OPT_MEMLOCK, OPT_MYISAM_RECOVER,
OPT_REPLICATE_REWRITE_DB, OPT_SERVER_ID, OPT_SKIP_SLAVE_START, OPT_REPLICATE_REWRITE_DB, OPT_SERVER_ID, OPT_SKIP_SLAVE_START,
OPT_SKIP_INNOBASE,OPT_SAFEMALLOC_MEM_LIMIT OPT_SKIP_INNOBASE,OPT_SAFEMALLOC_MEM_LIMIT,
OPT_REPLICATE_DO_TABLE, OPT_REPLICATE_IGNORE_TABLE
}; };
static struct option long_options[] = { static struct option long_options[] = {
...@@ -2297,7 +2298,12 @@ static struct option long_options[] = { ...@@ -2297,7 +2298,12 @@ static struct option long_options[] = {
{"pid-file", required_argument, 0, (int) OPT_PID_FILE}, {"pid-file", required_argument, 0, (int) OPT_PID_FILE},
{"port", required_argument, 0, 'P'}, {"port", required_argument, 0, 'P'},
{"replicate-do-db", required_argument, 0, (int) OPT_REPLICATE_DO_DB}, {"replicate-do-db", required_argument, 0, (int) OPT_REPLICATE_DO_DB},
{"replicate-ignore-db", required_argument, 0, (int) OPT_REPLICATE_IGNORE_DB}, {"replicate-do-table", required_argument, 0,
(int) OPT_REPLICATE_DO_TABLE},
{"replicate-ignore-db", required_argument, 0,
(int) OPT_REPLICATE_IGNORE_DB},
{"replicate-ignore-table", required_argument, 0,
(int) OPT_REPLICATE_IGNORE_TABLE},
{"replicate-rewrite-db", required_argument, 0, {"replicate-rewrite-db", required_argument, 0,
(int) OPT_REPLICATE_REWRITE_DB}, (int) OPT_REPLICATE_REWRITE_DB},
{"safe-mode", no_argument, 0, (int) OPT_SAFE}, {"safe-mode", no_argument, 0, (int) OPT_SAFE},
...@@ -3744,4 +3750,5 @@ skipp: ; ...@@ -3744,4 +3750,5 @@ skipp: ;
template class I_List<THD>; template class I_List<THD>;
template class I_List_iterator<THD>; template class I_List_iterator<THD>;
template class I_List<i_string>; template class I_List<i_string>;
template class I_List<i_string_pair>;
#endif #endif
...@@ -18,31 +18,20 @@ ...@@ -18,31 +18,20 @@
#include "mysql_priv.h" #include "mysql_priv.h"
#include <mysql.h> #include <mysql.h>
#include "mini_client.h" #include "mini_client.h"
#include "slave.h"
#include <thr_alarm.h> #include <thr_alarm.h>
#include <my_dir.h> #include <my_dir.h>
pthread_handler_decl(handle_slave,arg);
extern bool volatile abort_loop, abort_slave;
// the master variables are defaults read from my.cnf or command line
extern uint master_port, master_connect_retry;
extern my_string master_user, master_password, master_host,
master_info_file;
extern I_List<i_string> replicate_do_db, replicate_ignore_db;
extern I_List<i_string_pair> replicate_rewrite_db;
extern I_List<THD> threads;
bool slave_running = 0; bool slave_running = 0;
pthread_t slave_real_id; pthread_t slave_real_id;
MASTER_INFO glob_mi; MASTER_INFO glob_mi;
HASH replicate_do_table, replicate_ignore_table;
bool do_table_inited = 0, ignore_table_inited = 0;
extern bool opt_log_slave_updates ;
static inline void skip_load_data_infile(NET* net); static inline void skip_load_data_infile(NET* net);
static inline bool slave_killed(THD* thd); static inline bool slave_killed(THD* thd);
static int init_slave_thread(THD* thd); static int init_slave_thread(THD* thd);
int init_master_info(MASTER_INFO* mi);
static void safe_connect(THD* thd, MYSQL* mysql, MASTER_INFO* mi); static void safe_connect(THD* thd, MYSQL* mysql, MASTER_INFO* mi);
static void safe_reconnect(THD* thd, MYSQL* mysql, MASTER_INFO* mi); static void safe_reconnect(THD* thd, MYSQL* mysql, MASTER_INFO* mi);
static int safe_sleep(THD* thd, int sec); static int safe_sleep(THD* thd, int sec);
...@@ -50,6 +39,26 @@ static int request_table_dump(MYSQL* mysql, char* db, char* table); ...@@ -50,6 +39,26 @@ static int request_table_dump(MYSQL* mysql, char* db, char* table);
static int create_table_from_dump(THD* thd, NET* net, const char* db, static int create_table_from_dump(THD* thd, NET* net, const char* db,
const char* table_name); const char* table_name);
static inline char* rewrite_db(char* db); static inline char* rewrite_db(char* db);
static void free_table_ent(TABLE_RULE_ENT* e)
{
my_free((byte*)e, MYF(0));
}
static byte* get_table_key(TABLE_RULE_ENT* e, uint* len,
my_bool not_used __attribute__((unused)))
{
*len = e->key_len;
return (byte*)e->db;
}
void init_table_rule_hash(HASH* h, bool* h_inited)
{
hash_init(h, TABLE_RULE_HASH_SIZE,0,0,
(hash_get_key) get_table_key,
(void (*)(void*)) free_table_ent, 0);
*h_inited = 1;
}
static inline bool slave_killed(THD* thd) static inline bool slave_killed(THD* thd)
{ {
......
#ifndef SLAVE_H
#define SLAVE_H
typedef struct st_master_info
{
char log_file_name[FN_REFLEN];
ulonglong pos,pending;
FILE* file; // we keep the file open, so we need to remember the file pointer
// the variables below are needed because we can change masters on the fly
char host[HOSTNAME_LENGTH+1];
char user[USERNAME_LENGTH+1];
char password[HASH_PASSWORD_LENGTH+1];
uint port;
uint connect_retry;
pthread_mutex_t lock;
bool inited;
st_master_info():pending(0),inited(0)
{
host[0] = 0; user[0] = 0; password[0] = 0;
pthread_mutex_init(&lock, NULL);
}
~st_master_info()
{
pthread_mutex_destroy(&lock);
}
inline void inc_pending(ulonglong val)
{
pending += val;
}
inline void inc_pos(ulonglong val)
{
pthread_mutex_lock(&lock);
pos += val + pending;
pending = 0;
pthread_mutex_unlock(&lock);
}
// thread safe read of position - not needed if we are in the slave thread,
// but required otherwise
inline void read_pos(ulonglong& var)
{
pthread_mutex_lock(&lock);
var = pos;
pthread_mutex_unlock(&lock);
}
} MASTER_INFO;
typedef struct st_table_rule_ent
{
char* db;
char* tbl_name;
uint key_len;
} TABLE_RULE_ENT;
#define TABLE_RULE_HASH_SIZE 16
int flush_master_info(MASTER_INFO* mi);
int mysql_table_dump(THD* thd, char* db, char* tbl_name, int fd = -1);
// if fd is -1, dump to NET
int fetch_nx_table(THD* thd, MASTER_INFO* mi);
// retrieve non-exitent table from master
// the caller must set thd->last_nx_table and thd->last_nx_db first
int show_master_info(THD* thd);
int show_binlog_info(THD* thd);
int db_ok(const char* db, I_List<i_string> &do_list,
I_List<i_string> &ignore_list );
// check to see if the database is ok to operate on with respect to the
// do and ignore lists - used in replication
int init_master_info(MASTER_INFO* mi);
extern bool opt_log_slave_updates ;
pthread_handler_decl(handle_slave,arg);
extern bool volatile abort_loop, abort_slave;
extern bool slave_running;
extern pthread_t slave_real_id;
extern MASTER_INFO glob_mi;
extern HASH replicate_do_table, replicate_ignore_table;
extern bool do_table_inited, ignore_table_inited;
// the master variables are defaults read from my.cnf or command line
extern uint master_port, master_connect_retry;
extern my_string master_user, master_password, master_host,
master_info_file;
extern I_List<i_string> replicate_do_db, replicate_ignore_db;
extern I_List<i_string_pair> replicate_rewrite_db;
extern I_List<THD> threads;
#endif
...@@ -50,52 +50,6 @@ typedef struct st_log_info ...@@ -50,52 +50,6 @@ typedef struct st_log_info
~st_log_info() { pthread_mutex_destroy(&lock);} ~st_log_info() { pthread_mutex_destroy(&lock);}
} LOG_INFO; } LOG_INFO;
typedef struct st_master_info
{
char log_file_name[FN_REFLEN];
ulonglong pos,pending;
FILE* file; // we keep the file open, so we need to remember the file pointer
// the variables below are needed because we can change masters on the fly
char host[HOSTNAME_LENGTH+1];
char user[USERNAME_LENGTH+1];
char password[HASH_PASSWORD_LENGTH+1];
uint port;
uint connect_retry;
pthread_mutex_t lock;
bool inited;
st_master_info():inited(0),pending(0)
{
host[0] = 0; user[0] = 0; password[0] = 0;
pthread_mutex_init(&lock, NULL);
}
~st_master_info()
{
pthread_mutex_destroy(&lock);
}
inline void inc_pending(ulonglong val)
{
pending += val;
}
inline void inc_pos(ulonglong val)
{
pthread_mutex_lock(&lock);
pos += val + pending;
pending = 0;
pthread_mutex_unlock(&lock);
}
// thread safe read of position - not needed if we are in the slave thread,
// but required otherwise
inline void read_pos(ulonglong& var)
{
pthread_mutex_lock(&lock);
var = pos;
pthread_mutex_unlock(&lock);
}
} MASTER_INFO;
class MYSQL_LOG { class MYSQL_LOG {
public: public:
......
#ifndef SQL_REPL_H #ifndef SQL_REPL_H
#define SQL_REPL_H #define SQL_REPL_H
extern bool slave_running; #include "slave.h"
extern volatile bool abort_slave;
extern char* master_host; extern char* master_host;
extern pthread_t slave_real_id;
extern MASTER_INFO glob_mi;
extern my_string opt_bin_logname, master_info_file; extern my_string opt_bin_logname, master_info_file;
extern I_List<i_string> binlog_do_db, binlog_ignore_db; extern I_List<i_string> binlog_do_db, binlog_ignore_db;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment