Skip to content
Permalink
Browse files
MDEV-15443 Properly read wsrep XID and binlog position from rollback …
…segment headers

The problem is a regression caused by MDEV-15158.
If some transactions were committed with wsrep_on=0, a
rollback segment header having the highest trx_id assigned might
store undefined wsrep XID. When reading the wsrep checkpoint
from InnodB, the undefined wsrep XID might be returned instead
of the highest valid one.

Similarly, if the binary log is intermittently disabled or enabled
while InnoDB transactions are being committed, the latest updated
rollback segment header page might not contain the latest binlog metadata.

Therefore, the MDEV-15158 logic to rely on TRX_RSEG_MAX_TRX_ID for
determining the most recent WSREP XID or binlog position is invalid.
We must choose the maximum entries among the rollback segment header
pages.

This fix is based on code submitted by Teemu Ollakka from Codership
and by Thirunarayanan Balathandayuthapani from MariaDB Corporation.

trx_purge_add_undo_to_history(): Only write TRX_RSEG_MAX_TRX_ID
when it was used to be written before MDEV-15158.

wsrep_seqno: Renamed from trx_sys_cur_xid_seqno.

wsrep_uuid: Renamed from trx_sys_cur_xid_uuid, and enable in non-debug
builds.

read_wsrep_xid_uuid(): Make non-debug, and remove the memcpy().

trx_rseg_update_wsrep_checkpoint(): Correctly compare and copy
the entire UUID in the debug check. In case of UUID mismatch,
write the WSREP XID to all 128 rollback segment headers in
a single mini-transaction.

trx_rseg_read_wsrep_checkpoint(rseg_header, xid): Make static.
In case the information is absent, do not overwrite xid.

trx_rseg_read_wsrep_checkpoint(xid): Determine the maximum
WSREP XID.

trx_rseg_mem_restore(): Remove the parameter max_rseg_trx_id.
Determine the latest binlog file and position by comparing
file names and offsets. Declare trx_sys.recovered_binlog_offset
as an unsigned type.
  • Loading branch information
dr-m committed Mar 6, 2018
1 parent d705735 commit 67f6d40
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 85 deletions.
@@ -0,0 +1,15 @@
CREATE TABLE t1 (f1 INT PRIMARY KEY) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1);
connection node_2;
SELECT * FROM t1;
f1
1
SET GLOBAL wsrep_cluster_address='';
SET SESSION wsrep_on=0;
INSERT INTO t1 VALUES (2);
DELETE FROM t1 WHERE f1 = 2;
connection node_1;
INSERT INTO t1 VALUES (2);
connection node_2;
connection node_1;
DROP TABLE t1;
@@ -0,0 +1,5 @@
!include ../galera_2nodes.cnf
[mysqld.1]
wsrep_auto_increment_control=OFF
[mysqld.2]
wsrep_auto_increment_control=OFF
@@ -0,0 +1,53 @@
#
# MDEV-15443
#
# If transactions are executed into InnoDB without wsrep_on,
# rseg header trx_id gets incremented and the rseg header
# corresponding to maximum trx_id may store undefined wsrep XID.
# When the wsrep XID is read from the storage engine,
# undefined XID may returned instead the valid one.
#
# This test demonstrates the problem by taking a node_2 out
# of the cluster and writing and deleting a row with
# wsrep_on=0. When the bug is present, node_2 will fail to
# rejoin the cluster because an invalid XID is read from the
# storage engine after startup/recovery.
#

--source include/have_innodb.inc
--source include/galera_cluster.inc

# Initialize table on node_1
CREATE TABLE t1 (f1 INT PRIMARY KEY) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1);

# Go to node_2, verify that the previous INSERT completed.
# Take node_2 out of the cluster, insert and delete a record
# on a table with wsrep_on.
--connection node_2
SELECT * FROM t1;
SET GLOBAL wsrep_cluster_address='';
SET SESSION wsrep_on=0;
INSERT INTO t1 VALUES (2);
DELETE FROM t1 WHERE f1 = 2;

# Shutdown node_2
--source include/shutdown_mysqld.inc

# On node_1, verify that the node has left the cluster.
--connection node_1
--let $wait_condition = SELECT VARIABLE_VALUE = 1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size';
--source include/wait_condition.inc

# Insert into t1 to enforce IST on node_2 when it is restarted.
INSERT INTO t1 VALUES (2);

# Restart node_2
--connection node_2
--source include/start_mysqld.inc
--let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size';
--source include/wait_condition.inc

--connection node_1
--source include/wait_condition.inc
DROP TABLE t1;
@@ -281,16 +281,15 @@ trx_rseg_update_wsrep_checkpoint(
const XID* xid,
mtr_t* mtr);

/** Update WSREP checkpoint XID in first rollback segment header.
/** Update WSREP checkpoint XID in first rollback segment header
as part of wsrep_set_SE_checkpoint() when it is guaranteed that there
are no wsrep transactions committing.
If the UUID part of the WSREP XID does not match to the UUIDs of XIDs already
stored into rollback segments, the WSREP XID in all the remaining rollback
segments will be reset.
@param[in] xid WSREP XID */
void trx_rseg_update_wsrep_checkpoint(const XID* xid);

/** Read the WSREP XID information in rollback segment header.
@param[in] rseg_header Rollback segment header
@param[out] xid Transaction XID
@return whether the WSREP XID was present */
bool trx_rseg_read_wsrep_checkpoint(const trx_rsegf_t* rseg_header, XID& xid);

/** Recover the latest WSREP checkpoint XID.
@param[out] xid WSREP XID
@return whether the WSREP XID was found */
@@ -849,7 +849,7 @@ class trx_sys_t
XID recovered_wsrep_xid;
#endif
/** Latest recovered binlog offset */
int64_t recovered_binlog_offset;
uint64_t recovered_binlog_offset;
/** Latest recovred binlog file name */
char recovered_binlog_filename[TRX_SYS_MYSQL_LOG_NAME_LEN];

@@ -254,12 +254,10 @@ trx_purge_add_undo_to_history(const trx_t* trx, trx_undo_t*& undo, mtr_t* mtr)
mlog_write_ulint(
rseg_header + TRX_RSEG_HISTORY_SIZE,
hist_size + undo->size, MLOG_4BYTES, mtr);
}

/* This field now also serves as an identifier for the latest
binlog and WSREP XID information. */
mlog_write_ull(rseg_header + TRX_RSEG_MAX_TRX_ID,
trx_sys.get_max_trx_id(), mtr);
mlog_write_ull(rseg_header + TRX_RSEG_MAX_TRX_ID,
trx_sys.get_max_trx_id(), mtr);
}

/* Before any transaction-generating background threads or the
purge have been started, recv_recovery_rollback_active() can

0 comments on commit 67f6d40

Please sign in to comment.