Commit 16aefaaa authored by unknown's avatar unknown

show master forced rotate info in SHOW BINLOG EVENTS

mark a master-forced rotate with a special flag


mysql-test/r/rpl000014.result:
  updated result
mysql-test/r/rpl000015.result:
  updated result
mysql-test/r/rpl000016.result:
  updated result
mysql-test/r/rpl_log.result:
  updated result
mysql-test/t/rpl000017-slave.sh:
  fix for change in master.info format
mysql-test/t/rpl_log.test:
  test for correct last_log_seq in show slave status
sql/log.cc:
  mark a master-forced rotate with a special flag
sql/log_event.cc:
  show master forced rotate info in SHOW BINLOG EVENTS
sql/log_event.h:
  master forced rotation flag
sql/slave.cc:
  keep trace of last log sequences in MASTER_INFO
  do not rotate on slave, if the rotation on master was forced by its master
sql/slave.h:
  keep track of last log sequence number in MASTER_INFO
parent e37a9723
File Position Binlog_do_db Binlog_ignore_db File Position Binlog_do_db Binlog_ignore_db
master-bin.001 79 master-bin.001 79
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Last_log_seq
127.0.0.1 root 9999 1 master-bin.001 79 Yes 0 0 127.0.0.1 root 9999 1 master-bin.001 79 Yes 0 0 1
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Last_log_seq
127.0.0.1 root 9999 1 master-bin.001 73 No 0 0 127.0.0.1 root 9999 1 master-bin.001 73 No 0 0 1
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Last_log_seq
127.0.0.1 root 9999 1 master-bin.001 73 Yes 0 0 127.0.0.1 root 9999 1 master-bin.001 73 Yes 0 0 1
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Last_log_seq
127.0.0.1 root 9999 1 master-bin.001 173 Yes 0 0 127.0.0.1 root 9999 1 master-bin.001 173 Yes 0 0 1
File Position Binlog_do_db Binlog_ignore_db File Position Binlog_do_db Binlog_ignore_db
master-bin.001 79 master-bin.001 79
n n
......
File Position Binlog_do_db Binlog_ignore_db File Position Binlog_do_db Binlog_ignore_db
master-bin.001 79 master-bin.001 79
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Last_log_seq
0 0 0 No 0 0 0 0 0 No 0 0 0
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Last_log_seq
127.0.0.1 test 9998 60 4 No 0 0 127.0.0.1 test 9998 60 4 No 0 0 0
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Last_log_seq
127.0.0.1 root 9999 60 4 No 0 0 127.0.0.1 root 9999 60 4 No 0 0 0
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Last_log_seq
127.0.0.1 root 9999 60 master-bin.001 79 Yes 0 0 127.0.0.1 root 9999 60 master-bin.001 79 Yes 0 0 1
n n
10 10
45 45
......
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Last_log_seq
127.0.0.1 root 9999 60 master-bin.001 234 Yes 0 0 127.0.0.1 root 9999 60 master-bin.001 234 Yes 0 0 3
s s
Could not break slave Could not break slave
Tried hard Tried hard
...@@ -9,8 +9,8 @@ master-bin.002 ...@@ -9,8 +9,8 @@ master-bin.002
master-bin.003 master-bin.003
Log_name Log_name
master-bin.003 master-bin.003
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Last_log_seq
127.0.0.1 root 9999 60 master-bin.003 202 Yes 0 0 127.0.0.1 root 9999 60 master-bin.003 202 Yes 0 0 3
m m
34 34
65 65
...@@ -24,7 +24,7 @@ master-bin.005 ...@@ -24,7 +24,7 @@ master-bin.005
master-bin.006 master-bin.006
File Position Binlog_do_db Binlog_ignore_db File Position Binlog_do_db Binlog_ignore_db
master-bin.006 720 master-bin.006 720
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Last_log_seq
127.0.0.1 root 9999 60 master-bin.006 720 Yes 0 0 127.0.0.1 root 9999 60 master-bin.006 720 Yes 0 0 11
count(*) count(*)
100 100
...@@ -27,6 +27,9 @@ master-bin.001 516 Rotate 1 9 master-bin.002 ...@@ -27,6 +27,9 @@ master-bin.001 516 Rotate 1 9 master-bin.002
master-bin.001 549 Stop 1 10 master-bin.001 549 Stop 1 10
Log_name Pos Event_type Server_id Log_seq Info Log_name Pos Event_type Server_id Log_seq Info
master-bin.002 4 Start 1 1 Server ver: 4.0.0-debug-log, Binlog ver: 2 master-bin.002 4 Start 1 1 Server ver: 4.0.0-debug-log, Binlog ver: 2
master-bin.002 79 Query 1 2 use test; create table t1 (n int)
master-bin.002 137 Query 1 3 use test; insert into t1 values (1)
master-bin.002 197 Query 1 4 use test; drop table t1
Log_name Log_name
master-bin.001 master-bin.001
master-bin.002 master-bin.002
...@@ -42,8 +45,13 @@ slave-bin.001 253 Query 1 4 use test; insert into t1 values (NULL) ...@@ -42,8 +45,13 @@ slave-bin.001 253 Query 1 4 use test; insert into t1 values (NULL)
slave-bin.001 316 Query 1 5 use test; drop table t1 slave-bin.001 316 Query 1 5 use test; drop table t1
slave-bin.001 364 Query 1 6 use test; create table t1 (word char(20) not null) slave-bin.001 364 Query 1 6 use test; create table t1 (word char(20) not null)
slave-bin.001 439 Query 1 8 use test; drop table t1 slave-bin.001 439 Query 1 8 use test; drop table t1
slave-bin.001 487 Rotate 2 3 slave-bin.002 slave-bin.001 487 Rotate 2 3 slave-bin.002; forced by master
slave-bin.001 519 Stop 2 4 slave-bin.001 519 Stop 2 4
Log_name Pos Event_type Server_id Log_seq Info Log_name Pos Event_type Server_id Log_seq Info
slave-bin.002 4 Start 2 1 Server ver: 4.0.0-debug-log, Binlog ver: 2 slave-bin.002 4 Start 2 1 Server ver: 4.0.0-debug-log, Binlog ver: 2
slave-bin.002 79 Slave 2 2 host=127.0.0.1,port=9306,log=master-bin.002,pos=4 slave-bin.002 79 Slave 2 2 host=127.0.0.1,port=9306,log=master-bin.002,pos=4
slave-bin.002 132 Query 1 2 use test; create table t1 (n int)
slave-bin.002 190 Query 1 3 use test; insert into t1 values (1)
slave-bin.002 250 Query 1 4 use test; drop table t1
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Last_log_seq
127.0.0.1 root 9999 1 master-bin.002 245 Yes 0 0 4
...@@ -6,4 +6,5 @@ replicate ...@@ -6,4 +6,5 @@ replicate
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
9306 9306
1 1
0
EOF EOF
...@@ -20,6 +20,9 @@ show binlog events from 79 limit 1; ...@@ -20,6 +20,9 @@ show binlog events from 79 limit 1;
show binlog events from 79 limit 2; show binlog events from 79 limit 2;
show binlog events from 79 limit 2,1; show binlog events from 79 limit 2,1;
flush logs; flush logs;
create table t1 (n int);
insert into t1 values (1);
drop table t1;
show binlog events; show binlog events;
show binlog events in 'master-bin.002'; show binlog events in 'master-bin.002';
show master logs; show master logs;
...@@ -30,3 +33,5 @@ sync_with_master; ...@@ -30,3 +33,5 @@ sync_with_master;
show master logs; show master logs;
show binlog events in 'slave-bin.001' from 4; show binlog events in 'slave-bin.001' from 4;
show binlog events in 'slave-bin.002' from 4; show binlog events in 'slave-bin.002' from 4;
--replace_result 9306 9999 3334 9999 3335 9999
show slave status;
...@@ -534,7 +534,14 @@ void MYSQL_LOG::new_file() ...@@ -534,7 +534,14 @@ void MYSQL_LOG::new_file()
to change base names at some point. to change base names at some point.
*/ */
Rotate_log_event r(new_name+dirname_length(new_name)); Rotate_log_event r(new_name+dirname_length(new_name));
THD* thd = current_thd;
r.set_log_seq(0, this); r.set_log_seq(0, this);
// this log rotation could have been initiated by a master of
// the slave running with log-bin
// we set the flag on rotate event to prevent inifinite log rotation
// loop
if(thd && slave_thd && thd == slave_thd)
r.flags |= LOG_EVENT_FORCED_ROTATE_F;
r.write(&log_file); r.write(&log_file);
VOID(pthread_cond_broadcast(&COND_binlog_update)); VOID(pthread_cond_broadcast(&COND_binlog_update));
} }
......
...@@ -189,7 +189,11 @@ void Load_log_event::pack_info(String* packet) ...@@ -189,7 +189,11 @@ void Load_log_event::pack_info(String* packet)
void Rotate_log_event::pack_info(String* packet) void Rotate_log_event::pack_info(String* packet)
{ {
net_store_data(packet, new_log_ident, ident_len); String tmp;
tmp.append(new_log_ident, ident_len);
if(flags & LOG_EVENT_FORCED_ROTATE_F)
tmp.append("; forced by master");
net_store_data(packet, tmp.ptr(), tmp.length());
} }
void Intvar_log_event::pack_info(String* packet) void Intvar_log_event::pack_info(String* packet)
......
...@@ -107,6 +107,7 @@ ...@@ -107,6 +107,7 @@
#define BINLOG_MAGIC "\xfe\x62\x69\x6e" #define BINLOG_MAGIC "\xfe\x62\x69\x6e"
#define LOG_EVENT_TIME_F 0x1 #define LOG_EVENT_TIME_F 0x1
#define LOG_EVENT_FORCED_ROTATE_F 0x2
enum Log_event_type { START_EVENT = 1, QUERY_EVENT =2, enum Log_event_type { START_EVENT = 1, QUERY_EVENT =2,
STOP_EVENT=3, ROTATE_EVENT = 4, INTVAR_EVENT=5, STOP_EVENT=3, ROTATE_EVENT = 4, INTVAR_EVENT=5,
......
...@@ -545,7 +545,9 @@ int init_master_info(MASTER_INFO* mi) ...@@ -545,7 +545,9 @@ int init_master_info(MASTER_INFO* mi)
master_password) || master_password) ||
init_intvar_from_file((int*)&mi->port, &mi->file, master_port) || 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((int*)&mi->connect_retry, &mi->file,
master_connect_retry)) master_connect_retry) ||
init_intvar_from_file((int*)&mi->last_log_seq, &mi->file, 0)
)
{ {
msg="Error reading master configuration"; msg="Error reading master configuration";
goto error; goto error;
...@@ -625,10 +627,12 @@ int show_master_info(THD* thd) ...@@ -625,10 +627,12 @@ int show_master_info(THD* thd)
field_list.push_back(new Item_empty_string("Last_errno", 4)); field_list.push_back(new Item_empty_string("Last_errno", 4));
field_list.push_back(new Item_empty_string("Last_error", 20)); field_list.push_back(new Item_empty_string("Last_error", 20));
field_list.push_back(new Item_empty_string("Skip_counter", 12)); field_list.push_back(new Item_empty_string("Skip_counter", 12));
field_list.push_back(new Item_empty_string("Last_log_seq", 12));
if(send_fields(thd, field_list, 1)) if(send_fields(thd, field_list, 1))
DBUG_RETURN(-1); DBUG_RETURN(-1);
String* packet = &thd->packet; String* packet = &thd->packet;
uint32 last_log_seq;
packet->length(0); packet->length(0);
pthread_mutex_lock(&glob_mi.lock); pthread_mutex_lock(&glob_mi.lock);
...@@ -637,7 +641,8 @@ int show_master_info(THD* thd) ...@@ -637,7 +641,8 @@ int show_master_info(THD* thd)
net_store_data(packet, (uint32) glob_mi.port); net_store_data(packet, (uint32) glob_mi.port);
net_store_data(packet, (uint32) glob_mi.connect_retry); net_store_data(packet, (uint32) glob_mi.connect_retry);
net_store_data(packet, glob_mi.log_file_name); net_store_data(packet, glob_mi.log_file_name);
net_store_data(packet, (uint32) glob_mi.pos); // QQ: Should be fixed net_store_data(packet, (longlong) glob_mi.pos);
last_log_seq = glob_mi.last_log_seq;
pthread_mutex_unlock(&glob_mi.lock); pthread_mutex_unlock(&glob_mi.lock);
pthread_mutex_lock(&LOCK_slave); pthread_mutex_lock(&LOCK_slave);
net_store_data(packet, slave_running ? "Yes":"No"); net_store_data(packet, slave_running ? "Yes":"No");
...@@ -647,6 +652,7 @@ int show_master_info(THD* thd) ...@@ -647,6 +652,7 @@ int show_master_info(THD* thd)
net_store_data(packet, (uint32)last_slave_errno); net_store_data(packet, (uint32)last_slave_errno);
net_store_data(packet, last_slave_error); net_store_data(packet, last_slave_error);
net_store_data(packet, slave_skip_counter); net_store_data(packet, slave_skip_counter);
net_store_data(packet, last_log_seq);
if (my_net_write(&thd->net, (char*)thd->packet.ptr(), packet->length())) if (my_net_write(&thd->net, (char*)thd->packet.ptr(), packet->length()))
DBUG_RETURN(-1); DBUG_RETURN(-1);
...@@ -659,11 +665,13 @@ int flush_master_info(MASTER_INFO* mi) ...@@ -659,11 +665,13 @@ int flush_master_info(MASTER_INFO* mi)
{ {
IO_CACHE* file = &mi->file; IO_CACHE* file = &mi->file;
char lbuf[22]; char lbuf[22];
char lbuf1[22];
my_b_seek(file, 0L); my_b_seek(file, 0L);
my_b_printf(file, "%s\n%s\n%s\n%s\n%s\n%d\n%d\n", my_b_printf(file, "%s\n%s\n%s\n%s\n%s\n%d\n%d\n%d\n",
mi->log_file_name, llstr(mi->pos, lbuf), mi->host, mi->user, mi->log_file_name, llstr(mi->pos, lbuf), mi->host, mi->user,
mi->password, mi->port, mi->connect_retry); mi->password, mi->port, mi->connect_retry,
llstr(mi->last_log_seq, lbuf1));
flush_io_cache(file); flush_io_cache(file);
return 0; return 0;
} }
...@@ -1011,9 +1019,9 @@ static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len) ...@@ -1011,9 +1019,9 @@ static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len)
return 1; return 1;
} }
free_root(&thd->mem_root,0); free_root(&thd->mem_root,0);
mi->last_log_seq = ev->log_seq;
delete ev; delete ev;
thd->log_seq = 0; thd->log_seq = 0;
mi->inc_pos(event_len); mi->inc_pos(event_len);
flush_master_info(mi); flush_master_info(mi);
break; break;
...@@ -1027,8 +1035,11 @@ static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len) ...@@ -1027,8 +1035,11 @@ static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len)
mysql_bin_log.write(sev); mysql_bin_log.write(sev);
} }
mi->last_log_seq = ev->log_seq;
delete ev; delete ev;
thd->log_seq = 0; thd->log_seq = 0;
mi->inc_pos(event_len);
flush_master_info(mi);
break; break;
} }
...@@ -1139,6 +1150,7 @@ static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len) ...@@ -1139,6 +1150,7 @@ static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len)
return 1; return 1;
} }
mi->last_log_seq = ev->log_seq;
delete ev; delete ev;
thd->log_seq = 0; thd->log_seq = 0;
free_root(&thd->mem_root,0); free_root(&thd->mem_root,0);
...@@ -1158,6 +1170,7 @@ static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len) ...@@ -1158,6 +1170,7 @@ static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len)
case START_EVENT: case START_EVENT:
close_temporary_tables(thd); close_temporary_tables(thd);
mi->inc_pos(event_len); mi->inc_pos(event_len);
mi->last_log_seq = ev->log_seq;
flush_master_info(mi); flush_master_info(mi);
delete ev; delete ev;
thd->log_seq = 0; thd->log_seq = 0;
...@@ -1170,6 +1183,7 @@ static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len) ...@@ -1170,6 +1183,7 @@ static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len)
mi->inc_pos(event_len); mi->inc_pos(event_len);
flush_master_info(mi); flush_master_info(mi);
} }
mi->last_log_seq = ev->log_seq;
delete ev; delete ev;
thd->log_seq = 0; thd->log_seq = 0;
break; break;
...@@ -1185,21 +1199,26 @@ static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len) ...@@ -1185,21 +1199,26 @@ static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len)
if (!*log_name || !(log_name[ident_len] == 0 && if (!*log_name || !(log_name[ident_len] == 0 &&
!memcmp(log_name, rev->new_log_ident, ident_len))) !memcmp(log_name, rev->new_log_ident, ident_len)))
{ {
write_slave_event = mysql_bin_log.is_open(); write_slave_event = (!(rev->flags & LOG_EVENT_FORCED_ROTATE_F)
rotate_binlog = (*log_name && write_slave_event ); && mysql_bin_log.is_open());
rotate_binlog = (*log_name && write_slave_event);
memcpy(log_name, rev->new_log_ident,ident_len ); memcpy(log_name, rev->new_log_ident,ident_len );
log_name[ident_len] = 0; log_name[ident_len] = 0;
} }
mi->pos = 4; // skip magic number mi->pos = 4; // skip magic number
mi->last_log_seq = ev->log_seq;
pthread_cond_broadcast(&mi->cond); pthread_cond_broadcast(&mi->cond);
pthread_mutex_unlock(&mi->lock); pthread_mutex_unlock(&mi->lock);
flush_master_info(mi);
#ifndef DBUG_OFF #ifndef DBUG_OFF
if (abort_slave_event_count) if (abort_slave_event_count)
++events_till_abort; ++events_till_abort;
#endif #endif
if (rotate_binlog) if (rotate_binlog)
{
mi->last_log_seq = 0;
mysql_bin_log.new_file(); mysql_bin_log.new_file();
}
flush_master_info(mi);
if (write_slave_event) if (write_slave_event)
{ {
......
...@@ -15,11 +15,12 @@ typedef struct st_master_info ...@@ -15,11 +15,12 @@ typedef struct st_master_info
char password[HASH_PASSWORD_LENGTH+1]; char password[HASH_PASSWORD_LENGTH+1];
uint port; uint port;
uint connect_retry; uint connect_retry;
uint32 last_log_seq; // log sequence number of last processed event
pthread_mutex_t lock; pthread_mutex_t lock;
pthread_cond_t cond; pthread_cond_t cond;
bool inited; bool inited;
st_master_info():pending(0),fd(-1),inited(0) st_master_info():pending(0),fd(-1),last_log_seq(0),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);
......
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