mirror of
https://github.com/MariaDB/server.git
synced 2025-01-18 21:12:26 +01:00
050f14ac37
Fixed BUGS: #3300: "UPDATE statement with no index column in where condition locks all rows" Implement semi-consistent read to reduce lock conflicts at the cost of breaking serializability. ha_innobase::unlock_row(): reset the "did semi consistent read" flag ha_innobase::was_semi_consistent_read(), ha_innobase::try_semi_consistent_read(): new methods row_prebuilt_t, row_create_prebuilt(): add field row_read_type for keeping track of semi-consistent reads row_vers_build_for_semi_consistent_read(), row_sel_build_committed_vers_for_mysql(): new functions row_search_for_mysql(): implement semi-consistent reads #9802: "Foreign key checks disallow alter table". Added test cases. #12456: "Cursor shows incorrect data - DML does not affect, probably caching" This patch implements a high-granularity read view to be used with cursors. In this high-granularity consistent read view modifications done by the creating transaction after the cursor is created or future transactions are not visible. But those modifications that transaction did before the cursor was created are visible. #12701: "Support >4GB buffer pool and log files on 64-bit Windows" Do not call os_file_create_tmpfile() at runtime. Instead, create all tempfiles at startup and guard access to them with mutexes. #13778: "If FOREIGN_KEY_CHECKS=0, one can create inconsistent FOREIGN KEYs". When FOREIGN_KEY_CHECKS=0 we still need to check that datatypes between foreign key references are compatible. #14189: "VARBINARY and BINARY variables: trailing space ignored with InnoDB" innobase_init(): Assert that DATA_MYSQL_BINARY_CHARSET_COLL == my_charset_bin.number. dtype_get_pad_char(): Do not pad VARBINARY or BINARY columns. row_ins_cascade_calc_update_vec(): Refuse ON UPDATE CASCADE when trying to change the length of a VARBINARY column that refers to or is referenced by a BINARY column. BINARY columns are no longer padded on comparison, and thus they cannot be padded on storage either. #14747: "Race condition can cause btr_search_drop_page_hash_index() to crash" Note that buf_block_t::index should be protected by btr_search_latch or an s-latch or x-latch on the index page. btr_search_drop_page_hash_index(): Read block->index while holding btr_search_latch and use the cached value in the loop. Remove some redundant assertions. #15108: "mysqld crashes when innodb_log_file_size is set > 4G" #15308: "Problem of Order with Enum Column in Primary Key" #15550: "mysqld crashes in printing a FOREIGN KEY error in InnoDB" row_ins_foreign_report_add_err(): When printing the parent record, use the index in the parent table rather than the index in the child table. #15653: "Slow inserts to InnoDB if many thousands of .ibd files" Keep track on unflushed modifications to file spaces. When there are tens of thousands of file spaces, flushing all files in fil_flush_file_spaces() would be very slow. fil_flush_file_spaces(): Only flush unflushed file spaces. fil_space_t, fil_system_t: Add a list of unflushed spaces. #15991: "innodb-file-per-table + symlink database + rename = cr" os_file_handle_error(): Map the error codes EXDEV, ENOTDIR, and EISDIR to the new code OS_FILE_PATH_ERROR. Treat this code as OS_FILE_PATH_ERROR. This fixes the crash on RENAME TABLE when the .ibd file is a symbolic link to a different file system. #16157: "InnoDB crashes when main location settings are empty" This patch is from Heikki. #16298: "InnoDB segfaults in INSERTs in upgrade of 4.0 -> 5.0 tables with VARCHAR BINARY" dict_load_columns(): Set the charset-collation code DATA_MYSQL_BINARY_CHARSET_COLL for those binary string columns that lack a charset-collation code, i.e., the tables were created with an older version of MySQL/InnoDB than 4.1.2. #16229: "MySQL/InnoDB uses full explicit table locks in trigger processing" Take a InnoDB table lock only if user has explicitly requested a table lock. Added some additional comments to store_lock() and external_lock(). #16387: "InnoDB crash when dropping a foreign key <table>_ibfk_0" Do not mistake TABLENAME_ibfk_0 for auto-generated id. dict_table_get_highest_foreign_id(): Ignore foreign constraint identifiers starting with the pattern TABLENAME_ibfk_0. #16582: "InnoDB: Error in an adaptive hash index pointer to page" Account for a race condition when dropping the adaptive hash index for a B-tree page. btr_search_drop_page_hash_index(): Retry the operation if a hash index with different parameters was built meanwhile. Add diagnostics for the case that hash node pointers to the page remain. btr_search_info_update_hash(), btr_search_info_update_slow(): Document the parameter "info" as in/out. #16814: "SHOW INNODB STATUS format error in LATEST FOREIGN KEY ERROR section" Add a missing newline to the LAST FOREIGN KEY ERROR section in SHOW INNODB STATUS output. dict_foreign_error_report(): Always print a newline after invoking dict_print_info_on_foreign_key_in_create_format(). #16827: "Better InnoDB error message if ibdata files omitted from my.cnf" #17126: "CHECK TABLE on InnoDB causes a short hang during check of adaptive hash" CHECK TABLE blocking other queries, by releasing the btr_search_latch periodically during the adaptive hash table validation. #17405: "Valgrind: conditional jump or move depends on unititialised values" buf_block_init(): Reset magic_n, buf_fix_count and io_fix to avoid testing uninitialized variables. mysql-test/r/innodb.result: Applied innodb-5.1-ss269 snapshot. mysql-test/t/innodb.test: Applied innodb-5.1-ss269 snapshot. sql/ha_innodb.cc: Applied innodb-5.1-ss269 snapshot. sql/ha_innodb.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/btr/btr0btr.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/btr/btr0cur.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/btr/btr0pcur.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/btr/btr0sea.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/buf/buf0buf.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/buf/buf0flu.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/buf/buf0lru.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/buf/buf0rea.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/data/data0data.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/data/data0type.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/dict/dict0boot.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/dict/dict0crea.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/dict/dict0dict.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/dict/dict0load.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/dict/dict0mem.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/dyn/dyn0dyn.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/eval/eval0eval.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/eval/eval0proc.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/fil/fil0fil.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/fsp/fsp0fsp.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/fut/fut0lst.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/ha/ha0ha.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/ha/hash0hash.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/ibuf/ibuf0ibuf.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/btr0btr.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/btr0btr.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/btr0cur.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/btr0cur.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/btr0pcur.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/btr0pcur.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/btr0sea.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/btr0sea.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/btr0types.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/buf0buf.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/buf0buf.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/buf0flu.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/buf0flu.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/buf0lru.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/data0data.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/data0data.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/data0type.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/data0type.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/db0err.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/dict0boot.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/dict0boot.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/dict0crea.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/dict0dict.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/dict0dict.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/dict0load.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/dict0mem.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/dyn0dyn.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/dyn0dyn.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/eval0eval.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/eval0eval.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/eval0proc.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/eval0proc.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/fil0fil.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/fsp0fsp.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/fut0lst.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/ha0ha.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/hash0hash.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/hash0hash.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/ibuf0ibuf.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/ibuf0ibuf.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/lock0lock.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/lock0types.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/log0log.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/log0log.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/log0recv.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/mach0data.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/mach0data.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/mem0dbg.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/mem0dbg.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/mem0mem.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/mem0mem.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/mem0pool.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/mtr0log.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/mtr0mtr.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/mtr0mtr.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/os0file.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/os0proc.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/os0sync.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/os0sync.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/os0thread.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/page0cur.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/page0cur.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/page0page.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/page0page.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/page0types.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/pars0grm.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/pars0opt.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/pars0pars.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/pars0sym.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/pars0types.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/que0que.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/que0que.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/que0types.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/read0read.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/read0read.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/rem0cmp.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/rem0cmp.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/rem0rec.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/rem0rec.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/row0ins.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/row0mysql.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/row0purge.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/row0row.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/row0row.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/row0sel.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/row0sel.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/row0types.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/row0uins.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/row0umod.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/row0undo.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/row0upd.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/row0upd.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/row0vers.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/srv0srv.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/srv0start.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/sync0arr.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/sync0rw.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/sync0rw.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/sync0sync.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/sync0sync.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/trx0purge.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/trx0purge.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/trx0rec.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/trx0roll.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/trx0rseg.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/trx0rseg.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/trx0sys.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/trx0sys.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/trx0trx.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/trx0trx.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/trx0types.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/trx0undo.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/trx0undo.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/trx0xa.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/univ.i: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/usr0sess.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/usr0types.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/ut0byte.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/ut0byte.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/ut0dbg.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/ut0lst.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/ut0mem.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/ut0mem.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/ut0rnd.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/ut0rnd.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/ut0sort.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/ut0ut.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/include/ut0ut.ic: Applied innodb-5.1-ss269 snapshot. storage/innobase/lock/lock0lock.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/log/log0log.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/log/log0recv.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/mach/mach0data.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/mem/mem0dbg.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/mem/mem0mem.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/mem/mem0pool.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/mtr/mtr0log.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/mtr/mtr0mtr.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/os/os0file.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/os/os0proc.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/os/os0sync.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/os/os0thread.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/page/page0cur.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/page/page0page.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/pars/lexyy.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/pars/pars0grm.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/pars/pars0grm.h: Applied innodb-5.1-ss269 snapshot. storage/innobase/pars/pars0grm.y: Applied innodb-5.1-ss269 snapshot. storage/innobase/pars/pars0lex.l: Applied innodb-5.1-ss269 snapshot. storage/innobase/pars/pars0opt.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/pars/pars0pars.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/pars/pars0sym.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/que/que0que.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/read/read0read.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/rem/rem0cmp.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/rem/rem0rec.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/row/row0ins.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/row/row0mysql.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/row/row0purge.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/row/row0row.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/row/row0sel.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/row/row0uins.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/row/row0umod.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/row/row0undo.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/row/row0upd.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/row/row0vers.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/srv/srv0que.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/srv/srv0srv.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/srv/srv0start.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/sync/sync0arr.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/sync/sync0rw.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/sync/sync0sync.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/thr/thr0loc.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/trx/trx0purge.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/trx/trx0rec.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/trx/trx0roll.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/trx/trx0rseg.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/trx/trx0sys.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/trx/trx0trx.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/trx/trx0undo.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/usr/usr0sess.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/ut/ut0byte.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/ut/ut0dbg.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/ut/ut0mem.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/ut/ut0rnd.c: Applied innodb-5.1-ss269 snapshot. storage/innobase/ut/ut0ut.c: Applied innodb-5.1-ss269 snapshot. mysql-test/r/innodb_unsafe_binlog.result: New BitKeeper file ``mysql-test/r/innodb_unsafe_binlog.result'' mysql-test/t/innodb_unsafe_binlog-master.opt: New BitKeeper file ``mysql-test/t/innodb_unsafe_binlog-master.opt'' mysql-test/t/innodb_unsafe_binlog.test: New BitKeeper file ``mysql-test/t/innodb_unsafe_binlog.test'' storage/innobase/pars/make_bison.sh: New BitKeeper file ``storage/innobase/pars/make_bison.sh''
1165 lines
28 KiB
C
1165 lines
28 KiB
C
/******************************************************
|
|
Purge old versions
|
|
|
|
(c) 1996 Innobase Oy
|
|
|
|
Created 3/26/1996 Heikki Tuuri
|
|
*******************************************************/
|
|
|
|
#include "trx0purge.h"
|
|
|
|
#ifdef UNIV_NONINL
|
|
#include "trx0purge.ic"
|
|
#endif
|
|
|
|
#include "fsp0fsp.h"
|
|
#include "mach0data.h"
|
|
#include "trx0rseg.h"
|
|
#include "trx0trx.h"
|
|
#include "trx0roll.h"
|
|
#include "read0read.h"
|
|
#include "fut0fut.h"
|
|
#include "que0que.h"
|
|
#include "row0purge.h"
|
|
#include "row0upd.h"
|
|
#include "trx0rec.h"
|
|
#include "srv0que.h"
|
|
#include "os0thread.h"
|
|
|
|
/* The global data structure coordinating a purge */
|
|
trx_purge_t* purge_sys = NULL;
|
|
|
|
/* A dummy undo record used as a return value when we have a whole undo log
|
|
which needs no purge */
|
|
trx_undo_rec_t trx_purge_dummy_rec;
|
|
|
|
/*********************************************************************
|
|
Checks if trx_id is >= purge_view: then it is guaranteed that its update
|
|
undo log still exists in the system. */
|
|
|
|
ibool
|
|
trx_purge_update_undo_must_exist(
|
|
/*=============================*/
|
|
/* out: TRUE if is sure that it is preserved, also
|
|
if the function returns FALSE, it is possible that
|
|
the undo log still exists in the system */
|
|
dulint trx_id) /* in: transaction id */
|
|
{
|
|
#ifdef UNIV_SYNC_DEBUG
|
|
ut_ad(rw_lock_own(&(purge_sys->latch), RW_LOCK_SHARED));
|
|
#endif /* UNIV_SYNC_DEBUG */
|
|
|
|
if (!read_view_sees_trx_id(purge_sys->view, trx_id)) {
|
|
|
|
return(TRUE);
|
|
}
|
|
|
|
return(FALSE);
|
|
}
|
|
|
|
/*=================== PURGE RECORD ARRAY =============================*/
|
|
|
|
/***********************************************************************
|
|
Stores info of an undo log record during a purge. */
|
|
static
|
|
trx_undo_inf_t*
|
|
trx_purge_arr_store_info(
|
|
/*=====================*/
|
|
/* out: pointer to the storage cell */
|
|
dulint trx_no, /* in: transaction number */
|
|
dulint undo_no)/* in: undo number */
|
|
{
|
|
trx_undo_inf_t* cell;
|
|
trx_undo_arr_t* arr;
|
|
ulint i;
|
|
|
|
arr = purge_sys->arr;
|
|
|
|
for (i = 0;; i++) {
|
|
cell = trx_undo_arr_get_nth_info(arr, i);
|
|
|
|
if (!(cell->in_use)) {
|
|
/* Not in use, we may store here */
|
|
cell->undo_no = undo_no;
|
|
cell->trx_no = trx_no;
|
|
cell->in_use = TRUE;
|
|
|
|
arr->n_used++;
|
|
|
|
return(cell);
|
|
}
|
|
}
|
|
}
|
|
|
|
/***********************************************************************
|
|
Removes info of an undo log record during a purge. */
|
|
UNIV_INLINE
|
|
void
|
|
trx_purge_arr_remove_info(
|
|
/*======================*/
|
|
trx_undo_inf_t* cell) /* in: pointer to the storage cell */
|
|
{
|
|
trx_undo_arr_t* arr;
|
|
|
|
arr = purge_sys->arr;
|
|
|
|
cell->in_use = FALSE;
|
|
|
|
ut_ad(arr->n_used > 0);
|
|
|
|
arr->n_used--;
|
|
}
|
|
|
|
/***********************************************************************
|
|
Gets the biggest pair of a trx number and an undo number in a purge array. */
|
|
static
|
|
void
|
|
trx_purge_arr_get_biggest(
|
|
/*======================*/
|
|
trx_undo_arr_t* arr, /* in: purge array */
|
|
dulint* trx_no, /* out: transaction number: ut_dulint_zero
|
|
if array is empty */
|
|
dulint* undo_no)/* out: undo number */
|
|
{
|
|
trx_undo_inf_t* cell;
|
|
dulint pair_trx_no;
|
|
dulint pair_undo_no;
|
|
int trx_cmp;
|
|
ulint n_used;
|
|
ulint i;
|
|
ulint n;
|
|
|
|
n = 0;
|
|
n_used = arr->n_used;
|
|
pair_trx_no = ut_dulint_zero;
|
|
pair_undo_no = ut_dulint_zero;
|
|
|
|
for (i = 0;; i++) {
|
|
cell = trx_undo_arr_get_nth_info(arr, i);
|
|
|
|
if (cell->in_use) {
|
|
n++;
|
|
trx_cmp = ut_dulint_cmp(cell->trx_no, pair_trx_no);
|
|
|
|
if ((trx_cmp > 0)
|
|
|| ((trx_cmp == 0)
|
|
&& (ut_dulint_cmp(cell->undo_no,
|
|
pair_undo_no) >= 0))) {
|
|
|
|
pair_trx_no = cell->trx_no;
|
|
pair_undo_no = cell->undo_no;
|
|
}
|
|
}
|
|
|
|
if (n == n_used) {
|
|
*trx_no = pair_trx_no;
|
|
*undo_no = pair_undo_no;
|
|
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
/********************************************************************
|
|
Builds a purge 'query' graph. The actual purge is performed by executing
|
|
this query graph. */
|
|
static
|
|
que_t*
|
|
trx_purge_graph_build(void)
|
|
/*=======================*/
|
|
/* out, own: the query graph */
|
|
{
|
|
mem_heap_t* heap;
|
|
que_fork_t* fork;
|
|
que_thr_t* thr;
|
|
/* que_thr_t* thr2; */
|
|
|
|
heap = mem_heap_create(512);
|
|
fork = que_fork_create(NULL, NULL, QUE_FORK_PURGE, heap);
|
|
fork->trx = purge_sys->trx;
|
|
|
|
thr = que_thr_create(fork, heap);
|
|
|
|
thr->child = row_purge_node_create(thr, heap);
|
|
|
|
/* thr2 = que_thr_create(fork, fork, heap);
|
|
|
|
thr2->child = row_purge_node_create(fork, thr2, heap); */
|
|
|
|
return(fork);
|
|
}
|
|
|
|
/************************************************************************
|
|
Creates the global purge system control structure and inits the history
|
|
mutex. */
|
|
|
|
void
|
|
trx_purge_sys_create(void)
|
|
/*======================*/
|
|
{
|
|
#ifdef UNIV_SYNC_DEBUG
|
|
ut_ad(mutex_own(&kernel_mutex));
|
|
#endif /* UNIV_SYNC_DEBUG */
|
|
|
|
purge_sys = mem_alloc(sizeof(trx_purge_t));
|
|
|
|
purge_sys->state = TRX_STOP_PURGE;
|
|
|
|
purge_sys->n_pages_handled = 0;
|
|
|
|
purge_sys->purge_trx_no = ut_dulint_zero;
|
|
purge_sys->purge_undo_no = ut_dulint_zero;
|
|
purge_sys->next_stored = FALSE;
|
|
|
|
rw_lock_create(&(purge_sys->latch));
|
|
rw_lock_set_level(&(purge_sys->latch), SYNC_PURGE_LATCH);
|
|
|
|
mutex_create(&(purge_sys->mutex));
|
|
mutex_set_level(&(purge_sys->mutex), SYNC_PURGE_SYS);
|
|
|
|
purge_sys->heap = mem_heap_create(256);
|
|
|
|
purge_sys->arr = trx_undo_arr_create();
|
|
|
|
purge_sys->sess = sess_open();
|
|
|
|
purge_sys->trx = purge_sys->sess->trx;
|
|
|
|
purge_sys->trx->type = TRX_PURGE;
|
|
|
|
ut_a(trx_start_low(purge_sys->trx, ULINT_UNDEFINED));
|
|
|
|
purge_sys->query = trx_purge_graph_build();
|
|
|
|
purge_sys->view = read_view_oldest_copy_or_open_new(
|
|
ut_dulint_create(0,0), purge_sys->heap);
|
|
}
|
|
|
|
/*================ UNDO LOG HISTORY LIST =============================*/
|
|
|
|
/************************************************************************
|
|
Adds the update undo log as the first log in the history list. Removes the
|
|
update undo log segment from the rseg slot if it is too big for reuse. */
|
|
|
|
void
|
|
trx_purge_add_update_undo_to_history(
|
|
/*=================================*/
|
|
trx_t* trx, /* in: transaction */
|
|
page_t* undo_page, /* in: update undo log header page,
|
|
x-latched */
|
|
mtr_t* mtr) /* in: mtr */
|
|
{
|
|
trx_undo_t* undo;
|
|
trx_rseg_t* rseg;
|
|
trx_rsegf_t* rseg_header;
|
|
trx_usegf_t* seg_header;
|
|
trx_ulogf_t* undo_header;
|
|
trx_upagef_t* page_header;
|
|
ulint hist_size;
|
|
|
|
undo = trx->update_undo;
|
|
|
|
ut_ad(undo);
|
|
|
|
rseg = undo->rseg;
|
|
#ifdef UNIV_SYNC_DEBUG
|
|
ut_ad(mutex_own(&(rseg->mutex)));
|
|
#endif /* UNIV_SYNC_DEBUG */
|
|
|
|
rseg_header = trx_rsegf_get(rseg->space, rseg->page_no, mtr);
|
|
|
|
undo_header = undo_page + undo->hdr_offset;
|
|
seg_header = undo_page + TRX_UNDO_SEG_HDR;
|
|
page_header = undo_page + TRX_UNDO_PAGE_HDR;
|
|
|
|
if (undo->state != TRX_UNDO_CACHED) {
|
|
/* The undo log segment will not be reused */
|
|
|
|
if (undo->id >= TRX_RSEG_N_SLOTS) {
|
|
fprintf(stderr,
|
|
"InnoDB: Error: undo->id is %lu\n", (ulong) undo->id);
|
|
ut_error;
|
|
}
|
|
|
|
trx_rsegf_set_nth_undo(rseg_header, undo->id, FIL_NULL, mtr);
|
|
|
|
hist_size = mtr_read_ulint(rseg_header + TRX_RSEG_HISTORY_SIZE,
|
|
MLOG_4BYTES, mtr);
|
|
ut_ad(undo->size ==
|
|
flst_get_len(seg_header + TRX_UNDO_PAGE_LIST, mtr));
|
|
|
|
mlog_write_ulint(rseg_header + TRX_RSEG_HISTORY_SIZE,
|
|
hist_size + undo->size, MLOG_4BYTES, mtr);
|
|
}
|
|
|
|
/* Add the log as the first in the history list */
|
|
flst_add_first(rseg_header + TRX_RSEG_HISTORY,
|
|
undo_header + TRX_UNDO_HISTORY_NODE, mtr);
|
|
mutex_enter(&kernel_mutex);
|
|
trx_sys->rseg_history_len++;
|
|
mutex_exit(&kernel_mutex);
|
|
|
|
/* Write the trx number to the undo log header */
|
|
mlog_write_dulint(undo_header + TRX_UNDO_TRX_NO, trx->no, mtr);
|
|
/* Write information about delete markings to the undo log header */
|
|
|
|
if (!undo->del_marks) {
|
|
mlog_write_ulint(undo_header + TRX_UNDO_DEL_MARKS, FALSE,
|
|
MLOG_2BYTES, mtr);
|
|
}
|
|
|
|
if (rseg->last_page_no == FIL_NULL) {
|
|
|
|
rseg->last_page_no = undo->hdr_page_no;
|
|
rseg->last_offset = undo->hdr_offset;
|
|
rseg->last_trx_no = trx->no;
|
|
rseg->last_del_marks = undo->del_marks;
|
|
}
|
|
}
|
|
|
|
/**************************************************************************
|
|
Frees an undo log segment which is in the history list. Cuts the end of the
|
|
history list at the youngest undo log in this segment. */
|
|
static
|
|
void
|
|
trx_purge_free_segment(
|
|
/*===================*/
|
|
trx_rseg_t* rseg, /* in: rollback segment */
|
|
fil_addr_t hdr_addr, /* in: the file address of log_hdr */
|
|
ulint n_removed_logs) /* in: count of how many undo logs we
|
|
will cut off from the end of the
|
|
history list */
|
|
{
|
|
page_t* undo_page;
|
|
trx_rsegf_t* rseg_hdr;
|
|
trx_ulogf_t* log_hdr;
|
|
trx_usegf_t* seg_hdr;
|
|
ibool freed;
|
|
ulint seg_size;
|
|
ulint hist_size;
|
|
ibool marked = FALSE;
|
|
mtr_t mtr;
|
|
|
|
/* fputs("Freeing an update undo log segment\n", stderr); */
|
|
|
|
#ifdef UNIV_SYNC_DEBUG
|
|
ut_ad(mutex_own(&(purge_sys->mutex)));
|
|
#endif /* UNIV_SYNC_DEBUG */
|
|
loop:
|
|
mtr_start(&mtr);
|
|
mutex_enter(&(rseg->mutex));
|
|
|
|
rseg_hdr = trx_rsegf_get(rseg->space, rseg->page_no, &mtr);
|
|
|
|
undo_page = trx_undo_page_get(rseg->space, hdr_addr.page, &mtr);
|
|
seg_hdr = undo_page + TRX_UNDO_SEG_HDR;
|
|
log_hdr = undo_page + hdr_addr.boffset;
|
|
|
|
/* Mark the last undo log totally purged, so that if the system
|
|
crashes, the tail of the undo log will not get accessed again. The
|
|
list of pages in the undo log tail gets inconsistent during the
|
|
freeing of the segment, and therefore purge should not try to access
|
|
them again. */
|
|
|
|
if (!marked) {
|
|
mlog_write_ulint(log_hdr + TRX_UNDO_DEL_MARKS, FALSE,
|
|
MLOG_2BYTES, &mtr);
|
|
marked = TRUE;
|
|
}
|
|
|
|
freed = fseg_free_step_not_header(seg_hdr + TRX_UNDO_FSEG_HEADER,
|
|
&mtr);
|
|
if (!freed) {
|
|
mutex_exit(&(rseg->mutex));
|
|
mtr_commit(&mtr);
|
|
|
|
goto loop;
|
|
}
|
|
|
|
/* The page list may now be inconsistent, but the length field
|
|
stored in the list base node tells us how big it was before we
|
|
started the freeing. */
|
|
|
|
seg_size = flst_get_len(seg_hdr + TRX_UNDO_PAGE_LIST, &mtr);
|
|
|
|
/* We may free the undo log segment header page; it must be freed
|
|
within the same mtr as the undo log header is removed from the
|
|
history list: otherwise, in case of a database crash, the segment
|
|
could become inaccessible garbage in the file space. */
|
|
|
|
flst_cut_end(rseg_hdr + TRX_RSEG_HISTORY,
|
|
log_hdr + TRX_UNDO_HISTORY_NODE, n_removed_logs, &mtr);
|
|
|
|
mutex_enter(&kernel_mutex);
|
|
ut_ad(trx_sys->rseg_history_len >= n_removed_logs);
|
|
trx_sys->rseg_history_len -= n_removed_logs;
|
|
mutex_exit(&kernel_mutex);
|
|
|
|
freed = FALSE;
|
|
|
|
while (!freed) {
|
|
/* Here we assume that a file segment with just the header
|
|
page can be freed in a few steps, so that the buffer pool
|
|
is not flooded with bufferfixed pages: see the note in
|
|
fsp0fsp.c. */
|
|
|
|
freed = fseg_free_step(seg_hdr + TRX_UNDO_FSEG_HEADER,
|
|
&mtr);
|
|
}
|
|
|
|
hist_size = mtr_read_ulint(rseg_hdr + TRX_RSEG_HISTORY_SIZE,
|
|
MLOG_4BYTES, &mtr);
|
|
ut_ad(hist_size >= seg_size);
|
|
|
|
mlog_write_ulint(rseg_hdr + TRX_RSEG_HISTORY_SIZE,
|
|
hist_size - seg_size, MLOG_4BYTES, &mtr);
|
|
|
|
ut_ad(rseg->curr_size >= seg_size);
|
|
|
|
rseg->curr_size -= seg_size;
|
|
|
|
mutex_exit(&(rseg->mutex));
|
|
|
|
mtr_commit(&mtr);
|
|
}
|
|
|
|
/************************************************************************
|
|
Removes unnecessary history data from a rollback segment. */
|
|
static
|
|
void
|
|
trx_purge_truncate_rseg_history(
|
|
/*============================*/
|
|
trx_rseg_t* rseg, /* in: rollback segment */
|
|
dulint limit_trx_no, /* in: remove update undo logs whose
|
|
trx number is < limit_trx_no */
|
|
dulint limit_undo_no) /* in: if transaction number is equal
|
|
to limit_trx_no, truncate undo records
|
|
with undo number < limit_undo_no */
|
|
{
|
|
fil_addr_t hdr_addr;
|
|
fil_addr_t prev_hdr_addr;
|
|
trx_rsegf_t* rseg_hdr;
|
|
page_t* undo_page;
|
|
trx_ulogf_t* log_hdr;
|
|
trx_usegf_t* seg_hdr;
|
|
int cmp;
|
|
ulint n_removed_logs = 0;
|
|
mtr_t mtr;
|
|
|
|
#ifdef UNIV_SYNC_DEBUG
|
|
ut_ad(mutex_own(&(purge_sys->mutex)));
|
|
#endif /* UNIV_SYNC_DEBUG */
|
|
|
|
mtr_start(&mtr);
|
|
mutex_enter(&(rseg->mutex));
|
|
|
|
rseg_hdr = trx_rsegf_get(rseg->space, rseg->page_no, &mtr);
|
|
|
|
hdr_addr = trx_purge_get_log_from_hist(
|
|
flst_get_last(rseg_hdr + TRX_RSEG_HISTORY, &mtr));
|
|
loop:
|
|
if (hdr_addr.page == FIL_NULL) {
|
|
|
|
mutex_exit(&(rseg->mutex));
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
return;
|
|
}
|
|
|
|
undo_page = trx_undo_page_get(rseg->space, hdr_addr.page, &mtr);
|
|
|
|
log_hdr = undo_page + hdr_addr.boffset;
|
|
|
|
cmp = ut_dulint_cmp(mach_read_from_8(log_hdr + TRX_UNDO_TRX_NO),
|
|
limit_trx_no);
|
|
if (cmp == 0) {
|
|
trx_undo_truncate_start(rseg, rseg->space, hdr_addr.page,
|
|
hdr_addr.boffset, limit_undo_no);
|
|
}
|
|
|
|
if (cmp >= 0) {
|
|
mutex_enter(&kernel_mutex);
|
|
ut_a(trx_sys->rseg_history_len >= n_removed_logs);
|
|
trx_sys->rseg_history_len -= n_removed_logs;
|
|
mutex_exit(&kernel_mutex);
|
|
|
|
flst_truncate_end(rseg_hdr + TRX_RSEG_HISTORY,
|
|
log_hdr + TRX_UNDO_HISTORY_NODE,
|
|
n_removed_logs, &mtr);
|
|
|
|
mutex_exit(&(rseg->mutex));
|
|
mtr_commit(&mtr);
|
|
|
|
return;
|
|
}
|
|
|
|
prev_hdr_addr = trx_purge_get_log_from_hist(
|
|
flst_get_prev_addr(log_hdr + TRX_UNDO_HISTORY_NODE,
|
|
&mtr));
|
|
n_removed_logs++;
|
|
|
|
seg_hdr = undo_page + TRX_UNDO_SEG_HDR;
|
|
|
|
if ((mach_read_from_2(seg_hdr + TRX_UNDO_STATE) == TRX_UNDO_TO_PURGE)
|
|
&& (mach_read_from_2(log_hdr + TRX_UNDO_NEXT_LOG) == 0)) {
|
|
|
|
/* We can free the whole log segment */
|
|
|
|
mutex_exit(&(rseg->mutex));
|
|
mtr_commit(&mtr);
|
|
|
|
trx_purge_free_segment(rseg, hdr_addr, n_removed_logs);
|
|
|
|
n_removed_logs = 0;
|
|
} else {
|
|
mutex_exit(&(rseg->mutex));
|
|
mtr_commit(&mtr);
|
|
}
|
|
|
|
mtr_start(&mtr);
|
|
mutex_enter(&(rseg->mutex));
|
|
|
|
rseg_hdr = trx_rsegf_get(rseg->space, rseg->page_no, &mtr);
|
|
|
|
hdr_addr = prev_hdr_addr;
|
|
|
|
goto loop;
|
|
}
|
|
|
|
/************************************************************************
|
|
Removes unnecessary history data from rollback segments. NOTE that when this
|
|
function is called, the caller must not have any latches on undo log pages! */
|
|
static
|
|
void
|
|
trx_purge_truncate_history(void)
|
|
/*============================*/
|
|
{
|
|
trx_rseg_t* rseg;
|
|
dulint limit_trx_no;
|
|
dulint limit_undo_no;
|
|
|
|
#ifdef UNIV_SYNC_DEBUG
|
|
ut_ad(mutex_own(&(purge_sys->mutex)));
|
|
#endif /* UNIV_SYNC_DEBUG */
|
|
|
|
trx_purge_arr_get_biggest(purge_sys->arr, &limit_trx_no,
|
|
&limit_undo_no);
|
|
|
|
if (ut_dulint_cmp(limit_trx_no, ut_dulint_zero) == 0) {
|
|
|
|
limit_trx_no = purge_sys->purge_trx_no;
|
|
limit_undo_no = purge_sys->purge_undo_no;
|
|
}
|
|
|
|
/* We play safe and set the truncate limit at most to the purge view
|
|
low_limit number, though this is not necessary */
|
|
|
|
if (ut_dulint_cmp(limit_trx_no, purge_sys->view->low_limit_no) >= 0) {
|
|
limit_trx_no = purge_sys->view->low_limit_no;
|
|
limit_undo_no = ut_dulint_zero;
|
|
}
|
|
|
|
ut_ad((ut_dulint_cmp(limit_trx_no,
|
|
purge_sys->view->low_limit_no) <= 0));
|
|
|
|
rseg = UT_LIST_GET_FIRST(trx_sys->rseg_list);
|
|
|
|
while (rseg) {
|
|
trx_purge_truncate_rseg_history(rseg, limit_trx_no,
|
|
limit_undo_no);
|
|
rseg = UT_LIST_GET_NEXT(rseg_list, rseg);
|
|
}
|
|
}
|
|
|
|
/************************************************************************
|
|
Does a truncate if the purge array is empty. NOTE that when this function is
|
|
called, the caller must not have any latches on undo log pages! */
|
|
UNIV_INLINE
|
|
ibool
|
|
trx_purge_truncate_if_arr_empty(void)
|
|
/*=================================*/
|
|
/* out: TRUE if array empty */
|
|
{
|
|
#ifdef UNIV_SYNC_DEBUG
|
|
ut_ad(mutex_own(&(purge_sys->mutex)));
|
|
#endif /* UNIV_SYNC_DEBUG */
|
|
|
|
if (purge_sys->arr->n_used == 0) {
|
|
|
|
trx_purge_truncate_history();
|
|
|
|
return(TRUE);
|
|
}
|
|
|
|
return(FALSE);
|
|
}
|
|
|
|
/***************************************************************************
|
|
Updates the last not yet purged history log info in rseg when we have purged
|
|
a whole undo log. Advances also purge_sys->purge_trx_no past the purged log. */
|
|
static
|
|
void
|
|
trx_purge_rseg_get_next_history_log(
|
|
/*================================*/
|
|
trx_rseg_t* rseg) /* in: rollback segment */
|
|
{
|
|
page_t* undo_page;
|
|
trx_ulogf_t* log_hdr;
|
|
trx_usegf_t* seg_hdr;
|
|
fil_addr_t prev_log_addr;
|
|
dulint trx_no;
|
|
ibool del_marks;
|
|
mtr_t mtr;
|
|
|
|
#ifdef UNIV_SYNC_DEBUG
|
|
ut_ad(mutex_own(&(purge_sys->mutex)));
|
|
#endif /* UNIV_SYNC_DEBUG */
|
|
|
|
mutex_enter(&(rseg->mutex));
|
|
|
|
ut_a(rseg->last_page_no != FIL_NULL);
|
|
|
|
purge_sys->purge_trx_no = ut_dulint_add(rseg->last_trx_no, 1);
|
|
purge_sys->purge_undo_no = ut_dulint_zero;
|
|
purge_sys->next_stored = FALSE;
|
|
|
|
mtr_start(&mtr);
|
|
|
|
undo_page = trx_undo_page_get_s_latched(rseg->space,
|
|
rseg->last_page_no, &mtr);
|
|
log_hdr = undo_page + rseg->last_offset;
|
|
seg_hdr = undo_page + TRX_UNDO_SEG_HDR;
|
|
|
|
/* Increase the purge page count by one for every handled log */
|
|
|
|
purge_sys->n_pages_handled++;
|
|
|
|
prev_log_addr = trx_purge_get_log_from_hist(
|
|
flst_get_prev_addr(log_hdr + TRX_UNDO_HISTORY_NODE,
|
|
&mtr));
|
|
if (prev_log_addr.page == FIL_NULL) {
|
|
/* No logs left in the history list */
|
|
|
|
rseg->last_page_no = FIL_NULL;
|
|
|
|
mutex_exit(&(rseg->mutex));
|
|
mtr_commit(&mtr);
|
|
|
|
mutex_enter(&kernel_mutex);
|
|
|
|
/* Add debug code to track history list corruption reported
|
|
on the MySQL mailing list on Nov 9, 2004. The fut0lst.c
|
|
file-based list was corrupt. The prev node pointer was
|
|
FIL_NULL, even though the list length was over 8 million nodes!
|
|
We assume that purge truncates the history list in moderate
|
|
size pieces, and if we here reach the head of the list, the
|
|
list cannot be longer than 20 000 undo logs now. */
|
|
|
|
if (trx_sys->rseg_history_len > 20000) {
|
|
ut_print_timestamp(stderr);
|
|
fprintf(stderr,
|
|
" InnoDB: Warning: purge reached the head of the history list,\n"
|
|
"InnoDB: but its length is still reported as %lu! Make a detailed bug\n"
|
|
"InnoDB: report, and post it to bugs.mysql.com\n",
|
|
(ulong)trx_sys->rseg_history_len);
|
|
}
|
|
|
|
mutex_exit(&kernel_mutex);
|
|
|
|
return;
|
|
}
|
|
|
|
mutex_exit(&(rseg->mutex));
|
|
mtr_commit(&mtr);
|
|
|
|
/* Read the trx number and del marks from the previous log header */
|
|
mtr_start(&mtr);
|
|
|
|
log_hdr = trx_undo_page_get_s_latched(rseg->space,
|
|
prev_log_addr.page, &mtr)
|
|
+ prev_log_addr.boffset;
|
|
|
|
trx_no = mach_read_from_8(log_hdr + TRX_UNDO_TRX_NO);
|
|
|
|
del_marks = mach_read_from_2(log_hdr + TRX_UNDO_DEL_MARKS);
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
mutex_enter(&(rseg->mutex));
|
|
|
|
rseg->last_page_no = prev_log_addr.page;
|
|
rseg->last_offset = prev_log_addr.boffset;
|
|
rseg->last_trx_no = trx_no;
|
|
rseg->last_del_marks = del_marks;
|
|
|
|
mutex_exit(&(rseg->mutex));
|
|
}
|
|
|
|
/***************************************************************************
|
|
Chooses the next undo log to purge and updates the info in purge_sys. This
|
|
function is used to initialize purge_sys when the next record to purge is
|
|
not known, and also to update the purge system info on the next record when
|
|
purge has handled the whole undo log for a transaction. */
|
|
static
|
|
void
|
|
trx_purge_choose_next_log(void)
|
|
/*===========================*/
|
|
{
|
|
trx_undo_rec_t* rec;
|
|
trx_rseg_t* rseg;
|
|
trx_rseg_t* min_rseg;
|
|
dulint min_trx_no;
|
|
ulint space = 0; /* remove warning (??? bug ???) */
|
|
ulint page_no = 0; /* remove warning (??? bug ???) */
|
|
ulint offset = 0; /* remove warning (??? bug ???) */
|
|
mtr_t mtr;
|
|
|
|
#ifdef UNIV_SYNC_DEBUG
|
|
ut_ad(mutex_own(&(purge_sys->mutex)));
|
|
#endif /* UNIV_SYNC_DEBUG */
|
|
ut_ad(purge_sys->next_stored == FALSE);
|
|
|
|
rseg = UT_LIST_GET_FIRST(trx_sys->rseg_list);
|
|
|
|
min_trx_no = ut_dulint_max;
|
|
|
|
min_rseg = NULL;
|
|
|
|
while (rseg) {
|
|
mutex_enter(&(rseg->mutex));
|
|
|
|
if (rseg->last_page_no != FIL_NULL) {
|
|
|
|
if ((min_rseg == NULL)
|
|
|| (ut_dulint_cmp(min_trx_no,
|
|
rseg->last_trx_no) > 0)) {
|
|
|
|
min_rseg = rseg;
|
|
min_trx_no = rseg->last_trx_no;
|
|
space = rseg->space;
|
|
ut_a(space == 0); /* We assume in purge of
|
|
externally stored fields
|
|
that space id == 0 */
|
|
page_no = rseg->last_page_no;
|
|
offset = rseg->last_offset;
|
|
}
|
|
}
|
|
|
|
mutex_exit(&(rseg->mutex));
|
|
|
|
rseg = UT_LIST_GET_NEXT(rseg_list, rseg);
|
|
}
|
|
|
|
if (min_rseg == NULL) {
|
|
|
|
return;
|
|
}
|
|
|
|
mtr_start(&mtr);
|
|
|
|
if (!min_rseg->last_del_marks) {
|
|
/* No need to purge this log */
|
|
|
|
rec = &trx_purge_dummy_rec;
|
|
} else {
|
|
rec = trx_undo_get_first_rec(space, page_no, offset,
|
|
RW_S_LATCH, &mtr);
|
|
if (rec == NULL) {
|
|
/* Undo log empty */
|
|
|
|
rec = &trx_purge_dummy_rec;
|
|
}
|
|
}
|
|
|
|
purge_sys->next_stored = TRUE;
|
|
purge_sys->rseg = min_rseg;
|
|
|
|
purge_sys->hdr_page_no = page_no;
|
|
purge_sys->hdr_offset = offset;
|
|
|
|
purge_sys->purge_trx_no = min_trx_no;
|
|
|
|
if (rec == &trx_purge_dummy_rec) {
|
|
|
|
purge_sys->purge_undo_no = ut_dulint_zero;
|
|
purge_sys->page_no = page_no;
|
|
purge_sys->offset = 0;
|
|
} else {
|
|
purge_sys->purge_undo_no = trx_undo_rec_get_undo_no(rec);
|
|
|
|
purge_sys->page_no = buf_frame_get_page_no(rec);
|
|
purge_sys->offset = rec - buf_frame_align(rec);
|
|
}
|
|
|
|
mtr_commit(&mtr);
|
|
}
|
|
|
|
/***************************************************************************
|
|
Gets the next record to purge and updates the info in the purge system. */
|
|
static
|
|
trx_undo_rec_t*
|
|
trx_purge_get_next_rec(
|
|
/*===================*/
|
|
/* out: copy of an undo log record or
|
|
pointer to the dummy undo log record */
|
|
mem_heap_t* heap) /* in: memory heap where copied */
|
|
{
|
|
trx_undo_rec_t* rec;
|
|
trx_undo_rec_t* rec_copy;
|
|
trx_undo_rec_t* rec2;
|
|
trx_undo_rec_t* next_rec;
|
|
page_t* undo_page;
|
|
page_t* page;
|
|
ulint offset;
|
|
ulint page_no;
|
|
ulint space;
|
|
ulint type;
|
|
ulint cmpl_info;
|
|
mtr_t mtr;
|
|
|
|
#ifdef UNIV_SYNC_DEBUG
|
|
ut_ad(mutex_own(&(purge_sys->mutex)));
|
|
#endif /* UNIV_SYNC_DEBUG */
|
|
ut_ad(purge_sys->next_stored);
|
|
|
|
space = purge_sys->rseg->space;
|
|
page_no = purge_sys->page_no;
|
|
offset = purge_sys->offset;
|
|
|
|
if (offset == 0) {
|
|
/* It is the dummy undo log record, which means that there is
|
|
no need to purge this undo log */
|
|
|
|
trx_purge_rseg_get_next_history_log(purge_sys->rseg);
|
|
|
|
/* Look for the next undo log and record to purge */
|
|
|
|
trx_purge_choose_next_log();
|
|
|
|
return(&trx_purge_dummy_rec);
|
|
}
|
|
|
|
mtr_start(&mtr);
|
|
|
|
undo_page = trx_undo_page_get_s_latched(space, page_no, &mtr);
|
|
rec = undo_page + offset;
|
|
|
|
rec2 = rec;
|
|
|
|
for (;;) {
|
|
/* Try first to find the next record which requires a purge
|
|
operation from the same page of the same undo log */
|
|
|
|
next_rec = trx_undo_page_get_next_rec(rec2,
|
|
purge_sys->hdr_page_no,
|
|
purge_sys->hdr_offset);
|
|
if (next_rec == NULL) {
|
|
rec2 = trx_undo_get_next_rec(rec2,
|
|
purge_sys->hdr_page_no,
|
|
purge_sys->hdr_offset, &mtr);
|
|
break;
|
|
}
|
|
|
|
rec2 = next_rec;
|
|
|
|
type = trx_undo_rec_get_type(rec2);
|
|
|
|
if (type == TRX_UNDO_DEL_MARK_REC) {
|
|
|
|
break;
|
|
}
|
|
|
|
cmpl_info = trx_undo_rec_get_cmpl_info(rec2);
|
|
|
|
if (trx_undo_rec_get_extern_storage(rec2)) {
|
|
break;
|
|
}
|
|
|
|
if ((type == TRX_UNDO_UPD_EXIST_REC)
|
|
&& !(cmpl_info & UPD_NODE_NO_ORD_CHANGE)) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (rec2 == NULL) {
|
|
mtr_commit(&mtr);
|
|
|
|
trx_purge_rseg_get_next_history_log(purge_sys->rseg);
|
|
|
|
/* Look for the next undo log and record to purge */
|
|
|
|
trx_purge_choose_next_log();
|
|
|
|
mtr_start(&mtr);
|
|
|
|
undo_page = trx_undo_page_get_s_latched(space, page_no, &mtr);
|
|
|
|
rec = undo_page + offset;
|
|
} else {
|
|
page = buf_frame_align(rec2);
|
|
|
|
purge_sys->purge_undo_no = trx_undo_rec_get_undo_no(rec2);
|
|
purge_sys->page_no = buf_frame_get_page_no(page);
|
|
purge_sys->offset = rec2 - page;
|
|
|
|
if (undo_page != page) {
|
|
/* We advance to a new page of the undo log: */
|
|
purge_sys->n_pages_handled++;
|
|
}
|
|
}
|
|
|
|
rec_copy = trx_undo_rec_copy(rec, heap);
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
return(rec_copy);
|
|
}
|
|
|
|
/************************************************************************
|
|
Fetches the next undo log record from the history list to purge. It must be
|
|
released with the corresponding release function. */
|
|
|
|
trx_undo_rec_t*
|
|
trx_purge_fetch_next_rec(
|
|
/*=====================*/
|
|
/* out: copy of an undo log record or
|
|
pointer to the dummy undo log record
|
|
&trx_purge_dummy_rec, if the whole undo log
|
|
can skipped in purge; NULL if none left */
|
|
dulint* roll_ptr,/* out: roll pointer to undo record */
|
|
trx_undo_inf_t** cell, /* out: storage cell for the record in the
|
|
purge array */
|
|
mem_heap_t* heap) /* in: memory heap where copied */
|
|
{
|
|
trx_undo_rec_t* undo_rec;
|
|
|
|
mutex_enter(&(purge_sys->mutex));
|
|
|
|
if (purge_sys->state == TRX_STOP_PURGE) {
|
|
trx_purge_truncate_if_arr_empty();
|
|
|
|
mutex_exit(&(purge_sys->mutex));
|
|
|
|
return(NULL);
|
|
}
|
|
|
|
if (!purge_sys->next_stored) {
|
|
trx_purge_choose_next_log();
|
|
|
|
if (!purge_sys->next_stored) {
|
|
purge_sys->state = TRX_STOP_PURGE;
|
|
|
|
trx_purge_truncate_if_arr_empty();
|
|
|
|
if (srv_print_thread_releases) {
|
|
fprintf(stderr,
|
|
"Purge: No logs left in the history list; pages handled %lu\n",
|
|
(ulong) purge_sys->n_pages_handled);
|
|
}
|
|
|
|
mutex_exit(&(purge_sys->mutex));
|
|
|
|
return(NULL);
|
|
}
|
|
}
|
|
|
|
if (purge_sys->n_pages_handled >= purge_sys->handle_limit) {
|
|
|
|
purge_sys->state = TRX_STOP_PURGE;
|
|
|
|
trx_purge_truncate_if_arr_empty();
|
|
|
|
mutex_exit(&(purge_sys->mutex));
|
|
|
|
return(NULL);
|
|
}
|
|
|
|
if (ut_dulint_cmp(purge_sys->purge_trx_no,
|
|
purge_sys->view->low_limit_no) >= 0) {
|
|
purge_sys->state = TRX_STOP_PURGE;
|
|
|
|
trx_purge_truncate_if_arr_empty();
|
|
|
|
mutex_exit(&(purge_sys->mutex));
|
|
|
|
return(NULL);
|
|
}
|
|
|
|
/* fprintf(stderr, "Thread %lu purging trx %lu undo record %lu\n",
|
|
os_thread_get_curr_id(),
|
|
ut_dulint_get_low(purge_sys->purge_trx_no),
|
|
ut_dulint_get_low(purge_sys->purge_undo_no)); */
|
|
|
|
*roll_ptr = trx_undo_build_roll_ptr(FALSE, (purge_sys->rseg)->id,
|
|
purge_sys->page_no,
|
|
purge_sys->offset);
|
|
|
|
*cell = trx_purge_arr_store_info(purge_sys->purge_trx_no,
|
|
purge_sys->purge_undo_no);
|
|
|
|
ut_ad(ut_dulint_cmp(purge_sys->purge_trx_no,
|
|
(purge_sys->view)->low_limit_no) < 0);
|
|
|
|
/* The following call will advance the stored values of purge_trx_no
|
|
and purge_undo_no, therefore we had to store them first */
|
|
|
|
undo_rec = trx_purge_get_next_rec(heap);
|
|
|
|
mutex_exit(&(purge_sys->mutex));
|
|
|
|
return(undo_rec);
|
|
}
|
|
|
|
/***********************************************************************
|
|
Releases a reserved purge undo record. */
|
|
|
|
void
|
|
trx_purge_rec_release(
|
|
/*==================*/
|
|
trx_undo_inf_t* cell) /* in: storage cell */
|
|
{
|
|
trx_undo_arr_t* arr;
|
|
|
|
mutex_enter(&(purge_sys->mutex));
|
|
|
|
arr = purge_sys->arr;
|
|
|
|
trx_purge_arr_remove_info(cell);
|
|
|
|
mutex_exit(&(purge_sys->mutex));
|
|
}
|
|
|
|
/***********************************************************************
|
|
This function runs a purge batch. */
|
|
|
|
ulint
|
|
trx_purge(void)
|
|
/*===========*/
|
|
/* out: number of undo log pages handled in
|
|
the batch */
|
|
{
|
|
que_thr_t* thr;
|
|
/* que_thr_t* thr2; */
|
|
ulint old_pages_handled;
|
|
|
|
mutex_enter(&(purge_sys->mutex));
|
|
|
|
if (purge_sys->trx->n_active_thrs > 0) {
|
|
|
|
mutex_exit(&(purge_sys->mutex));
|
|
|
|
/* Should not happen */
|
|
|
|
ut_error;
|
|
|
|
return(0);
|
|
}
|
|
|
|
rw_lock_x_lock(&(purge_sys->latch));
|
|
|
|
mutex_enter(&kernel_mutex);
|
|
|
|
/* Close and free the old purge view */
|
|
|
|
read_view_close(purge_sys->view);
|
|
purge_sys->view = NULL;
|
|
mem_heap_empty(purge_sys->heap);
|
|
|
|
/* Determine how much data manipulation language (DML) statements
|
|
need to be delayed in order to reduce the lagging of the purge
|
|
thread. */
|
|
srv_dml_needed_delay = 0; /* in microseconds; default: no delay */
|
|
|
|
/* If we cannot advance the 'purge view' because of an old
|
|
'consistent read view', then the DML statements cannot be delayed.
|
|
Also, srv_max_purge_lag <= 0 means 'infinity'. */
|
|
if (srv_max_purge_lag > 0
|
|
&& !UT_LIST_GET_LAST(trx_sys->view_list)) {
|
|
float ratio = (float) trx_sys->rseg_history_len
|
|
/ srv_max_purge_lag;
|
|
if (ratio > ULINT_MAX / 10000) {
|
|
/* Avoid overflow: maximum delay is 4295 seconds */
|
|
srv_dml_needed_delay = ULINT_MAX;
|
|
} else if (ratio > 1) {
|
|
/* If the history list length exceeds the
|
|
innodb_max_purge_lag, the
|
|
data manipulation statements are delayed
|
|
by at least 5000 microseconds. */
|
|
srv_dml_needed_delay = (ulint) ((ratio - .5) * 10000);
|
|
}
|
|
}
|
|
|
|
purge_sys->view = read_view_oldest_copy_or_open_new(
|
|
ut_dulint_create(0, 0),
|
|
purge_sys->heap);
|
|
mutex_exit(&kernel_mutex);
|
|
|
|
rw_lock_x_unlock(&(purge_sys->latch));
|
|
|
|
purge_sys->state = TRX_PURGE_ON;
|
|
|
|
/* Handle at most 20 undo log pages in one purge batch */
|
|
|
|
purge_sys->handle_limit = purge_sys->n_pages_handled + 20;
|
|
|
|
old_pages_handled = purge_sys->n_pages_handled;
|
|
|
|
mutex_exit(&(purge_sys->mutex));
|
|
|
|
mutex_enter(&kernel_mutex);
|
|
|
|
thr = que_fork_start_command(purge_sys->query);
|
|
|
|
ut_ad(thr);
|
|
|
|
/* thr2 = que_fork_start_command(purge_sys->query);
|
|
|
|
ut_ad(thr2); */
|
|
|
|
|
|
mutex_exit(&kernel_mutex);
|
|
|
|
/* srv_que_task_enqueue(thr2); */
|
|
|
|
if (srv_print_thread_releases) {
|
|
|
|
fputs("Starting purge\n", stderr);
|
|
}
|
|
|
|
que_run_threads(thr);
|
|
|
|
if (srv_print_thread_releases) {
|
|
|
|
fprintf(stderr,
|
|
"Purge ends; pages handled %lu\n",
|
|
(ulong) purge_sys->n_pages_handled);
|
|
}
|
|
|
|
return(purge_sys->n_pages_handled - old_pages_handled);
|
|
}
|
|
|
|
/**********************************************************************
|
|
Prints information of the purge system to stderr. */
|
|
|
|
void
|
|
trx_purge_sys_print(void)
|
|
/*=====================*/
|
|
{
|
|
fprintf(stderr, "InnoDB: Purge system view:\n");
|
|
read_view_print(purge_sys->view);
|
|
|
|
fprintf(stderr, "InnoDB: Purge trx n:o %lu %lu, undo n_o %lu %lu\n",
|
|
(ulong) ut_dulint_get_high(purge_sys->purge_trx_no),
|
|
(ulong) ut_dulint_get_low(purge_sys->purge_trx_no),
|
|
(ulong) ut_dulint_get_high(purge_sys->purge_undo_no),
|
|
(ulong) ut_dulint_get_low(purge_sys->purge_undo_no));
|
|
fprintf(stderr,
|
|
"InnoDB: Purge next stored %lu, page_no %lu, offset %lu,\n"
|
|
"InnoDB: Purge hdr_page_no %lu, hdr_offset %lu\n",
|
|
(ulong) purge_sys->next_stored,
|
|
(ulong) purge_sys->page_no,
|
|
(ulong) purge_sys->offset,
|
|
(ulong) purge_sys->hdr_page_no,
|
|
(ulong) purge_sys->hdr_offset);
|
|
}
|