[Commits] 391b1af0fbb: MDEV-13471: Test failure on innodb.log_file_size, 4k

jan jan.lindstrom at mariadb.com
Thu Aug 10 13:46:36 EEST 2017


revision-id: 391b1af0fbb9723ce768d0b06830865fa983a8dd (mariadb-galera-10.0.31-3-g391b1af0fbb)
parent(s): 56b03e308fb4c0feee166ddf6a707d855affa3c3
author: Jan Lindström
committer: Jan Lindström
timestamp: 2017-08-10 13:09:27 +0300
message:

MDEV-13471: Test failure on innodb.log_file_size,4k

Problem was that 4k page size is not really supported in
Galera. For reference see:
	codership/galera#398

Page size 4k is problematic because WSREP XID info location
that was set to constant UNIV_PAGE_SIZE - 3500 and that is conflicting
with rseg undo slots location if there is lot of undo tablespaces.
Undo tablespace identifiers and page numbers require
at least 126*8=1024 bytes starting from offset 56. Therefore,
WSREP XID startig from offset 596 would overwrite several
space_id,page_no pairs starting from 72th undo log tablespace
space_id,page_no pair at offset 594.
This will cause InnoDB startup failure seen as
[ERROR] InnoDB: Unable to open undo tablespace './undo30579'.

Originally, the undo tablespace ID would always be between
0 and 127. Starting with MySQL 5.6.36 which introduced
Bug #25551311 BACKPORT BUG #23517560 REMOVE SPACE_ID RESTRICTION
FOR UNDO TABLESPACES (merged to MariaDB 10.0.31)
it is possible for an undo tablespace ID to be 0x7773. But in
this case, the page number should be 3, not 0x72650003.
This is just the first collision. The WSREP XID data would
overwrite subsequent slots.

trx0sys.h

trx0sys.cc
	Code formatting and add comments.

---
 storage/innobase/include/trx0sys.h |  86 +++++++++++++++++---
 storage/innobase/trx/trx0sys.cc    | 161 ++++++++++++++++++++-----------------
 storage/xtradb/include/trx0sys.h   |  86 +++++++++++++++++---
 storage/xtradb/trx/trx0sys.cc      | 161 ++++++++++++++++++++-----------------
 4 files changed, 322 insertions(+), 172 deletions(-)

diff --git a/storage/innobase/include/trx0sys.h b/storage/innobase/include/trx0sys.h
index 8c6b13f9dd4..83814d088f3 100644
--- a/storage/innobase/include/trx0sys.h
+++ b/storage/innobase/include/trx0sys.h
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -307,19 +308,26 @@ UNIV_INTERN
 void
 trx_sys_print_mysql_binlog_offset(void);
 /*===================================*/
+
 #ifdef WITH_WSREP
-/** Update WSREP checkpoint XID in sys header. */
+
+/** Update WSREP XID info in sys_header of TRX_SYS_PAGE_NO = 5.
+ at param[in]	xid		Transaction XID
+ at param[in,out]	sys_header	sys_header
+ at param[in]	mtr		minitransaction */
 void
 trx_sys_update_wsrep_checkpoint(
-        const XID*      xid,         /*!< in: WSREP XID */
-        trx_sysf_t*     sys_header,  /*!< in: sys_header */
-        mtr_t*          mtr);        /*!< in: mtr       */
+	const XID*	xid,
+	trx_sysf_t*	sys_header,
+	mtr_t*		mtr);
 
+/** Read WSREP XID from sys_header of TRX_SYS_PAGE_NO = 5.
+ at param[out]	xid	Transaction XID */
 void
-/** Read WSREP checkpoint XID from sys header. */
-trx_sys_read_wsrep_checkpoint(
-        XID* xid); /*!< out: WSREP XID */
+trx_sys_read_wsrep_checkpoint(XID* xid);
+
 #endif /* WITH_WSREP */
+
 /*****************************************************************//**
 Prints to stderr the MySQL master log offset info in the trx system header if
 the magic number shows it valid. */
@@ -548,13 +556,71 @@ this contains the same fields as TRX_SYS_MYSQL_LOG_INFO below */
 						within that file */
 #define TRX_SYS_MYSQL_LOG_NAME		12	/*!< MySQL log file name */
 
