Commit 591edccc authored by Marko Mäkelä's avatar Marko Mäkelä

Simplify access to the binlog offset in InnoDB

trx_sys_print_mysql_binlog_offset(): Use 64-bit arithmetics and ib::info().

TRX_SYS_MYSQL_LOG_OFFSET: Replaces TRX_SYS_MYSQL_LOG_OFFSET_HIGH,
TRX_SYS_MYSQL_LOG_OFFSET_LOW.

trx_sys_update_mysql_binlog_offset(): Remove the constant parameter
field=TRX_SYS_MYSQL_LOG_INFO. Use 64-bit arithmetics.
parent aea0e125
......@@ -43,6 +43,6 @@ a
1
2
3
InnoDB: Last MySQL binlog file position 0 <pos>, file name ./master-bin.000001
InnoDB: Last binlog file './master-bin.000001', position <pos>
SET DEBUG_SYNC= 'RESET';
DROP TABLE t1;
......@@ -44,6 +44,6 @@ a
1
2
3
InnoDB: Last MySQL binlog file position 0 <pos>, file name ./master-bin.000001
InnoDB: Last binlog file './master-bin.000001', position <pos>
SET DEBUG_SYNC= 'RESET';
DROP TABLE t1;
......@@ -9,7 +9,7 @@
# Don't test this under valgrind, memory leaks will occur as we crash
--source include/not_valgrind.inc
# The test case currently uses grep and tail, which may be unavailable on
# The test case currently uses sed and tail, which may be unavailable on
# some windows systems. But see MWL#191 for how to remove the need for grep.
--source include/not_windows.inc
......@@ -99,7 +99,7 @@ SELECT * FROM t1 ORDER BY a;
let $MYSQLD_DATADIR= `SELECT @@datadir`;
let pos=`select $binlog_start_pos + 730`;
--replace_result $pos <pos>
--exec grep 'InnoDB: Last MySQL binlog file position' $MYSQLD_DATADIR/../../log/mysqld.1.err | tail -1
--exec sed -ne 's/.*\(InnoDB: Last binlog file .* position.*\)/\1/p' $MYSQLD_DATADIR/../../log/mysqld.1.err | tail -1
SET DEBUG_SYNC= 'RESET';
DROP TABLE t1;
......@@ -9,7 +9,7 @@
# Don't test this under valgrind, memory leaks will occur as we crash
--source include/not_valgrind.inc
# The test case currently uses grep and tail, which may be unavailable on
# The test case currently uses sed and tail, which may be unavailable on
# some windows systems. But see MWL#191 for how to remove the need for grep.
--source include/not_windows.inc
......@@ -100,6 +100,6 @@ SELECT * FROM t1 ORDER BY a;
let $MYSQLD_DATADIR= `SELECT @@datadir`;
let pos=`select $binlog_start_pos + 730`;
--replace_result $pos <pos>
--exec grep 'InnoDB: Last MySQL binlog file position' $MYSQLD_DATADIR/../../log/mysqld.1.err | tail -1
--exec sed -ne 's/.*\(InnoDB: Last binlog file .* position.*\)/\1/p' $MYSQLD_DATADIR/../../log/mysqld.1.err | tail -1
SET DEBUG_SYNC= 'RESET';
DROP TABLE t1;
......@@ -236,16 +236,12 @@ trx_sys_update_mysql_binlog_offset(
/*===============================*/
const char* file_name,/*!< in: MySQL log file name */
int64_t offset, /*!< in: position in that log file */
ulint field, /*!< in: offset of the MySQL log info field in
the trx sys header */
trx_sysf_t* sys_header, /*!< in: trx sys header */
mtr_t* mtr); /*!< in: mtr */
/*****************************************************************//**
Prints to stderr the MySQL binlog offset info in the trx system header if
the magic number shows it valid. */
/** Display the MySQL binlog offset info if it is present in the trx
system header. */
void
trx_sys_print_mysql_binlog_offset(void);
/*===================================*/
trx_sys_print_mysql_binlog_offset();
#ifdef WITH_WSREP
/** Update WSREP checkpoint XID in sys header. */
void
......@@ -420,9 +416,7 @@ impose the 7 bit restriction. e.g., mach_write_to_3() */
TRX_SYS_MYSQL_LOG_MAGIC_N
if we have valid data in the
MySQL binlog info */
#define TRX_SYS_MYSQL_LOG_OFFSET_HIGH 4 /*!< high 4 bytes of the offset
within that file */
#define TRX_SYS_MYSQL_LOG_OFFSET_LOW 8 /*!< low 4 bytes of the offset
#define TRX_SYS_MYSQL_LOG_OFFSET 4 /*!< the 64-bit offset
within that file */
#define TRX_SYS_MYSQL_LOG_NAME 12 /*!< MySQL log file name */
......
......@@ -176,95 +176,67 @@ trx_sys_update_mysql_binlog_offset(
/*===============================*/
const char* file_name,/*!< in: MySQL log file name */
int64_t offset, /*!< in: position in that log file */
ulint field, /*!< in: offset of the MySQL log info field in
the trx sys header */
trx_sysf_t* sys_header, /*!< in: trx sys header */
mtr_t* mtr) /*!< in: mtr */
{
DBUG_PRINT("InnoDB",("trx_mysql_binlog_offset: %lld", (longlong) offset));
if (ut_strlen(file_name) >= TRX_SYS_MYSQL_LOG_NAME_LEN) {
const size_t len = strlen(file_name) + 1;
if (len > TRX_SYS_MYSQL_LOG_NAME_LEN) {
/* We cannot fit the name to the 512 bytes we have reserved */
return;
}
if (mach_read_from_4(sys_header + field
+ TRX_SYS_MYSQL_LOG_MAGIC_N_FLD)
if (mach_read_from_4(TRX_SYS_MYSQL_LOG_MAGIC_N_FLD
+ TRX_SYS_MYSQL_LOG_INFO + sys_header)
!= TRX_SYS_MYSQL_LOG_MAGIC_N) {
mlog_write_ulint(sys_header + field
+ TRX_SYS_MYSQL_LOG_MAGIC_N_FLD,
mlog_write_ulint(TRX_SYS_MYSQL_LOG_MAGIC_N_FLD
+ TRX_SYS_MYSQL_LOG_INFO + sys_header,
TRX_SYS_MYSQL_LOG_MAGIC_N,
MLOG_4BYTES, mtr);
}
if (0 != strcmp((char*) (sys_header + field + TRX_SYS_MYSQL_LOG_NAME),
file_name)) {
mlog_write_string(sys_header + field
+ TRX_SYS_MYSQL_LOG_NAME,
(byte*) file_name, 1 + ut_strlen(file_name),
mtr);
}
if (mach_read_from_4(sys_header + field
+ TRX_SYS_MYSQL_LOG_OFFSET_HIGH) > 0
|| (offset >> 32) > 0) {
mlog_write_ulint(sys_header + field
+ TRX_SYS_MYSQL_LOG_OFFSET_HIGH,
(ulint)(offset >> 32),
MLOG_4BYTES, mtr);
if (memcmp(file_name, TRX_SYS_MYSQL_LOG_NAME + TRX_SYS_MYSQL_LOG_INFO
+ sys_header, len)) {
mlog_write_string(TRX_SYS_MYSQL_LOG_NAME
+ TRX_SYS_MYSQL_LOG_INFO
+ sys_header,
reinterpret_cast<const byte*>(file_name),
len, mtr);
}
mlog_write_ulint(sys_header + field
+ TRX_SYS_MYSQL_LOG_OFFSET_LOW,
(ulint)(offset & 0xFFFFFFFFUL),
MLOG_4BYTES, mtr);
mlog_write_ull(TRX_SYS_MYSQL_LOG_INFO + TRX_SYS_MYSQL_LOG_OFFSET
+ sys_header, offset, mtr);
}
/*****************************************************************//**
Stores the MySQL binlog offset info in the trx system header if
the magic number shows it valid, and print the info to stderr */
/** Display the MySQL binlog offset info if it is present in the trx
system header. */
void
trx_sys_print_mysql_binlog_offset(void)
/*===================================*/
trx_sys_print_mysql_binlog_offset()
{
trx_sysf_t* sys_header;
mtr_t mtr;
ulint trx_sys_mysql_bin_log_pos_high;
ulint trx_sys_mysql_bin_log_pos_low;
mtr_start(&mtr);
sys_header = trx_sysf_get(&mtr);
if (mach_read_from_4(sys_header + TRX_SYS_MYSQL_LOG_INFO
+ TRX_SYS_MYSQL_LOG_MAGIC_N_FLD)
!= TRX_SYS_MYSQL_LOG_MAGIC_N) {
mtr_commit(&mtr);
mtr.start();
return;
const trx_sysf_t* sys_header = trx_sysf_get(&mtr);
if (mach_read_from_4(TRX_SYS_MYSQL_LOG_INFO
+ TRX_SYS_MYSQL_LOG_MAGIC_N_FLD + sys_header)
== TRX_SYS_MYSQL_LOG_MAGIC_N) {
ib::info() << "Last binlog file '"
<< TRX_SYS_MYSQL_LOG_INFO + TRX_SYS_MYSQL_LOG_NAME
+ sys_header
<< "', position "
<< mach_read_from_8(TRX_SYS_MYSQL_LOG_INFO
+ TRX_SYS_MYSQL_LOG_OFFSET
+ sys_header);
}
trx_sys_mysql_bin_log_pos_high = mach_read_from_4(
sys_header + TRX_SYS_MYSQL_LOG_INFO
+ TRX_SYS_MYSQL_LOG_OFFSET_HIGH);
trx_sys_mysql_bin_log_pos_low = mach_read_from_4(
sys_header + TRX_SYS_MYSQL_LOG_INFO
+ TRX_SYS_MYSQL_LOG_OFFSET_LOW);
fprintf(stderr,
"InnoDB: Last MySQL binlog file position " ULINTPF " " ULINTPF
", file name %s\n",
trx_sys_mysql_bin_log_pos_high, trx_sys_mysql_bin_log_pos_low,
sys_header + TRX_SYS_MYSQL_LOG_INFO
+ TRX_SYS_MYSQL_LOG_NAME);
mtr_commit(&mtr);
mtr.commit();
}
#ifdef WITH_WSREP
......
......@@ -1496,7 +1496,6 @@ trx_write_serialisation_history(
trx_sys_update_mysql_binlog_offset(
trx->mysql_log_file_name,
trx->mysql_log_offset,
TRX_SYS_MYSQL_LOG_INFO,
sys_header,
mtr);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment