summaryrefslogtreecommitdiff
path: root/innobase/trx/trx0sys.c
diff options
context:
space:
mode:
authorunknown <guilhem@mysql.com>2004-06-20 19:11:02 +0200
committerunknown <guilhem@mysql.com>2004-06-20 19:11:02 +0200
commit3220a94519f0376e1f3fb479ef305633f1ab0067 (patch)
tree1f069b5091cf2391e994e78a943d6b484dc6fe51 /innobase/trx/trx0sys.c
parent60cb0e5f6d6626a2d2a574e58b6a1abf7a4a9449 (diff)
downloadmariadb-git-3220a94519f0376e1f3fb479ef305633f1ab0067.tar.gz
Robustness feature.
Won't be pushed as is - separate email sent for internal review. WL#1717 "binlog-innodb consistency". Now when mysqld starts, if InnoDB does a crash recovery, we use the binlog name and position retrieved from InnoDB (corresponding to the last transaction successfully committed by InnoDB) to cut any rolled back transaction from the binary log. This is triggered by the --innodb-safe-binlog option. Provided you configure mysqld to fsync() InnoDB at every commit (using flush_log_at_trx_commit) and to fsync() the binlog at every write (using --sync-binlog=1), this behaviour guarantees that a master always has consistency between binlog and InnoDB, whenever the crash happens. 6 tests to verify that it works. client/mysqltest.c: New command require_os (only "unix" accepted for now). innobase/include/trx0sys.h: when InnoDB does crash recovery, we now save the binlog coords it prints, into variables for later use. innobase/trx/trx0sys.c: when InnoDB does crash recovery, we now save the binlog coords it prints, into variables for later use. mysql-test/mysql-test-run.sh: The tests which check that the binlog is cut at restart, need to not delete those binlogs, of course. And not delete replication info, so that we can test that the slave does not receive anything wrong from the cut binlog. sql/ha_innodb.cc: methods to read from InnoDB the binlog coords stored into it sql/ha_innodb.h: ethods to read from InnoDB the binlog coords stored into it sql/log.cc: Added my_sync() when we create a binlog (my_sync of the binlog and of the index file); this is always done, whether --sync-binlog or not (binlog creation is rare, so no speed problem, and I like to have the existence of the binlog always reliably recorded, even if later content is not). If --crash-binlog-innodb, crash between the binlog write and the InnoDB commit. New methods: - report_pos_in_innodb() to store the binlog name and position into InnoDB (used only when we create a new binlog: at startup and at FLUSH LOGS) - cut_spurious_tail() to possibly cut the tail of a binlog based on the info we read from InnoDB (does something only if InnoDB has just done a crash recovery). sql/mysql_priv.h: new option, to crash (use for testing only) sql/mysqld.cc: New option --innodb-safe-binlog and --crash-binlog-innodb (the latter is for testing, it makes mysqld crash). Just after opening the logs and opening the storage engines, cut any wrong statement from the binlog, based on info read from InnoDB. sql/sql_class.h: new methods for MYSQL_LOG.
Diffstat (limited to 'innobase/trx/trx0sys.c')
-rw-r--r--innobase/trx/trx0sys.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/innobase/trx/trx0sys.c b/innobase/trx/trx0sys.c
index b377bdb9809..a0dfdb51259 100644
--- a/innobase/trx/trx0sys.c
+++ b/innobase/trx/trx0sys.c
@@ -45,6 +45,15 @@ or there was no master log position info inside InnoDB. */
char trx_sys_mysql_master_log_name[TRX_SYS_MYSQL_LOG_NAME_LEN];
ib_longlong trx_sys_mysql_master_log_pos = -1;
+/* If this MySQL server uses binary logging, after InnoDB has been inited
+and if it has done a crash recovery, we store the binlog file name and position
+here. If .._pos is -1, it means there was no binlog position info inside
+InnoDB. */
+
+char trx_sys_mysql_bin_log_name[TRX_SYS_MYSQL_LOG_NAME_LEN];
+ib_longlong trx_sys_mysql_bin_log_pos = -1;
+
+
/********************************************************************
Determines if a page number is located inside the doublewrite buffer. */
@@ -650,8 +659,8 @@ trx_sys_print_mysql_binlog_offset_from_page(
#endif /* UNIV_HOTBACKUP */
/*********************************************************************
-Prints to stderr the MySQL binlog offset info in the trx system header if
-the magic number shows it valid. */
+Stores the MySQL binlog offset info in the trx system header if
+the magic number shows it valid, and print the info to stderr */
void
trx_sys_print_mysql_binlog_offset(void)
@@ -659,7 +668,8 @@ trx_sys_print_mysql_binlog_offset(void)
{
trx_sysf_t* sys_header;
mtr_t mtr;
-
+ ulong trx_sys_mysql_bin_log_pos_high, trx_sys_mysql_bin_log_pos_low;
+
mtr_start(&mtr);
sys_header = trx_sysf_get(&mtr);
@@ -673,14 +683,22 @@ trx_sys_print_mysql_binlog_offset(void)
return;
}
- fprintf(stderr,
- "InnoDB: Last MySQL binlog file position %lu %lu, file name %s\n",
- (ulong) mach_read_from_4(sys_header + TRX_SYS_MYSQL_LOG_INFO
- + TRX_SYS_MYSQL_LOG_OFFSET_HIGH),
- (ulong) mach_read_from_4(sys_header + TRX_SYS_MYSQL_LOG_INFO
- + TRX_SYS_MYSQL_LOG_OFFSET_LOW),
- sys_header + TRX_SYS_MYSQL_LOG_INFO + TRX_SYS_MYSQL_LOG_NAME);
+ 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);
+
+ trx_sys_mysql_bin_log_pos = (((ib_longlong)trx_sys_mysql_bin_log_pos_high) << 32) +
+ (ib_longlong)trx_sys_mysql_bin_log_pos_low;
+
+ ut_memcpy(trx_sys_mysql_bin_log_name, sys_header + TRX_SYS_MYSQL_LOG_INFO +
+ TRX_SYS_MYSQL_LOG_NAME, TRX_SYS_MYSQL_LOG_NAME_LEN);
+ fprintf(stderr,
+ "InnoDB: Last MySQL binlog file position %lu %lu, file name %s\n",
+ trx_sys_mysql_bin_log_pos_high, trx_sys_mysql_bin_log_pos_low,
+ trx_sys_mysql_bin_log_name);
+
mtr_commit(&mtr);
}