+/** Memory map TRX_SYS_PAGE_NO = 5 when UNIV_PAGE_SIZE = 4096
+
+0...37 FIL_HEADER
+38...45 TRX_SYS_TRX_ID_STORE
+46...55 TRX_SYS_FSEG_HEADER (FSEG_HEADER_SIZE == 10)
+56      TRX_SYS_RSEGS
+  56...59  TRX_SYS_RSEG_SPACE       for slot 0
+  60...63  TRX_SYS_RSEG_PAGE_NO     for slot 0
+  64...67  TRX_SYS_RSEG_SPACE       for slot 1
+  68...71  TRX_SYS_RSEG_PAGE_NO     for slot 1
+....
+ 594..597  TRX_SYS_RSEG_SPACE       for slot 72
+ 598..601  TRX_SYS_RSEG_PAGE_NO     for slot 72
+...
+  ...1063  TRX_SYS_RSEG_PAGE_NO     for slot 126
+
+(UNIV_PAGE_SIZE-3500 WSREP ::: FAIL would overwrite undo tablespace
+space_id, page_no pairs :::)
+596 TRX_SYS_WSREP_XID_INFO             TRX_SYS_WSREP_XID_MAGIC_N_FLD
+600 TRX_SYS_WSREP_XID_FORMAT
+604 TRX_SYS_WSREP_XID_GTRID_LEN
+608 TRX_SYS_WSREP_XID_BQUAL_LEN
+612 TRX_SYS_WSREP_XID_DATA   (len = 128)
+739 TRX_SYS_WSREP_XID_DATA_END
+
+FIXED WSREP XID info offsets for 4k page size 10.0.32-galera
+(UNIV_PAGE_SIZE-2500)
+1596 TRX_SYS_WSREP_XID_INFO             TRX_SYS_WSREP_XID_MAGIC_N_FLD
+1600 TRX_SYS_WSREP_XID_FORMAT
+1604 TRX_SYS_WSREP_XID_GTRID_LEN
+1608 TRX_SYS_WSREP_XID_BQUAL_LEN
+1612 TRX_SYS_WSREP_XID_DATA   (len = 128)
+1739 TRX_SYS_WSREP_XID_DATA_END
+
+(UNIV_PAGE_SIZE - 2000 MYSQL MASTER LOG)
+2096   TRX_SYS_MYSQL_MASTER_LOG_INFO   TRX_SYS_MYSQL_LOG_MAGIC_N_FLD
+2100   TRX_SYS_MYSQL_LOG_OFFSET_HIGH
+2104   TRX_SYS_MYSQL_LOG_OFFSET_LOW
+2108   TRX_SYS_MYSQL_LOG_NAME
+
+(UNIV_PAGE_SIZE - 1000 MYSQL LOG)
+3096   TRX_SYS_MYSQL_LOG_INFO          TRX_SYS_MYSQL_LOG_MAGIC_N_FLD
+3100   TRX_SYS_MYSQL_LOG_OFFSET_HIGH
+3104   TRX_SYS_MYSQL_LOG_OFFSET_LOW
+3108   TRX_SYS_MYSQL_LOG_NAME
+
+(UNIV_PAGE_SIZE - 200 DOUBLEWRITE)
+3896   TRX_SYS_DOUBLEWRITE		TRX_SYS_DOUBLEWRITE_FSEG
+3906         TRX_SYS_DOUBLEWRITE_MAGIC
+3910         TRX_SYS_DOUBLEWRITE_BLOCK1
+3914         TRX_SYS_DOUBLEWRITE_BLOCK2
+3918         TRX_SYS_DOUBLEWRITE_REPEAT
+3930         TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED_N
+
+(UNIV_PAGE_SIZE - 8, TAILER)
+4088..4096	FIL_TAILER
+
+*/
 #ifdef WITH_WSREP
-/* The offset to WSREP XID headers */
-#define TRX_SYS_WSREP_XID_INFO (UNIV_PAGE_SIZE - 3500)
+/** The offset to WSREP XID headers */
+#define TRX_SYS_WSREP_XID_INFO (ut_max(UNIV_PAGE_SIZE - 3500, 1596))
 #define TRX_SYS_WSREP_XID_MAGIC_N_FLD 0
 #define TRX_SYS_WSREP_XID_MAGIC_N 0x77737265
 
-/* XID field: formatID, gtrid_len, bqual_len, xid_data */
+/** XID field: formatID, gtrid_len, bqual_len, xid_data */
 #define TRX_SYS_WSREP_XID_LEN        (4 + 4 + 4 + XIDDATASIZE)
 #define TRX_SYS_WSREP_XID_FORMAT     4
 #define TRX_SYS_WSREP_XID_GTRID_LEN  8
