mirror of
https://github.com/MariaDB/server.git
synced 2025-01-26 08:44:33 +01:00
32b5fb7323
After applying the snapshots, ensure that code conforms to the final version of WL 3914. It is signficant that, after these changes, InnoDB does not define MYSQL_SERVER, and can be built as an independent storage engine plugin. Fixes: Bug#9709: InnoDB inconsistensy causes "Operating System Error 32/33" Bug#18828: If InnoDB runs out of undo slots, it returns misleading 'table is full' Bug#20090: InnoDB: Error: trying to declare trx to enter InnoDB Bug#20352: Make ibuf_contract_for_n_pages tunable Bug#21101: Wrong error on exceeding max row size for InnoDB table Bug#21293: Deadlock detection prefers to kill long running FOR UPDATE queries Bug#22819: SHOW INNODB STATUS crashes the server with an assertion failure under high load Bug#25078: Make the replication thread to ignore innodb_thread_concurrency Bug#25645: Assertion failure in file srv0srv.c Bug#28138: indexing column prefixes produces corruption in InnoDB BitKeeper/deleted/.del-Makefile.am~55504c43d99979e4: Delete: storage/innobase/buf/Makefile.am BitKeeper/deleted/.del-Makefile.am~79bb55303929b560: Delete: storage/innobase/dict/Makefile.am BitKeeper/deleted/.del-Makefile.am~7cd88e5f9a8d7ce8: Delete: storage/innobase/data/Makefile.am BitKeeper/deleted/.del-Makefile.am~e19a1fb29b1fe527: Delete: storage/innobase/btr/Makefile.am BitKeeper/deleted/.del-Makefile.am~4ae65b009d41d1d: Delete: storage/innobase/eval/Makefile.am BitKeeper/deleted/.del-Makefile.am~679131a02af3f6fb: Delete: storage/innobase/fsp/Makefile.am BitKeeper/deleted/.del-Makefile.am~6acac9ae30eabdb3: Delete: storage/innobase/dyn/Makefile.am BitKeeper/deleted/.del-Makefile.am~a5e6b4385717fcb7: Delete: storage/innobase/fil/Makefile.am BitKeeper/deleted/.del-Makefile.am~11d601934b49c19: Delete: storage/innobase/fut/Makefile.am BitKeeper/deleted/.del-Makefile.am~5aab37bf3b6c430: Delete: storage/innobase/ibuf/Makefile.am BitKeeper/deleted/.del-Makefile.am~af2d719bb6e66986: Delete: storage/innobase/handler/Makefile.am BitKeeper/deleted/.del-Makefile.am~f0dbbc7a78648e18: Delete: storage/innobase/ha/Makefile.am BitKeeper/deleted/.del-Makefile.am~41684e54a5b0d26a: Delete: storage/innobase/log/Makefile.am BitKeeper/deleted/.del-Makefile.am~edd95d7290ddeff3: Delete: storage/innobase/lock/Makefile.am BitKeeper/deleted/.del-Makefile.i: Delete: storage/innobase/include/Makefile.i BitKeeper/deleted/.del-Makefile.am~2a6ccdba41b591a3: Delete: storage/innobase/mach/Makefile.am BitKeeper/deleted/.del-Makefile.am~2bd35bda856342: Delete: storage/innobase/os/Makefile.am BitKeeper/deleted/.del-Makefile.am~8448688c5ab92132: Delete: storage/innobase/mem/Makefile.am BitKeeper/deleted/.del-Makefile.am~b5a7a8cfa711b6de: Delete: storage/innobase/mtr/Makefile.am BitKeeper/deleted/.del-Makefile.am~2cee8a309eb8eee2: Delete: storage/innobase/page/Makefile.am BitKeeper/deleted/.del-Makefile.am~3d0553f8aa9c456b: Delete: storage/innobase/read/Makefile.am BitKeeper/deleted/.del-Makefile.am~7b0c4abae6684f8c: Delete: storage/innobase/pars/Makefile.am BitKeeper/deleted/.del-Makefile.am~d0e0dd55cbd413f0: Delete: storage/innobase/que/Makefile.am BitKeeper/deleted/.del-Makefile.am~20a219ccf7825d65: Delete: storage/innobase/row/Makefile.am BitKeeper/deleted/.del-Makefile.am~37bdfb2973b2442b: Delete: storage/innobase/rem/Makefile.am BitKeeper/deleted/.del-Makefile.am~557098c4e5c01ee2: Delete: storage/innobase/thr/Makefile.am BitKeeper/deleted/.del-Makefile.am~fdfe12f48c2499af: Delete: storage/innobase/sync/Makefile.am BitKeeper/deleted/.del-Makefile.am~feb2280a52035d8d: Delete: storage/innobase/srv/Makefile.am BitKeeper/deleted/.del-Makefile.am~456d34c4816dbda4: Delete: storage/innobase/ut/Makefile.am BitKeeper/deleted/.del-Makefile.am~5ec2ef0d2c35e138: Delete: storage/innobase/usr/Makefile.am BitKeeper/deleted/.del-Makefile.am~d25c456e48393313: Delete: storage/innobase/trx/Makefile.am mysql-test/r/innodb.result: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1421: Fix the innodb test by shifting some of the contents of the .result file. Approved by: Marko Revision r1422: Fix for Bug#21101 - returns wrong error message when table column defs exceed the max row size. The fix returns a more appropriate error message. Add a test case to innodb.test and expected output to innodb.result. mysql-test/t/innodb.test: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1422: Fix for Bug#21101 - returns wrong error message when table column defs exceed the max row size. The fix returns a more appropriate error message. Add a test case to innodb.test and expected output to innodb.result. storage/innobase/btr/btr0btr.c: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1546: When buffering an insert to a prefix index of a variable-length column, do not incorrectly mark the column as fixed-length. (Bug#28138) ibuf_entry_build(): Instead of prefix_len, pass fixed_len to dtype_new_store_for_order_and_null_size(). Add debug assertions. btr_index_rec_validate(): Correct a comment about prefix indexes. rec_get_converted_size_new(), rec_convert_dtuple_to_rec_new(): Add debug assertions and comments. dict_col_type_assert_equal(): New debug function. storage/innobase/data/data0data.c: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1490: Add #include <ctype.h>. Apparently, this header is no longer included by the common headers. This may be related to WL#2936 (pluggable storage engines). storage/innobase/data/data0type.c: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1513: Split ut_a(a && b [&& c...]); into separate ut_a(a); ut_a(b); [ut_a(c); ...]. This makes it possible to see which expression was false by looking at the error message. Approved by: Marko storage/innobase/dict/dict0crea.c: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1423: Fix for Bug#18828. Return DB_TOO_MANY_CONCURRENT_TRXS when we run out of UNDO slots in the rollback segment. This is a partial fix since the MySQL error code requested to properly report the error condition back to the client has not yet materialized. Currently we have #ifdef'd the error code translation in ha_innodb.cc. This will have to be changed as and when MySQl add the new requested code or an equivalent code that we can then use. Given the above, currently we will get the old behaviour, not the "fixed" and intended behaviour. storage/innobase/dict/dict0dict.c: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1490: Add #include <ctype.h>. Apparently, this header is no longer included by the common headers. This may be related to WL#2936 (pluggable storage engines). Revision r1513: Split ut_a(a && b [&& c...]); into separate ut_a(a); ut_a(b); [ut_a(c); ...]. This makes it possible to see which expression was false by looking at the error message. Approved by: Marko Revision r1528: Define an auxiliary macro UT_BITS_IN_BYTES() and use it where possible. Revision r1529: Revert r799, which was supposed to prevent similar cases as Bug#21638. In reality, the patch breaks the handling of prefix indexes of variable-length columns in ROW_FORMAT=COMPACT. Reverting the patch is only a partial fix of Bug#28138. Revision r1535: Document that DICT_MAX_INDEX_COL_LEN must not be changed. storage/innobase/fsp/fsp0fsp.c: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1513: Split ut_a(a && b [&& c...]); into separate ut_a(a); ut_a(b); [ut_a(c); ...]. This makes it possible to see which expression was false by looking at the error message. Approved by: Marko Revision r1528: Define an auxiliary macro UT_BITS_IN_BYTES() and use it where possible. storage/innobase/ibuf/ibuf0ibuf.c: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1420: Output to the error log information about the limitations of UNIV_IBUF_DEBUG. innobase_start_or_create_for_mysql(): Note that crash recovery is broken when UNIV_IBUF_DEBUG is defined. ibuf_counts[]: Make this a two-dimensional array. No need to allocate anything from the heap. Eliminate ibuf_counts_inited, as the array will be zero-filled by the runtime environment. ibuf_count_check(): New function, to print out an explanation before assertion failure. Revision r1528: Define an auxiliary macro UT_BITS_IN_BYTES() and use it where possible. Revision r1546: When buffering an insert to a prefix index of a variable-length column, do not incorrectly mark the column as fixed-length. (Bug#28138) ibuf_entry_build(): Instead of prefix_len, pass fixed_len to dtype_new_store_for_order_and_null_size(). Add debug assertions. btr_index_rec_validate(): Correct a comment about prefix indexes. rec_get_converted_size_new(), rec_convert_dtuple_to_rec_new(): Add debug assertions and comments. dict_col_type_assert_equal(): New debug function. storage/innobase/include/db0err.h: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1423: Fix for Bug#18828. Return DB_TOO_MANY_CONCURRENT_TRXS when we run out of UNDO slots in the rollback segment. This is a partial fix since the MySQL error code requested to properly report the error condition back to the client has not yet materialized. Currently we have #ifdef'd the error code translation in ha_innodb.cc. This will have to be changed as and when MySQl add the new requested code or an equivalent code that we can then use. Given the above, currently we will get the old behaviour, not the "fixed" and intended behaviour. storage/innobase/include/dict0dict.h: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1546: When buffering an insert to a prefix index of a variable-length column, do not incorrectly mark the column as fixed-length. (Bug#28138) ibuf_entry_build(): Instead of prefix_len, pass fixed_len to dtype_new_store_for_order_and_null_size(). Add debug assertions. btr_index_rec_validate(): Correct a comment about prefix indexes. rec_get_converted_size_new(), rec_convert_dtuple_to_rec_new(): Add debug assertions and comments. dict_col_type_assert_equal(): New debug function. storage/innobase/include/dict0dict.ic: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1546: When buffering an insert to a prefix index of a variable-length column, do not incorrectly mark the column as fixed-length. (Bug#28138) ibuf_entry_build(): Instead of prefix_len, pass fixed_len to dtype_new_store_for_order_and_null_size(). Add debug assertions. btr_index_rec_validate(): Correct a comment about prefix indexes. rec_get_converted_size_new(), rec_convert_dtuple_to_rec_new(): Add debug assertions and comments. dict_col_type_assert_equal(): New debug function. storage/innobase/include/dict0mem.h: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1535: Document that DICT_MAX_INDEX_COL_LEN must not be changed. Revision r1536: Change the comment to a more appropriate one. Discussed with Heikki on IM. Approved by: Heikki storage/innobase/include/ha_prototypes.h: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1482: Fix Bug#25078 by always letting the replication thread on the slave server to enter InnoDB. This can be made further customizable by the user if we introduce a new config parameter. This will wait until config parameters can be easily added. Approved by: Marko Revision r1501: Fix Bug#21293: Consider transactions that had edited non-transactional tables heavier than ones that had not. This helps killing the "right" transaction in case of a deadlock. Approved by: Heikki storage/innobase/include/os0file.h: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1431: Fix Bug#9709 by retrying (forever) if ERROR_SHARING_VIOLATION or ERROR_LOCK_VIOLATION is encountered during file operation. This is caused by backup software, so InnoDB should retry while the backup software is done with the file. Approved by: Heikki storage/innobase/include/rem0rec.ic: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1569: Fix some in:/out: comments. Approved by: Marko storage/innobase/include/row0mysql.h: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1422: Fix for Bug#21101 - returns wrong error message when table column defs exceed the max row size. The fix returns a more appropriate error message. Add a test case to innodb.test and expected output to innodb.result. storage/innobase/include/trx0trx.h: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1462: Fix typo in comment. Revision r1486: Improve the comment for trx_struct::undo_no. Suggested by: Heikki Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1497: Add the number of locks acquired by a transaction to its weight when choosing the lightest transaction to kill when a deadlock occurs. This fixes Bug#21293 partially. Approved by: Heikki Revision r1501: Fix Bug#21293: Consider transactions that had edited non-transactional tables heavier than ones that had not. This helps killing the "right" transaction in case of a deadlock. Approved by: Heikki storage/innobase/include/trx0undo.h: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1423: Fix for Bug#18828. Return DB_TOO_MANY_CONCURRENT_TRXS when we run out of UNDO slots in the rollback segment. This is a partial fix since the MySQL error code requested to properly report the error condition back to the client has not yet materialized. Currently we have #ifdef'd the error code translation in ha_innodb.cc. This will have to be changed as and when MySQl add the new requested code or an equivalent code that we can then use. Given the above, currently we will get the old behaviour, not the "fixed" and intended behaviour. storage/innobase/include/ut0ut.h: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1528: Define an auxiliary macro UT_BITS_IN_BYTES() and use it where possible. storage/innobase/lock/lock0lock.c: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1457: Fix Bug#22819, remove assertion. (http://bugs.mysql.com/bug.php?id=22819) Revision r1497: Add the number of locks acquired by a transaction to its weight when choosing the lightest transaction to kill when a deadlock occurs. This fixes Bug#21293 partially. Approved by: Heikki Revision r1513: Split ut_a(a && b [&& c...]); into separate ut_a(a); ut_a(b); [ut_a(c); ...]. This makes it possible to see which expression was false by looking at the error message. Approved by: Marko storage/innobase/log/log0log.c: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1521: Forward port r1520 from branches/5.0 Patch to allow monitor threads to stop before proceeding with normal shutdown. Also have a separate time counter for tablespace monitor. reviewed by: Heikki Revision r1524: Undo bad space formatting introduced in earlier commit r1521 spotted by: Marko Revision r1533: logs_empty_and_mark_files_at_shutdown(): Remove trailing whitespace that was added in r1521. storage/innobase/os/os0file.c: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1431: Fix Bug#9709 by retrying (forever) if ERROR_SHARING_VIOLATION or ERROR_LOCK_VIOLATION is encountered during file operation. This is caused by backup software, so InnoDB should retry while the backup software is done with the file. Approved by: Heikki storage/innobase/rem/rem0rec.c: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1528: Define an auxiliary macro UT_BITS_IN_BYTES() and use it where possible. Revision r1531: rec_get_converted_size_new(): Simplify and move a debug assertion. Revision r1546: When buffering an insert to a prefix index of a variable-length column, do not incorrectly mark the column as fixed-length. (Bug#28138) ibuf_entry_build(): Instead of prefix_len, pass fixed_len to dtype_new_store_for_order_and_null_size(). Add debug assertions. btr_index_rec_validate(): Correct a comment about prefix indexes. rec_get_converted_size_new(), rec_convert_dtuple_to_rec_new(): Add debug assertions and comments. dict_col_type_assert_equal(): New debug function. Revision r1555: rec_get_converted_size_new(): The total size of the infimum and supremum records in ROW_FORMAT=COMPACT is REC_N_NEW_EXTRA_BYTES + 8. The REC_N_NEW_EXTRA_BYTES was accidentally omitted in r1546. This function should never be called on those records, though. Revision r1569: Fix some in:/out: comments. Approved by: Marko storage/innobase/row/row0ins.c: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1485: Minor cleanup. row_ins_check_foreign_constraint(), row_ins_scan_sec_index_for_duplicate(): Make use of the predicates page_rec_is_infimum() and page_rec_is_supremum(). Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1513: Split ut_a(a && b [&& c...]); into separate ut_a(a); ut_a(b); [ut_a(c); ...]. This makes it possible to see which expression was false by looking at the error message. Approved by: Marko storage/innobase/row/row0mysql.c: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1422: Fix for Bug#21101 - returns wrong error message when table column defs exceed the max row size. The fix returns a more appropriate error message. Add a test case to innodb.test and expected output to innodb.result. Revision r1423: Fix for Bug#18828. Return DB_TOO_MANY_CONCURRENT_TRXS when we run out of UNDO slots in the rollback segment. This is a partial fix since the MySQL error code requested to properly report the error condition back to the client has not yet materialized. Currently we have #ifdef'd the error code translation in ha_innodb.cc. This will have to be changed as and when MySQl add the new requested code or an equivalent code that we can then use. Given the above, currently we will get the old behaviour, not the "fixed" and intended behaviour. storage/innobase/row/row0row.c: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1513: Split ut_a(a && b [&& c...]); into separate ut_a(a); ut_a(b); [ut_a(c); ...]. This makes it possible to see which expression was false by looking at the error message. Approved by: Marko Revision r1529: Revert r799, which was supposed to prevent similar cases as Bug#21638. In reality, the patch breaks the handling of prefix indexes of variable-length columns in ROW_FORMAT=COMPACT. Reverting the patch is only a partial fix of Bug#28138. storage/innobase/row/row0sel.c: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1452: Fix phantom reads (http://bugs.mysql.com/27197) following Heikki's patch in the bug followup. Approved by: Heikki Revision r1455: Reindent with tabs instead of spaces. Spotted by: Marko storage/innobase/srv/srv0srv.c: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1424: Bug#20352. Added variable srv_insert_buffer_batch_size. We want to make this variable settable. Since the pluggable engine interface currently doesn't provide a usable mechanism, we will add the latter functionality once it's available. Revision r1426: Fix code indentation from r1424. Revision r1459: Fix typo in the comment. Revision r1482: Fix Bug#25078 by always letting the replication thread on the slave server to enter InnoDB. This can be made further customizable by the user if we introduce a new config parameter. This will wait until config parameters can be easily added. Approved by: Marko Revision r1487: Fix typo in comment. Spotted by: Marko Revision r1521: Forward port r1520 from branches/5.0 Patch to allow monitor threads to stop before proceeding with normal shutdown. Also have a separate time counter for tablespace monitor. reviewed by: Heikki Revision r1532: srv_lock_timeout_and_monitor_thread(): Correct the indentation that was broken in r1521. Revision r1553: Fix Bug#20090 as suggested in the bug followup by Heikki. Approved by: Heikki storage/innobase/srv/srv0start.c: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1420: Output to the error log information about the limitations of UNIV_IBUF_DEBUG. innobase_start_or_create_for_mysql(): Note that crash recovery is broken when UNIV_IBUF_DEBUG is defined. ibuf_counts[]: Make this a two-dimensional array. No need to allocate anything from the heap. Eliminate ibuf_counts_inited, as the array will be zero-filled by the runtime environment. ibuf_count_check(): New function, to print out an explanation before assertion failure. storage/innobase/sync/sync0arr.c: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1513: Split ut_a(a && b [&& c...]); into separate ut_a(a); ut_a(b); [ut_a(c); ...]. This makes it possible to see which expression was false by looking at the error message. Approved by: Marko storage/innobase/trx/trx0rec.c: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1423: Fix for Bug#18828. Return DB_TOO_MANY_CONCURRENT_TRXS when we run out of UNDO slots in the rollback segment. This is a partial fix since the MySQL error code requested to properly report the error condition back to the client has not yet materialized. Currently we have #ifdef'd the error code translation in ha_innodb.cc. This will have to be changed as and when MySQl add the new requested code or an equivalent code that we can then use. Given the above, currently we will get the old behaviour, not the "fixed" and intended behaviour. storage/innobase/trx/trx0trx.c: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1491: Fix typo in comment. Revision r1497: Add the number of locks acquired by a transaction to its weight when choosing the lightest transaction to kill when a deadlock occurs. This fixes Bug#21293 partially. Approved by: Heikki Revision r1501: Fix Bug#21293: Consider transactions that had edited non-transactional tables heavier than ones that had not. This helps killing the "right" transaction in case of a deadlock. Approved by: Heikki Revision r1522: trx0trx.c: Add missing #include "ha_prototypes.h". storage/innobase/trx/trx0undo.c: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1423: Fix for Bug#18828. Return DB_TOO_MANY_CONCURRENT_TRXS when we run out of UNDO slots in the rollback segment. This is a partial fix since the MySQL error code requested to properly report the error condition back to the client has not yet materialized. Currently we have #ifdef'd the error code translation in ha_innodb.cc. This will have to be changed as and when MySQl add the new requested code or an equivalent code that we can then use. Given the above, currently we will get the old behaviour, not the "fixed" and intended behaviour. storage/innobase/ut/ut0ut.c: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1490: Add #include <ctype.h>. Apparently, this header is no longer included by the common headers. This may be related to WL#2936 (pluggable storage engines). mysql-test/r/innodb_trx_weight.result: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1498: Add a test about the behavior introduced in r1497. Revision r1501: Fix Bug#21293: Consider transactions that had edited non-transactional tables heavier than ones that had not. This helps killing the "right" transaction in case of a deadlock. Approved by: Heikki mysql-test/include/innodb_trx_weight.inc: Apply the following innodb-5.1-* snapshots: ss1489, ss1496, ss1550, ss1569. Revision r1501: Fix Bug#21293: Consider transactions that had edited non-transactional tables heavier than ones that had not. This helps killing the "right" transaction in case of a deadlock. Approved by: Heikki Revision r1556: mysql-test/innodb_trx_weight.inc: Add username root to the "connect" statement. The Unix user running mysql-test-run usually does not have any privileges on the MySQL test database. mysql-test/t/innodb_trx_weight.test: Fixes after merging InnoDB snapshots. Revision r1498: Add a test about the behavior introduced in r1497. Revision r1501: Fix Bug#21293: Consider transactions that had edited non-transactional tables heavier than ones that had not. This helps killing the "right" transaction in case of a deadlock. Approved by: Heikki sql/sql_class.cc: Fixes after merging InnoDB snapshots. storage/innobase/Makefile.am: Fixes after merging InnoDB snapshots. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. storage/innobase/handler/ha_innodb.cc: Fixes after merging InnoDB snapshots. Revision r1422: Fix for Bug#21101 - returns wrong error message when table column defs exceed the max row size. The fix returns a more appropriate error message. Add a test case to innodb.test and expected output to innodb.result. Revision r1423: Fix for Bug#18828. Return DB_TOO_MANY_CONCURRENT_TRXS when we run out of UNDO slots in the rollback segment. This is a partial fix since the MySQL error code requested to properly report the error condition back to the client has not yet materialized. Currently we have #ifdef'd the error code translation in ha_innodb.cc. This will have to be changed as and when MySQl add the new requested code or an equivalent code that we can then use. Given the above, currently we will get the old behaviour, not the "fixed" and intended behaviour. Revision r1425: Fixed a missing function decoration that slipped into r1422. Revision r1434: Fix typo. Revision r1442: Potential fix for Bug#25645: "Move innobase_release_stat_resources(trx) outside the 'if' in ha_innobase::external_lock(). That would add more safety that whatever MySQL does at a query end, there would be no risk of a hang on the btr search latch." Also call innobase_release_temporary_latches() in the beginning of ha_innobase::close(). Approved by: Heikki Revision r1453: Bugfix: only call innobase_release_temporary_latches() in case of current_thd is not NULL, otherwise we get NULL pointer dereferencing. Approved by: Heikki Revision r1474: Fix typo in comment: the exact prototype is in include/data0type.ic, not in data/data0type.ic Revision r1482: Fix Bug#25078 by always letting the replication thread on the slave server to enter InnoDB. This can be made further customizable by the user if we introduce a new config parameter. This will wait until config parameters can be easily added. Approved by: Marko Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. Revision r1489: thd_to_trx(), check_trx_exists(): Remove the handlerton parameter. It is a singleton object whose address is stored into innodb_hton_ptr. Revision r1492: Convert innobase_buffer_pool_size and innobase_log_file_size types from longlong to long long because MYSQL_SYSVAR_LONGLONG marco expects long long type. Also change ((ulint)innobase_buffer_pool_size) / 1024 to (ulint)(innobase_buffer_pool_size / 1024) and remove comment which is no longer true. Provided that innobase_buffer_pool_size is always 64bits these statements are equivalent if ulint is 64 bit (well it will screw up if innobase_buffer_pool_size is negative). And if ulint is 32 bit the later variant gives a little more chance that the value will fit. Approved by: Heikki Revision r1493: ha_innodb.cc: Remove the declarations of some global InnoDB variables whose name starts with srv_. These variables are declared in the header files that are covered by #include directives in ha_innodb.cc. Revision r1495: Introduce the function reset_template() for resetting some fields of row_prebuilt_t; currently prebuilt->read_just_key and prebuilt->keep_other_fields_on_keyread. Revision r1496: ha_innobase::extra(): Replace references to prebuilt->trx with thd_to_trx(ha_thd()), in order to avoid potential memory corruption. Revision r1501: Fix Bug#21293: Consider transactions that had edited non-transactional tables heavier than ones that had not. This helps killing the "right" transaction in case of a deadlock. Approved by: Heikki Revision r1513: Split ut_a(a && b [&& c...]); into separate ut_a(a); ut_a(b); [ut_a(c); ...]. This makes it possible to see which expression was false by looking at the error message. Approved by: Marko Revision r1527: Cleanup in ha_innodb.cc: thd_is_replication_slave_thread(), thd_has_edited_nontrans_tables(): Remove blank line between the function comment and the function definition. There should be exactly one line between the return type and the function comment, and this line should be one of '', 'static', 'UNIV_INLINE', and 'extern "C"'. Revision r1538: Do not return error in ha_innobase::info if srv_force_recovery >= 4. This is to allow for normal processing of the query by MySQL instead of generating an error. Reviewed by: Heikki Revision r1551: ha_innobase::innobase_read_and_init_auto_inc(): Remember and restore prebuilt->sql_stat_start. In an ALTER TABLE statement in the innodb_gis test, an ut_ad() assertion failed, because no IX lock had been acquired on the table, because prebuilt->sql_stat_start was inadvertently reset to FALSE, by this function. This function was called via ha_innobase::info() and mysql_prepare_alter_table(). storage/innobase/plug.in: Fixes after merging InnoDB snapshots. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead. storage/innobase/handler/ha_innodb.h: Fixes after merging InnoDB snapshots. Revision r1488: Make InnoDB pluggable. That is, merge the modifications from MySQL WL#2936 and adapt some things. Note that ha_innodb.cc depends on mysql_tmpfile() being declared in <mysql/plugin.h>. Until the function is declared there, you can uncomment the buggy definition of mysql_tmpfile in ha_innodb.cc. Remove storage/innobase/*/Makefile.am. The whole compilation is driven by storage/innobase/Makefile.am and storage/innobase/plug.in. plug.in: Declare InnoDB as a dynamic plugin. ha_innodb.h: Remove the declarations of many global variables. The variables are no longer directly referenced outside of storage/innobase. trx_t: Add the field trx->duplicates. trx_create(): Initialize the fields trx->active_trans and trx->duplicates. innobase_query_is_update(): Remove. Consult trx->duplicates instead.
1902 lines
50 KiB
C
1902 lines
50 KiB
C
/******************************************************
|
|
Transaction undo log
|
|
|
|
(c) 1996 Innobase Oy
|
|
|
|
Created 3/26/1996 Heikki Tuuri
|
|
*******************************************************/
|
|
|
|
#include "trx0undo.h"
|
|
|
|
#ifdef UNIV_NONINL
|
|
#include "trx0undo.ic"
|
|
#endif
|
|
|
|
#include "fsp0fsp.h"
|
|
#include "mach0data.h"
|
|
#include "trx0rseg.h"
|
|
#include "trx0trx.h"
|
|
#include "srv0srv.h"
|
|
#include "trx0rec.h"
|
|
#include "trx0purge.h"
|
|
#include "trx0xa.h"
|
|
|
|
/* How should the old versions in the history list be managed?
|
|
----------------------------------------------------------
|
|
If each transaction is given a whole page for its update undo log, file
|
|
space consumption can be 10 times higher than necessary. Therefore,
|
|
partly filled update undo log pages should be reusable. But then there
|
|
is no way individual pages can be ordered so that the ordering agrees
|
|
with the serialization numbers of the transactions on the pages. Thus,
|
|
the history list must be formed of undo logs, not their header pages as
|
|
it was in the old implementation.
|
|
However, on a single header page the transactions are placed in
|
|
the order of their serialization numbers. As old versions are purged, we
|
|
may free the page when the last transaction on the page has been purged.
|
|
A problem is that the purge has to go through the transactions
|
|
in the serialization order. This means that we have to look through all
|
|
rollback segments for the one that has the smallest transaction number
|
|
in its history list.
|
|
When should we do a purge? A purge is necessary when space is
|
|
running out in any of the rollback segments. Then we may have to purge
|
|
also old version which might be needed by some consistent read. How do
|
|
we trigger the start of a purge? When a transaction writes to an undo log,
|
|
it may notice that the space is running out. When a read view is closed,
|
|
it may make some history superfluous. The server can have an utility which
|
|
periodically checks if it can purge some history.
|
|
In a parallellized purge we have the problem that a query thread
|
|
can remove a delete marked clustered index record before another query
|
|
thread has processed an earlier version of the record, which cannot then
|
|
be done because the row cannot be constructed from the clustered index
|
|
record. To avoid this problem, we will store in the update and delete mark
|
|
undo record also the columns necessary to construct the secondary index
|
|
entries which are modified.
|
|
We can latch the stack of versions of a single clustered index record
|
|
by taking a latch on the clustered index page. As long as the latch is held,
|
|
no new versions can be added and no versions removed by undo. But, a purge
|
|
can still remove old versions from the bottom of the stack. */
|
|
|
|
/* How to protect rollback segments, undo logs, and history lists with
|
|
-------------------------------------------------------------------
|
|
latches?
|
|
-------
|
|
The contention of the kernel mutex should be minimized. When a transaction
|
|
does its first insert or modify in an index, an undo log is assigned for it.
|
|
Then we must have an x-latch to the rollback segment header.
|
|
When the transaction does more modifys or rolls back, the undo log is
|
|
protected with undo_mutex in the transaction.
|
|
When the transaction commits, its insert undo log is either reset and
|
|
cached for a fast reuse, or freed. In these cases we must have an x-latch on
|
|
the rollback segment page. The update undo log is put to the history list. If
|
|
it is not suitable for reuse, its slot in the rollback segment is reset. In
|
|
both cases, an x-latch must be acquired on the rollback segment.
|
|
The purge operation steps through the history list without modifying
|
|
it until a truncate operation occurs, which can remove undo logs from the end
|
|
of the list and release undo log segments. In stepping through the list,
|
|
s-latches on the undo log pages are enough, but in a truncate, x-latches must
|
|
be obtained on the rollback segment and individual pages. */
|
|
|
|
/************************************************************************
|
|
Initializes the fields in an undo log segment page. */
|
|
static
|
|
void
|
|
trx_undo_page_init(
|
|
/*===============*/
|
|
page_t* undo_page, /* in: undo log segment page */
|
|
ulint type, /* in: undo log segment type */
|
|
mtr_t* mtr); /* in: mtr */
|
|
/************************************************************************
|
|
Creates and initializes an undo log memory object. */
|
|
static
|
|
trx_undo_t*
|
|
trx_undo_mem_create(
|
|
/*================*/
|
|
/* out, own: the undo log memory object */
|
|
trx_rseg_t* rseg, /* in: rollback segment memory object */
|
|
ulint id, /* in: slot index within rseg */
|
|
ulint type, /* in: type of the log: TRX_UNDO_INSERT or
|
|
TRX_UNDO_UPDATE */
|
|
dulint trx_id, /* in: id of the trx for which the undo log
|
|
is created */
|
|
XID* xid, /* in: X/Open XA transaction identification*/
|
|
ulint page_no,/* in: undo log header page number */
|
|
ulint offset);/* in: undo log header byte offset on page */
|
|
/*******************************************************************
|
|
Initializes a cached insert undo log header page for new use. NOTE that this
|
|
function has its own log record type MLOG_UNDO_HDR_REUSE. You must NOT change
|
|
the operation of this function! */
|
|
static
|
|
ulint
|
|
trx_undo_insert_header_reuse(
|
|
/*=========================*/
|
|
/* out: undo log header byte offset on page */
|
|
page_t* undo_page, /* in: insert undo log segment header page,
|
|
x-latched */
|
|
dulint trx_id, /* in: transaction id */
|
|
mtr_t* mtr); /* in: mtr */
|
|
/**************************************************************************
|
|
If an update undo log can be discarded immediately, this function frees the
|
|
space, resetting the page to the proper state for caching. */
|
|
static
|
|
void
|
|
trx_undo_discard_latest_update_undo(
|
|
/*================================*/
|
|
page_t* undo_page, /* in: header page of an undo log of size 1 */
|
|
mtr_t* mtr); /* in: mtr */
|
|
|
|
|
|
/***************************************************************************
|
|
Gets the previous record in an undo log from the previous page. */
|
|
static
|
|
trx_undo_rec_t*
|
|
trx_undo_get_prev_rec_from_prev_page(
|
|
/*=================================*/
|
|
/* out: undo log record, the page s-latched,
|
|
NULL if none */
|
|
trx_undo_rec_t* rec, /* in: undo record */
|
|
ulint page_no,/* in: undo log header page number */
|
|
ulint offset, /* in: undo log header offset on page */
|
|
mtr_t* mtr) /* in: mtr */
|
|
{
|
|
ulint prev_page_no;
|
|
page_t* prev_page;
|
|
page_t* undo_page;
|
|
|
|
undo_page = buf_frame_align(rec);
|
|
|
|
prev_page_no = flst_get_prev_addr(undo_page + TRX_UNDO_PAGE_HDR
|
|
+ TRX_UNDO_PAGE_NODE, mtr)
|
|
.page;
|
|
|
|
if (prev_page_no == FIL_NULL) {
|
|
|
|
return(NULL);
|
|
}
|
|
|
|
prev_page = trx_undo_page_get_s_latched(
|
|
buf_frame_get_space_id(undo_page), prev_page_no, mtr);
|
|
|
|
return(trx_undo_page_get_last_rec(prev_page, page_no, offset));
|
|
}
|
|
|
|
/***************************************************************************
|
|
Gets the previous record in an undo log. */
|
|
|
|
trx_undo_rec_t*
|
|
trx_undo_get_prev_rec(
|
|
/*==================*/
|
|
/* out: undo log record, the page s-latched,
|
|
NULL if none */
|
|
trx_undo_rec_t* rec, /* in: undo record */
|
|
ulint page_no,/* in: undo log header page number */
|
|
ulint offset, /* in: undo log header offset on page */
|
|
mtr_t* mtr) /* in: mtr */
|
|
{
|
|
trx_undo_rec_t* prev_rec;
|
|
|
|
prev_rec = trx_undo_page_get_prev_rec(rec, page_no, offset);
|
|
|
|
if (prev_rec) {
|
|
|
|
return(prev_rec);
|
|
}
|
|
|
|
/* We have to go to the previous undo log page to look for the
|
|
previous record */
|
|
|
|
return(trx_undo_get_prev_rec_from_prev_page(rec, page_no, offset,
|
|
mtr));
|
|
}
|
|
|
|
/***************************************************************************
|
|
Gets the next record in an undo log from the next page. */
|
|
static
|
|
trx_undo_rec_t*
|
|
trx_undo_get_next_rec_from_next_page(
|
|
/*=================================*/
|
|
/* out: undo log record, the page latched, NULL if
|
|
none */
|
|
page_t* undo_page, /* in: undo log page */
|
|
ulint page_no,/* in: undo log header page number */
|
|
ulint offset, /* in: undo log header offset on page */
|
|
ulint mode, /* in: latch mode: RW_S_LATCH or RW_X_LATCH */
|
|
mtr_t* mtr) /* in: mtr */
|
|
{
|
|
trx_ulogf_t* log_hdr;
|
|
ulint next_page_no;
|
|
page_t* next_page;
|
|
ulint space;
|
|
ulint next;
|
|
|
|
if (page_no == buf_frame_get_page_no(undo_page)) {
|
|
|
|
log_hdr = undo_page + offset;
|
|
next = mach_read_from_2(log_hdr + TRX_UNDO_NEXT_LOG);
|
|
|
|
if (next != 0) {
|
|
|
|
return(NULL);
|
|
}
|
|
}
|
|
|
|
space = buf_frame_get_space_id(undo_page);
|
|
|
|
next_page_no = flst_get_next_addr(undo_page + TRX_UNDO_PAGE_HDR
|
|
+ TRX_UNDO_PAGE_NODE, mtr)
|
|
.page;
|
|
if (next_page_no == FIL_NULL) {
|
|
|
|
return(NULL);
|
|
}
|
|
|
|
if (mode == RW_S_LATCH) {
|
|
next_page = trx_undo_page_get_s_latched(space, next_page_no,
|
|
mtr);
|
|
} else {
|
|
ut_ad(mode == RW_X_LATCH);
|
|
next_page = trx_undo_page_get(space, next_page_no, mtr);
|
|
}
|
|
|
|
return(trx_undo_page_get_first_rec(next_page, page_no, offset));
|
|
}
|
|
|
|
/***************************************************************************
|
|
Gets the next record in an undo log. */
|
|
|
|
trx_undo_rec_t*
|
|
trx_undo_get_next_rec(
|
|
/*==================*/
|
|
/* out: undo log record, the page s-latched,
|
|
NULL if none */
|
|
trx_undo_rec_t* rec, /* in: undo record */
|
|
ulint page_no,/* in: undo log header page number */
|
|
ulint offset, /* in: undo log header offset on page */
|
|
mtr_t* mtr) /* in: mtr */
|
|
{
|
|
trx_undo_rec_t* next_rec;
|
|
|
|
next_rec = trx_undo_page_get_next_rec(rec, page_no, offset);
|
|
|
|
if (next_rec) {
|
|
return(next_rec);
|
|
}
|
|
|
|
return(trx_undo_get_next_rec_from_next_page(buf_frame_align(rec),
|
|
page_no, offset,
|
|
RW_S_LATCH, mtr));
|
|
}
|
|
|
|
/***************************************************************************
|
|
Gets the first record in an undo log. */
|
|
|
|
trx_undo_rec_t*
|
|
trx_undo_get_first_rec(
|
|
/*===================*/
|
|
/* out: undo log record, the page latched, NULL if
|
|
none */
|
|
ulint space, /* in: undo log header space */
|
|
ulint page_no,/* in: undo log header page number */
|
|
ulint offset, /* in: undo log header offset on page */
|
|
ulint mode, /* in: latching mode: RW_S_LATCH or RW_X_LATCH */
|
|
mtr_t* mtr) /* in: mtr */
|
|
{
|
|
page_t* undo_page;
|
|
trx_undo_rec_t* rec;
|
|
|
|
if (mode == RW_S_LATCH) {
|
|
undo_page = trx_undo_page_get_s_latched(space, page_no, mtr);
|
|
} else {
|
|
undo_page = trx_undo_page_get(space, page_no, mtr);
|
|
}
|
|
|
|
rec = trx_undo_page_get_first_rec(undo_page, page_no, offset);
|
|
|
|
if (rec) {
|
|
return(rec);
|
|
}
|
|
|
|
return(trx_undo_get_next_rec_from_next_page(undo_page, page_no, offset,
|
|
mode, mtr));
|
|
}
|
|
|
|
/*============== UNDO LOG FILE COPY CREATION AND FREEING ==================*/
|
|
|
|
/**************************************************************************
|
|
Writes the mtr log entry of an undo log page initialization. */
|
|
UNIV_INLINE
|
|
void
|
|
trx_undo_page_init_log(
|
|
/*===================*/
|
|
page_t* undo_page, /* in: undo log page */
|
|
ulint type, /* in: undo log type */
|
|
mtr_t* mtr) /* in: mtr */
|
|
{
|
|
mlog_write_initial_log_record(undo_page, MLOG_UNDO_INIT, mtr);
|
|
|
|
mlog_catenate_ulint_compressed(mtr, type);
|
|
}
|
|
|
|
/***************************************************************
|
|
Parses the redo log entry of an undo log page initialization. */
|
|
|
|
byte*
|
|
trx_undo_parse_page_init(
|
|
/*=====================*/
|
|
/* out: end of log record or NULL */
|
|
byte* ptr, /* in: buffer */
|
|
byte* end_ptr,/* in: buffer end */
|
|
page_t* page, /* in: page or NULL */
|
|
mtr_t* mtr) /* in: mtr or NULL */
|
|
{
|
|
ulint type;
|
|
|
|
ptr = mach_parse_compressed(ptr, end_ptr, &type);
|
|
|
|
if (ptr == NULL) {
|
|
|
|
return(NULL);
|
|
}
|
|
|
|
if (page) {
|
|
trx_undo_page_init(page, type, mtr);
|
|
}
|
|
|
|
return(ptr);
|
|
}
|
|
|
|
/************************************************************************
|
|
Initializes the fields in an undo log segment page. */
|
|
static
|
|
void
|
|
trx_undo_page_init(
|
|
/*===============*/
|
|
page_t* undo_page, /* in: undo log segment page */
|
|
ulint type, /* in: undo log segment type */
|
|
mtr_t* mtr) /* in: mtr */
|
|
{
|
|
trx_upagef_t* page_hdr;
|
|
|
|
page_hdr = undo_page + TRX_UNDO_PAGE_HDR;
|
|
|
|
mach_write_to_2(page_hdr + TRX_UNDO_PAGE_TYPE, type);
|
|
|
|
mach_write_to_2(page_hdr + TRX_UNDO_PAGE_START,
|
|
TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_HDR_SIZE);
|
|
mach_write_to_2(page_hdr + TRX_UNDO_PAGE_FREE,
|
|
TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_HDR_SIZE);
|
|
|
|
fil_page_set_type(undo_page, FIL_PAGE_UNDO_LOG);
|
|
|
|
trx_undo_page_init_log(undo_page, type, mtr);
|
|
}
|
|
|
|
/*******************************************************************
|
|
Creates a new undo log segment in file. */
|
|
static
|
|
ulint
|
|
trx_undo_seg_create(
|
|
/*================*/
|
|
/* out: DB_SUCCESS if page creation OK
|
|
possible error codes are:
|
|
DB_TOO_MANY_CONCURRENT_TRXS
|
|
DB_OUT_OF_FILE_SPACE */
|
|
trx_rseg_t* rseg __attribute__((unused)),/* in: rollback segment */
|
|
trx_rsegf_t* rseg_hdr,/* in: rollback segment header, page
|
|
x-latched */
|
|
ulint type, /* in: type of the segment: TRX_UNDO_INSERT or
|
|
TRX_UNDO_UPDATE */
|
|
ulint* id, /* out: slot index within rseg header */
|
|
page_t** undo_page,
|
|
/* out: segment header page x-latched, NULL
|
|
if there was an error */
|
|
mtr_t* mtr) /* in: mtr */
|
|
{
|
|
ulint slot_no;
|
|
ulint space;
|
|
trx_upagef_t* page_hdr;
|
|
trx_usegf_t* seg_hdr;
|
|
ulint n_reserved;
|
|
ibool success;
|
|
ulint err = DB_SUCCESS;
|
|
|
|
ut_ad(mtr && id && rseg_hdr);
|
|
ut_ad(mutex_own(&(rseg->mutex)));
|
|
|
|
/* fputs(type == TRX_UNDO_INSERT
|
|
? "Creating insert undo log segment\n"
|
|
: "Creating update undo log segment\n", stderr); */
|
|
slot_no = trx_rsegf_undo_find_free(rseg_hdr, mtr);
|
|
|
|
if (slot_no == ULINT_UNDEFINED) {
|
|
ut_print_timestamp(stderr);
|
|
fprintf(stderr,
|
|
"InnoDB: Warning: cannot find a free slot for"
|
|
" an undo log. Do you have too\n"
|
|
"InnoDB: many active transactions"
|
|
" running concurrently?\n");
|
|
|
|
return(DB_TOO_MANY_CONCURRENT_TRXS);
|
|
}
|
|
|
|
space = buf_frame_get_space_id(rseg_hdr);
|
|
|
|
success = fsp_reserve_free_extents(&n_reserved, space, 2, FSP_UNDO,
|
|
mtr);
|
|
if (!success) {
|
|
|
|
return(DB_OUT_OF_FILE_SPACE);
|
|
}
|
|
|
|
/* Allocate a new file segment for the undo log */
|
|
*undo_page = fseg_create_general(space, 0,
|
|
TRX_UNDO_SEG_HDR
|
|
+ TRX_UNDO_FSEG_HEADER, TRUE, mtr);
|
|
|
|
fil_space_release_free_extents(space, n_reserved);
|
|
|
|
if (*undo_page == NULL) {
|
|
/* No space left */
|
|
|
|
return(DB_OUT_OF_FILE_SPACE);
|
|
}
|
|
|
|
#ifdef UNIV_SYNC_DEBUG
|
|
buf_page_dbg_add_level(*undo_page, SYNC_TRX_UNDO_PAGE);
|
|
#endif /* UNIV_SYNC_DEBUG */
|
|
|
|
page_hdr = *undo_page + TRX_UNDO_PAGE_HDR;
|
|
seg_hdr = *undo_page + TRX_UNDO_SEG_HDR;
|
|
|
|
trx_undo_page_init(*undo_page, type, mtr);
|
|
|
|
mlog_write_ulint(page_hdr + TRX_UNDO_PAGE_FREE,
|
|
TRX_UNDO_SEG_HDR + TRX_UNDO_SEG_HDR_SIZE,
|
|
MLOG_2BYTES, mtr);
|
|
|
|
mlog_write_ulint(seg_hdr + TRX_UNDO_LAST_LOG, 0, MLOG_2BYTES, mtr);
|
|
|
|
flst_init(seg_hdr + TRX_UNDO_PAGE_LIST, mtr);
|
|
|
|
flst_add_last(seg_hdr + TRX_UNDO_PAGE_LIST,
|
|
page_hdr + TRX_UNDO_PAGE_NODE, mtr);
|
|
|
|
trx_rsegf_set_nth_undo(rseg_hdr, slot_no,
|
|
buf_frame_get_page_no(*undo_page), mtr);
|
|
|
|
*id = slot_no;
|
|
|
|
return(err);
|
|
}
|
|
|
|
/**************************************************************************
|
|
Writes the mtr log entry of an undo log header initialization. */
|
|
UNIV_INLINE
|
|
void
|
|
trx_undo_header_create_log(
|
|
/*=======================*/
|
|
page_t* undo_page, /* in: undo log header page */
|
|
dulint trx_id, /* in: transaction id */
|
|
mtr_t* mtr) /* in: mtr */
|
|
{
|
|
mlog_write_initial_log_record(undo_page, MLOG_UNDO_HDR_CREATE, mtr);
|
|
|
|
mlog_catenate_dulint_compressed(mtr, trx_id);
|
|
}
|
|
|
|
/*******************************************************************
|
|
Creates a new undo log header in file. NOTE that this function has its own
|
|
log record type MLOG_UNDO_HDR_CREATE. You must NOT change the operation of
|
|
this function! */
|
|
static
|
|
ulint
|
|
trx_undo_header_create(
|
|
/*===================*/
|
|
/* out: header byte offset on page */
|
|
page_t* undo_page, /* in: undo log segment header page,
|
|
x-latched; it is assumed that there are
|
|
TRX_UNDO_LOG_XA_HDR_SIZE bytes free space
|
|
on it */
|
|
dulint trx_id, /* in: transaction id */
|
|
mtr_t* mtr) /* in: mtr */
|
|
{
|
|
trx_upagef_t* page_hdr;
|
|
trx_usegf_t* seg_hdr;
|
|
trx_ulogf_t* log_hdr;
|
|
trx_ulogf_t* prev_log_hdr;
|
|
ulint prev_log;
|
|
ulint free;
|
|
ulint new_free;
|
|
|
|
ut_ad(mtr && undo_page);
|
|
|
|
page_hdr = undo_page + TRX_UNDO_PAGE_HDR;
|
|
seg_hdr = undo_page + TRX_UNDO_SEG_HDR;
|
|
|
|
free = mach_read_from_2(page_hdr + TRX_UNDO_PAGE_FREE);
|
|
|
|
log_hdr = undo_page + free;
|
|
|
|
new_free = free + TRX_UNDO_LOG_OLD_HDR_SIZE;
|
|
|
|
ut_a(free + TRX_UNDO_LOG_XA_HDR_SIZE < UNIV_PAGE_SIZE - 100);
|
|
|
|
mach_write_to_2(page_hdr + TRX_UNDO_PAGE_START, new_free);
|
|
|
|
mach_write_to_2(page_hdr + TRX_UNDO_PAGE_FREE, new_free);
|
|
|
|
mach_write_to_2(seg_hdr + TRX_UNDO_STATE, TRX_UNDO_ACTIVE);
|
|
|
|
prev_log = mach_read_from_2(seg_hdr + TRX_UNDO_LAST_LOG);
|
|
|
|
if (prev_log != 0) {
|
|
prev_log_hdr = undo_page + prev_log;
|
|
|
|
mach_write_to_2(prev_log_hdr + TRX_UNDO_NEXT_LOG, free);
|
|
}
|
|
|
|
mach_write_to_2(seg_hdr + TRX_UNDO_LAST_LOG, free);
|
|
|
|
log_hdr = undo_page + free;
|
|
|
|
mach_write_to_2(log_hdr + TRX_UNDO_DEL_MARKS, TRUE);
|
|
|
|
mach_write_to_8(log_hdr + TRX_UNDO_TRX_ID, trx_id);
|
|
mach_write_to_2(log_hdr + TRX_UNDO_LOG_START, new_free);
|
|
|
|
mach_write_to_1(log_hdr + TRX_UNDO_XID_EXISTS, FALSE);
|
|
mach_write_to_1(log_hdr + TRX_UNDO_DICT_TRANS, FALSE);
|
|
|
|
mach_write_to_2(log_hdr + TRX_UNDO_NEXT_LOG, 0);
|
|
mach_write_to_2(log_hdr + TRX_UNDO_PREV_LOG, prev_log);
|
|
|
|
/* Write the log record about the header creation */
|
|
trx_undo_header_create_log(undo_page, trx_id, mtr);
|
|
|
|
return(free);
|
|
}
|
|
|
|
/************************************************************************
|
|
Write X/Open XA Transaction Identification (XID) to undo log header */
|
|
static
|
|
void
|
|
trx_undo_write_xid(
|
|
/*===============*/
|
|
trx_ulogf_t* log_hdr,/* in: undo log header */
|
|
const XID* xid, /* in: X/Open XA Transaction Identification */
|
|
mtr_t* mtr) /* in: mtr */
|
|
{
|
|
mlog_write_ulint(log_hdr + TRX_UNDO_XA_FORMAT,
|
|
(ulint)xid->formatID, MLOG_4BYTES, mtr);
|
|
|
|
mlog_write_ulint(log_hdr + TRX_UNDO_XA_TRID_LEN,
|
|
(ulint)xid->gtrid_length, MLOG_4BYTES, mtr);
|
|
|
|
mlog_write_ulint(log_hdr + TRX_UNDO_XA_BQUAL_LEN,
|
|
(ulint)xid->bqual_length, MLOG_4BYTES, mtr);
|
|
|
|
mlog_write_string(log_hdr + TRX_UNDO_XA_XID, (const byte*) xid->data,
|
|
XIDDATASIZE, mtr);
|
|
}
|
|
|
|
/************************************************************************
|
|
Read X/Open XA Transaction Identification (XID) from undo log header */
|
|
static
|
|
void
|
|
trx_undo_read_xid(
|
|
/*==============*/
|
|
trx_ulogf_t* log_hdr,/* in: undo log header */
|
|
XID* xid) /* out: X/Open XA Transaction Identification */
|
|
{
|
|
xid->formatID = (long)mach_read_from_4(log_hdr + TRX_UNDO_XA_FORMAT);
|
|
|
|
xid->gtrid_length
|
|
= (long) mach_read_from_4(log_hdr + TRX_UNDO_XA_TRID_LEN);
|
|
xid->bqual_length
|
|
= (long) mach_read_from_4(log_hdr + TRX_UNDO_XA_BQUAL_LEN);
|
|
|
|
memcpy(xid->data, log_hdr + TRX_UNDO_XA_XID, XIDDATASIZE);
|
|
}
|
|
|
|
/*******************************************************************
|
|
Adds space for the XA XID after an undo log old-style header. */
|
|
static
|
|
void
|
|
trx_undo_header_add_space_for_xid(
|
|
/*==============================*/
|
|
page_t* undo_page,/* in: undo log segment header page */
|
|
trx_ulogf_t* log_hdr,/* in: undo log header */
|
|
mtr_t* mtr) /* in: mtr */
|
|
{
|
|
trx_upagef_t* page_hdr;
|
|
ulint free;
|
|
ulint new_free;
|
|
|
|
page_hdr = undo_page + TRX_UNDO_PAGE_HDR;
|
|
|
|
free = mach_read_from_2(page_hdr + TRX_UNDO_PAGE_FREE);
|
|
|
|
/* free is now the end offset of the old style undo log header */
|
|
|
|
ut_a(free == (ulint)(log_hdr - undo_page) + TRX_UNDO_LOG_OLD_HDR_SIZE);
|
|
|
|
new_free = free + (TRX_UNDO_LOG_XA_HDR_SIZE
|
|
- TRX_UNDO_LOG_OLD_HDR_SIZE);
|
|
|
|
/* Add space for a XID after the header, update the free offset
|
|
fields on the undo log page and in the undo log header */
|
|
|
|
mlog_write_ulint(page_hdr + TRX_UNDO_PAGE_START, new_free,
|
|
MLOG_2BYTES, mtr);
|
|
|
|
mlog_write_ulint(page_hdr + TRX_UNDO_PAGE_FREE, new_free,
|
|
MLOG_2BYTES, mtr);
|
|
|
|
mlog_write_ulint(log_hdr + TRX_UNDO_LOG_START, new_free,
|
|
MLOG_2BYTES, mtr);
|
|
}
|
|
|
|
/**************************************************************************
|
|
Writes the mtr log entry of an undo log header reuse. */
|
|
UNIV_INLINE
|
|
void
|
|
trx_undo_insert_header_reuse_log(
|
|
/*=============================*/
|
|
page_t* undo_page, /* in: undo log header page */
|
|
dulint trx_id, /* in: transaction id */
|
|
mtr_t* mtr) /* in: mtr */
|
|
{
|
|
mlog_write_initial_log_record(undo_page, MLOG_UNDO_HDR_REUSE, mtr);
|
|
|
|
mlog_catenate_dulint_compressed(mtr, trx_id);
|
|
}
|
|
|
|
/***************************************************************
|
|
Parses the redo log entry of an undo log page header create or reuse. */
|
|
|
|
byte*
|
|
trx_undo_parse_page_header(
|
|
/*=======================*/
|
|
/* out: end of log record or NULL */
|
|
ulint type, /* in: MLOG_UNDO_HDR_CREATE or MLOG_UNDO_HDR_REUSE */
|
|
byte* ptr, /* in: buffer */
|
|
byte* end_ptr,/* in: buffer end */
|
|
page_t* page, /* in: page or NULL */
|
|
mtr_t* mtr) /* in: mtr or NULL */
|
|
{
|
|
dulint trx_id;
|
|
|
|
ptr = mach_dulint_parse_compressed(ptr, end_ptr, &trx_id);
|
|
|
|
if (ptr == NULL) {
|
|
|
|
return(NULL);
|
|
}
|
|
|
|
if (page) {
|
|
if (type == MLOG_UNDO_HDR_CREATE) {
|
|
trx_undo_header_create(page, trx_id, mtr);
|
|
} else {
|
|
ut_ad(type == MLOG_UNDO_HDR_REUSE);
|
|
trx_undo_insert_header_reuse(page, trx_id, mtr);
|
|
}
|
|
}
|
|
|
|
return(ptr);
|
|
}
|
|
|
|
/*******************************************************************
|
|
Initializes a cached insert undo log header page for new use. NOTE that this
|
|
function has its own log record type MLOG_UNDO_HDR_REUSE. You must NOT change
|
|
the operation of this function! */
|
|
static
|
|
ulint
|
|
trx_undo_insert_header_reuse(
|
|
/*=========================*/
|
|
/* out: undo log header byte offset on page */
|
|
page_t* undo_page, /* in: insert undo log segment header page,
|
|
x-latched */
|
|
dulint trx_id, /* in: transaction id */
|
|
mtr_t* mtr) /* in: mtr */
|
|
{
|
|
trx_upagef_t* page_hdr;
|
|
trx_usegf_t* seg_hdr;
|
|
trx_ulogf_t* log_hdr;
|
|
ulint free;
|
|
ulint new_free;
|
|
|
|
ut_ad(mtr && undo_page);
|
|
|
|
page_hdr = undo_page + TRX_UNDO_PAGE_HDR;
|
|
seg_hdr = undo_page + TRX_UNDO_SEG_HDR;
|
|
|
|
free = TRX_UNDO_SEG_HDR + TRX_UNDO_SEG_HDR_SIZE;
|
|
|
|
ut_a(free + TRX_UNDO_LOG_XA_HDR_SIZE < UNIV_PAGE_SIZE - 100);
|
|
|
|
log_hdr = undo_page + free;
|
|
|
|
new_free = free + TRX_UNDO_LOG_OLD_HDR_SIZE;
|
|
|
|
/* Insert undo data is not needed after commit: we may free all
|
|
the space on the page */
|
|
|
|
ut_a(mach_read_from_2(undo_page + TRX_UNDO_PAGE_HDR
|
|
+ TRX_UNDO_PAGE_TYPE)
|
|
== TRX_UNDO_INSERT);
|
|
|
|
mach_write_to_2(page_hdr + TRX_UNDO_PAGE_START, new_free);
|
|
|
|
mach_write_to_2(page_hdr + TRX_UNDO_PAGE_FREE, new_free);
|
|
|
|
mach_write_to_2(seg_hdr + TRX_UNDO_STATE, TRX_UNDO_ACTIVE);
|
|
|
|
log_hdr = undo_page + free;
|
|
|
|
mach_write_to_8(log_hdr + TRX_UNDO_TRX_ID, trx_id);
|
|
mach_write_to_2(log_hdr + TRX_UNDO_LOG_START, new_free);
|
|
|
|
mach_write_to_1(log_hdr + TRX_UNDO_XID_EXISTS, FALSE);
|
|
mach_write_to_1(log_hdr + TRX_UNDO_DICT_TRANS, FALSE);
|
|
|
|
/* Write the log record MLOG_UNDO_HDR_REUSE */
|
|
trx_undo_insert_header_reuse_log(undo_page, trx_id, mtr);
|
|
|
|
return(free);
|
|
}
|
|
|
|
/**************************************************************************
|
|
Writes the redo log entry of an update undo log header discard. */
|
|
UNIV_INLINE
|
|
void
|
|
trx_undo_discard_latest_log(
|
|
/*========================*/
|
|
page_t* undo_page, /* in: undo log header page */
|
|
mtr_t* mtr) /* in: mtr */
|
|
{
|
|
mlog_write_initial_log_record(undo_page, MLOG_UNDO_HDR_DISCARD, mtr);
|
|
}
|
|
|
|
/***************************************************************
|
|
Parses the redo log entry of an undo log page header discard. */
|
|
|
|
byte*
|
|
trx_undo_parse_discard_latest(
|
|
/*==========================*/
|
|
/* out: end of log record or NULL */
|
|
byte* ptr, /* in: buffer */
|
|
byte* end_ptr __attribute__((unused)), /* in: buffer end */
|
|
page_t* page, /* in: page or NULL */
|
|
mtr_t* mtr) /* in: mtr or NULL */
|
|
{
|
|
ut_ad(end_ptr);
|
|
|
|
if (page) {
|
|
trx_undo_discard_latest_update_undo(page, mtr);
|
|
}
|
|
|
|
return(ptr);
|
|
}
|
|
|
|
/**************************************************************************
|
|
If an update undo log can be discarded immediately, this function frees the
|
|
space, resetting the page to the proper state for caching. */
|
|
static
|
|
void
|
|
trx_undo_discard_latest_update_undo(
|
|
/*================================*/
|
|
page_t* undo_page, /* in: header page of an undo log of size 1 */
|
|
mtr_t* mtr) /* in: mtr */
|
|
{
|
|
trx_usegf_t* seg_hdr;
|
|
trx_upagef_t* page_hdr;
|
|
trx_ulogf_t* log_hdr;
|
|
trx_ulogf_t* prev_log_hdr;
|
|
ulint free;
|
|
ulint prev_hdr_offset;
|
|
|
|
seg_hdr = undo_page + TRX_UNDO_SEG_HDR;
|
|
page_hdr = undo_page + TRX_UNDO_PAGE_HDR;
|
|
|
|
free = mach_read_from_2(seg_hdr + TRX_UNDO_LAST_LOG);
|
|
log_hdr = undo_page + free;
|
|
|
|
prev_hdr_offset = mach_read_from_2(log_hdr + TRX_UNDO_PREV_LOG);
|
|
|
|
if (prev_hdr_offset != 0) {
|
|
prev_log_hdr = undo_page + prev_hdr_offset;
|
|
|
|
mach_write_to_2(page_hdr + TRX_UNDO_PAGE_START,
|
|
mach_read_from_2(prev_log_hdr
|
|
+ TRX_UNDO_LOG_START));
|
|
mach_write_to_2(prev_log_hdr + TRX_UNDO_NEXT_LOG, 0);
|
|
}
|
|
|
|
mach_write_to_2(page_hdr + TRX_UNDO_PAGE_FREE, free);
|
|
|
|
mach_write_to_2(seg_hdr + TRX_UNDO_STATE, TRX_UNDO_CACHED);
|
|
mach_write_to_2(seg_hdr + TRX_UNDO_LAST_LOG, prev_hdr_offset);
|
|
|
|
trx_undo_discard_latest_log(undo_page, mtr);
|
|
}
|
|
|
|
/************************************************************************
|
|
Tries to add a page to the undo log segment where the undo log is placed. */
|
|
|
|
ulint
|
|
trx_undo_add_page(
|
|
/*==============*/
|
|
/* out: page number if success, else
|
|
FIL_NULL */
|
|
trx_t* trx, /* in: transaction */
|
|
trx_undo_t* undo, /* in: undo log memory object */
|
|
mtr_t* mtr) /* in: mtr which does not have a latch to any
|
|
undo log page; the caller must have reserved
|
|
the rollback segment mutex */
|
|
{
|
|
page_t* header_page;
|
|
page_t* new_page;
|
|
trx_rseg_t* rseg;
|
|
ulint page_no;
|
|
ulint n_reserved;
|
|
ibool success;
|
|
|
|
ut_ad(mutex_own(&(trx->undo_mutex)));
|
|
ut_ad(!mutex_own(&kernel_mutex));
|
|
ut_ad(mutex_own(&(trx->rseg->mutex)));
|
|
|
|
rseg = trx->rseg;
|
|
|
|
if (rseg->curr_size == rseg->max_size) {
|
|
|
|
return(FIL_NULL);
|
|
}
|
|
|
|
header_page = trx_undo_page_get(undo->space, undo->hdr_page_no, mtr);
|
|
|
|
success = fsp_reserve_free_extents(&n_reserved, undo->space, 1,
|
|
FSP_UNDO, mtr);
|
|
if (!success) {
|
|
|
|
return(FIL_NULL);
|
|
}
|
|
|
|
page_no = fseg_alloc_free_page_general(header_page + TRX_UNDO_SEG_HDR
|
|
+ TRX_UNDO_FSEG_HEADER,
|
|
undo->top_page_no + 1, FSP_UP,
|
|
TRUE, mtr);
|
|
|
|
fil_space_release_free_extents(undo->space, n_reserved);
|
|
|
|
if (page_no == FIL_NULL) {
|
|
|
|
/* No space left */
|
|
|
|
return(FIL_NULL);
|
|
}
|
|
|
|
undo->last_page_no = page_no;
|
|
|
|
new_page = trx_undo_page_get(undo->space, page_no, mtr);
|
|
|
|
trx_undo_page_init(new_page, undo->type, mtr);
|
|
|
|
flst_add_last(header_page + TRX_UNDO_SEG_HDR + TRX_UNDO_PAGE_LIST,
|
|
new_page + TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_NODE, mtr);
|
|
undo->size++;
|
|
rseg->curr_size++;
|
|
|
|
return(page_no);
|
|
}
|
|
|
|
/************************************************************************
|
|
Frees an undo log page that is not the header page. */
|
|
static
|
|
ulint
|
|
trx_undo_free_page(
|
|
/*===============*/
|
|
/* out: last page number in remaining log */
|
|
trx_rseg_t* rseg, /* in: rollback segment */
|
|
ibool in_history, /* in: TRUE if the undo log is in the history
|
|
list */
|
|
ulint space, /* in: space */
|
|
ulint hdr_page_no, /* in: header page number */
|
|
ulint page_no, /* in: page number to free: must not be the
|
|
header page */
|
|
mtr_t* mtr) /* in: mtr which does not have a latch to any
|
|
undo log page; the caller must have reserved
|
|
the rollback segment mutex */
|
|
{
|
|
page_t* header_page;
|
|
page_t* undo_page;
|
|
fil_addr_t last_addr;
|
|
trx_rsegf_t* rseg_header;
|
|
ulint hist_size;
|
|
|
|
ut_a(hdr_page_no != page_no);
|
|
ut_ad(!mutex_own(&kernel_mutex));
|
|
ut_ad(mutex_own(&(rseg->mutex)));
|
|
|
|
undo_page = trx_undo_page_get(space, page_no, mtr);
|
|
|
|
header_page = trx_undo_page_get(space, hdr_page_no, mtr);
|
|
|
|
flst_remove(header_page + TRX_UNDO_SEG_HDR + TRX_UNDO_PAGE_LIST,
|
|
undo_page + TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_NODE, mtr);
|
|
|
|
fseg_free_page(header_page + TRX_UNDO_SEG_HDR + TRX_UNDO_FSEG_HEADER,
|
|
space, page_no, mtr);
|
|
|
|
last_addr = flst_get_last(header_page + TRX_UNDO_SEG_HDR
|
|
+ TRX_UNDO_PAGE_LIST, mtr);
|
|
rseg->curr_size--;
|
|
|
|
if (in_history) {
|
|
rseg_header = trx_rsegf_get(space, rseg->page_no, mtr);
|
|
|
|
hist_size = mtr_read_ulint(rseg_header + TRX_RSEG_HISTORY_SIZE,
|
|
MLOG_4BYTES, mtr);
|
|
ut_ad(hist_size > 0);
|
|
mlog_write_ulint(rseg_header + TRX_RSEG_HISTORY_SIZE,
|
|
hist_size - 1, MLOG_4BYTES, mtr);
|
|
}
|
|
|
|
return(last_addr.page);
|
|
}
|
|
|
|
/************************************************************************
|
|
Frees an undo log page when there is also the memory object for the undo
|
|
log. */
|
|
static
|
|
void
|
|
trx_undo_free_page_in_rollback(
|
|
/*===========================*/
|
|
trx_t* trx __attribute__((unused)), /* in: transaction */
|
|
trx_undo_t* undo, /* in: undo log memory copy */
|
|
ulint page_no,/* in: page number to free: must not be the
|
|
header page */
|
|
mtr_t* mtr) /* in: mtr which does not have a latch to any
|
|
undo log page; the caller must have reserved
|
|
the rollback segment mutex */
|
|
{
|
|
ulint last_page_no;
|
|
|
|
ut_ad(undo->hdr_page_no != page_no);
|
|
ut_ad(mutex_own(&(trx->undo_mutex)));
|
|
|
|
last_page_no = trx_undo_free_page(undo->rseg, FALSE, undo->space,
|
|
undo->hdr_page_no, page_no, mtr);
|
|
|
|
undo->last_page_no = last_page_no;
|
|
undo->size--;
|
|
}
|
|
|
|
/************************************************************************
|
|
Empties an undo log header page of undo records for that undo log. Other
|
|
undo logs may still have records on that page, if it is an update undo log. */
|
|
static
|
|
void
|
|
trx_undo_empty_header_page(
|
|
/*=======================*/
|
|
ulint space, /* in: space */
|
|
ulint hdr_page_no, /* in: header page number */
|
|
ulint hdr_offset, /* in: header offset */
|
|
mtr_t* mtr) /* in: mtr */
|
|
{
|
|
page_t* header_page;
|
|
trx_ulogf_t* log_hdr;
|
|
ulint end;
|
|
|
|
header_page = trx_undo_page_get(space, hdr_page_no, mtr);
|
|
|
|
log_hdr = header_page + hdr_offset;
|
|
|
|
end = trx_undo_page_get_end(header_page, hdr_page_no, hdr_offset);
|
|
|
|
mlog_write_ulint(log_hdr + TRX_UNDO_LOG_START, end, MLOG_2BYTES, mtr);
|
|
}
|
|
|
|
/***************************************************************************
|
|
Truncates an undo log from the end. This function is used during a rollback
|
|
to free space from an undo log. */
|
|
|
|
void
|
|
trx_undo_truncate_end(
|
|
/*==================*/
|
|
trx_t* trx, /* in: transaction whose undo log it is */
|
|
trx_undo_t* undo, /* in: undo log */
|
|
dulint limit) /* in: all undo records with undo number
|
|
>= this value should be truncated */
|
|
{
|
|
page_t* undo_page;
|
|
ulint last_page_no;
|
|
trx_undo_rec_t* rec;
|
|
trx_undo_rec_t* trunc_here;
|
|
trx_rseg_t* rseg;
|
|
mtr_t mtr;
|
|
|
|
ut_ad(mutex_own(&(trx->undo_mutex)));
|
|
ut_ad(mutex_own(&(trx->rseg->mutex)));
|
|
|
|
rseg = trx->rseg;
|
|
|
|
for (;;) {
|
|
mtr_start(&mtr);
|
|
|
|
trunc_here = NULL;
|
|
|
|
last_page_no = undo->last_page_no;
|
|
|
|
undo_page = trx_undo_page_get(undo->space, last_page_no, &mtr);
|
|
|
|
rec = trx_undo_page_get_last_rec(undo_page, undo->hdr_page_no,
|
|
undo->hdr_offset);
|
|
for (;;) {
|
|
if (rec == NULL) {
|
|
if (last_page_no == undo->hdr_page_no) {
|
|
|
|
goto function_exit;
|
|
}
|
|
|
|
trx_undo_free_page_in_rollback(
|
|
trx, undo, last_page_no, &mtr);
|
|
break;
|
|
}
|
|
|
|
if (ut_dulint_cmp(trx_undo_rec_get_undo_no(rec), limit)
|
|
>= 0) {
|
|
/* Truncate at least this record off, maybe
|
|
more */
|
|
trunc_here = rec;
|
|
} else {
|
|
goto function_exit;
|
|
}
|
|
|
|
rec = trx_undo_page_get_prev_rec(rec,
|
|
undo->hdr_page_no,
|
|
undo->hdr_offset);
|
|
}
|
|
|
|
mtr_commit(&mtr);
|
|
}
|
|
|
|
function_exit:
|
|
if (trunc_here) {
|
|
mlog_write_ulint(undo_page + TRX_UNDO_PAGE_HDR
|
|
+ TRX_UNDO_PAGE_FREE,
|
|
trunc_here - undo_page, MLOG_2BYTES, &mtr);
|
|
}
|
|
|
|
mtr_commit(&mtr);
|
|
}
|
|
|
|
/***************************************************************************
|
|
Truncates an undo log from the start. This function is used during a purge
|
|
operation. */
|
|
|
|
void
|
|
trx_undo_truncate_start(
|
|
/*====================*/
|
|
trx_rseg_t* rseg, /* in: rollback segment */
|
|
ulint space, /* in: space id of the log */
|
|
ulint hdr_page_no, /* in: header page number */
|
|
ulint hdr_offset, /* in: header offset on the page */
|
|
dulint limit) /* in: all undo pages with undo numbers <
|
|
this value should be truncated; NOTE that
|
|
the function only frees whole pages; the
|
|
header page is not freed, but emptied, if
|
|
all the records there are < limit */
|
|
{
|
|
page_t* undo_page;
|
|
trx_undo_rec_t* rec;
|
|
trx_undo_rec_t* last_rec;
|
|
ulint page_no;
|
|
mtr_t mtr;
|
|
|
|
ut_ad(mutex_own(&(rseg->mutex)));
|
|
|
|
if (0 == ut_dulint_cmp(limit, ut_dulint_zero)) {
|
|
|
|
return;
|
|
}
|
|
loop:
|
|
mtr_start(&mtr);
|
|
|
|
rec = trx_undo_get_first_rec(space, hdr_page_no, hdr_offset,
|
|
RW_X_LATCH, &mtr);
|
|
if (rec == NULL) {
|
|
/* Already empty */
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
return;
|
|
}
|
|
|
|
undo_page = buf_frame_align(rec);
|
|
|
|
last_rec = trx_undo_page_get_last_rec(undo_page, hdr_page_no,
|
|
hdr_offset);
|
|
if (ut_dulint_cmp(trx_undo_rec_get_undo_no(last_rec), limit) >= 0) {
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
return;
|
|
}
|
|
|
|
page_no = buf_frame_get_page_no(undo_page);
|
|
|
|
if (page_no == hdr_page_no) {
|
|
trx_undo_empty_header_page(space, hdr_page_no, hdr_offset,
|
|
&mtr);
|
|
} else {
|
|
trx_undo_free_page(rseg, TRUE, space, hdr_page_no,
|
|
page_no, &mtr);
|
|
}
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
goto loop;
|
|
}
|
|
|
|
/**************************************************************************
|
|
Frees an undo log segment which is not in the history list. */
|
|
static
|
|
void
|
|
trx_undo_seg_free(
|
|
/*==============*/
|
|
trx_undo_t* undo) /* in: undo log */
|
|
{
|
|
trx_rseg_t* rseg;
|
|
fseg_header_t* file_seg;
|
|
trx_rsegf_t* rseg_header;
|
|
trx_usegf_t* seg_header;
|
|
ibool finished;
|
|
mtr_t mtr;
|
|
|
|
finished = FALSE;
|
|
rseg = undo->rseg;
|
|
|
|
while (!finished) {
|
|
|
|
mtr_start(&mtr);
|
|
|
|
ut_ad(!mutex_own(&kernel_mutex));
|
|
|
|
mutex_enter(&(rseg->mutex));
|
|
|
|
seg_header = trx_undo_page_get(undo->space, undo->hdr_page_no,
|
|
&mtr) + TRX_UNDO_SEG_HDR;
|
|
|
|
file_seg = seg_header + TRX_UNDO_FSEG_HEADER;
|
|
|
|
finished = fseg_free_step(file_seg, &mtr);
|
|
|
|
if (finished) {
|
|
/* Update the rseg header */
|
|
rseg_header = trx_rsegf_get(rseg->space, rseg->page_no,
|
|
&mtr);
|
|
trx_rsegf_set_nth_undo(rseg_header, undo->id, FIL_NULL,
|
|
&mtr);
|
|
}
|
|
|
|
mutex_exit(&(rseg->mutex));
|
|
mtr_commit(&mtr);
|
|
}
|
|
}
|
|
|
|
/*========== UNDO LOG MEMORY COPY INITIALIZATION =====================*/
|
|
|
|
/************************************************************************
|
|
Creates and initializes an undo log memory object according to the values
|
|
in the header in file, when the database is started. The memory object is
|
|
inserted in the appropriate list of rseg. */
|
|
static
|
|
trx_undo_t*
|
|
trx_undo_mem_create_at_db_start(
|
|
/*============================*/
|
|
/* out, own: the undo log memory object */
|
|
trx_rseg_t* rseg, /* in: rollback segment memory object */
|
|
ulint id, /* in: slot index within rseg */
|
|
ulint page_no,/* in: undo log segment page number */
|
|
mtr_t* mtr) /* in: mtr */
|
|
{
|
|
page_t* undo_page;
|
|
trx_upagef_t* page_header;
|
|
trx_usegf_t* seg_header;
|
|
trx_ulogf_t* undo_header;
|
|
trx_undo_t* undo;
|
|
ulint type;
|
|
ulint state;
|
|
dulint trx_id;
|
|
ulint offset;
|
|
fil_addr_t last_addr;
|
|
page_t* last_page;
|
|
trx_undo_rec_t* rec;
|
|
XID xid;
|
|
ibool xid_exists = FALSE;
|
|
|
|
if (id >= TRX_RSEG_N_SLOTS) {
|
|
fprintf(stderr,
|
|
"InnoDB: Error: undo->id is %lu\n", (ulong) id);
|
|
ut_error;
|
|
}
|
|
|
|
undo_page = trx_undo_page_get(rseg->space, page_no, mtr);
|
|
|
|
page_header = undo_page + TRX_UNDO_PAGE_HDR;
|
|
|
|
type = mtr_read_ulint(page_header + TRX_UNDO_PAGE_TYPE, MLOG_2BYTES,
|
|
mtr);
|
|
seg_header = undo_page + TRX_UNDO_SEG_HDR;
|
|
|
|
state = mach_read_from_2(seg_header + TRX_UNDO_STATE);
|
|
|
|
offset = mach_read_from_2(seg_header + TRX_UNDO_LAST_LOG);
|
|
|
|
undo_header = undo_page + offset;
|
|
|
|
trx_id = mtr_read_dulint(undo_header + TRX_UNDO_TRX_ID, mtr);
|
|
|
|
xid_exists = mtr_read_ulint(undo_header + TRX_UNDO_XID_EXISTS,
|
|
MLOG_1BYTE, mtr);
|
|
|
|
/* Read X/Open XA transaction identification if it exists, or
|
|
set it to NULL. */
|
|
|
|
memset(&xid, 0, sizeof(xid));
|
|
xid.formatID = -1;
|
|
|
|
if (xid_exists == TRUE) {
|
|
trx_undo_read_xid(undo_header, &xid);
|
|
}
|
|
|
|
mutex_enter(&(rseg->mutex));
|
|
|
|
undo = trx_undo_mem_create(rseg, id, type, trx_id, &xid,
|
|
page_no, offset);
|
|
mutex_exit(&(rseg->mutex));
|
|
|
|
undo->dict_operation = mtr_read_ulint(
|
|
undo_header + TRX_UNDO_DICT_TRANS, MLOG_1BYTE, mtr);
|
|
|
|
undo->table_id = mtr_read_dulint(undo_header + TRX_UNDO_TABLE_ID, mtr);
|
|
undo->state = state;
|
|
undo->size = flst_get_len(seg_header + TRX_UNDO_PAGE_LIST, mtr);
|
|
|
|
/* If the log segment is being freed, the page list is inconsistent! */
|
|
if (state == TRX_UNDO_TO_FREE) {
|
|
|
|
goto add_to_list;
|
|
}
|
|
|
|
last_addr = flst_get_last(seg_header + TRX_UNDO_PAGE_LIST, mtr);
|
|
|
|
undo->last_page_no = last_addr.page;
|
|
undo->top_page_no = last_addr.page;
|
|
|
|
last_page = trx_undo_page_get(rseg->space, undo->last_page_no, mtr);
|
|
|
|
rec = trx_undo_page_get_last_rec(last_page, page_no, offset);
|
|
|
|
if (rec == NULL) {
|
|
undo->empty = TRUE;
|
|
} else {
|
|
undo->empty = FALSE;
|
|
undo->top_offset = rec - last_page;
|
|
undo->top_undo_no = trx_undo_rec_get_undo_no(rec);
|
|
}
|
|
add_to_list:
|
|
if (type == TRX_UNDO_INSERT) {
|
|
if (state != TRX_UNDO_CACHED) {
|
|
UT_LIST_ADD_LAST(undo_list, rseg->insert_undo_list,
|
|
undo);
|
|
} else {
|
|
UT_LIST_ADD_LAST(undo_list, rseg->insert_undo_cached,
|
|
undo);
|
|
}
|
|
} else {
|
|
ut_ad(type == TRX_UNDO_UPDATE);
|
|
if (state != TRX_UNDO_CACHED) {
|
|
UT_LIST_ADD_LAST(undo_list, rseg->update_undo_list,
|
|
undo);
|
|
} else {
|
|
UT_LIST_ADD_LAST(undo_list, rseg->update_undo_cached,
|
|
undo);
|
|
}
|
|
}
|
|
|
|
return(undo);
|
|
}
|
|
|
|
/************************************************************************
|
|
Initializes the undo log lists for a rollback segment memory copy. This
|
|
function is only called when the database is started or a new rollback
|
|
segment is created. */
|
|
|
|
ulint
|
|
trx_undo_lists_init(
|
|
/*================*/
|
|
/* out: the combined size of undo log segments
|
|
in pages */
|
|
trx_rseg_t* rseg) /* in: rollback segment memory object */
|
|
{
|
|
ulint page_no;
|
|
trx_undo_t* undo;
|
|
ulint size = 0;
|
|
trx_rsegf_t* rseg_header;
|
|
ulint i;
|
|
mtr_t mtr;
|
|
|
|
UT_LIST_INIT(rseg->update_undo_list);
|
|
UT_LIST_INIT(rseg->update_undo_cached);
|
|
UT_LIST_INIT(rseg->insert_undo_list);
|
|
UT_LIST_INIT(rseg->insert_undo_cached);
|
|
|
|
mtr_start(&mtr);
|
|
|
|
rseg_header = trx_rsegf_get_new(rseg->space, rseg->page_no, &mtr);
|
|
|
|
for (i = 0; i < TRX_RSEG_N_SLOTS; i++) {
|
|
page_no = trx_rsegf_get_nth_undo(rseg_header, i, &mtr);
|
|
|
|
/* In forced recovery: try to avoid operations which look
|
|
at database pages; undo logs are rapidly changing data, and
|
|
the probability that they are in an inconsistent state is
|
|
high */
|
|
|
|
if (page_no != FIL_NULL
|
|
&& srv_force_recovery < SRV_FORCE_NO_UNDO_LOG_SCAN) {
|
|
|
|
undo = trx_undo_mem_create_at_db_start(rseg, i,
|
|
page_no, &mtr);
|
|
size += undo->size;
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
mtr_start(&mtr);
|
|
|
|
rseg_header = trx_rsegf_get(rseg->space,
|
|
rseg->page_no, &mtr);
|
|
}
|
|
}
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
return(size);
|
|
}
|
|
|
|
/************************************************************************
|
|
Creates and initializes an undo log memory object. */
|
|
static
|
|
trx_undo_t*
|
|
trx_undo_mem_create(
|
|
/*================*/
|
|
/* out, own: the undo log memory object */
|
|
trx_rseg_t* rseg, /* in: rollback segment memory object */
|
|
ulint id, /* in: slot index within rseg */
|
|
ulint type, /* in: type of the log: TRX_UNDO_INSERT or
|
|
TRX_UNDO_UPDATE */
|
|
dulint trx_id, /* in: id of the trx for which the undo log
|
|
is created */
|
|
XID* xid, /* in: X/Open transaction identification */
|
|
ulint page_no,/* in: undo log header page number */
|
|
ulint offset) /* in: undo log header byte offset on page */
|
|
{
|
|
trx_undo_t* undo;
|
|
|
|
ut_ad(mutex_own(&(rseg->mutex)));
|
|
|
|
if (id >= TRX_RSEG_N_SLOTS) {
|
|
fprintf(stderr,
|
|
"InnoDB: Error: undo->id is %lu\n", (ulong) id);
|
|
ut_error;
|
|
}
|
|
|
|
undo = mem_alloc(sizeof(trx_undo_t));
|
|
|
|
if (undo == NULL) {
|
|
|
|
return NULL;
|
|
}
|
|
|
|
undo->id = id;
|
|
undo->type = type;
|
|
undo->state = TRX_UNDO_ACTIVE;
|
|
undo->del_marks = FALSE;
|
|
undo->trx_id = trx_id;
|
|
undo->xid = *xid;
|
|
|
|
undo->dict_operation = FALSE;
|
|
|
|
undo->rseg = rseg;
|
|
|
|
undo->space = rseg->space;
|
|
undo->hdr_page_no = page_no;
|
|
undo->hdr_offset = offset;
|
|
undo->last_page_no = page_no;
|
|
undo->size = 1;
|
|
|
|
undo->empty = TRUE;
|
|
undo->top_page_no = page_no;
|
|
undo->guess_page = NULL;
|
|
|
|
return(undo);
|
|
}
|
|
|
|
/************************************************************************
|
|
Initializes a cached undo log object for new use. */
|
|
static
|
|
void
|
|
trx_undo_mem_init_for_reuse(
|
|
/*========================*/
|
|
trx_undo_t* undo, /* in: undo log to init */
|
|
dulint trx_id, /* in: id of the trx for which the undo log
|
|
is created */
|
|
XID* xid, /* in: X/Open XA transaction identification*/
|
|
ulint offset) /* in: undo log header byte offset on page */
|
|
{
|
|
ut_ad(mutex_own(&((undo->rseg)->mutex)));
|
|
|
|
if (UNIV_UNLIKELY(undo->id >= TRX_RSEG_N_SLOTS)) {
|
|
fprintf(stderr, "InnoDB: Error: undo->id is %lu\n",
|
|
(ulong) undo->id);
|
|
|
|
mem_analyze_corruption(undo);
|
|
ut_error;
|
|
}
|
|
|
|
undo->state = TRX_UNDO_ACTIVE;
|
|
undo->del_marks = FALSE;
|
|
undo->trx_id = trx_id;
|
|
undo->xid = *xid;
|
|
|
|
undo->dict_operation = FALSE;
|
|
|
|
undo->hdr_offset = offset;
|
|
undo->empty = TRUE;
|
|
}
|
|
|
|
/************************************************************************
|
|
Frees an undo log memory copy. */
|
|
static
|
|
void
|
|
trx_undo_mem_free(
|
|
/*==============*/
|
|
trx_undo_t* undo) /* in: the undo object to be freed */
|
|
{
|
|
if (undo->id >= TRX_RSEG_N_SLOTS) {
|
|
fprintf(stderr,
|
|
"InnoDB: Error: undo->id is %lu\n", (ulong) undo->id);
|
|
ut_error;
|
|
}
|
|
|
|
mem_free(undo);
|
|
}
|
|
|
|
/**************************************************************************
|
|
Creates a new undo log. */
|
|
static
|
|
ulint
|
|
trx_undo_create(
|
|
/*============*/
|
|
/* out: DB_SUCCESS if successful in creating
|
|
the new undo lob object, possible error
|
|
codes are:
|
|
DB_TOO_MANY_CONCURRENT_TRXS
|
|
DB_OUT_OF_FILE_SPACE
|
|
DB_OUT_OF_MEMORY*/
|
|
trx_t* trx, /* in: transaction */
|
|
trx_rseg_t* rseg, /* in: rollback segment memory copy */
|
|
ulint type, /* in: type of the log: TRX_UNDO_INSERT or
|
|
TRX_UNDO_UPDATE */
|
|
dulint trx_id, /* in: id of the trx for which the undo log
|
|
is created */
|
|
XID* xid, /* in: X/Open transaction identification*/
|
|
trx_undo_t** undo, /* out: the new undo log object, undefined
|
|
* if did not succeed */
|
|
mtr_t* mtr) /* in: mtr */
|
|
{
|
|
trx_rsegf_t* rseg_header;
|
|
ulint page_no;
|
|
ulint offset;
|
|
ulint id;
|
|
page_t* undo_page;
|
|
ulint err;
|
|
|
|
ut_ad(mutex_own(&(rseg->mutex)));
|
|
|
|
if (rseg->curr_size == rseg->max_size) {
|
|
|
|
return(DB_OUT_OF_FILE_SPACE);
|
|
}
|
|
|
|
rseg->curr_size++;
|
|
|
|
rseg_header = trx_rsegf_get(rseg->space, rseg->page_no, mtr);
|
|
|
|
err = trx_undo_seg_create(rseg, rseg_header, type, &id,
|
|
&undo_page, mtr);
|
|
|
|
if (err != DB_SUCCESS) {
|
|
/* Did not succeed */
|
|
|
|
rseg->curr_size--;
|
|
|
|
return(err);
|
|
}
|
|
|
|
page_no = buf_frame_get_page_no(undo_page);
|
|
|
|
offset = trx_undo_header_create(undo_page, trx_id, mtr);
|
|
|
|
if (trx->support_xa) {
|
|
trx_undo_header_add_space_for_xid(undo_page,
|
|
undo_page + offset, mtr);
|
|
}
|
|
|
|
*undo = trx_undo_mem_create(rseg, id, type, trx_id, xid,
|
|
page_no, offset);
|
|
if (*undo == NULL) {
|
|
|
|
err = DB_OUT_OF_MEMORY;
|
|
}
|
|
|
|
return(err);
|
|
}
|
|
|
|
/*================ UNDO LOG ASSIGNMENT AND CLEANUP =====================*/
|
|
|
|
/************************************************************************
|
|
Reuses a cached undo log. */
|
|
static
|
|
trx_undo_t*
|
|
trx_undo_reuse_cached(
|
|
/*==================*/
|
|
/* out: the undo log memory object, NULL if
|
|
none cached */
|
|
trx_t* trx, /* in: transaction */
|
|
trx_rseg_t* rseg, /* in: rollback segment memory object */
|
|
ulint type, /* in: type of the log: TRX_UNDO_INSERT or
|
|
TRX_UNDO_UPDATE */
|
|
dulint trx_id, /* in: id of the trx for which the undo log
|
|
is used */
|
|
XID* xid, /* in: X/Open XA transaction identification */
|
|
mtr_t* mtr) /* in: mtr */
|
|
{
|
|
trx_undo_t* undo;
|
|
page_t* undo_page;
|
|
ulint offset;
|
|
|
|
ut_ad(mutex_own(&(rseg->mutex)));
|
|
|
|
if (type == TRX_UNDO_INSERT) {
|
|
|
|
undo = UT_LIST_GET_FIRST(rseg->insert_undo_cached);
|
|
if (undo == NULL) {
|
|
|
|
return(NULL);
|
|
}
|
|
|
|
UT_LIST_REMOVE(undo_list, rseg->insert_undo_cached, undo);
|
|
} else {
|
|
ut_ad(type == TRX_UNDO_UPDATE);
|
|
|
|
undo = UT_LIST_GET_FIRST(rseg->update_undo_cached);
|
|
if (undo == NULL) {
|
|
|
|
return(NULL);
|
|
}
|
|
|
|
UT_LIST_REMOVE(undo_list, rseg->update_undo_cached, undo);
|
|
}
|
|
|
|
ut_ad(undo->size == 1);
|
|
|
|
if (undo->id >= TRX_RSEG_N_SLOTS) {
|
|
fprintf(stderr, "InnoDB: Error: undo->id is %lu\n",
|
|
(ulong) undo->id);
|
|
mem_analyze_corruption(undo);
|
|
ut_error;
|
|
}
|
|
|
|
undo_page = trx_undo_page_get(undo->space, undo->hdr_page_no, mtr);
|
|
|
|
if (type == TRX_UNDO_INSERT) {
|
|
offset = trx_undo_insert_header_reuse(undo_page, trx_id, mtr);
|
|
|
|
if (trx->support_xa) {
|
|
trx_undo_header_add_space_for_xid(
|
|
undo_page, undo_page + offset, mtr);
|
|
}
|
|
} else {
|
|
ut_a(mach_read_from_2(undo_page + TRX_UNDO_PAGE_HDR
|
|
+ TRX_UNDO_PAGE_TYPE)
|
|
== TRX_UNDO_UPDATE);
|
|
|
|
offset = trx_undo_header_create(undo_page, trx_id, mtr);
|
|
|
|
if (trx->support_xa) {
|
|
trx_undo_header_add_space_for_xid(
|
|
undo_page, undo_page + offset, mtr);
|
|
}
|
|
}
|
|
|
|
trx_undo_mem_init_for_reuse(undo, trx_id, xid, offset);
|
|
|
|
return(undo);
|
|
}
|
|
|
|
/**************************************************************************
|
|
Marks an undo log header as a header of a data dictionary operation
|
|
transaction. */
|
|
static
|
|
void
|
|
trx_undo_mark_as_dict_operation(
|
|
/*============================*/
|
|
trx_t* trx, /* in: dict op transaction */
|
|
trx_undo_t* undo, /* in: assigned undo log */
|
|
mtr_t* mtr) /* in: mtr */
|
|
{
|
|
page_t* hdr_page;
|
|
|
|
ut_a(trx->dict_operation);
|
|
|
|
hdr_page = trx_undo_page_get(undo->space, undo->hdr_page_no, mtr);
|
|
|
|
mlog_write_ulint(hdr_page + undo->hdr_offset
|
|
+ TRX_UNDO_DICT_TRANS,
|
|
trx->dict_operation, MLOG_1BYTE, mtr);
|
|
|
|
mlog_write_dulint(hdr_page + undo->hdr_offset + TRX_UNDO_TABLE_ID,
|
|
trx->table_id, mtr);
|
|
|
|
undo->dict_operation = trx->dict_operation;
|
|
undo->table_id = trx->table_id;
|
|
}
|
|
|
|
/**************************************************************************
|
|
Assigns an undo log for a transaction. A new undo log is created or a cached
|
|
undo log reused. */
|
|
|
|
ulint
|
|
trx_undo_assign_undo(
|
|
/*=================*/
|
|
/* out: DB_SUCCESS if undo log assign
|
|
successful, possible error codes are:
|
|
DD_TOO_MANY_CONCURRENT_TRXS
|
|
DB_OUT_OF_FILE_SPACE DB_OUT_OF_MEMORY*/
|
|
trx_t* trx, /* in: transaction */
|
|
ulint type) /* in: TRX_UNDO_INSERT or TRX_UNDO_UPDATE */
|
|
{
|
|
trx_rseg_t* rseg;
|
|
trx_undo_t* undo;
|
|
mtr_t mtr;
|
|
ulint err = DB_SUCCESS;
|
|
|
|
ut_ad(trx);
|
|
ut_ad(trx->rseg);
|
|
|
|
rseg = trx->rseg;
|
|
|
|
ut_ad(mutex_own(&(trx->undo_mutex)));
|
|
|
|
mtr_start(&mtr);
|
|
|
|
ut_ad(!mutex_own(&kernel_mutex));
|
|
|
|
mutex_enter(&(rseg->mutex));
|
|
|
|
undo = trx_undo_reuse_cached(trx, rseg, type, trx->id, &trx->xid,
|
|
&mtr);
|
|
if (undo == NULL) {
|
|
err = trx_undo_create(trx, rseg, type, trx->id, &trx->xid,
|
|
&undo, &mtr);
|
|
if (err != DB_SUCCESS) {
|
|
|
|
goto func_exit;
|
|
}
|
|
}
|
|
|
|
if (type == TRX_UNDO_INSERT) {
|
|
UT_LIST_ADD_FIRST(undo_list, rseg->insert_undo_list, undo);
|
|
ut_ad(trx->insert_undo == NULL);
|
|
trx->insert_undo = undo;
|
|
} else {
|
|
UT_LIST_ADD_FIRST(undo_list, rseg->update_undo_list, undo);
|
|
ut_ad(trx->update_undo == NULL);
|
|
trx->update_undo = undo;
|
|
}
|
|
|
|
if (trx->dict_operation) {
|
|
trx_undo_mark_as_dict_operation(trx, undo, &mtr);
|
|
}
|
|
|
|
func_exit:
|
|
mutex_exit(&(rseg->mutex));
|
|
mtr_commit(&mtr);
|
|
|
|
return err;
|
|
}
|
|
|
|
/**********************************************************************
|
|
Sets the state of the undo log segment at a transaction finish. */
|
|
|
|
page_t*
|
|
trx_undo_set_state_at_finish(
|
|
/*=========================*/
|
|
/* out: undo log segment header page,
|
|
x-latched */
|
|
trx_t* trx __attribute__((unused)), /* in: transaction */
|
|
trx_undo_t* undo, /* in: undo log memory copy */
|
|
mtr_t* mtr) /* in: mtr */
|
|
{
|
|
trx_usegf_t* seg_hdr;
|
|
trx_upagef_t* page_hdr;
|
|
page_t* undo_page;
|
|
ulint state;
|
|
|
|
ut_ad(trx && undo && mtr);
|
|
|
|
if (undo->id >= TRX_RSEG_N_SLOTS) {
|
|
fprintf(stderr, "InnoDB: Error: undo->id is %lu\n",
|
|
(ulong) undo->id);
|
|
mem_analyze_corruption(undo);
|
|
ut_error;
|
|
}
|
|
|
|
undo_page = trx_undo_page_get(undo->space, undo->hdr_page_no, mtr);
|
|
|
|
seg_hdr = undo_page + TRX_UNDO_SEG_HDR;
|
|
page_hdr = undo_page + TRX_UNDO_PAGE_HDR;
|
|
|
|
if (undo->size == 1 && mach_read_from_2(page_hdr + TRX_UNDO_PAGE_FREE)
|
|
< TRX_UNDO_PAGE_REUSE_LIMIT) {
|
|
state = TRX_UNDO_CACHED;
|
|
|
|
} else if (undo->type == TRX_UNDO_INSERT) {
|
|
|
|
state = TRX_UNDO_TO_FREE;
|
|
} else {
|
|
state = TRX_UNDO_TO_PURGE;
|
|
}
|
|
|
|
undo->state = state;
|
|
|
|
mlog_write_ulint(seg_hdr + TRX_UNDO_STATE, state, MLOG_2BYTES, mtr);
|
|
|
|
return(undo_page);
|
|
}
|
|
|
|
/**********************************************************************
|
|
Sets the state of the undo log segment at a transaction prepare. */
|
|
|
|
page_t*
|
|
trx_undo_set_state_at_prepare(
|
|
/*==========================*/
|
|
/* out: undo log segment header page,
|
|
x-latched */
|
|
trx_t* trx, /* in: transaction */
|
|
trx_undo_t* undo, /* in: undo log memory copy */
|
|
mtr_t* mtr) /* in: mtr */
|
|
{
|
|
trx_usegf_t* seg_hdr;
|
|
trx_upagef_t* page_hdr;
|
|
trx_ulogf_t* undo_header;
|
|
page_t* undo_page;
|
|
ulint offset;
|
|
|
|
ut_ad(trx && undo && mtr);
|
|
|
|
if (undo->id >= TRX_RSEG_N_SLOTS) {
|
|
fprintf(stderr, "InnoDB: Error: undo->id is %lu\n",
|
|
(ulong) undo->id);
|
|
mem_analyze_corruption(undo);
|
|
ut_error;
|
|
}
|
|
|
|
undo_page = trx_undo_page_get(undo->space, undo->hdr_page_no, mtr);
|
|
|
|
seg_hdr = undo_page + TRX_UNDO_SEG_HDR;
|
|
page_hdr = undo_page + TRX_UNDO_PAGE_HDR;
|
|
|
|
/*------------------------------*/
|
|
undo->state = TRX_UNDO_PREPARED;
|
|
undo->xid = trx->xid;
|
|
/*------------------------------*/
|
|
|
|
mlog_write_ulint(seg_hdr + TRX_UNDO_STATE, undo->state,
|
|
MLOG_2BYTES, mtr);
|
|
|
|
offset = mach_read_from_2(seg_hdr + TRX_UNDO_LAST_LOG);
|
|
undo_header = undo_page + offset;
|
|
|
|
mlog_write_ulint(undo_header + TRX_UNDO_XID_EXISTS,
|
|
TRUE, MLOG_1BYTE, mtr);
|
|
|
|
trx_undo_write_xid(undo_header, &undo->xid, mtr);
|
|
|
|
return(undo_page);
|
|
}
|
|
|
|
/**************************************************************************
|
|
Adds the update undo log header as the first in the history list, and
|
|
frees the memory object, or puts it to the list of cached update undo log
|
|
segments. */
|
|
|
|
void
|
|
trx_undo_update_cleanup(
|
|
/*====================*/
|
|
trx_t* trx, /* in: trx owning the update undo log */
|
|
page_t* undo_page, /* in: update undo log header page,
|
|
x-latched */
|
|
mtr_t* mtr) /* in: mtr */
|
|
{
|
|
trx_rseg_t* rseg;
|
|
trx_undo_t* undo;
|
|
|
|
undo = trx->update_undo;
|
|
rseg = trx->rseg;
|
|
|
|
ut_ad(mutex_own(&(rseg->mutex)));
|
|
|
|
trx_purge_add_update_undo_to_history(trx, undo_page, mtr);
|
|
|
|
UT_LIST_REMOVE(undo_list, rseg->update_undo_list, undo);
|
|
|
|
trx->update_undo = NULL;
|
|
|
|
if (undo->state == TRX_UNDO_CACHED) {
|
|
|
|
UT_LIST_ADD_FIRST(undo_list, rseg->update_undo_cached, undo);
|
|
} else {
|
|
ut_ad(undo->state == TRX_UNDO_TO_PURGE);
|
|
|
|
trx_undo_mem_free(undo);
|
|
}
|
|
}
|
|
|
|
/**********************************************************************
|
|
Frees or caches an insert undo log after a transaction commit or rollback.
|
|
Knowledge of inserts is not needed after a commit or rollback, therefore
|
|
the data can be discarded. */
|
|
|
|
void
|
|
trx_undo_insert_cleanup(
|
|
/*====================*/
|
|
trx_t* trx) /* in: transaction handle */
|
|
{
|
|
trx_undo_t* undo;
|
|
trx_rseg_t* rseg;
|
|
|
|
undo = trx->insert_undo;
|
|
ut_ad(undo);
|
|
|
|
rseg = trx->rseg;
|
|
|
|
mutex_enter(&(rseg->mutex));
|
|
|
|
UT_LIST_REMOVE(undo_list, rseg->insert_undo_list, undo);
|
|
trx->insert_undo = NULL;
|
|
|
|
if (undo->state == TRX_UNDO_CACHED) {
|
|
|
|
UT_LIST_ADD_FIRST(undo_list, rseg->insert_undo_cached, undo);
|
|
} else {
|
|
ut_ad(undo->state == TRX_UNDO_TO_FREE);
|
|
|
|
/* Delete first the undo log segment in the file */
|
|
|
|
mutex_exit(&(rseg->mutex));
|
|
|
|
trx_undo_seg_free(undo);
|
|
|
|
mutex_enter(&(rseg->mutex));
|
|
|
|
ut_ad(rseg->curr_size > undo->size);
|
|
|
|
rseg->curr_size -= undo->size;
|
|
|
|
trx_undo_mem_free(undo);
|
|
}
|
|
|
|
mutex_exit(&(rseg->mutex));
|
|
}
|