mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 12:02:42 +01:00
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
This commit is contained in:
parent
a697e30a3a
commit
bcc51cb0a3
11 changed files with 79 additions and 33 deletions
|
@ -1,13 +1,13 @@
|
|||
File Position Binlog_do_db Binlog_ignore_db
|
||||
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
|
||||
127.0.0.1 root 9999 1 master-bin.001 79 Yes 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
|
||||
127.0.0.1 root 9999 1 master-bin.001 73 No 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
|
||||
127.0.0.1 root 9999 1 master-bin.001 73 Yes 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
|
||||
127.0.0.1 root 9999 1 master-bin.001 173 Yes 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 Last_log_seq
|
||||
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 Last_log_seq
|
||||
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 Last_log_seq
|
||||
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 Last_log_seq
|
||||
127.0.0.1 root 9999 1 master-bin.001 173 Yes 0 0 1
|
||||
File Position Binlog_do_db Binlog_ignore_db
|
||||
master-bin.001 79
|
||||
n
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
File Position Binlog_do_db Binlog_ignore_db
|
||||
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
|
||||
0 0 0 No 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
|
||||
127.0.0.1 test 9998 60 4 No 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
|
||||
127.0.0.1 root 9999 60 4 No 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
|
||||
127.0.0.1 root 9999 60 master-bin.001 79 Yes 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 Last_log_seq
|
||||
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 Last_log_seq
|
||||
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 Last_log_seq
|
||||
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 Last_log_seq
|
||||
127.0.0.1 root 9999 60 master-bin.001 79 Yes 0 0 1
|
||||
n
|
||||
10
|
||||
45
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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
|
||||
127.0.0.1 root 9999 60 master-bin.001 234 Yes 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 Last_log_seq
|
||||
127.0.0.1 root 9999 60 master-bin.001 234 Yes 0 0 3
|
||||
s
|
||||
Could not break slave
|
||||
Tried hard
|
||||
|
@ -9,8 +9,8 @@ master-bin.002
|
|||
master-bin.003
|
||||
Log_name
|
||||
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
|
||||
127.0.0.1 root 9999 60 master-bin.003 202 Yes 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 Last_log_seq
|
||||
127.0.0.1 root 9999 60 master-bin.003 202 Yes 0 0 3
|
||||
m
|
||||
34
|
||||
65
|
||||
|
@ -24,7 +24,7 @@ master-bin.005
|
|||
master-bin.006
|
||||
File Position Binlog_do_db Binlog_ignore_db
|
||||
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
|
||||
127.0.0.1 root 9999 60 master-bin.006 720 Yes 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 Last_log_seq
|
||||
127.0.0.1 root 9999 60 master-bin.006 720 Yes 0 0 11
|
||||
count(*)
|
||||
100
|
||||
|
|
|
@ -27,6 +27,9 @@ master-bin.001 516 Rotate 1 9 master-bin.002
|
|||
master-bin.001 549 Stop 1 10
|
||||
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 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
|
||||
master-bin.001
|
||||
master-bin.002
|
||||
|
@ -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 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 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
|
||||
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 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
|
|||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
9306
|
||||
1
|
||||
0
|
||||
EOF
|
||||
|
|
|
@ -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,1;
|
||||
flush logs;
|
||||
create table t1 (n int);
|
||||
insert into t1 values (1);
|
||||
drop table t1;
|
||||
show binlog events;
|
||||
show binlog events in 'master-bin.002';
|
||||
show master logs;
|
||||
|
@ -30,3 +33,5 @@ sync_with_master;
|
|||
show master logs;
|
||||
show binlog events in 'slave-bin.001' 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()
|
|||
to change base names at some point.
|
||||
*/
|
||||
Rotate_log_event r(new_name+dirname_length(new_name));
|
||||
THD* thd = current_thd;
|
||||
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);
|
||||
VOID(pthread_cond_broadcast(&COND_binlog_update));
|
||||
}
|
||||
|
|
|
@ -189,7 +189,11 @@ void Load_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)
|
||||
|
|
|
@ -107,6 +107,7 @@
|
|||
#define BINLOG_MAGIC "\xfe\x62\x69\x6e"
|
||||
|
||||
#define LOG_EVENT_TIME_F 0x1
|
||||
#define LOG_EVENT_FORCED_ROTATE_F 0x2
|
||||
|
||||
enum Log_event_type { START_EVENT = 1, QUERY_EVENT =2,
|
||||
STOP_EVENT=3, ROTATE_EVENT = 4, INTVAR_EVENT=5,
|
||||
|
|
35
sql/slave.cc
35
sql/slave.cc
|
@ -545,7 +545,9 @@ int init_master_info(MASTER_INFO* mi)
|
|||
master_password) ||
|
||||
init_intvar_from_file((int*)&mi->port, &mi->file, master_port) ||
|
||||
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";
|
||||
goto error;
|
||||
|
@ -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_error", 20));
|
||||
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))
|
||||
DBUG_RETURN(-1);
|
||||
|
||||
String* packet = &thd->packet;
|
||||
uint32 last_log_seq;
|
||||
packet->length(0);
|
||||
|
||||
pthread_mutex_lock(&glob_mi.lock);
|
||||
|
@ -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.connect_retry);
|
||||
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_lock(&LOCK_slave);
|
||||
net_store_data(packet, slave_running ? "Yes":"No");
|
||||
|
@ -647,6 +652,7 @@ int show_master_info(THD* thd)
|
|||
net_store_data(packet, (uint32)last_slave_errno);
|
||||
net_store_data(packet, last_slave_error);
|
||||
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()))
|
||||
DBUG_RETURN(-1);
|
||||
|
@ -659,11 +665,13 @@ int flush_master_info(MASTER_INFO* mi)
|
|||
{
|
||||
IO_CACHE* file = &mi->file;
|
||||
char lbuf[22];
|
||||
char lbuf1[22];
|
||||
|
||||
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->password, mi->port, mi->connect_retry);
|
||||
mi->password, mi->port, mi->connect_retry,
|
||||
llstr(mi->last_log_seq, lbuf1));
|
||||
flush_io_cache(file);
|
||||
return 0;
|
||||
}
|
||||
|
@ -1011,9 +1019,9 @@ static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len)
|
|||
return 1;
|
||||
}
|
||||
free_root(&thd->mem_root,0);
|
||||
mi->last_log_seq = ev->log_seq;
|
||||
delete ev;
|
||||
thd->log_seq = 0;
|
||||
|
||||
mi->inc_pos(event_len);
|
||||
flush_master_info(mi);
|
||||
break;
|
||||
|
@ -1027,8 +1035,11 @@ static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len)
|
|||
mysql_bin_log.write(sev);
|
||||
}
|
||||
|
||||
mi->last_log_seq = ev->log_seq;
|
||||
delete ev;
|
||||
thd->log_seq = 0;
|
||||
mi->inc_pos(event_len);
|
||||
flush_master_info(mi);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1139,6 +1150,7 @@ static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len)
|
|||
return 1;
|
||||
}
|
||||
|
||||
mi->last_log_seq = ev->log_seq;
|
||||
delete ev;
|
||||
thd->log_seq = 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)
|
|||
case START_EVENT:
|
||||
close_temporary_tables(thd);
|
||||
mi->inc_pos(event_len);
|
||||
mi->last_log_seq = ev->log_seq;
|
||||
flush_master_info(mi);
|
||||
delete ev;
|
||||
thd->log_seq = 0;
|
||||
|
@ -1170,6 +1183,7 @@ static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len)
|
|||
mi->inc_pos(event_len);
|
||||
flush_master_info(mi);
|
||||
}
|
||||
mi->last_log_seq = ev->log_seq;
|
||||
delete ev;
|
||||
thd->log_seq = 0;
|
||||
break;
|
||||
|
@ -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 &&
|
||||
!memcmp(log_name, rev->new_log_ident, ident_len)))
|
||||
{
|
||||
write_slave_event = mysql_bin_log.is_open();
|
||||
rotate_binlog = (*log_name && write_slave_event );
|
||||
write_slave_event = (!(rev->flags & LOG_EVENT_FORCED_ROTATE_F)
|
||||
&& mysql_bin_log.is_open());
|
||||
rotate_binlog = (*log_name && write_slave_event);
|
||||
memcpy(log_name, rev->new_log_ident,ident_len );
|
||||
log_name[ident_len] = 0;
|
||||
}
|
||||
mi->pos = 4; // skip magic number
|
||||
mi->last_log_seq = ev->log_seq;
|
||||
pthread_cond_broadcast(&mi->cond);
|
||||
pthread_mutex_unlock(&mi->lock);
|
||||
flush_master_info(mi);
|
||||
#ifndef DBUG_OFF
|
||||
if (abort_slave_event_count)
|
||||
++events_till_abort;
|
||||
#endif
|
||||
if (rotate_binlog)
|
||||
{
|
||||
mi->last_log_seq = 0;
|
||||
mysql_bin_log.new_file();
|
||||
}
|
||||
flush_master_info(mi);
|
||||
|
||||
if (write_slave_event)
|
||||
{
|
||||
|
|
|
@ -15,11 +15,12 @@ typedef struct st_master_info
|
|||
char password[HASH_PASSWORD_LENGTH+1];
|
||||
uint port;
|
||||
uint connect_retry;
|
||||
uint32 last_log_seq; // log sequence number of last processed event
|
||||
pthread_mutex_t lock;
|
||||
pthread_cond_t cond;
|
||||
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;
|
||||
pthread_mutex_init(&lock, MY_MUTEX_INIT_FAST);
|
||||
|
|
Loading…
Reference in a new issue