diff --git a/storage/innobase/trx/trx0sys.cc b/storage/innobase/trx/trx0sys.cc
index 7f8bbafe99c..152813d9f3b 100644
--- a/storage/innobase/trx/trx0sys.cc
+++ b/storage/innobase/trx/trx0sys.cc
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1996, 2017, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -325,112 +326,120 @@ trx_sys_print_mysql_binlog_offset(void)
 static long long trx_sys_cur_xid_seqno = -1;
 static unsigned char trx_sys_cur_xid_uuid[16];
 
-long long read_wsrep_xid_seqno(const XID* xid)
+/** Read WSREP XID seqno */
+static inline long long read_wsrep_xid_seqno(const XID* xid)
 {
-    long long seqno;
-    memcpy(&seqno, xid->data + 24, sizeof(long long));
-    return seqno;
+	long long seqno;
+	memcpy(&seqno, xid->data + 24, sizeof(long long));
+	return seqno;
 }
 
-void read_wsrep_xid_uuid(const XID* xid, unsigned char* buf)
+/** Read WSREP XID UUID */
+static inline void read_wsrep_xid_uuid(const XID* xid, unsigned char* buf)
 {
-    memcpy(buf, xid->data + 8, 16);
+	memcpy(buf, xid->data + 8, 16);
 }
 
 #endif /* UNIV_DEBUG */
 
+/** Update WSREP XID info in sys_header of TRX_SYS_PAGE_NO = 5.
+ at param[in]	xid		Transaction XID
+ at param[in,out]	sys_header	sys_header
+ at param[in]	mtr		minitransaction */
 void
 trx_sys_update_wsrep_checkpoint(
-        const XID*      xid,        /*!< in: transaction XID */
-        trx_sysf_t*     sys_header, /*!< in: sys_header */
-        mtr_t*          mtr)        /*!< in: mtr */
+	const XID*	xid,
+	trx_sysf_t*	sys_header,
+	mtr_t*		mtr)
 {
 #ifdef UNIV_DEBUG
-        {
-            /* Check that seqno is monotonically increasing */
-            unsigned char xid_uuid[16];
-            long long xid_seqno = read_wsrep_xid_seqno(xid);
-            read_wsrep_xid_uuid(xid, xid_uuid);
-            if (!memcmp(xid_uuid, trx_sys_cur_xid_uuid, 8))
-            {
-                ut_ad(xid_seqno > trx_sys_cur_xid_seqno);
-                trx_sys_cur_xid_seqno = xid_seqno;
-            }
-            else
-            {
-                memcpy(trx_sys_cur_xid_uuid, xid_uuid, 16);
-            }
-            trx_sys_cur_xid_seqno = xid_seqno;
-        }
+	if (xid->formatID != -1
+	    && mach_read_from_4(sys_header + TRX_SYS_WSREP_XID_INFO
+			+ TRX_SYS_WSREP_XID_MAGIC_N_FLD)
+		== TRX_SYS_WSREP_XID_MAGIC_N) {
+		/* Check that seqno is monotonically increasing */
+		unsigned char xid_uuid[16];
+		long long xid_seqno = read_wsrep_xid_seqno(xid);
+		read_wsrep_xid_uuid(xid, xid_uuid);
+
+		if (!memcmp(xid_uuid, trx_sys_cur_xid_uuid, 8)) {
+			ut_ad(xid_seqno > trx_sys_cur_xid_seqno);
+			trx_sys_cur_xid_seqno = xid_seqno;
+		} else {
+			memcpy(trx_sys_cur_xid_uuid, xid_uuid, 16);
+		}
+
+		trx_sys_cur_xid_seqno = xid_seqno;
+	}
 #endif /* UNIV_DEBUG */
 
-        ut_ad(xid && mtr);
-        ut_a(xid->formatID == -1 || wsrep_is_wsrep_xid(xid));
+	ut_ad(xid && mtr);
+	ut_a(xid->formatID == -1 || wsrep_is_wsrep_xid((const void *)xid));
 
-        if (mach_read_from_4(sys_header + TRX_SYS_WSREP_XID_INFO
-                             + TRX_SYS_WSREP_XID_MAGIC_N_FLD)
-            != TRX_SYS_WSREP_XID_MAGIC_N) {
-                mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
-                                 + TRX_SYS_WSREP_XID_MAGIC_N_FLD,
-                                 TRX_SYS_WSREP_XID_MAGIC_N,
-                                 MLOG_4BYTES, mtr);
-        }
-
-        mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
-                         + TRX_SYS_WSREP_XID_FORMAT,
-                         (int)xid->formatID,
-                         MLOG_4BYTES, mtr);
-        mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
-                         + TRX_SYS_WSREP_XID_GTRID_LEN,
-                         (int)xid->gtrid_length,
-                         MLOG_4BYTES, mtr);
-        mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
-                         + TRX_SYS_WSREP_XID_BQUAL_LEN,
-                         (int)xid->bqual_length,
-                         MLOG_4BYTES, mtr);
-        mlog_write_string(sys_header + TRX_SYS_WSREP_XID_INFO
-                          + TRX_SYS_WSREP_XID_DATA,
-                          (const unsigned char*) xid->data,
-                          XIDDATASIZE, mtr);
+	if (mach_read_from_4(sys_header + TRX_SYS_WSREP_XID_INFO
+			+ TRX_SYS_WSREP_XID_MAGIC_N_FLD)
+		!= TRX_SYS_WSREP_XID_MAGIC_N) {
+		mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
+			+ TRX_SYS_WSREP_XID_MAGIC_N_FLD,
+			TRX_SYS_WSREP_XID_MAGIC_N,
+			MLOG_4BYTES, mtr);
+	}
 
