reversed virtual master

parent af27c38f
reset master;
drop table if exists t1;
create table t1(n int);
insert into t1 values (1),(2),(3),(4);
flush logs;
update t1 set n = n + 10;
save_master_pos;
flush tables with read lock;
system rm -rf var/tmp/backup;
system mkdir -p var/tmp/backup;
system cp var/master-data/master-bin.* var/tmp/backup;
unlock tables;
drop table t1;
eval change master to master_host='$MYSQL_TEST_DIR/var/tmp/backup/master-bin';
slave start;
sync_with_master;
select * from t1;
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include <myisam.h> #include <myisam.h>
#include "mini_client.h" #include "mini_client.h"
#include "slave.h" #include "slave.h"
#include "sql_repl.h"
#include <thr_alarm.h> #include <thr_alarm.h>
#include <my_dir.h> #include <my_dir.h>
...@@ -442,101 +441,6 @@ int fetch_nx_table(THD* thd, MASTER_INFO* mi) ...@@ -442,101 +441,6 @@ int fetch_nx_table(THD* thd, MASTER_INFO* mi)
return error; return error;
} }
void MASTER_INFO::close_virtual_master()
{
vm_binlog.close_index();
end_io_cache(&vm_cache);
if(vm_fd >= 0)
{
my_close(vm_fd, MYF(0));
vm_fd = -1;
}
}
int MASTER_INFO::setup_virtual_master()
{
vm_binlog.init(LOG_BIN);
vm_binlog.set_index_file_name(host);
if(vm_binlog.open_index(O_RDONLY))
{
sql_print_error("virtual master: could not open index file '%s': \
(%d)", host, my_errno);
return 1;
}
if(vm_binlog.find_first_log(&vm_linfo,log_file_name))
{
sql_print_error("virtual master: could not find first log");
return 1;
}
if(open_log())
return 1;
return 0;
}
int MASTER_INFO::open_log()
{
const char* errmsg = "Unknown error";
if(vm_fd >= 0)
{
end_io_cache(&vm_cache);
my_close(vm_fd, MYF(0));
}
// if backup-up logs have relative paths, assume they are relative to
// the directory that has the log index, not cwd
char logname_buf[FN_REFLEN+1], *logname;
if(vm_linfo.log_file_name[0] == FN_LIBCHAR)
logname = vm_linfo.log_file_name;
else
{
char* end = strnmov(logname_buf, host,
sizeof(logname_buf));
for(; *end != FN_LIBCHAR; --end); // we will always find it, first
// char of host is always FN_LIBCHAR for virtual master
strncpy(end + 1, vm_linfo.log_file_name,
sizeof(logname_buf) - (end - logname_buf));
logname = logname_buf;
}
if((vm_fd = open_binlog(&vm_cache, logname, &errmsg)) < 0)
{
sql_print_error("virtual master: error opening binlog '%s': %s",
vm_linfo.log_file_name, errmsg);
return 1;
}
strncpy(log_file_name, vm_linfo.log_file_name, sizeof(log_file_name));
return 0;
}
uint MASTER_INFO::read_event()
{
for(;!(vm_ev = Log_event::read_log_event(&vm_cache, 0));)
{
if(!vm_cache.error) // eof - try next log
{
switch(vm_binlog.find_next_log(&vm_linfo))
{
case LOG_INFO_EOF:
return 0;
case 0:
if(open_log())
return packet_error;
continue;
default:
sql_print_error("virtual master: could not read next log");
return packet_error;
}
}
}
return vm_ev->get_data_size() + LOG_EVENT_HEADER_LEN;
}
void end_master_info(MASTER_INFO* mi) void end_master_info(MASTER_INFO* mi)
{ {
if(mi->fd >= 0) if(mi->fd >= 0)
...@@ -546,8 +450,6 @@ void end_master_info(MASTER_INFO* mi) ...@@ -546,8 +450,6 @@ void end_master_info(MASTER_INFO* mi)
mi->fd = -1; mi->fd = -1;
} }
mi->inited = 0; mi->inited = 0;
if(mi->virtual_master)
mi->close_virtual_master();
} }
int init_master_info(MASTER_INFO* mi) int init_master_info(MASTER_INFO* mi)
...@@ -643,7 +545,6 @@ int init_master_info(MASTER_INFO* mi) ...@@ -643,7 +545,6 @@ int init_master_info(MASTER_INFO* mi)
} }
mi->inited = 1; mi->inited = 1;
mi->virtual_master = (mi->host[0] == FN_LIBCHAR);
// now change the cache from READ to WRITE - must do this // now change the cache from READ to WRITE - must do this
// before flush_master_info // before flush_master_info
reinit_io_cache(&mi->file, WRITE_CACHE, 0L,0,1); reinit_io_cache(&mi->file, WRITE_CACHE, 0L,0,1);
...@@ -841,9 +742,6 @@ static int safe_sleep(THD* thd, int sec) ...@@ -841,9 +742,6 @@ static int safe_sleep(THD* thd, int sec)
static int request_dump(MYSQL* mysql, MASTER_INFO* mi) static int request_dump(MYSQL* mysql, MASTER_INFO* mi)
{ {
if(mi->virtual_master)
return 0;
char buf[FN_REFLEN + 10]; char buf[FN_REFLEN + 10];
int len; int len;
int binlog_flags = 0; // for now int binlog_flags = 0; // for now
...@@ -897,9 +795,6 @@ command"); ...@@ -897,9 +795,6 @@ command");
static uint read_event(MYSQL* mysql, MASTER_INFO *mi) static uint read_event(MYSQL* mysql, MASTER_INFO *mi)
{ {
if(mi->virtual_master)
return mi->read_event();
uint len = packet_error; uint len = packet_error;
// for convinience lets think we start by // for convinience lets think we start by
// being in the interrupted state :-) // being in the interrupted state :-)
...@@ -965,18 +860,16 @@ point. If you are sure that your master is ok, run this query manually on the\ ...@@ -965,18 +860,16 @@ point. If you are sure that your master is ok, run this query manually on the\
static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len) static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len)
{ {
Log_event * ev = (mi->virtual_master) ? mi->vm_ev : Log_event * ev = Log_event::read_log_event((const char*)net->read_pos + 1,
Log_event::read_log_event((const char*)net->read_pos + 1, event_len);
event_len) ;
char llbuff[22]; char llbuff[22];
if (ev) if (ev)
{ {
int type_code = ev->get_type_code(); int type_code = ev->get_type_code();
if ((!mi->virtual_master && ev->server_id == ::server_id) if (ev->server_id == ::server_id || slave_skip_counter)
|| slave_skip_counter)
{ {
if(type_code == LOAD_EVENT && !mi->virtual_master) if(type_code == LOAD_EVENT)
skip_load_data_infile(net); skip_load_data_infile(net);
mi->inc_pos(event_len); mi->inc_pos(event_len);
...@@ -1078,14 +971,6 @@ static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len) ...@@ -1078,14 +971,6 @@ static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len)
case LOAD_EVENT: case LOAD_EVENT:
{ {
if(mi->virtual_master)
{
delete ev;
sql_print_error("LOAD DATA INFILE does not yet work with virtual \
master. Perform in manually, then restart slave with SET SQL_SKIP_COUNTER=1;\
SLAVE START");
return 1;
}
Load_log_event* lev = (Load_log_event*)ev; Load_log_event* lev = (Load_log_event*)ev;
init_sql_alloc(&thd->mem_root, 8192,0); init_sql_alloc(&thd->mem_root, 8192,0);
thd->db = rewrite_db((char*)lev->db); thd->db = rewrite_db((char*)lev->db);
...@@ -1108,8 +993,7 @@ SLAVE START"); ...@@ -1108,8 +993,7 @@ SLAVE START");
// the table will be opened in mysql_load // the table will be opened in mysql_load
if(table_rules_on && !tables_ok(thd, &tables)) if(table_rules_on && !tables_ok(thd, &tables))
{ {
if(!mi->virtual_master) skip_load_data_infile(net);
skip_load_data_infile(net);
} }
else else
{ {
...@@ -1173,8 +1057,7 @@ SLAVE START"); ...@@ -1173,8 +1057,7 @@ SLAVE START");
{ {
// we will just ask the master to send us /dev/null if we do not // we will just ask the master to send us /dev/null if we do not
// want to load the data :-) // want to load the data :-)
if(!mi->virtual_master) skip_load_data_infile(net);
skip_load_data_infile(net);
} }
thd->net.vio = 0; thd->net.vio = 0;
...@@ -1410,21 +1293,9 @@ try again, log '%s' at postion %s", RPL_LOG_NAME, ...@@ -1410,21 +1293,9 @@ try again, log '%s' at postion %s", RPL_LOG_NAME,
sql_print_error("Slave thread killed while reading event"); sql_print_error("Slave thread killed while reading event");
goto err; goto err;
} }
if(!event_len && glob_mi.virtual_master)
{
sql_print_error("Virtual master replication finished");
goto err;
}
if (event_len == packet_error) if (event_len == packet_error)
{ {
if(glob_mi.virtual_master)
{
sql_print_error("Virtual master replication encountered \
error while reading event, replication terminated");
goto err;
}
thd->proc_info = "Waiting to reconnect after a failed read"; thd->proc_info = "Waiting to reconnect after a failed read";
if(mysql->net.vio) if(mysql->net.vio)
vio_close(mysql->net.vio); vio_close(mysql->net.vio);
...@@ -1532,8 +1403,6 @@ position %s", ...@@ -1532,8 +1403,6 @@ position %s",
static int safe_connect(THD* thd, MYSQL* mysql, MASTER_INFO* mi) static int safe_connect(THD* thd, MYSQL* mysql, MASTER_INFO* mi)
{ {
if(mi->virtual_master)
return mi->setup_virtual_master();
int slave_was_killed; int slave_was_killed;
#ifndef DBUG_OFF #ifndef DBUG_OFF
events_till_disconnect = disconnect_slave_event_count; events_till_disconnect = disconnect_slave_event_count;
...@@ -1563,9 +1432,6 @@ static int safe_connect(THD* thd, MYSQL* mysql, MASTER_INFO* mi) ...@@ -1563,9 +1432,6 @@ static int safe_connect(THD* thd, MYSQL* mysql, MASTER_INFO* mi)
static int safe_reconnect(THD* thd, MYSQL* mysql, MASTER_INFO* mi) static int safe_reconnect(THD* thd, MYSQL* mysql, MASTER_INFO* mi)
{ {
if(mi->virtual_master)
return mi->setup_virtual_master();
int slave_was_killed; int slave_was_killed;
char llbuff[22]; char llbuff[22];
......
...@@ -16,14 +16,8 @@ typedef struct st_master_info ...@@ -16,14 +16,8 @@ typedef struct st_master_info
pthread_mutex_t lock; pthread_mutex_t lock;
pthread_cond_t cond; pthread_cond_t cond;
bool inited; bool inited;
bool virtual_master; // for replay of binlogs from a directory
MYSQL_LOG vm_binlog;
LOG_INFO vm_linfo;
IO_CACHE vm_cache;
int vm_fd;
Log_event* vm_ev;
st_master_info():pending(0),fd(-1),inited(0),virtual_master(0),vm_fd(-1) st_master_info():pending(0),fd(-1),inited(0)
{ {
host[0] = 0; user[0] = 0; password[0] = 0; host[0] = 0; user[0] = 0; password[0] = 0;
pthread_mutex_init(&lock, MY_MUTEX_INIT_FAST); pthread_mutex_init(&lock, MY_MUTEX_INIT_FAST);
...@@ -34,8 +28,6 @@ typedef struct st_master_info ...@@ -34,8 +28,6 @@ typedef struct st_master_info
{ {
pthread_mutex_destroy(&lock); pthread_mutex_destroy(&lock);
pthread_cond_destroy(&cond); pthread_cond_destroy(&cond);
if(virtual_master)
close_virtual_master();
} }
inline void inc_pending(ulonglong val) inline void inc_pending(ulonglong val)
{ {
...@@ -59,11 +51,6 @@ typedef struct st_master_info ...@@ -59,11 +51,6 @@ typedef struct st_master_info
} }
int wait_for_pos(THD* thd, String* log_name, ulonglong log_pos); int wait_for_pos(THD* thd, String* log_name, ulonglong log_pos);
int setup_virtual_master();
void close_virtual_master();
uint read_event();
int open_log();
} MASTER_INFO; } MASTER_INFO;
typedef struct st_table_rule_ent typedef struct st_table_rule_ent
......
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