[MDEV-4692] mysql.gtid_slave_pos accumulates values for a domain Created: 2013-06-21  Updated: 2016-03-21  Resolved: 2013-06-21

Status: Closed
Project: MariaDB Server
Component/s: None
Affects Version/s: None
Fix Version/s: 10.0.4

Type: Bug Priority: Minor
Reporter: Elena Stepanova Assignee: Kristian Nielsen
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-26 Global transaction ID Closed

 Description   

After the fix for MDEV-4688, at any point of time I see two consequent values in mysql.gtid_slave_pos for a given domain:

# [slave] Table contents after 1st synchronization 
domain_id	sub_id	server_id	seq_no
0	1	1	1
0	2	1	2

As long as the slave is running, the values get rotated:

# [slave] Table contents after 2nd synchronization
domain_id	sub_id	server_id	seq_no
0	2	1	2
0	3	1	3

It's new, but doesn't seem too bad in itself, so if it helps to fix some other issues, so be it.
However, after server restart, the old values are kept in the table, and new ones are added when replication resumes:

# [slave] Table contents after 1st restart 
domain_id	sub_id	server_id	seq_no
0	2	1	2
0	3	1	3

# [slave] Table contents after 3rd synchronization 
domain_id	sub_id	server_id	seq_no
0	2	1	2
0	3	1	3
0	4	1	4

# [slave] Table contents after 2nd restart
domain_id	sub_id	server_id	seq_no
0	2	1	2
0	3	1	3
0	4	1	4

# [slave] Table contents after 4th synchronization 
domain_id	sub_id	server_id	seq_no
0	2	1	2
0	3	1	3
0	5	1	5
0	6	1	6

etc.

It's possibly harmless if the slave makes sure it always uses the greatest value for a domain (as it probably does anyway), but with time the table might get cluttered, so if it's fixable, I think it's better to fix it

bzr version-info

revision-id: knielsen@knielsen-hq.org-20130621095346-9bi73emjowwe396n
revno: 3663
branch-nick: 10.0-base

Test case:

--source include/master-slave.inc
--source include/have_innodb.inc
--source include/have_binlog_format_row.inc
 
--connection slave
set sql_log_bin=0;
--source include/stop_slave.inc
alter table mysql.gtid_slave_pos engine=InnoDB;
change master to master_use_gtid=current_pos;
--source include/start_slave.inc
 
--connection master
create table t1 (i int, c varchar(8)) engine=InnoDB;
insert into t1 values (1,'a'),(2,'b');
 
--sync_slave_with_master
--echo # [slave] Table contents after 1st synchronization 
select * from mysql.gtid_slave_pos;
 
--connection master
insert into t1 values (3,'c'),(4,'d');
 
--sync_slave_with_master
--echo # [slave] Table contents after 2nd synchronization 
select * from mysql.gtid_slave_pos;
 
--enable_reconnect
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
restart
EOF
 
--shutdown_server 0
--source include/wait_until_connected_again.inc
 
--echo # [slave] Table contents after 1st restart 
select * from mysql.gtid_slave_pos;
--source include/start_slave.inc
 
 
--connection master
 
insert into t1 values (5,'e'),(6,'f');
 
--sync_slave_with_master
--echo # [slave] Table contents after 3nd synchronization 
select * from mysql.gtid_slave_pos;
 
--enable_reconnect
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
restart
EOF
 
--shutdown_server 0
--source include/wait_until_connected_again.inc
 
--echo # [slave] Table contents after 2nd restart
select * from mysql.gtid_slave_pos;
--source include/start_slave.inc
 
--connection master
 
insert into t1 values (7,'g'),(8,'h');
drop table t1;
 
--sync_slave_with_master
--echo # [slave] Table contents after 4th synchronization 
select * from mysql.gtid_slave_pos;
 



 Comments   
Comment by Kristian Nielsen [ 2013-06-21 ]

It is deliberate that there can be multiple entries (this is for parallel
replication, so that multiple threads running in parallel can add each
their own entries without conflicting on row locks).

The correct way to select from the table is:

SELECT CONCAT(domain_id, "-", server_id, "-", seq_no)
FROM rpl_slave_state
WHERE (domain_id, sub_id) IN
  (SELECT domain_id, MAX(sub_id) FROM rpl_slave_state GROUP BY domain_id)

(one could make a view for this, but it's better to use @@gtid_slave_pos and
leave the table for the server to manage).

But it is a bug that they accumulate on server restart, I'll fix it.

Comment by Kristian Nielsen [ 2013-06-21 ]

Pushed to 10.0-base

Generated at Thu Feb 08 06:58:24 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.