+	mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
+		+ TRX_SYS_WSREP_XID_FORMAT,
+		(int)xid->formatID,
+		MLOG_4BYTES, mtr);
+	mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
+		+ TRX_SYS_WSREP_XID_GTRID_LEN,
+		(int)xid->gtrid_length,
+		MLOG_4BYTES, mtr);
+	mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
+		+ TRX_SYS_WSREP_XID_BQUAL_LEN,
+		(int)xid->bqual_length,
+		MLOG_4BYTES, mtr);
+	mlog_write_string(sys_header + TRX_SYS_WSREP_XID_INFO
+		+ TRX_SYS_WSREP_XID_DATA,
+		(const unsigned char*) xid->data,
+		XIDDATASIZE, mtr);
 }
 
+/** Read WSREP XID from sys_header of TRX_SYS_PAGE_NO = 5.
+ at param[out]	xid	Transaction XID */
 void
 trx_sys_read_wsrep_checkpoint(XID* xid)
-/*===================================*/
 {
-        trx_sysf_t* sys_header;
+	trx_sysf_t* sys_header;
 	mtr_t	    mtr;
-        ulint       magic;
+	ulint       magic;
 
-        ut_ad(xid);
+	ut_ad(xid);
 
 	mtr_start(&mtr);
 
 	sys_header = trx_sysf_get(&mtr);
 
-        if ((magic = mach_read_from_4(sys_header + TRX_SYS_WSREP_XID_INFO
-                                      + TRX_SYS_WSREP_XID_MAGIC_N_FLD))
-            != TRX_SYS_WSREP_XID_MAGIC_N) {
-                memset(xid, 0, sizeof(*xid));
-                xid->formatID = -1;
-                trx_sys_update_wsrep_checkpoint(xid, sys_header, &mtr);
-                mtr_commit(&mtr);
-                return;
+	if ((magic = mach_read_from_4(sys_header + TRX_SYS_WSREP_XID_INFO
+				+ TRX_SYS_WSREP_XID_MAGIC_N_FLD))
+		!= TRX_SYS_WSREP_XID_MAGIC_N) {
+		memset(xid, 0, sizeof(*xid));
+		xid->formatID = -1;
+		trx_sys_update_wsrep_checkpoint(xid, sys_header, &mtr);
+		mtr_commit(&mtr);
+		return;
         }
 
-        xid->formatID     = (int)mach_read_from_4(
-                sys_header
-                + TRX_SYS_WSREP_XID_INFO + TRX_SYS_WSREP_XID_FORMAT);
-        xid->gtrid_length = (int)mach_read_from_4(
-                sys_header
-                + TRX_SYS_WSREP_XID_INFO + TRX_SYS_WSREP_XID_GTRID_LEN);
-        xid->bqual_length = (int)mach_read_from_4(
-                sys_header
-                + TRX_SYS_WSREP_XID_INFO + TRX_SYS_WSREP_XID_BQUAL_LEN);
-        ut_memcpy(xid->data,
-                  sys_header + TRX_SYS_WSREP_XID_INFO + TRX_SYS_WSREP_XID_DATA,
-                  XIDDATASIZE);
+	xid->formatID     = (int)mach_read_from_4(
+		sys_header
+		+ TRX_SYS_WSREP_XID_INFO + TRX_SYS_WSREP_XID_FORMAT);
+	xid->gtrid_length = (int)mach_read_from_4(
+		sys_header
+		+ TRX_SYS_WSREP_XID_INFO + TRX_SYS_WSREP_XID_GTRID_LEN);
+	xid->bqual_length = (int)mach_read_from_4(
+		sys_header
+		+ TRX_SYS_WSREP_XID_INFO + TRX_SYS_WSREP_XID_BQUAL_LEN);
+	ut_memcpy(xid->data,
+		sys_header + TRX_SYS_WSREP_XID_INFO + TRX_SYS_WSREP_XID_DATA,
+		XIDDATASIZE);
 
 	mtr_commit(&mtr);
 }
diff --git a/storage/xtradb/include/trx0sys.h b/storage/xtradb/include/trx0sys.h
index e4956c6a822..7f06d3247a1 100644
--- a/storage/xtradb/include/trx0sys.h
+++ b/storage/xtradb/include/trx0sys.h
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -328,19 +329,26 @@ UNIV_INTERN
 void
 trx_sys_print_mysql_binlog_offset(void);
 /*===================================*/
+
 #ifdef WITH_WSREP
-/** Update WSREP checkpoint XID in sys header. */
+
+/** Update WSREP XID info in sys_header of TRX_SYS_PAGE_NO = 5.
+ at param[in]	xid		Transaction XID
+ at param[in,out]	sys_header	sys_header
+ at param[in]	mtr		minitransaction */
 void
 trx_sys_update_wsrep_checkpoint(
-        const XID*      xid,         /*!< in: WSREP XID */
-        trx_sysf_t*     sys_header,  /*!< in: sys_header */
-        mtr_t*          mtr);        /*!< in: mtr       */
+	const XID*	xid,
+	trx_sysf_t*	sys_header,
+	mtr_t*		mtr);
 
