Commit 9b6df03c authored by monty@bitch.mysql.fi's avatar monty@bitch.mysql.fi

Added a lot of DBUG_xxx statements to be able to find replication bug.

Fixed critical bug on 64 bit systems.
Cleanups
parent 23e9db94
#! /bin/sh
while test $# -gt 0
do
case "$1" in
--debug) EXTRA_CONFIG_FLAGS=--with-debug; shift ;;
-h | --help ) cat <<EOF; exit 0 ;;
Usage: $0 [-h|-n] [configure-options]
--debug Compile with DBUG enabled
EOF
*) echo "No such option '$1'" ; exit ;;
esac
done
gmake -k clean || true
/bin/rm -f */.deps/*.P config.cache
aclocal && autoheader && aclocal && automake && autoconf
(cd bdb/dist && sh s_all)
(cd innobase && aclocal && autoheader && aclocal && automake && autoconf)
CFLAGS="-g -Wimplicit -Wreturn-type -Wswitch -Wtrigraphs -Wcomment -W -Wchar-subscripts -Wformat -Wimplicit-function-dec -Wimplicit-int -Wparentheses -Wsign-compare -Wwrite-strings -Wunused -DHAVE_purify -DEXTRA_DEBUG -O2" CXX=gcc CXXLD=g++ CXXFLAGS="-g -Wimplicit -Wreturn-type -Wswitch -Wtrigraphs -Wcomment -W -Wchar-subscripts -Wformat -Wparentheses -Wsign-compare -Wwrite-strings -Woverloaded-virtual -Wsign-promo -Wreorder -Wctor-dtor-privacy -Wnon-virtual-dtor -felide-constructors -fno-exceptions -fno-rtti -DHAVE_purify -DEXTRA_DEBUG -O2" ./configure --prefix=/usr/local/mysql --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-berkeley-db --with-innodb
CFLAGS="-g -Wimplicit -Wreturn-type -Wswitch -Wtrigraphs -Wcomment -W -Wchar-subscripts -Wformat -Wimplicit-function-dec -Wimplicit-int -Wparentheses -Wsign-compare -Wwrite-strings -Wunused -DHAVE_purify -DEXTRA_DEBUG -O2" CXX=gcc CXXLD=g++ CXXFLAGS="-g -Wimplicit -Wreturn-type -Wswitch -Wtrigraphs -Wcomment -W -Wchar-subscripts -Wformat -Wparentheses -Wsign-compare -Wwrite-strings -Woverloaded-virtual -Wsign-promo -Wreorder -Wctor-dtor-privacy -Wnon-virtual-dtor -felide-constructors -fno-exceptions -fno-rtti -DHAVE_purify -DEXTRA_DEBUG -O2" ./configure --prefix=/usr/local/mysql --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-berkeley-db --with-innodb $EXTRA_CONFIG_FLAGS
gmake -j 4
cd sql ; rm mysqld ;
cd sql ; mv mysqld mysqld-org ;
make CXXLD="purify -best-effort g++" mysqld ; mv mysqld mysqld-purify
make CXXLD="quantify -best-effort g++" mysqld ; mv mysqld mysqld-quantify
make CXXLD="purecov -best-effort g++" mysqld ; mv mysqld mysqld-purecov
mv mysqld-org mysqld
......@@ -1240,8 +1240,9 @@ Slave_log_event::Slave_log_event(THD* thd_arg,
struct st_relay_log_info* rli):
Log_event(thd_arg),mem_pool(0),master_host(0)
{
DBUG_ENTER("Slave_log_event");
if (!rli->inited)
return;
DBUG_VOID_RETURN;
MASTER_INFO* mi = rli->mi;
// TODO: re-write this better without holding both locks at the same time
......@@ -1259,11 +1260,14 @@ Slave_log_event::Slave_log_event(THD* thd_arg,
memcpy(master_log, rli->master_log_name, master_log_len + 1);
master_port = mi->port;
master_pos = rli->master_log_pos;
DBUG_PRINT("info", ("master_log: %s pos: %d", master_log,
(ulong) master_pos));
}
else
sql_print_error("Out of memory while recording slave event");
pthread_mutex_unlock(&rli->data_lock);
pthread_mutex_unlock(&mi->data_lock);
DBUG_VOID_RETURN;
}
......@@ -1284,8 +1288,8 @@ void Slave_log_event::print(FILE* file, bool short_form, char* last_db)
return;
print_header(file);
fputc('\n', file);
fprintf(file, "Slave: master_host='%s' master_port=%d \
master_log=%s master_pos=%s\n",
fprintf(file, "Slave: master_host: '%s' master_port: %d \
master_log: '%s' master_pos: %s\n",
master_host, master_port, master_log, llstr(master_pos, llbuff));
}
......@@ -1791,9 +1795,13 @@ int Rotate_log_event::exec_event(struct st_relay_log_info* rli)
{
bool rotate_binlog = 0, write_slave_event = 0;
char* log_name = rli->master_log_name;
DBUG_ENTER("Rotate_log_event::exec_event");
pthread_mutex_lock(&rli->data_lock);
// TODO: probably needs re-write
// rotate local binlog only if the name of remote has changed
/*
TODO: probably needs re-write
rotate local binlog only if the name of remote has changed
*/
if (!*log_name || !(log_name[ident_len] == 0 &&
!memcmp(log_name, new_log_ident, ident_len)))
{
......@@ -1801,7 +1809,7 @@ int Rotate_log_event::exec_event(struct st_relay_log_info* rli)
&& mysql_bin_log.is_open());
rotate_binlog = (*log_name && write_slave_event);
if (ident_len >= sizeof(rli->master_log_name))
return 1;
DBUG_RETURN(1);
memcpy(log_name, new_log_ident,ident_len);
log_name[ident_len] = 0;
}
......@@ -1812,6 +1820,7 @@ int Rotate_log_event::exec_event(struct st_relay_log_info* rli)
mysql_bin_log.new_file();
rli->master_log_pos = 4;
}
DBUG_PRINT("info", ("master_log_pos: %d", (ulong) rli->master_log_pos));
pthread_cond_broadcast(&rli->data_cond);
pthread_mutex_unlock(&rli->data_lock);
flush_relay_log_info(rli);
......@@ -1826,13 +1835,12 @@ int Rotate_log_event::exec_event(struct st_relay_log_info* rli)
mysql_bin_log.write(&s);
}
}
return 0;
DBUG_RETURN(0);
}
int Intvar_log_event::exec_event(struct st_relay_log_info* rli)
{
switch (type)
{
switch (type) {
case LAST_INSERT_ID_EVENT:
thd->last_insert_id_used = 1;
thd->last_insert_id = val;
......
......@@ -38,10 +38,14 @@ typedef struct st_key_part {
Field *field;
} KEY_PART;
class QUICK_RANGE :public Sql_alloc {
public:
char *min_key,*max_key;
uint16 min_length,max_length,flag;
#ifdef HAVE_purify
uint16 dummy; /* Avoid warnings on 'flag' */
#endif
QUICK_RANGE(); /* Full range */
QUICK_RANGE(const char *min_key_arg,uint min_length_arg,
const char *max_key_arg,uint max_length_arg,
......@@ -51,7 +55,11 @@ class QUICK_RANGE :public Sql_alloc {
min_length((uint16) min_length_arg),
max_length((uint16) max_length_arg),
flag((uint16) flag_arg)
{}
{
#ifdef HAVE_purify
dummy=0;
#endif
}
};
......
......@@ -811,8 +811,9 @@ int load_master_data(THD* thd)
strmake(active_mi->master_log_name, row[0],
sizeof(active_mi->master_log_name));
active_mi->master_log_pos = strtoull(row[1], (char**) 0, 10);
if (active_mi->master_log_pos < 4)
active_mi->master_log_pos = 4; // don't hit the magic number
// don't hit the magic number
if (active_mi->master_log_pos < BIN_LOG_HEADER_SIZE)
active_mi->master_log_pos = BIN_LOG_HEADER_SIZE;
active_mi->rli.pending = 0;
flush_master_info(active_mi);
}
......
......@@ -119,6 +119,7 @@ void unlock_slave_threads(MASTER_INFO* mi)
int init_slave()
{
DBUG_ENTER("init_slave");
// TODO (multi-master): replace this with list initialization
active_mi = &main_mi;
......@@ -129,8 +130,10 @@ int init_slave()
*/
if (server_id && !master_host)
{
// TODO: re-write this to interate through the list of files
// for multi-master
/*
TODO: re-write this to interate through the list of files
for multi-master
*/
char fname[FN_REFLEN+128];
MY_STAT stat_area;
fn_format(fname, master_info_file, mysql_data_home, "", 4+16+32);
......@@ -141,21 +144,24 @@ int init_slave()
// slave thread
if (master_host)
{
if (!opt_skip_slave_start && start_slave_threads(1 /* need mutex */,
if (!opt_skip_slave_start)
{
if (start_slave_threads(1 /* need mutex */,
0 /* no wait for start*/,
active_mi,
master_info_file,
relay_log_info_file,
SLAVE_IO|SLAVE_SQL
))
SLAVE_IO | SLAVE_SQL))
sql_print_error("Warning: Can't create threads to handle slave");
else if (opt_skip_slave_start)
if (init_master_info(active_mi, master_info_file, relay_log_info_file))
}
else if (init_master_info(active_mi, master_info_file,
relay_log_info_file))
sql_print_error("Warning: failed to initialized master info");
}
return 0;
DBUG_RETURN(0);
}
static void free_table_ent(TABLE_RULE_ENT* e)
{
my_free((gptr) e, MYF(0));
......@@ -495,6 +501,7 @@ int start_slave_threads(bool need_slave_mutex, bool wait_for_start,
pthread_mutex_t *lock_io=0,*lock_sql=0,*lock_cond_io=0,*lock_cond_sql=0;
pthread_cond_t* cond_io=0,*cond_sql=0;
int error=0;
DBUG_ENTER("start_slave_threads");
if (need_slave_mutex)
{
......@@ -509,21 +516,20 @@ int start_slave_threads(bool need_slave_mutex, bool wait_for_start,
lock_cond_sql = &mi->rli.run_lock;
}
if (init_master_info(mi,master_info_fname,slave_info_fname))
return ER_MASTER_INFO;
DBUG_RETURN(ER_MASTER_INFO);
if ((thread_mask & SLAVE_IO) &&
(error=start_slave_thread(handle_slave_io,lock_io,lock_cond_io,
if (thread_mask & SLAVE_IO)
error=start_slave_thread(handle_slave_io,lock_io,lock_cond_io,
cond_io,&mi->slave_running,
mi)))
return error;
if ((thread_mask & SLAVE_SQL) &&
(error=start_slave_thread(handle_slave_sql,lock_sql,lock_cond_sql,
mi);
if (!error && (thread_mask & SLAVE_SQL))
error=start_slave_thread(handle_slave_sql,lock_sql,lock_cond_sql,
cond_sql,
&mi->rli.slave_running,mi)))
return error;
return 0;
&mi->rli.slave_running,mi);
DBUG_RETURN(error);
}
void init_table_rule_hash(HASH* h, bool* h_inited)
{
hash_init(h, TABLE_RULE_HASH_SIZE,0,0,
......@@ -1083,20 +1089,23 @@ int init_relay_log_info(RELAY_LOG_INFO* rli, const char* info_fname)
}
rli->info_fd = info_fd;
int relay_log_pos, master_log_pos;
if (init_strvar_from_file(rli->relay_log_name,
sizeof(rli->relay_log_name), &rli->info_file,
"") ||
init_intvar_from_file((int*)&rli->relay_log_pos,
init_intvar_from_file(&relay_log_pos,
&rli->info_file, BIN_LOG_HEADER_SIZE) ||
init_strvar_from_file(rli->master_log_name,
sizeof(rli->master_log_name), &rli->info_file,
"") ||
init_intvar_from_file((int*)&rli->master_log_pos,
&rli->info_file, 0))
init_intvar_from_file(&master_log_pos, &rli->info_file, 0))
{
msg="Error reading slave log configuration";
goto err;
}
rli->relay_log_pos= relay_log_pos;
rli->master_log_pos= master_log_pos;
if (init_relay_log_pos(rli,0 /* log already inited */,
0 /* pos already inited */,
0 /* no data lock*/,
......@@ -1252,25 +1261,36 @@ int init_master_info(MASTER_INFO* mi, const char* master_info_fname,
goto err;
mi->fd = fd;
int port, connect_retry, master_log_pos;
if (init_strvar_from_file(mi->master_log_name,
sizeof(mi->master_log_name), &mi->file,
"") ||
init_intvar_from_file((int*)&mi->master_log_pos, &mi->file, 4) ||
init_intvar_from_file(&master_log_pos, &mi->file, 4) ||
init_strvar_from_file(mi->host, sizeof(mi->host), &mi->file,
master_host) ||
init_strvar_from_file(mi->user, sizeof(mi->user), &mi->file,
master_user) ||
init_strvar_from_file(mi->password, HASH_PASSWORD_LENGTH+1, &mi->file,
master_password) ||
init_intvar_from_file((int*)&mi->port, &mi->file, master_port) ||
init_intvar_from_file((int*)&mi->connect_retry, &mi->file,
init_intvar_from_file(&port, &mi->file, master_port) ||
init_intvar_from_file(&connect_retry, &mi->file,
master_connect_retry))
{
sql_print_error("Error reading master configuration");
goto err;
}
/*
This has to be handled here as init_intvar_from_file can't handle
my_off_t types
*/
mi->master_log_pos= (my_off_t) master_log_pos;
mi->port= (uint) port;
mi->connect_retry= (uint) connect_retry;
}
DBUG_PRINT("master_info",("log_file_name: %s position: %ld",
mi->master_log_name,
(ulong) mi->master_log_pos));
mi->inited = 1;
// now change cache READ -> WRITE - must do this before flush_master_info
reinit_io_cache(&mi->file, WRITE_CACHE,0L,0,1);
......@@ -1399,6 +1419,8 @@ int flush_master_info(MASTER_INFO* mi)
{
IO_CACHE* file = &mi->file;
char lbuf[22];
DBUG_ENTER("flush_master_info");
DBUG_PRINT("enter",("master_pos: %ld", (long) mi->master_log_pos));
my_b_seek(file, 0L);
my_b_printf(file, "%s\n%s\n%s\n%s\n%s\n%d\n%d\n%d\n",
......@@ -1407,7 +1429,7 @@ int flush_master_info(MASTER_INFO* mi)
mi->password, mi->port, mi->connect_retry
);
flush_io_cache(file);
return 0;
DBUG_RETURN(0);
}
int st_relay_log_info::wait_for_pos(THD* thd, String* log_name,
......@@ -1496,13 +1518,9 @@ static int init_slave_thread(THD* thd, SLAVE_THD_TYPE thd_type)
thd->options |= OPTION_BIG_SELECTS;
if (thd_type == SLAVE_THD_SQL)
{
thd->proc_info = "Waiting for the next event in slave queue";
}
thd->proc_info= "Waiting for the next event in slave queue";
else
{
thd->proc_info="Waiting for master update";
}
thd->proc_info= "Waiting for master update";
thd->version=refresh_version;
thd->set_time();
DBUG_RETURN(0);
......@@ -1751,8 +1769,9 @@ slave_begin:
pthread_cond_broadcast(&mi->start_cond);
pthread_mutex_unlock(&mi->run_lock);
DBUG_PRINT("info",("master info: log_file_name='%s', position=%s",
mi->master_log_name, llstr(mi->master_log_pos,llbuff)));
DBUG_PRINT("master_info",("log_file_name: '%s' position: %s",
mi->master_log_name,
llstr(mi->master_log_pos,llbuff)));
if (!(mi->mysql = mysql = mc_mysql_init(NULL)))
{
......@@ -2013,10 +2032,12 @@ slave_begin:
}
DBUG_ASSERT(rli->relay_log_pos >= BIN_LOG_HEADER_SIZE);
DBUG_ASSERT(my_b_tell(rli->cur_log) == rli->relay_log_pos);
DBUG_PRINT("info",("master info: log_file_name: %s, position: %s",
rli->master_log_name, llstr(rli->master_log_pos,llbuff)));
DBUG_ASSERT(rli->sql_thd == thd);
DBUG_PRINT("master_info",("log_file_name: %s position: %s",
rli->master_log_name,
llstr(rli->master_log_pos,llbuff)));
sql_print_error("Slave SQL thread initialized, starting replication in \
log '%s' at position %s, relay log '%s' position: %s", RPL_LOG_NAME,
llstr(rli->master_log_pos,llbuff),rli->relay_log_name,
......@@ -2180,13 +2201,16 @@ err:
static int process_io_rotate(MASTER_INFO* mi, Rotate_log_event* rev)
{
DBUG_ENTER("process_io_rotate");
if (unlikely(!rev->is_valid()))
return 1;
DBUG_ASSERT(rev->ident_len<sizeof(mi->master_log_name));
DBUG_RETURN(1);
DBUG_ASSERT(rev->ident_len < sizeof(mi->master_log_name));
memcpy(mi->master_log_name,rev->new_log_ident,
rev->ident_len);
mi->master_log_name[rev->ident_len] = 0;
mi->master_log_pos = rev->pos;
DBUG_PRINT("info", ("master_log_pos: %d", (ulong) mi->master_log_pos));
#ifndef DBUG_OFF
/*
If we do not do this, we will be getting the first
......@@ -2195,7 +2219,7 @@ static int process_io_rotate(MASTER_INFO* mi, Rotate_log_event* rev)
if (disconnect_slave_event_count)
events_till_disconnect++;
#endif
return 0;
DBUG_RETURN(0);
}
/*
......@@ -2260,6 +2284,7 @@ static int queue_old_event(MASTER_INFO *mi, const char *buf,
int error = process_io_create_file(mi,(Create_file_log_event*)ev);
delete ev;
mi->master_log_pos += event_len;
DBUG_PRINT("info", ("master_log_pos: %d", (ulong) mi->master_log_pos));
pthread_mutex_unlock(&mi->data_lock);
DBUG_ASSERT(tmp_buf);
my_free((char*)tmp_buf, MYF(0));
......@@ -2283,6 +2308,7 @@ static int queue_old_event(MASTER_INFO *mi, const char *buf,
delete ev;
if (likely(inc_pos))
mi->master_log_pos += event_len;
DBUG_PRINT("info", ("master_log_pos: %d", (ulong) mi->master_log_pos));
if (unlikely(processed_stop_event))
mi->ignore_stop_event=1;
pthread_mutex_unlock(&mi->data_lock);
......@@ -2334,6 +2360,7 @@ int queue_event(MASTER_INFO* mi,const char* buf, ulong event_len)
{
if (likely(inc_pos))
mi->master_log_pos += event_len;
DBUG_PRINT("info", ("master_log_pos: %d", (ulong) mi->master_log_pos));
mi->rli.relay_log.harvest_bytes_written(&mi->rli.log_space_total);
}
if (unlikely(processed_stop_event))
......
......@@ -323,7 +323,7 @@ void mysql_binlog_send(THD* thd, char* log_ident, ulong pos, ushort flags)
if (pos < 4)
{
errmsg = "Client requested master to start repliction from \
errmsg= "Client requested master to start replication from \
impossible position";
goto err;
}
......@@ -691,6 +691,7 @@ int change_master(THD* thd, MASTER_INFO* mi)
int error=0,restart_thread_mask;
const char* errmsg=0;
bool need_relay_log_purge=1;
DBUG_ENTER("change_master");
// kill slave thread
lock_slave_threads(mi);
......@@ -702,7 +703,7 @@ int change_master(THD* thd, MASTER_INFO* mi)
{
send_error(&thd->net,error);
unlock_slave_threads(mi);
return 1;
DBUG_RETURN(1);
}
thd->proc_info = "changing master";
LEX_MASTER_INFO* lex_mi = &thd->lex.mi;
......@@ -711,7 +712,7 @@ int change_master(THD* thd, MASTER_INFO* mi)
{
send_error(&thd->net, 0, "Could not initialize master info");
unlock_slave_threads(mi);
return 1;
DBUG_RETURN(1);
}
/* data lock not needed since we have already stopped the running threads,
......@@ -722,7 +723,7 @@ int change_master(THD* thd, MASTER_INFO* mi)
{
// if we change host or port, we must reset the postion
mi->master_log_name[0] = 0;
mi->master_log_pos = 4; // skip magic number
mi->master_log_pos= BIN_LOG_HEADER_SIZE;
mi->rli.pending = 0;
}
......@@ -731,9 +732,10 @@ int change_master(THD* thd, MASTER_INFO* mi)
sizeof(mi->master_log_name));
if (lex_mi->pos)
{
mi->master_log_pos = lex_mi->pos;
mi->master_log_pos= lex_mi->pos;
mi->rli.pending = 0;
}
DBUG_PRINT("info", ("master_log_pos: %d", (ulong) mi->master_log_pos));
if (lex_mi->host)
strmake(mi->host, lex_mi->host, sizeof(mi->host));
......@@ -769,7 +771,7 @@ int change_master(THD* thd, MASTER_INFO* mi)
&errmsg))
{
net_printf(&thd->net, 0, "Failed purging old relay logs: %s",errmsg);
return 1;
DBUG_RETURN(1);
}
}
else
......@@ -783,11 +785,11 @@ int change_master(THD* thd, MASTER_INFO* mi)
//Sasha: note that I had to change net_printf() to make this work
net_printf(&thd->net,0,"Failed initializing relay log position: %s",msg);
unlock_slave_threads(mi);
return 1;
DBUG_RETURN(1);
}
}
mi->rli.master_log_pos = mi->master_log_pos;
DBUG_PRINT("info", ("master_log_pos: %d", (ulong) mi->master_log_pos));
strnmov(mi->rli.master_log_name,mi->master_log_name,
sizeof(mi->rli.master_log_name));
if (!mi->rli.master_log_name[0]) // uninitialized case
......@@ -810,7 +812,7 @@ int change_master(THD* thd, MASTER_INFO* mi)
send_error(&thd->net,error);
else
send_ok(&thd->net);
return 0;
DBUG_RETURN(0);
}
int reset_master(THD* thd)
......
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