summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <sasha@mysql.sashanet.com>2002-01-26 22:26:24 -0700
committerunknown <sasha@mysql.sashanet.com>2002-01-26 22:26:24 -0700
commit83666b3e54fb1ae572f1125bfc171b42c9692436 (patch)
tree7805cfd6c7eb661c4f3022b7fc37478a0908a190 /sql
parent845db7c20ba28e014c5a36a6c95afd8ed111f316 (diff)
downloadmariadb-git-83666b3e54fb1ae572f1125bfc171b42c9692436.tar.gz
misc replication bugfixes including some needed modifications in IO_CACHE
likely() and unlikely() branch prediction compiler hint macros clean-up of comments include/my_global.h: added likely() and unlikely() macros to help some compilers optimize the code for architecture-specific branch prediction policies include/my_sys.h: coverted my_b_append_tell() from macro to a function as it needed to be more complex to avoid a potential race condition mysql-test/mysql-test-run.sh: hostname-independent relay log name to have consistent SHOW SLAVE STATUS output mysql-test/r/rpl000014.result: result update mysql-test/r/rpl000015.result: result update mysql-test/r/rpl000016.result: result update mysql-test/r/rpl_log.result: result update mysql-test/t/rpl000017-slave.sh: proper cleanup of old logs mysys/mf_iocache.c: cosmetic changes + more debugging asserts mysys/mf_iocache2.c: my_b_append_tell() cleanup of comments sql/log.cc: fix potential bug - do not rotate log in the middle of event sql/slave.cc: do not write stop events when the server does not actually stop but just rotates the log fixed race between queue_event() and show_slave_status() clean-up of comments sql/slave.h: added ignore_stop_event flag to SLAVE_LOG_INFO
Diffstat (limited to 'sql')
-rw-r--r--sql/log.cc9
-rw-r--r--sql/slave.cc63
-rw-r--r--sql/slave.h3
3 files changed, 56 insertions, 19 deletions
diff --git a/sql/log.cc b/sql/log.cc
index d3ad4564a73..17b6ef4344c 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -742,12 +742,13 @@ bool MYSQL_LOG::appendv(const char* buf, uint len,...)
error = 1;
break;
}
- if ((uint)my_b_append_tell(&log_file) > max_binlog_size)
- {
- new_file(1);
- }
} while ((buf=va_arg(args,const char*)) && (len=va_arg(args,uint)));
+ if ((uint)my_b_append_tell(&log_file) > max_binlog_size)
+ {
+ new_file(1);
+ }
+
if (!error)
signal_update();
pthread_mutex_unlock(&LOCK_log);
diff --git a/sql/slave.cc b/sql/slave.cc
index 97efbf6036c..59e07040528 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -1057,6 +1057,7 @@ int init_master_info(MASTER_INFO* mi, const char* master_info_fname,
if (init_relay_log_info(&mi->rli, slave_info_fname))
return 1;
mi->rli.mi = mi;
+ mi->ignore_stop_event=0;
int fd,length,error;
MY_STAT stat_area;
char fname[FN_REFLEN+128];
@@ -1275,10 +1276,6 @@ int flush_master_info(MASTER_INFO* mi)
return 0;
}
-/* TODO: the code below needs to be re-written almost from scratch
- Main issue is how to find out if we have reached a certain position
- in the master log my knowing the offset in the relay log.
- */
int st_relay_log_info::wait_for_pos(THD* thd, String* log_name,
ulonglong log_pos)
{
@@ -1921,6 +1918,7 @@ the slave SQL thread with \"mysqladmin start-slave\". We stopped at log \
DBUG_RETURN(0); // Can't return anything here
}
+// We assume we already locked mi->data_lock
static int process_io_rotate(MASTER_INFO* mi, Rotate_log_event* rev)
{
if (!rev->is_valid())
@@ -1941,77 +1939,112 @@ static int process_io_rotate(MASTER_INFO* mi, Rotate_log_event* rev)
return 0;
}
+// TODO: verify the issue with stop events, see if we need them at all
+// in the relay log
+// TODO: test this code before release - it has to be tested on a separte
+// setup with 3.23 master
static int queue_old_event(MASTER_INFO* mi, const char* buf,
uint event_len)
{
const char* errmsg = 0;
bool inc_pos = 1;
+ bool processed_stop_event = 0;
Log_event* ev = Log_event::read_log_event(buf,event_len, &errmsg,
1/*old format*/);
- if (!ev)
+ if (unlikely(!ev))
{
sql_print_error("Read invalid event from master: '%s',\
master could be corrupt but a more likely cause of this is a bug",
errmsg);
return 1;
}
+ pthread_mutex_lock(&mi->data_lock);
ev->log_pos = mi->master_log_pos;
switch (ev->get_type_code())
{
case ROTATE_EVENT:
- if (process_io_rotate(mi,(Rotate_log_event*)ev))
+ if (unlikely(process_io_rotate(mi,(Rotate_log_event*)ev)))
{
delete ev;
+ pthread_mutex_unlock(&mi->data_lock);
return 1;
}
+ mi->ignore_stop_event=1;
inc_pos = 0;
break;
+ case STOP_EVENT:
+ processed_stop_event=1;
+ break;
case LOAD_EVENT:
// TODO: actually process it
mi->master_log_pos += event_len;
+ delete ev;
+ pthread_mutex_unlock(&mi->data_lock);
return 0;
- break;
default:
+ mi->ignore_stop_event=0;
break;
}
- if (mi->rli.relay_log.append(ev))
+ if (likely(!processed_stop_event || !mi->ignore_stop_event))
{
- delete ev;
- return 1;
+ if (unlikely(mi->rli.relay_log.append(ev)))
+ {
+ delete ev;
+ pthread_mutex_unlock(&mi->data_lock);
+ return 1;
+ }
}
delete ev;
- if (inc_pos)
+ if (likely(inc_pos))
mi->master_log_pos += event_len;
+ if (unlikely(processed_stop_event))
+ mi->ignore_stop_event=1;
+ pthread_mutex_lock(&mi->data_lock);
return 0;
}
+// TODO: verify the issue with stop events, see if we need them at all
+// in the relay log
int queue_event(MASTER_INFO* mi,const char* buf,uint event_len)
{
- int error;
+ int error=0;
bool inc_pos = 1;
+ bool processed_stop_event = 0;
if (mi->old_format)
return queue_old_event(mi,buf,event_len);
+
+ pthread_mutex_lock(&mi->data_lock);
+
// TODO: figure out if other events in addition to Rotate
// require special processing
switch (buf[EVENT_TYPE_OFFSET])
{
+ case STOP_EVENT:
+ processed_stop_event=1;
+ break;
case ROTATE_EVENT:
{
Rotate_log_event rev(buf,event_len,0);
- if (process_io_rotate(mi,&rev))
+ if (unlikely(process_io_rotate(mi,&rev)))
return 1;
inc_pos=0;
+ mi->ignore_stop_event=1;
break;
}
default:
+ mi->ignore_stop_event=0;
break;
}
- if (!(error = mi->rli.relay_log.appendv(buf,event_len,0)))
+ if (likely((!processed_stop_event || !mi->ignore_stop_event) &&
+ !(error = mi->rli.relay_log.appendv(buf,event_len,0))))
{
- if (inc_pos)
+ if (likely(inc_pos))
mi->master_log_pos += event_len;
}
+ if (unlikely(processed_stop_event))
+ mi->ignore_stop_event=1;
+ pthread_mutex_unlock(&mi->data_lock);
return error;
}
diff --git a/sql/slave.h b/sql/slave.h
index f1dd0130500..9632b108ab5 100644
--- a/sql/slave.h
+++ b/sql/slave.h
@@ -240,6 +240,9 @@ typedef struct st_master_info
int events_till_abort;
#endif
volatile bool abort_slave, slave_running;
+
+ bool ignore_stop_event;
+
THD* io_thd;
st_master_info():fd(-1),inited(0),