+/** Read WSREP XID from sys_header of TRX_SYS_PAGE_NO = 5.
+ at param[out]	xid	Transaction XID */
 void
-/** Read WSREP checkpoint XID from sys header. */
-trx_sys_read_wsrep_checkpoint(
-        XID* xid); /*!< out: WSREP XID */
+trx_sys_read_wsrep_checkpoint(XID* xid);
+
 #endif /* WITH_WSREP */
+
 /*****************************************************************//**
 Prints to stderr the MySQL master log offset info in the trx system header if
 the magic number shows it valid. */
@@ -569,13 +577,71 @@ this contains the same fields as TRX_SYS_MYSQL_LOG_INFO below */
 						within that file */
 #define TRX_SYS_MYSQL_LOG_NAME		12	/*!< MySQL log file name */
 
+/** Memory map TRX_SYS_PAGE_NO = 5 when UNIV_PAGE_SIZE = 4096
+
+0...37 FIL_HEADER
+38...45 TRX_SYS_TRX_ID_STORE
+46...55 TRX_SYS_FSEG_HEADER (FSEG_HEADER_SIZE == 10)
+56      TRX_SYS_RSEGS
+  56...59  TRX_SYS_RSEG_SPACE       for slot 0
+  60...63  TRX_SYS_RSEG_PAGE_NO     for slot 0
+  64...67  TRX_SYS_RSEG_SPACE       for slot 1
+  68...71  TRX_SYS_RSEG_PAGE_NO     for slot 1
+....
+ 594..597  TRX_SYS_RSEG_SPACE       for slot 72
+ 598..601  TRX_SYS_RSEG_PAGE_NO     for slot 72
+...
+  ...1063  TRX_SYS_RSEG_PAGE_NO     for slot 126
+
+(UNIV_PAGE_SIZE-3500 WSREP ::: FAIL would overwrite undo tablespace
+space_id, page_no pairs :::)
+596 TRX_SYS_WSREP_XID_INFO             TRX_SYS_WSREP_XID_MAGIC_N_FLD
+600 TRX_SYS_WSREP_XID_FORMAT
+604 TRX_SYS_WSREP_XID_GTRID_LEN
+608 TRX_SYS_WSREP_XID_BQUAL_LEN
+612 TRX_SYS_WSREP_XID_DATA   (len = 128)
+739 TRX_SYS_WSREP_XID_DATA_END
+
+FIXED WSREP XID info offsets for 4k page size 10.0.32-galera
+(UNIV_PAGE_SIZE-2500)
+1596 TRX_SYS_WSREP_XID_INFO             TRX_SYS_WSREP_XID_MAGIC_N_FLD
+1600 TRX_SYS_WSREP_XID_FORMAT
+1604 TRX_SYS_WSREP_XID_GTRID_LEN
+1608 TRX_SYS_WSREP_XID_BQUAL_LEN
+1612 TRX_SYS_WSREP_XID_DATA   (len = 128)
+1739 TRX_SYS_WSREP_XID_DATA_END
+
+(UNIV_PAGE_SIZE - 2000 MYSQL MASTER LOG)
+2096   TRX_SYS_MYSQL_MASTER_LOG_INFO   TRX_SYS_MYSQL_LOG_MAGIC_N_FLD
+2100   TRX_SYS_MYSQL_LOG_OFFSET_HIGH
+2104   TRX_SYS_MYSQL_LOG_OFFSET_LOW
+2108   TRX_SYS_MYSQL_LOG_NAME
+
+(UNIV_PAGE_SIZE - 1000 MYSQL LOG)
+3096   TRX_SYS_MYSQL_LOG_INFO          TRX_SYS_MYSQL_LOG_MAGIC_N_FLD
+3100   TRX_SYS_MYSQL_LOG_OFFSET_HIGH
+3104   TRX_SYS_MYSQL_LOG_OFFSET_LOW
+3108   TRX_SYS_MYSQL_LOG_NAME
+
+(UNIV_PAGE_SIZE - 200 DOUBLEWRITE)
+3896   TRX_SYS_DOUBLEWRITE		TRX_SYS_DOUBLEWRITE_FSEG
+3906         TRX_SYS_DOUBLEWRITE_MAGIC
+3910         TRX_SYS_DOUBLEWRITE_BLOCK1
+3914         TRX_SYS_DOUBLEWRITE_BLOCK2
+3918         TRX_SYS_DOUBLEWRITE_REPEAT
+3930         TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED_N
+
+(UNIV_PAGE_SIZE - 8, TAILER)
+4088..4096	FIL_TAILER
+
+*/
 #ifdef WITH_WSREP
