MDEV-742 XA PREPAREd transaction survive disconnect/server restart
Lifted long standing limitation to the XA of rolling it back at the
transaction's
connection close even if the XA is prepared.
Prepared XA-transaction is made to sustain connection close or server
restart.
The patch consists of
- binary logging extension to write prepared XA part of
transaction signified with
its XID in a new XA_prepare_log_event. The concusion part -
with Commit or Rollback decision - is logged separately as
Query_log_event.
That is in the binlog the XA consists of two separate group of
events.
That makes the whole XA possibly interweaving in binlog with
other XA:s or regular transaction but with no harm to
replication and data consistency.
Gtid_log_event receives two more flags to identify which of the
two XA phases of the transaction it represents. With either flag
set also XID info is added to the event.
When binlog is ON on the server XID::formatID is
constrained to 4 bytes.
- engines are made aware of the server policy to keep up user
prepared XA:s so they (Innodb, rocksdb) don't roll them back
anymore at their disconnect methods.
- slave applier is refined to cope with two phase logged XA:s
including parallel modes of execution.
This patch does not address crash-safe logging of the new events which
is being addressed by MDEV-21469.
CORNER CASES: read-only, pure myisam, binlog-*, @@skip_log_bin, etc
Are addressed along the following policies.
1. The read-only at reconnect marks XID to fail for future
completion with ER_XA_RBROLLBACK.
2. binlog-* filtered XA when it changes engine data is regarded as
loggable even when nothing got cached for binlog. An empty
XA-prepare group is recorded. Consequent Commit-or-Rollback
succeeds in the Engine(s) as well as recorded into binlog.
3. The same applies to the non-transactional engine XA.
4. @@skip_log_bin=OFF does not record anything at XA-prepare
(obviously), but the completion event is recorded into binlog to
admit inconsistency with slave.
The following actions are taken by the patch.
At XA-prepare:
when empty binlog cache - don't do anything to binlog if RO,
otherwise write empty XA_prepare (assert(binlog-filter case)).
At Disconnect:
when Prepared && RO (=> no binlogging was done)
set Xid_cache_element::error := ER_XA_RBROLLBACK
*keep* XID in the cache, and rollback the transaction.
At XA-"complete":
Discover the error, if any don't binlog the "complete",
return the error to the user.
Kudos
-----
Alexey Botchkov took to drive this work initially.
Sergei Golubchik, Sergei Petrunja, Marko Mäkelä provided a number of
good recommendations.
Sergei Voitovich made a magnificent review and improvements to the code.
They all deserve a bunch of thanks for making this work done!
2019-03-31 01:47:28 +04:00
|
|
|
include/master-slave.inc
|
|
|
|
[connection master]
|
|
|
|
connection master;
|
|
|
|
create table t1 (a int, b int) engine=InnoDB;
|
|
|
|
insert into t1 values(0, 0);
|
|
|
|
xa start 't';
|
|
|
|
insert into t1 values(1, 2);
|
|
|
|
xa end 't';
|
|
|
|
xa prepare 't';
|
|
|
|
xa commit 't';
|
|
|
|
connection slave;
|
|
|
|
include/diff_tables.inc [master:t1, slave:t1]
|
|
|
|
connection master;
|
|
|
|
xa start 't';
|
|
|
|
insert into t1 values(3, 4);
|
|
|
|
xa end 't';
|
|
|
|
xa prepare 't';
|
|
|
|
xa rollback 't';
|
|
|
|
connection slave;
|
|
|
|
include/diff_tables.inc [master:t1, slave:t1]
|
|
|
|
connection master;
|
|
|
|
SET pseudo_slave_mode=1;
|
|
|
|
create table t2 (a int) engine=InnoDB;
|
|
|
|
xa start 't';
|
|
|
|
insert into t1 values (5, 6);
|
|
|
|
xa end 't';
|
|
|
|
xa prepare 't';
|
|
|
|
xa start 's';
|
|
|
|
insert into t2 values (0);
|
|
|
|
xa end 's';
|
|
|
|
xa prepare 's';
|
|
|
|
include/save_master_gtid.inc
|
|
|
|
connection slave;
|
|
|
|
include/sync_with_master_gtid.inc
|
|
|
|
xa recover;
|
|
|
|
formatID gtrid_length bqual_length data
|
|
|
|
1 1 0 s
|
2020-03-15 12:52:53 +04:00
|
|
|
1 1 0 t
|
MDEV-742 XA PREPAREd transaction survive disconnect/server restart
Lifted long standing limitation to the XA of rolling it back at the
transaction's
connection close even if the XA is prepared.
Prepared XA-transaction is made to sustain connection close or server
restart.
The patch consists of
- binary logging extension to write prepared XA part of
transaction signified with
its XID in a new XA_prepare_log_event. The concusion part -
with Commit or Rollback decision - is logged separately as
Query_log_event.
That is in the binlog the XA consists of two separate group of
events.
That makes the whole XA possibly interweaving in binlog with
other XA:s or regular transaction but with no harm to
replication and data consistency.
Gtid_log_event receives two more flags to identify which of the
two XA phases of the transaction it represents. With either flag
set also XID info is added to the event.
When binlog is ON on the server XID::formatID is
constrained to 4 bytes.
- engines are made aware of the server policy to keep up user
prepared XA:s so they (Innodb, rocksdb) don't roll them back
anymore at their disconnect methods.
- slave applier is refined to cope with two phase logged XA:s
including parallel modes of execution.
This patch does not address crash-safe logging of the new events which
is being addressed by MDEV-21469.
CORNER CASES: read-only, pure myisam, binlog-*, @@skip_log_bin, etc
Are addressed along the following policies.
1. The read-only at reconnect marks XID to fail for future
completion with ER_XA_RBROLLBACK.
2. binlog-* filtered XA when it changes engine data is regarded as
loggable even when nothing got cached for binlog. An empty
XA-prepare group is recorded. Consequent Commit-or-Rollback
succeeds in the Engine(s) as well as recorded into binlog.
3. The same applies to the non-transactional engine XA.
4. @@skip_log_bin=OFF does not record anything at XA-prepare
(obviously), but the completion event is recorded into binlog to
admit inconsistency with slave.
The following actions are taken by the patch.
At XA-prepare:
when empty binlog cache - don't do anything to binlog if RO,
otherwise write empty XA_prepare (assert(binlog-filter case)).
At Disconnect:
when Prepared && RO (=> no binlogging was done)
set Xid_cache_element::error := ER_XA_RBROLLBACK
*keep* XID in the cache, and rollback the transaction.
At XA-"complete":
Discover the error, if any don't binlog the "complete",
return the error to the user.
Kudos
-----
Alexey Botchkov took to drive this work initially.
Sergei Golubchik, Sergei Petrunja, Marko Mäkelä provided a number of
good recommendations.
Sergei Voitovich made a magnificent review and improvements to the code.
They all deserve a bunch of thanks for making this work done!
2019-03-31 01:47:28 +04:00
|
|
|
connection master;
|
|
|
|
xa commit 't';
|
|
|
|
xa commit 's';
|
|
|
|
SET pseudo_slave_mode=0;
|
|
|
|
connection slave;
|
|
|
|
include/diff_tables.inc [master:t1, slave:t1]
|
|
|
|
include/diff_tables.inc [master:t2, slave:t2]
|
|
|
|
connection master;
|
|
|
|
*** At the start of read-only section gtid list is:
|
|
|
|
flush logs;
|
|
|
|
show binlog events in 'master-bin.000002' limit 1,1;
|
|
|
|
Log_name Pos Event_type Server_id End_log_pos Info
|
|
|
|
master-bin.000002 # Gtid_list 1 # [0-1-11]
|
|
|
|
set @query1="select 1";
|
|
|
|
set @query2="select count(*) into @s2 from t1";
|
|
|
|
connection master;
|
|
|
|
connect master_$xid, 127.0.0.1,root,,$db,$MASTER_MYPORT,;
|
|
|
|
xa start 'ro_2';
|
|
|
|
select count(*) into @s2 from t1;
|
|
|
|
xa end 'ro_2';
|
|
|
|
xa prepare 'ro_2';;
|
|
|
|
disconnect master_ro_2;
|
|
|
|
connection master;
|
|
|
|
connect master_$xid, 127.0.0.1,root,,$db,$MASTER_MYPORT,;
|
|
|
|
xa start 'ro_1';
|
|
|
|
select 1;
|
|
|
|
1
|
|
|
|
1
|
|
|
|
xa end 'ro_1';
|
|
|
|
xa prepare 'ro_1';;
|
|
|
|
disconnect master_ro_1;
|
|
|
|
connection master;
|
|
|
|
connect master_$xid, 127.0.0.1,root,,$db,$MASTER_MYPORT,;
|
|
|
|
xa start 'ro_2';
|
|
|
|
select count(*) into @s2 from t1;
|
|
|
|
xa end 'ro_2';
|
|
|
|
xa prepare 'ro_2';;
|
|
|
|
disconnect master_ro_2;
|
|
|
|
connection master;
|
|
|
|
connect master_$xid, 127.0.0.1,root,,$db,$MASTER_MYPORT,;
|
|
|
|
xa start 'ro_1';
|
|
|
|
select 1;
|
|
|
|
1
|
|
|
|
1
|
|
|
|
xa end 'ro_1';
|
|
|
|
xa prepare 'ro_1';;
|
|
|
|
disconnect master_ro_1;
|
|
|
|
*** 2 prepared xa:s must be in the list:
|
|
|
|
connection master;
|
|
|
|
xa recover;
|
|
|
|
formatID gtrid_length bqual_length data
|
|
|
|
1 4 0 ro_1
|
2020-03-15 12:52:53 +04:00
|
|
|
1 4 0 ro_2
|
MDEV-742 XA PREPAREd transaction survive disconnect/server restart
Lifted long standing limitation to the XA of rolling it back at the
transaction's
connection close even if the XA is prepared.
Prepared XA-transaction is made to sustain connection close or server
restart.
The patch consists of
- binary logging extension to write prepared XA part of
transaction signified with
its XID in a new XA_prepare_log_event. The concusion part -
with Commit or Rollback decision - is logged separately as
Query_log_event.
That is in the binlog the XA consists of two separate group of
events.
That makes the whole XA possibly interweaving in binlog with
other XA:s or regular transaction but with no harm to
replication and data consistency.
Gtid_log_event receives two more flags to identify which of the
two XA phases of the transaction it represents. With either flag
set also XID info is added to the event.
When binlog is ON on the server XID::formatID is
constrained to 4 bytes.
- engines are made aware of the server policy to keep up user
prepared XA:s so they (Innodb, rocksdb) don't roll them back
anymore at their disconnect methods.
- slave applier is refined to cope with two phase logged XA:s
including parallel modes of execution.
This patch does not address crash-safe logging of the new events which
is being addressed by MDEV-21469.
CORNER CASES: read-only, pure myisam, binlog-*, @@skip_log_bin, etc
Are addressed along the following policies.
1. The read-only at reconnect marks XID to fail for future
completion with ER_XA_RBROLLBACK.
2. binlog-* filtered XA when it changes engine data is regarded as
loggable even when nothing got cached for binlog. An empty
XA-prepare group is recorded. Consequent Commit-or-Rollback
succeeds in the Engine(s) as well as recorded into binlog.
3. The same applies to the non-transactional engine XA.
4. @@skip_log_bin=OFF does not record anything at XA-prepare
(obviously), but the completion event is recorded into binlog to
admit inconsistency with slave.
The following actions are taken by the patch.
At XA-prepare:
when empty binlog cache - don't do anything to binlog if RO,
otherwise write empty XA_prepare (assert(binlog-filter case)).
At Disconnect:
when Prepared && RO (=> no binlogging was done)
set Xid_cache_element::error := ER_XA_RBROLLBACK
*keep* XID in the cache, and rollback the transaction.
At XA-"complete":
Discover the error, if any don't binlog the "complete",
return the error to the user.
Kudos
-----
Alexey Botchkov took to drive this work initially.
Sergei Golubchik, Sergei Petrunja, Marko Mäkelä provided a number of
good recommendations.
Sergei Voitovich made a magnificent review and improvements to the code.
They all deserve a bunch of thanks for making this work done!
2019-03-31 01:47:28 +04:00
|
|
|
*** Zero prepared xa:s must be in the list:
|
|
|
|
xa recover;
|
|
|
|
formatID gtrid_length bqual_length data
|
|
|
|
*** At the end of read-only section gtid list has 0 more compare with previous check:
|
|
|
|
flush logs;
|
|
|
|
show binlog events in 'master-bin.000003' limit 1,1;
|
|
|
|
Log_name Pos Event_type Server_id End_log_pos Info
|
|
|
|
master-bin.000003 # Gtid_list 1 # [0-1-11]
|
|
|
|
create database test_ign;
|
|
|
|
set @@sql_log_bin = 0;
|
|
|
|
create table test_ign.t (a int) engine=InnoDB;
|
|
|
|
set @@sql_log_bin = 1;
|
|
|
|
connect master_$xid, 127.0.0.1,root,,$db,$MASTER_MYPORT,;
|
|
|
|
xa start 'rw_no_binlog';
|
|
|
|
insert into test_ign.t set a=1;
|
|
|
|
xa end 'rw_no_binlog';
|
|
|
|
xa prepare 'rw_no_binlog';;
|
|
|
|
disconnect master_rw_no_binlog;
|
|
|
|
*** rw_no_binlog must be in the list:
|
|
|
|
connection master;
|
|
|
|
xa recover;
|
|
|
|
formatID gtrid_length bqual_length data
|
|
|
|
1 12 0 rw_no_binlog
|
|
|
|
*** Zero must be in the list:
|
|
|
|
connection master;
|
|
|
|
xa recover;
|
|
|
|
formatID gtrid_length bqual_length data
|
|
|
|
*** At the end of --binlog-ignore-db section gtid list has 2 more:
|
|
|
|
flush logs;
|
|
|
|
show binlog events in 'master-bin.000004' limit 1,1;
|
|
|
|
Log_name Pos Event_type Server_id End_log_pos Info
|
|
|
|
master-bin.000004 # Gtid_list 1 # [0-1-13]
|
|
|
|
connection master;
|
|
|
|
create table t3 (a int) engine=innodb;
|
|
|
|
*** the disconnected prepare case
|
|
|
|
connect master_$xid, 127.0.0.1,root,,$db,$MASTER_MYPORT,;
|
|
|
|
set @@binlog_format=statement;
|
|
|
|
xa start 'rw_binlog_only';
|
|
|
|
delete from t3;
|
|
|
|
xa end 'rw_binlog_only';
|
|
|
|
xa prepare 'rw_binlog_only';
|
|
|
|
disconnect master_rw_binlog_only;
|
|
|
|
connection master;
|
|
|
|
*** rw_binlog_only must be in the list:
|
|
|
|
xa recover;
|
|
|
|
formatID gtrid_length bqual_length data
|
|
|
|
1 14 0 rw_binlog_only
|
|
|
|
*** Zero must be in the list:
|
|
|
|
xa recover;
|
|
|
|
formatID gtrid_length bqual_length data
|
|
|
|
*** the same connection complete case.
|
|
|
|
connection master;
|
|
|
|
connect master_$xid, 127.0.0.1,root,,$db,$MASTER_MYPORT,;
|
|
|
|
set @@binlog_format=statement;
|
|
|
|
xa start 'rw_binlog_only';
|
|
|
|
delete from t3;
|
|
|
|
xa end 'rw_binlog_only';
|
|
|
|
xa prepare 'rw_binlog_only';
|
|
|
|
*** rw_binlog_only must be in the list:
|
|
|
|
xa recover;
|
|
|
|
formatID gtrid_length bqual_length data
|
|
|
|
1 14 0 rw_binlog_only
|
|
|
|
disconnect master_rw_binlog_only;
|
|
|
|
*** Zero must be in the list:
|
|
|
|
connection master;
|
|
|
|
xa recover;
|
|
|
|
formatID gtrid_length bqual_length data
|
|
|
|
*** At the end of ineffective in engine section gtid list has 5 more:
|
|
|
|
flush logs;
|
|
|
|
show binlog events in 'master-bin.000005' limit 1,1;
|
|
|
|
Log_name Pos Event_type Server_id End_log_pos Info
|
|
|
|
master-bin.000005 # Gtid_list 1 # [0-1-18]
|
|
|
|
create table tm (a int) engine=myisam;
|
|
|
|
connection master;
|
|
|
|
connect master_$xid, 127.0.0.1,root,,$db,$MASTER_MYPORT,;
|
|
|
|
xa start 'rw_myisam';
|
|
|
|
insert into tm set a=1;
|
|
|
|
xa end 'rw_myisam';
|
|
|
|
xa prepare 'rw_myisam';;
|
|
|
|
disconnect master_rw_myisam;
|
|
|
|
connection master;
|
|
|
|
connect master_$xid, 127.0.0.1,root,,$db,$MASTER_MYPORT,;
|
|
|
|
xa start 'rw_myisam';
|
|
|
|
insert into tm set a=1;
|
|
|
|
xa end 'rw_myisam';
|
|
|
|
xa prepare 'rw_myisam';;
|
|
|
|
disconnect master_rw_myisam;
|
|
|
|
*** rw_myisam prepared must be in the list:
|
|
|
|
connection master;
|
|
|
|
xa recover;
|
|
|
|
formatID gtrid_length bqual_length data
|
|
|
|
1 9 0 rw_myisam
|
|
|
|
*** Zero prepared xa:s must be in the list:
|
|
|
|
xa recover;
|
|
|
|
formatID gtrid_length bqual_length data
|
|
|
|
*** At the end of MyISAM "xa" section gtid list has 7 more compare with previous check:
|
|
|
|
flush logs;
|
|
|
|
show binlog events in 'master-bin.000006' limit 1,1;
|
|
|
|
Log_name Pos Event_type Server_id End_log_pos Info
|
|
|
|
master-bin.000006 # Gtid_list 1 # [0-1-25]
|
|
|
|
connect master_$xid, 127.0.0.1,root,,$db,$MASTER_MYPORT,;
|
|
|
|
set @@session.sql_log_bin = OFF;
|
|
|
|
xa start 'skip_binlog';
|
|
|
|
insert into t2 values(1);
|
|
|
|
xa end 'skip_binlog';
|
|
|
|
xa prepare 'skip_binlog';
|
|
|
|
disconnect master_skip_binlog;
|
|
|
|
*** skip_binlog must be in the list:
|
|
|
|
connection master;
|
|
|
|
xa recover;
|
|
|
|
formatID gtrid_length bqual_length data
|
|
|
|
1 11 0 skip_binlog
|
2020-03-15 14:14:35 +02:00
|
|
|
set @@session.sql_log_bin = OFF;
|
MDEV-742 XA PREPAREd transaction survive disconnect/server restart
Lifted long standing limitation to the XA of rolling it back at the
transaction's
connection close even if the XA is prepared.
Prepared XA-transaction is made to sustain connection close or server
restart.
The patch consists of
- binary logging extension to write prepared XA part of
transaction signified with
its XID in a new XA_prepare_log_event. The concusion part -
with Commit or Rollback decision - is logged separately as
Query_log_event.
That is in the binlog the XA consists of two separate group of
events.
That makes the whole XA possibly interweaving in binlog with
other XA:s or regular transaction but with no harm to
replication and data consistency.
Gtid_log_event receives two more flags to identify which of the
two XA phases of the transaction it represents. With either flag
set also XID info is added to the event.
When binlog is ON on the server XID::formatID is
constrained to 4 bytes.
- engines are made aware of the server policy to keep up user
prepared XA:s so they (Innodb, rocksdb) don't roll them back
anymore at their disconnect methods.
- slave applier is refined to cope with two phase logged XA:s
including parallel modes of execution.
This patch does not address crash-safe logging of the new events which
is being addressed by MDEV-21469.
CORNER CASES: read-only, pure myisam, binlog-*, @@skip_log_bin, etc
Are addressed along the following policies.
1. The read-only at reconnect marks XID to fail for future
completion with ER_XA_RBROLLBACK.
2. binlog-* filtered XA when it changes engine data is regarded as
loggable even when nothing got cached for binlog. An empty
XA-prepare group is recorded. Consequent Commit-or-Rollback
succeeds in the Engine(s) as well as recorded into binlog.
3. The same applies to the non-transactional engine XA.
4. @@skip_log_bin=OFF does not record anything at XA-prepare
(obviously), but the completion event is recorded into binlog to
admit inconsistency with slave.
The following actions are taken by the patch.
At XA-prepare:
when empty binlog cache - don't do anything to binlog if RO,
otherwise write empty XA_prepare (assert(binlog-filter case)).
At Disconnect:
when Prepared && RO (=> no binlogging was done)
set Xid_cache_element::error := ER_XA_RBROLLBACK
*keep* XID in the cache, and rollback the transaction.
At XA-"complete":
Discover the error, if any don't binlog the "complete",
return the error to the user.
Kudos
-----
Alexey Botchkov took to drive this work initially.
Sergei Golubchik, Sergei Petrunja, Marko Mäkelä provided a number of
good recommendations.
Sergei Voitovich made a magnificent review and improvements to the code.
They all deserve a bunch of thanks for making this work done!
2019-03-31 01:47:28 +04:00
|
|
|
xa rollback 'skip_binlog';
|
2020-03-15 14:14:35 +02:00
|
|
|
set @@session.sql_log_bin = ON;
|
|
|
|
include/save_master_gtid.inc
|
MDEV-742 XA PREPAREd transaction survive disconnect/server restart
Lifted long standing limitation to the XA of rolling it back at the
transaction's
connection close even if the XA is prepared.
Prepared XA-transaction is made to sustain connection close or server
restart.
The patch consists of
- binary logging extension to write prepared XA part of
transaction signified with
its XID in a new XA_prepare_log_event. The concusion part -
with Commit or Rollback decision - is logged separately as
Query_log_event.
That is in the binlog the XA consists of two separate group of
events.
That makes the whole XA possibly interweaving in binlog with
other XA:s or regular transaction but with no harm to
replication and data consistency.
Gtid_log_event receives two more flags to identify which of the
two XA phases of the transaction it represents. With either flag
set also XID info is added to the event.
When binlog is ON on the server XID::formatID is
constrained to 4 bytes.
- engines are made aware of the server policy to keep up user
prepared XA:s so they (Innodb, rocksdb) don't roll them back
anymore at their disconnect methods.
- slave applier is refined to cope with two phase logged XA:s
including parallel modes of execution.
This patch does not address crash-safe logging of the new events which
is being addressed by MDEV-21469.
CORNER CASES: read-only, pure myisam, binlog-*, @@skip_log_bin, etc
Are addressed along the following policies.
1. The read-only at reconnect marks XID to fail for future
completion with ER_XA_RBROLLBACK.
2. binlog-* filtered XA when it changes engine data is regarded as
loggable even when nothing got cached for binlog. An empty
XA-prepare group is recorded. Consequent Commit-or-Rollback
succeeds in the Engine(s) as well as recorded into binlog.
3. The same applies to the non-transactional engine XA.
4. @@skip_log_bin=OFF does not record anything at XA-prepare
(obviously), but the completion event is recorded into binlog to
admit inconsistency with slave.
The following actions are taken by the patch.
At XA-prepare:
when empty binlog cache - don't do anything to binlog if RO,
otherwise write empty XA_prepare (assert(binlog-filter case)).
At Disconnect:
when Prepared && RO (=> no binlogging was done)
set Xid_cache_element::error := ER_XA_RBROLLBACK
*keep* XID in the cache, and rollback the transaction.
At XA-"complete":
Discover the error, if any don't binlog the "complete",
return the error to the user.
Kudos
-----
Alexey Botchkov took to drive this work initially.
Sergei Golubchik, Sergei Petrunja, Marko Mäkelä provided a number of
good recommendations.
Sergei Voitovich made a magnificent review and improvements to the code.
They all deserve a bunch of thanks for making this work done!
2019-03-31 01:47:28 +04:00
|
|
|
*** Zero must be in the list:
|
|
|
|
connection master;
|
|
|
|
xa recover;
|
|
|
|
formatID gtrid_length bqual_length data
|
2020-03-15 14:14:35 +02:00
|
|
|
*** At the end of skip_log_binb section gtid list has 0 more:
|
MDEV-742 XA PREPAREd transaction survive disconnect/server restart
Lifted long standing limitation to the XA of rolling it back at the
transaction's
connection close even if the XA is prepared.
Prepared XA-transaction is made to sustain connection close or server
restart.
The patch consists of
- binary logging extension to write prepared XA part of
transaction signified with
its XID in a new XA_prepare_log_event. The concusion part -
with Commit or Rollback decision - is logged separately as
Query_log_event.
That is in the binlog the XA consists of two separate group of
events.
That makes the whole XA possibly interweaving in binlog with
other XA:s or regular transaction but with no harm to
replication and data consistency.
Gtid_log_event receives two more flags to identify which of the
two XA phases of the transaction it represents. With either flag
set also XID info is added to the event.
When binlog is ON on the server XID::formatID is
constrained to 4 bytes.
- engines are made aware of the server policy to keep up user
prepared XA:s so they (Innodb, rocksdb) don't roll them back
anymore at their disconnect methods.
- slave applier is refined to cope with two phase logged XA:s
including parallel modes of execution.
This patch does not address crash-safe logging of the new events which
is being addressed by MDEV-21469.
CORNER CASES: read-only, pure myisam, binlog-*, @@skip_log_bin, etc
Are addressed along the following policies.
1. The read-only at reconnect marks XID to fail for future
completion with ER_XA_RBROLLBACK.
2. binlog-* filtered XA when it changes engine data is regarded as
loggable even when nothing got cached for binlog. An empty
XA-prepare group is recorded. Consequent Commit-or-Rollback
succeeds in the Engine(s) as well as recorded into binlog.
3. The same applies to the non-transactional engine XA.
4. @@skip_log_bin=OFF does not record anything at XA-prepare
(obviously), but the completion event is recorded into binlog to
admit inconsistency with slave.
The following actions are taken by the patch.
At XA-prepare:
when empty binlog cache - don't do anything to binlog if RO,
otherwise write empty XA_prepare (assert(binlog-filter case)).
At Disconnect:
when Prepared && RO (=> no binlogging was done)
set Xid_cache_element::error := ER_XA_RBROLLBACK
*keep* XID in the cache, and rollback the transaction.
At XA-"complete":
Discover the error, if any don't binlog the "complete",
return the error to the user.
Kudos
-----
Alexey Botchkov took to drive this work initially.
Sergei Golubchik, Sergei Petrunja, Marko Mäkelä provided a number of
good recommendations.
Sergei Voitovich made a magnificent review and improvements to the code.
They all deserve a bunch of thanks for making this work done!
2019-03-31 01:47:28 +04:00
|
|
|
flush logs;
|
|
|
|
show binlog events in 'master-bin.000007' limit 1,1;
|
|
|
|
Log_name Pos Event_type Server_id End_log_pos Info
|
2020-03-15 14:14:35 +02:00
|
|
|
master-bin.000007 # Gtid_list 1 # [0-1-25]
|
MDEV-742 XA PREPAREd transaction survive disconnect/server restart
Lifted long standing limitation to the XA of rolling it back at the
transaction's
connection close even if the XA is prepared.
Prepared XA-transaction is made to sustain connection close or server
restart.
The patch consists of
- binary logging extension to write prepared XA part of
transaction signified with
its XID in a new XA_prepare_log_event. The concusion part -
with Commit or Rollback decision - is logged separately as
Query_log_event.
That is in the binlog the XA consists of two separate group of
events.
That makes the whole XA possibly interweaving in binlog with
other XA:s or regular transaction but with no harm to
replication and data consistency.
Gtid_log_event receives two more flags to identify which of the
two XA phases of the transaction it represents. With either flag
set also XID info is added to the event.
When binlog is ON on the server XID::formatID is
constrained to 4 bytes.
- engines are made aware of the server policy to keep up user
prepared XA:s so they (Innodb, rocksdb) don't roll them back
anymore at their disconnect methods.
- slave applier is refined to cope with two phase logged XA:s
including parallel modes of execution.
This patch does not address crash-safe logging of the new events which
is being addressed by MDEV-21469.
CORNER CASES: read-only, pure myisam, binlog-*, @@skip_log_bin, etc
Are addressed along the following policies.
1. The read-only at reconnect marks XID to fail for future
completion with ER_XA_RBROLLBACK.
2. binlog-* filtered XA when it changes engine data is regarded as
loggable even when nothing got cached for binlog. An empty
XA-prepare group is recorded. Consequent Commit-or-Rollback
succeeds in the Engine(s) as well as recorded into binlog.
3. The same applies to the non-transactional engine XA.
4. @@skip_log_bin=OFF does not record anything at XA-prepare
(obviously), but the completion event is recorded into binlog to
admit inconsistency with slave.
The following actions are taken by the patch.
At XA-prepare:
when empty binlog cache - don't do anything to binlog if RO,
otherwise write empty XA_prepare (assert(binlog-filter case)).
At Disconnect:
when Prepared && RO (=> no binlogging was done)
set Xid_cache_element::error := ER_XA_RBROLLBACK
*keep* XID in the cache, and rollback the transaction.
At XA-"complete":
Discover the error, if any don't binlog the "complete",
return the error to the user.
Kudos
-----
Alexey Botchkov took to drive this work initially.
Sergei Golubchik, Sergei Petrunja, Marko Mäkelä provided a number of
good recommendations.
Sergei Voitovich made a magnificent review and improvements to the code.
They all deserve a bunch of thanks for making this work done!
2019-03-31 01:47:28 +04:00
|
|
|
connection slave;
|
2020-03-15 14:14:35 +02:00
|
|
|
include/sync_with_master_gtid.inc
|
MDEV-742 XA PREPAREd transaction survive disconnect/server restart
Lifted long standing limitation to the XA of rolling it back at the
transaction's
connection close even if the XA is prepared.
Prepared XA-transaction is made to sustain connection close or server
restart.
The patch consists of
- binary logging extension to write prepared XA part of
transaction signified with
its XID in a new XA_prepare_log_event. The concusion part -
with Commit or Rollback decision - is logged separately as
Query_log_event.
That is in the binlog the XA consists of two separate group of
events.
That makes the whole XA possibly interweaving in binlog with
other XA:s or regular transaction but with no harm to
replication and data consistency.
Gtid_log_event receives two more flags to identify which of the
two XA phases of the transaction it represents. With either flag
set also XID info is added to the event.
When binlog is ON on the server XID::formatID is
constrained to 4 bytes.
- engines are made aware of the server policy to keep up user
prepared XA:s so they (Innodb, rocksdb) don't roll them back
anymore at their disconnect methods.
- slave applier is refined to cope with two phase logged XA:s
including parallel modes of execution.
This patch does not address crash-safe logging of the new events which
is being addressed by MDEV-21469.
CORNER CASES: read-only, pure myisam, binlog-*, @@skip_log_bin, etc
Are addressed along the following policies.
1. The read-only at reconnect marks XID to fail for future
completion with ER_XA_RBROLLBACK.
2. binlog-* filtered XA when it changes engine data is regarded as
loggable even when nothing got cached for binlog. An empty
XA-prepare group is recorded. Consequent Commit-or-Rollback
succeeds in the Engine(s) as well as recorded into binlog.
3. The same applies to the non-transactional engine XA.
4. @@skip_log_bin=OFF does not record anything at XA-prepare
(obviously), but the completion event is recorded into binlog to
admit inconsistency with slave.
The following actions are taken by the patch.
At XA-prepare:
when empty binlog cache - don't do anything to binlog if RO,
otherwise write empty XA_prepare (assert(binlog-filter case)).
At Disconnect:
when Prepared && RO (=> no binlogging was done)
set Xid_cache_element::error := ER_XA_RBROLLBACK
*keep* XID in the cache, and rollback the transaction.
At XA-"complete":
Discover the error, if any don't binlog the "complete",
return the error to the user.
Kudos
-----
Alexey Botchkov took to drive this work initially.
Sergei Golubchik, Sergei Petrunja, Marko Mäkelä provided a number of
good recommendations.
Sergei Voitovich made a magnificent review and improvements to the code.
They all deserve a bunch of thanks for making this work done!
2019-03-31 01:47:28 +04:00
|
|
|
connection master;
|
|
|
|
drop database test_ign;
|
|
|
|
drop table t1, t2, t3, tm;
|
2021-10-18 12:49:10 +03:00
|
|
|
#
|
|
|
|
# MDEV-26682 slave lock timeout with XA and gap locks
|
|
|
|
#
|
|
|
|
create table t1 (a int primary key, b int unique) engine=innodb;
|
|
|
|
insert t1 values (1,1),(3,3),(5,5);
|
|
|
|
connection slave;
|
|
|
|
set session tx_isolation='repeatable-read';
|
|
|
|
start transaction;
|
|
|
|
select * from t1;
|
|
|
|
a b
|
|
|
|
1 1
|
|
|
|
3 3
|
|
|
|
5 5
|
|
|
|
connect m2, localhost, root;
|
|
|
|
delete from t1 where a=3;
|
|
|
|
xa start 'x1';
|
|
|
|
update t1 set b=3 where a=5;
|
|
|
|
xa end 'x1';
|
|
|
|
xa prepare 'x1';
|
|
|
|
connect m3, localhost, root;
|
|
|
|
insert t1 values (2, 2);
|
|
|
|
-->slave
|
|
|
|
connection slave;
|
|
|
|
commit;
|
|
|
|
select * from t1;
|
|
|
|
a b
|
|
|
|
1 1
|
|
|
|
2 2
|
|
|
|
5 5
|
|
|
|
connection m2;
|
|
|
|
xa rollback 'x1';
|
|
|
|
disconnect m2;
|
|
|
|
disconnect m3;
|
|
|
|
connection master;
|
|
|
|
drop table t1;
|
|
|
|
create table t1 (id int auto_increment primary key, c1 int not null unique)
|
|
|
|
engine=innodb;
|
|
|
|
create table t2 (id int auto_increment primary key, c1 int not null,
|
|
|
|
foreign key(c1) references t1(c1), unique key(c1)) engine=innodb;
|
|
|
|
insert t1 values (869,1), (871,3), (873,4), (872,5), (870,6), (877,7);
|
|
|
|
insert t2 values (795,6), (800,7);
|
|
|
|
xa start '1';
|
|
|
|
update t2 set id = 9, c1 = 5 where c1 in (null, null, null, null, null, 7, 3);
|
|
|
|
connect con1, localhost,root;
|
|
|
|
xa start '2';
|
|
|
|
delete from t1 where c1 like '3%';
|
|
|
|
xa end '2';
|
|
|
|
xa prepare '2';
|
|
|
|
connection master;
|
|
|
|
xa end '1';
|
|
|
|
xa prepare '1';
|
|
|
|
->slave
|
|
|
|
connection slave;
|
|
|
|
connection slave;
|
|
|
|
include/sync_with_master_gtid.inc
|
|
|
|
connection con1;
|
|
|
|
xa commit '2';
|
|
|
|
disconnect con1;
|
|
|
|
connection master;
|
|
|
|
xa commit '1';
|
|
|
|
drop table t2, t1;
|
MDEV-742 XA PREPAREd transaction survive disconnect/server restart
Lifted long standing limitation to the XA of rolling it back at the
transaction's
connection close even if the XA is prepared.
Prepared XA-transaction is made to sustain connection close or server
restart.
The patch consists of
- binary logging extension to write prepared XA part of
transaction signified with
its XID in a new XA_prepare_log_event. The concusion part -
with Commit or Rollback decision - is logged separately as
Query_log_event.
That is in the binlog the XA consists of two separate group of
events.
That makes the whole XA possibly interweaving in binlog with
other XA:s or regular transaction but with no harm to
replication and data consistency.
Gtid_log_event receives two more flags to identify which of the
two XA phases of the transaction it represents. With either flag
set also XID info is added to the event.
When binlog is ON on the server XID::formatID is
constrained to 4 bytes.
- engines are made aware of the server policy to keep up user
prepared XA:s so they (Innodb, rocksdb) don't roll them back
anymore at their disconnect methods.
- slave applier is refined to cope with two phase logged XA:s
including parallel modes of execution.
This patch does not address crash-safe logging of the new events which
is being addressed by MDEV-21469.
CORNER CASES: read-only, pure myisam, binlog-*, @@skip_log_bin, etc
Are addressed along the following policies.
1. The read-only at reconnect marks XID to fail for future
completion with ER_XA_RBROLLBACK.
2. binlog-* filtered XA when it changes engine data is regarded as
loggable even when nothing got cached for binlog. An empty
XA-prepare group is recorded. Consequent Commit-or-Rollback
succeeds in the Engine(s) as well as recorded into binlog.
3. The same applies to the non-transactional engine XA.
4. @@skip_log_bin=OFF does not record anything at XA-prepare
(obviously), but the completion event is recorded into binlog to
admit inconsistency with slave.
The following actions are taken by the patch.
At XA-prepare:
when empty binlog cache - don't do anything to binlog if RO,
otherwise write empty XA_prepare (assert(binlog-filter case)).
At Disconnect:
when Prepared && RO (=> no binlogging was done)
set Xid_cache_element::error := ER_XA_RBROLLBACK
*keep* XID in the cache, and rollback the transaction.
At XA-"complete":
Discover the error, if any don't binlog the "complete",
return the error to the user.
Kudos
-----
Alexey Botchkov took to drive this work initially.
Sergei Golubchik, Sergei Petrunja, Marko Mäkelä provided a number of
good recommendations.
Sergei Voitovich made a magnificent review and improvements to the code.
They all deserve a bunch of thanks for making this work done!
2019-03-31 01:47:28 +04:00
|
|
|
include/rpl_end.inc
|