-/* The offset to WSREP XID headers */
-#define TRX_SYS_WSREP_XID_INFO (UNIV_PAGE_SIZE - 3500)
+/** The offset to WSREP XID headers */
+#define TRX_SYS_WSREP_XID_INFO (ut_max(UNIV_PAGE_SIZE - 3500, 1596))
 #define TRX_SYS_WSREP_XID_MAGIC_N_FLD 0
 #define TRX_SYS_WSREP_XID_MAGIC_N 0x77737265
 
-/* XID field: formatID, gtrid_len, bqual_len, xid_data */
+/** XID field: formatID, gtrid_len, bqual_len, xid_data */
 #define TRX_SYS_WSREP_XID_LEN        (4 + 4 + 4 + XIDDATASIZE)
 #define TRX_SYS_WSREP_XID_FORMAT     4
 #define TRX_SYS_WSREP_XID_GTRID_LEN  8
diff --git a/storage/xtradb/trx/trx0sys.cc b/storage/xtradb/trx/trx0sys.cc
index 9a0b7180435..8c11d22489a 100644
--- a/storage/xtradb/trx/trx0sys.cc
+++ b/storage/xtradb/trx/trx0sys.cc
@@ -1,6 +1,7 @@
 /*****************************************************************************
 
 Copyright (c) 1996, 2017, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2017, MariaDB Corporation.
 
 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
@@ -325,112 +326,120 @@ trx_sys_print_mysql_binlog_offset(void)
 static long long trx_sys_cur_xid_seqno = -1;
 static unsigned char trx_sys_cur_xid_uuid[16];
 
-long long read_wsrep_xid_seqno(const XID* xid)
+/** Read WSREP XID seqno */
+static inline long long read_wsrep_xid_seqno(const XID* xid)
 {
-    long long seqno;
-    memcpy(&seqno, xid->data + 24, sizeof(long long));
-    return seqno;
+	long long seqno;
+	memcpy(&seqno, xid->data + 24, sizeof(long long));
+	return seqno;
 }
 
-void read_wsrep_xid_uuid(const XID* xid, unsigned char* buf)
+/** Read WSREP XID UUID */
+static inline void read_wsrep_xid_uuid(const XID* xid, unsigned char* buf)
 {
-    memcpy(buf, xid->data + 8, 16);
+	memcpy(buf, xid->data + 8, 16);
 }
 
 #endif /* UNIV_DEBUG */
 
+/** Update WSREP XID info in sys_header of TRX_SYS_PAGE_NO = 5.
+ at param[in]	xid		Transaction XID
+ at param[in,out]	sys_header	sys_header
+ at param[in]	mtr		minitransaction */
 void
 trx_sys_update_wsrep_checkpoint(
-        const XID*      xid,        /*!< in: transaction XID */
-        trx_sysf_t*     sys_header, /*!< in: sys_header */
-        mtr_t*          mtr)        /*!< in: mtr */
+	const XID*	xid,
+	trx_sysf_t*	sys_header,
+	mtr_t*		mtr)
 {
 #ifdef UNIV_DEBUG
-        {
-            /* Check that seqno is monotonically increasing */
-            unsigned char xid_uuid[16];
-            long long xid_seqno = read_wsrep_xid_seqno(xid);
-            read_wsrep_xid_uuid(xid, xid_uuid);
-            if (!memcmp(xid_uuid, trx_sys_cur_xid_uuid, 8))
-            {
-                ut_ad(xid_seqno > trx_sys_cur_xid_seqno);
-                trx_sys_cur_xid_seqno = xid_seqno;
-            }
-            else
-            {
-                memcpy(trx_sys_cur_xid_uuid, xid_uuid, 16);
-            }
-            trx_sys_cur_xid_seqno = xid_seqno;
-        }
+	if (xid->formatID != -1
+	    && mach_read_from_4(sys_header + TRX_SYS_WSREP_XID_INFO
+			+ TRX_SYS_WSREP_XID_MAGIC_N_FLD)
+		== TRX_SYS_WSREP_XID_MAGIC_N) {
+		/* Check that seqno is monotonically increasing */
+		unsigned char xid_uuid[16];
+		long long xid_seqno = read_wsrep_xid_seqno(xid);
+		read_wsrep_xid_uuid(xid, xid_uuid);
+
+		if (!memcmp(xid_uuid, trx_sys_cur_xid_uuid, 8)) {
+			ut_ad(xid_seqno > trx_sys_cur_xid_seqno);
+			trx_sys_cur_xid_seqno = xid_seqno;
+		} else {
+			memcpy(trx_sys_cur_xid_uuid, xid_uuid, 16);
+		}
+
+		trx_sys_cur_xid_seqno = xid_seqno;
+	}
 #endif /* UNIV_DEBUG */
 
-        ut_ad(xid && mtr);
-        ut_a(xid->formatID == -1 || wsrep_is_wsrep_xid((const void *)xid));
+	ut_ad(xid && mtr);
+	ut_a(xid->formatID == -1 || wsrep_is_wsrep_xid((const void *)xid));
 
-        if (mach_read_from_4(sys_header + TRX_SYS_WSREP_XID_INFO
-                             + TRX_SYS_WSREP_XID_MAGIC_N_FLD)
-            != TRX_SYS_WSREP_XID_MAGIC_N) {
-                mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
-                                 + TRX_SYS_WSREP_XID_MAGIC_N_FLD,
-                                 TRX_SYS_WSREP_XID_MAGIC_N,
-                                 MLOG_4BYTES, mtr);
-        }
-
-        mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
-                         + TRX_SYS_WSREP_XID_FORMAT,
-                         (int)xid->formatID,
-                         MLOG_4BYTES, mtr);
-        mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
-                         + TRX_SYS_WSREP_XID_GTRID_LEN,
-                         (int)xid->gtrid_length,
-                         MLOG_4BYTES, mtr);
-        mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
-                         + TRX_SYS_WSREP_XID_BQUAL_LEN,
-                         (int)xid->bqual_length,
-                         MLOG_4BYTES, mtr);
-        mlog_write_string(sys_header + TRX_SYS_WSREP_XID_INFO
-                          + TRX_SYS_WSREP_XID_DATA,
-                          (const unsigned char*) xid->data,
-                          XIDDATASIZE, mtr);
+	if (mach_read_from_4(sys_header + TRX_SYS_WSREP_XID_INFO
+			+ TRX_SYS_WSREP_XID_MAGIC_N_FLD)
+		!= TRX_SYS_WSREP_XID_MAGIC_N) {
+		mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
+			+ TRX_SYS_WSREP_XID_MAGIC_N_FLD,
+			TRX_SYS_WSREP_XID_MAGIC_N,
+			MLOG_4BYTES, mtr);
+	}
 
+	mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
+		+ TRX_SYS_WSREP_XID_FORMAT,
+		(int)xid->formatID,
+		MLOG_4BYTES, mtr);
+	mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
+		+ TRX_SYS_WSREP_XID_GTRID_LEN,
+		(int)xid->gtrid_length,
+		MLOG_4BYTES, mtr);
+	mlog_write_ulint(sys_header + TRX_SYS_WSREP_XID_INFO
+		+ TRX_SYS_WSREP_XID_BQUAL_LEN,
+		(int)xid->bqual_length,
+		MLOG_4BYTES, mtr);
+	mlog_write_string(sys_header + TRX_SYS_WSREP_XID_INFO
+		+ TRX_SYS_WSREP_XID_DATA,
+		(const unsigned char*) xid->data,
+		XIDDATASIZE, mtr);
 }
 
+/** Read WSREP XID from sys_header of TRX_SYS_PAGE_NO = 5.
+ at param[out]	xid	Transaction XID */
 void
 trx_sys_read_wsrep_checkpoint(XID* xid)
-/*===================================*/
 {
-        trx_sysf_t* sys_header;
+	trx_sysf_t* sys_header;
 	mtr_t	    mtr;
-        ulint       magic;
+	ulint       magic;
 
-        ut_ad(xid);
+	ut_ad(xid);
 
 	mtr_start(&mtr);
 
 	sys_header = trx_sysf_get(&mtr);
 
-        if ((magic = mach_read_from_4(sys_header + TRX_SYS_WSREP_XID_INFO
-                                      + TRX_SYS_WSREP_XID_MAGIC_N_FLD))
-            != TRX_SYS_WSREP_XID_MAGIC_N) {
-                memset(xid, 0, sizeof(*xid));
-                xid->formatID = -1;
-                trx_sys_update_wsrep_checkpoint(xid, sys_header, &mtr);
-                mtr_commit(&mtr);
-                return;
+	if ((magic = mach_read_from_4(sys_header + TRX_SYS_WSREP_XID_INFO
+				+ TRX_SYS_WSREP_XID_MAGIC_N_FLD))
+		!= TRX_SYS_WSREP_XID_MAGIC_N) {
+		memset(xid, 0, sizeof(*xid));
+		xid->formatID = -1;
+		trx_sys_update_wsrep_checkpoint(xid, sys_header, &mtr);
+		mtr_commit(&mtr);
+		return;
         }
 
-        xid->formatID     = (int)mach_read_from_4(
-                sys_header
-                + TRX_SYS_WSREP_XID_INFO + TRX_SYS_WSREP_XID_FORMAT);
-        xid->gtrid_length = (int)mach_read_from_4(
-                sys_header
-                + TRX_SYS_WSREP_XID_INFO + TRX_SYS_WSREP_XID_GTRID_LEN);
-        xid->bqual_length = (int)mach_read_from_4(
-                sys_header
-                + TRX_SYS_WSREP_XID_INFO + TRX_SYS_WSREP_XID_BQUAL_LEN);
-        ut_memcpy(xid->data,
-                  sys_header + TRX_SYS_WSREP_XID_INFO + TRX_SYS_WSREP_XID_DATA,
-                  XIDDATASIZE);
+	xid->formatID     = (int)mach_read_from_4(
+		sys_header
+		+ TRX_SYS_WSREP_XID_INFO + TRX_SYS_WSREP_XID_FORMAT);
+	xid->gtrid_length = (int)mach_read_from_4(
+		sys_header
+		+ TRX_SYS_WSREP_XID_INFO + TRX_SYS_WSREP_XID_GTRID_LEN);
+	xid->bqual_length = (int)mach_read_from_4(
+		sys_header
+		+ TRX_SYS_WSREP_XID_INFO + TRX_SYS_WSREP_XID_BQUAL_LEN);
+	ut_memcpy(xid->data,
+		sys_header + TRX_SYS_WSREP_XID_INFO + TRX_SYS_WSREP_XID_DATA,
+		XIDDATASIZE);
 
 	mtr_commit(&mtr);
 }


More information about the commits mailing list