mirror of
https://github.com/MariaDB/server.git
synced 2025-02-01 11:31:51 +01:00
e578585049
------------------------------------------------------------------------ r6130 | marko | 2009-11-02 11:42:56 +0200 (Mon, 02 Nov 2009) | 9 lines Changed paths: M /branches/zip/ChangeLog M /branches/zip/btr/btr0sea.c M /branches/zip/buf/buf0buf.c M /branches/zip/dict/dict0dict.c M /branches/zip/fil/fil0fil.c M /branches/zip/ibuf/ibuf0ibuf.c M /branches/zip/include/btr0sea.h M /branches/zip/include/dict0dict.h M /branches/zip/include/fil0fil.h M /branches/zip/include/ibuf0ibuf.h M /branches/zip/include/lock0lock.h M /branches/zip/include/log0log.h M /branches/zip/include/log0recv.h M /branches/zip/include/mem0mem.h M /branches/zip/include/mem0pool.h M /branches/zip/include/os0file.h M /branches/zip/include/pars0pars.h M /branches/zip/include/srv0srv.h M /branches/zip/include/thr0loc.h M /branches/zip/include/trx0i_s.h M /branches/zip/include/trx0purge.h M /branches/zip/include/trx0rseg.h M /branches/zip/include/trx0sys.h M /branches/zip/include/trx0undo.h M /branches/zip/include/usr0sess.h M /branches/zip/lock/lock0lock.c M /branches/zip/log/log0log.c M /branches/zip/log/log0recv.c M /branches/zip/mem/mem0dbg.c M /branches/zip/mem/mem0pool.c M /branches/zip/os/os0file.c M /branches/zip/os/os0sync.c M /branches/zip/os/os0thread.c M /branches/zip/pars/lexyy.c M /branches/zip/pars/pars0lex.l M /branches/zip/que/que0que.c M /branches/zip/srv/srv0srv.c M /branches/zip/srv/srv0start.c M /branches/zip/sync/sync0arr.c M /branches/zip/sync/sync0sync.c M /branches/zip/thr/thr0loc.c M /branches/zip/trx/trx0i_s.c M /branches/zip/trx/trx0purge.c M /branches/zip/trx/trx0rseg.c M /branches/zip/trx/trx0sys.c M /branches/zip/trx/trx0undo.c M /branches/zip/usr/usr0sess.c M /branches/zip/ut/ut0mem.c branches/zip: Free all resources at shutdown. Set pointers to NULL, so that Valgrind will not complain about freed data structures that are reachable via pointers. This addresses Bug #45992 and Bug #46656. This patch is mostly based on changes copied from branches/embedded-1.0, mainly c5432, c3439, c3134, c2994, c2978, but also some other code was copied. Some added cleanup code is specific to MySQL/InnoDB. rb://199 approved by Sunny Bains ------------------------------------------------------------------------ r6134 | marko | 2009-11-04 09:57:29 +0200 (Wed, 04 Nov 2009) | 5 lines Changed paths: M /branches/zip/ChangeLog M /branches/zip/handler/ha_innodb.cc branches/zip: innobase_convert_identifier(): Convert table names with explain_filename() to address Bug #32430: 'show innodb status' causes errors Invalid (old?) table or database name in logs. rb://134 approved by Sunny Bains ------------------------------------------------------------------------ r6137 | marko | 2009-11-04 15:24:28 +0200 (Wed, 04 Nov 2009) | 1 line Changed paths: M /branches/zip/dict/dict0dict.c branches/zip: dict_index_too_big_for_undo(): Correct a typo. ------------------------------------------------------------------------ r6153 | vasil | 2009-11-10 15:33:22 +0200 (Tue, 10 Nov 2009) | 145 lines Changed paths: M /branches/zip/handler/ha_innodb.cc branches/zip: Merge r6125:6152 from branches/5.1: (everything except the last white-space change was skipped as it is already in branches/zip) ------------------------------------------------------------------------ r6127 | vasil | 2009-10-30 11:18:25 +0200 (Fri, 30 Oct 2009) | 18 lines Changed paths: M /branches/5.1/Makefile.am M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test branches/5.1: Backport c6121 from branches/zip: ------------------------------------------------------------------------ r6121 | sunny | 2009-10-30 01:42:11 +0200 (Fri, 30 Oct 2009) | 7 lines Changed paths: M /branches/zip/mysql-test/innodb-autoinc.result branches/zip: This test has been problematic for sometime now. The underlying bug is that the data dictionaries get out of sync. In the AUTOINC code we try and apply salve to the symptoms. In the past MySQL made some unrelated change and the dictionaries stopped getting out of sync and this test started to fail. Now, it seems they have reverted that changed and the test is passing again. I suspect this is not he last time that this test will change. ------------------------------------------------------------------------ ------------------------------------------------------------------------ r6129 | vasil | 2009-10-30 17:14:22 +0200 (Fri, 30 Oct 2009) | 4 lines Changed paths: M /branches/5.1/Makefile.am branches/5.1: Revert a change to Makefile.am that sneaked unnoticed in c6127. ------------------------------------------------------------------------ r6136 | marko | 2009-11-04 12:28:10 +0200 (Wed, 04 Nov 2009) | 15 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/ha_prototypes.h M /branches/5.1/ut/ut0ut.c branches/5.1: Port r6134 from branches/zip: ------------------------------------------------------------------------ r6134 | marko | 2009-11-04 07:57:29 +0000 (Wed, 04 Nov 2009) | 5 lines branches/zip: innobase_convert_identifier(): Convert table names with explain_filename() to address Bug #32430: 'show innodb status' causes errors Invalid (old?) table or database name in logs. rb://134 approved by Sunny Bains ------------------------------------------------------------------------ innobase_print_identifier(): Replace with innobase_convert_name(). innobase_convert_identifier(): New function, called by innobase_convert_name(). ------------------------------------------------------------------------ r6149 | vasil | 2009-11-09 11:15:01 +0200 (Mon, 09 Nov 2009) | 5 lines Changed paths: M /branches/5.1/CMakeLists.txt branches/5.1: Followup to r5700: Adjust the changes so they are the same as in the BZR repository. ------------------------------------------------------------------------ r6150 | vasil | 2009-11-09 11:43:31 +0200 (Mon, 09 Nov 2009) | 58 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Merge a part of r2911.5.5 from MySQL: (the other part of this was merged in c5700) ------------------------------------------------------------ revno: 2911.5.5 committer: Vladislav Vaintroub <vvaintroub@mysql.com> branch nick: 5.1-innodb_plugin timestamp: Wed 2009-06-10 10:59:49 +0200 message: Backport WL#3653 to 5.1 to enable bundled innodb plugin. Remove custom DLL loader code from innodb plugin code, use symbols exported from mysqld. removed: storage/innodb_plugin/handler/handler0vars.h storage/innodb_plugin/handler/win_delay_loader.cc added: storage/mysql_storage_engine.cmake win/create_def_file.js modified: CMakeLists.txt include/m_ctype.h include/my_global.h include/my_sys.h include/mysql/plugin.h libmysqld/CMakeLists.txt mysql-test/mysql-test-run.pl mysql-test/t/plugin.test mysql-test/t/plugin_load-master.opt mysys/charset.c sql/CMakeLists.txt sql/handler.h sql/mysql_priv.h sql/mysqld.cc sql/sql_class.cc sql/sql_class.h sql/sql_list.h sql/sql_profile.h storage/Makefile.am storage/archive/CMakeLists.txt storage/blackhole/CMakeLists.txt storage/csv/CMakeLists.txt storage/example/CMakeLists.txt storage/federated/CMakeLists.txt storage/heap/CMakeLists.txt storage/innobase/CMakeLists.txt storage/innobase/handler/ha_innodb.cc storage/innodb_plugin/CMakeLists.txt storage/innodb_plugin/handler/ha_innodb.cc storage/innodb_plugin/handler/handler0alter.cc storage/innodb_plugin/handler/i_s.cc storage/innodb_plugin/plug.in storage/myisam/CMakeLists.txt storage/myisammrg/CMakeLists.txt win/Makefile.am win/configure.js ------------------------------------------------------------------------ r6152 | vasil | 2009-11-10 15:30:20 +0200 (Tue, 10 Nov 2009) | 4 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: White space fixup. ------------------------------------------------------------------------ ------------------------------------------------------------------------ r6157 | jyang | 2009-11-11 14:27:09 +0200 (Wed, 11 Nov 2009) | 10 lines Changed paths: M /branches/zip/handler/ha_innodb.cc A /branches/zip/mysql-test/innodb_bug47167.result A /branches/zip/mysql-test/innodb_bug47167.test M /branches/zip/mysql-test/innodb_file_format.result branches/zip: Fix an issue that a local variable defined in innodb_file_format_check_validate() is being referenced across function in innodb_file_format_check_update(). In addition, fix "set global innodb_file_format_check = DEFAULT" call. Bug #47167: "set global innodb_file_format_check" cannot set value by User-Defined Variable." rb://169 approved by Sunny Bains and Marko. ------------------------------------------------------------------------ r6159 | vasil | 2009-11-11 15:13:01 +0200 (Wed, 11 Nov 2009) | 37 lines Changed paths: M /branches/zip/handler/ha_innodb.cc M /branches/zip/handler/ha_innodb.h branches/zip: Merge a change from MySQL: (this has been reviewed by Calvin and Marko, and Calvin says Luis has incorporated Marko's suggestions) ------------------------------------------------------------ revno: 3092.5.1 committer: Luis Soares <luis.soares@sun.com> branch nick: mysql-5.1-bugteam timestamp: Thu 2009-09-24 15:52:52 +0100 message: BUG#42829: binlogging enabled for all schemas regardless of binlog-db-db / binlog-ignore-db InnoDB will return an error if statement based replication is used along with transaction isolation level READ-COMMITTED (or weaker), even if the statement in question is filtered out according to the binlog-do-db rules set. In this case, an error should not be printed. This patch addresses this issue by extending the existing check in external_lock to take into account the filter rules before deciding to print an error. Furthermore, it also changes decide_logging_format to take into consideration whether the statement is filtered out from binlog before decision is made. added: mysql-test/suite/binlog/r/binlog_stm_do_db.result mysql-test/suite/binlog/t/binlog_stm_do_db-master.opt mysql-test/suite/binlog/t/binlog_stm_do_db.test modified: sql/sql_base.cc sql/sql_class.cc storage/innobase/handler/ha_innodb.cc storage/innobase/handler/ha_innodb.h storage/innodb_plugin/handler/ha_innodb.cc storage/innodb_plugin/handler/ha_innodb.h ------------------------------------------------------------------------ r6160 | vasil | 2009-11-11 15:33:49 +0200 (Wed, 11 Nov 2009) | 72 lines Changed paths: M /branches/zip/include/os0file.h M /branches/zip/os/os0file.c branches/zip: Merge r6152:6159 from branches/5.1: (r6158 was skipped as an equivallent change has already been merged from MySQL) ------------------------------------------------------------------------ r6154 | calvin | 2009-11-11 02:51:17 +0200 (Wed, 11 Nov 2009) | 17 lines Changed paths: M /branches/5.1/include/os0file.h M /branches/5.1/os/os0file.c branches/5.1: fix bug#3139: Mysql crashes: 'windows error 995' after several selects on a large DB During stress environment, Windows AIO may fail with error code ERROR_OPERATION_ABORTED. InnoDB does not handle the error, rather crashes. The cause of the error is unknown, but likely due to faulty hardware or driver. This patch introduces a new error code OS_FILE_OPERATION_ABORTED, which maps to Windows ERROR_OPERATION_ABORTED (995). When the error is detected during AIO, the InnoDB will issue a synchronous retry (read/write). This patch has been extensively tested by MySQL support. Approved by: Marko rb://196 ------------------------------------------------------------------------ r6158 | vasil | 2009-11-11 14:52:14 +0200 (Wed, 11 Nov 2009) | 37 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/handler/ha_innodb.h branches/5.1: Merge a change from MySQL: (this has been reviewed by Calvin and Marko, and Calvin says Luis has incorporated Marko's suggestions) ------------------------------------------------------------ revno: 3092.5.1 committer: Luis Soares <luis.soares@sun.com> branch nick: mysql-5.1-bugteam timestamp: Thu 2009-09-24 15:52:52 +0100 message: BUG#42829: binlogging enabled for all schemas regardless of binlog-db-db / binlog-ignore-db InnoDB will return an error if statement based replication is used along with transaction isolation level READ-COMMITTED (or weaker), even if the statement in question is filtered out according to the binlog-do-db rules set. In this case, an error should not be printed. This patch addresses this issue by extending the existing check in external_lock to take into account the filter rules before deciding to print an error. Furthermore, it also changes decide_logging_format to take into consideration whether the statement is filtered out from binlog before decision is made. added: mysql-test/suite/binlog/r/binlog_stm_do_db.result mysql-test/suite/binlog/t/binlog_stm_do_db-master.opt mysql-test/suite/binlog/t/binlog_stm_do_db.test modified: sql/sql_base.cc sql/sql_class.cc storage/innobase/handler/ha_innodb.cc storage/innobase/handler/ha_innodb.h storage/innodb_plugin/handler/ha_innodb.cc storage/innodb_plugin/handler/ha_innodb.h ------------------------------------------------------------------------ ------------------------------------------------------------------------ r6161 | vasil | 2009-11-11 15:36:16 +0200 (Wed, 11 Nov 2009) | 4 lines Changed paths: M /branches/zip/ChangeLog branches/zip: Add changelog entry for r6160. ------------------------------------------------------------------------ r6162 | vasil | 2009-11-11 16:00:12 +0200 (Wed, 11 Nov 2009) | 4 lines Changed paths: M /branches/zip/ChangeLog branches/zip: Add ChangeLog for r6157. ------------------------------------------------------------------------ r6163 | calvin | 2009-11-11 17:53:20 +0200 (Wed, 11 Nov 2009) | 8 lines Changed paths: M /branches/zip/handler/ha_innodb.cc M /branches/zip/handler/ha_innodb.h branches/zip: Exclude thd_binlog_filter_ok() when building with older version of MySQL. thd_binlog_filter_ok() is introduced in MySQL 5.1.41. But the plugin can be built with MySQL prior to 5.1.41. Approved by Heikki (on IM). ------------------------------------------------------------------------ r6169 | calvin | 2009-11-12 14:40:43 +0200 (Thu, 12 Nov 2009) | 6 lines Changed paths: A /branches/zip/mysql-test/innodb_bug46676.result A /branches/zip/mysql-test/innodb_bug46676.test branches/zip: add test case for bug#46676 This crash is reproducible with InnoDB plugin 1.0.4 + MySQL 5.1.37. But no longer reproducible after MySQL 5.1.38 (with plugin 1.0.5). Add test case to catch future regression. ------------------------------------------------------------------------ r6170 | marko | 2009-11-12 15:49:08 +0200 (Thu, 12 Nov 2009) | 4 lines Changed paths: M /branches/zip/ChangeLog M /branches/zip/handler/ha_innodb.cc M /branches/zip/include/db0err.h M /branches/zip/row/row0merge.c M /branches/zip/row/row0mysql.c branches/zip: Allow CREATE INDEX to be interrupted. (Issue #354) rb://183 approved by Heikki Tuuri ------------------------------------------------------------------------ r6175 | vasil | 2009-11-16 20:07:39 +0200 (Mon, 16 Nov 2009) | 4 lines Changed paths: M /branches/zip/ChangeLog branches/zip: Wrap line at 78th char in the ChangeLog ------------------------------------------------------------------------ r6177 | calvin | 2009-11-16 20:20:38 +0200 (Mon, 16 Nov 2009) | 2 lines Changed paths: M /branches/zip/ChangeLog branches/zip: add an entry to ChangeLog for r6065 ------------------------------------------------------------------------ r6179 | marko | 2009-11-17 10:19:34 +0200 (Tue, 17 Nov 2009) | 2 lines Changed paths: M /branches/zip/handler/ha_innodb.cc branches/zip: ha_innobase::change_active_index(): When the history is missing, report it to the client, not to the error log. ------------------------------------------------------------------------ r6181 | vasil | 2009-11-17 12:21:41 +0200 (Tue, 17 Nov 2009) | 33 lines Changed paths: M /branches/zip/mysql-test/innodb-index.test branches/zip: At the end of innodb-index.test: restore the environment as it was before the test was started to silence this warning: MTR's internal check of the test case 'main.innodb-index' failed. This means that the test case does not preserve the state that existed before the test case was executed. Most likely the test case did not do a proper clean-up. This is the diff of the states of the servers before and after the test case was executed: mysqltest: Logging to '/tmp/autotest.sh-20091117_033000-zip.btyZwu/mysql-5.1/mysql-test/var/tmp/check-mysqld_1.log'. mysqltest: Results saved in '/tmp/autotest.sh-20091117_033000-zip.btyZwu/mysql-5.1/mysql-test/var/tmp/check-mysqld_1.result'. mysqltest: Connecting to server localhost:13000 (socket /tmp/autotest.sh-20091117_033000-zip.btyZwu/mysql-5.1/mysql-test/var/tmp/mysqld.1.sock) as 'root', connection 'default', attempt 0 ... mysqltest: ... Connected. mysqltest: Start processing test commands from './include/check-testcase.test' ... mysqltest: ... Done processing test commands. --- /tmp/autotest.sh-20091117_033000-zip.btyZwu/mysql-5.1/mysql-test/var/tmp/check-mysqld_1.result 2009-11-17 13:10:40.000000000 +0300 +++ /tmp/autotest.sh-20091117_033000-zip.btyZwu/mysql-5.1/mysql-test/var/tmp/check-mysqld_1.reject 2009-11-17 13:10:54.000000000 +0300 @@ -84,7 +84,7 @@ INNODB_DOUBLEWRITE ON INNODB_FAST_SHUTDOWN 1 INNODB_FILE_FORMAT Antelope -INNODB_FILE_FORMAT_CHECK Antelope +INNODB_FILE_FORMAT_CHECK Barracuda INNODB_FILE_PER_TABLE OFF INNODB_FLUSH_LOG_AT_TRX_COMMIT 1 INNODB_FLUSH_METHOD mysqltest: Result content mismatch not ok ------------------------------------------------------------------------ r6182 | marko | 2009-11-17 13:49:15 +0200 (Tue, 17 Nov 2009) | 1 line Changed paths: M /branches/zip/mysql-test/innodb-consistent-master.opt M /branches/zip/mysql-test/innodb-consistent.result M /branches/zip/mysql-test/innodb-consistent.test M /branches/zip/mysql-test/innodb-use-sys-malloc-master.opt M /branches/zip/mysql-test/innodb-use-sys-malloc.result M /branches/zip/mysql-test/innodb-use-sys-malloc.test M /branches/zip/mysql-test/innodb_bug21704.result M /branches/zip/mysql-test/innodb_bug21704.test M /branches/zip/mysql-test/innodb_bug40360.test M /branches/zip/mysql-test/innodb_bug40565.result M /branches/zip/mysql-test/innodb_bug40565.test M /branches/zip/mysql-test/innodb_bug41904.result M /branches/zip/mysql-test/innodb_bug41904.test M /branches/zip/mysql-test/innodb_bug42101-nonzero-master.opt M /branches/zip/mysql-test/innodb_bug42101-nonzero.result M /branches/zip/mysql-test/innodb_bug42101-nonzero.test M /branches/zip/mysql-test/innodb_bug42101.result M /branches/zip/mysql-test/innodb_bug42101.test M /branches/zip/mysql-test/innodb_bug44032.result M /branches/zip/mysql-test/innodb_bug44032.test M /branches/zip/mysql-test/innodb_bug44369.result M /branches/zip/mysql-test/innodb_bug44369.test M /branches/zip/mysql-test/innodb_bug44571.result M /branches/zip/mysql-test/innodb_bug44571.test M /branches/zip/mysql-test/innodb_bug45357.test M /branches/zip/mysql-test/innodb_bug46000.result M /branches/zip/mysql-test/innodb_bug46000.test M /branches/zip/mysql-test/innodb_bug46676.result M /branches/zip/mysql-test/innodb_bug46676.test M /branches/zip/mysql-test/innodb_bug47167.result M /branches/zip/mysql-test/innodb_bug47167.test M /branches/zip/mysql-test/innodb_bug47777.result M /branches/zip/mysql-test/innodb_bug47777.test M /branches/zip/mysql-test/innodb_file_format.result M /branches/zip/mysql-test/innodb_file_format.test branches/zip: Set svn:eol-style on mysql-test files. ------------------------------------------------------------------------ r6183 | marko | 2009-11-17 13:51:16 +0200 (Tue, 17 Nov 2009) | 1 line Changed paths: M /branches/zip/mysql-test/innodb-consistent-master.opt M /branches/zip/mysql-test/innodb-master.opt M /branches/zip/mysql-test/innodb-semi-consistent-master.opt M /branches/zip/mysql-test/innodb-use-sys-malloc-master.opt M /branches/zip/mysql-test/innodb_bug42101-nonzero-master.opt branches/zip: Prepend loose_ to plugin-only mysql-test options. ------------------------------------------------------------------------ r6184 | marko | 2009-11-17 13:52:01 +0200 (Tue, 17 Nov 2009) | 1 line Changed paths: M /branches/zip/mysql-test/innodb-index.result M /branches/zip/mysql-test/innodb-index.test branches/zip: innodb-index.test: Restore innodb_file_format_check. ------------------------------------------------------------------------ r6185 | marko | 2009-11-17 16:44:20 +0200 (Tue, 17 Nov 2009) | 16 lines Changed paths: M /branches/zip/handler/ha_innodb.cc M /branches/zip/mysql-test/innodb.result M /branches/zip/mysql-test/innodb.test M /branches/zip/mysql-test/innodb_bug44369.result M /branches/zip/mysql-test/innodb_bug44369.test D /branches/zip/mysql-test/patches/innodb-index.diff M /branches/zip/row/row0mysql.c branches/zip: Report duplicate table names to the client connection, not to the error log. This change will allow innodb-index.test to be re-enabled. It was previously disabled, because mysql-test-run does not like output in the error log. row_create_table_for_mysql(): Do not output anything to the error log when reporting DB_DUPLICATE_KEY. Let the caller report the error. Add a TODO comment that the dict_table_t object is apparently not freed when an error occurs. create_table_def(): Convert InnoDB table names to the character set of the client connection for reporting. Use my_error(ER_WRONG_COLUMN_NAME) for reporting reserved column names. Report my_error(ER_TABLE_EXISTS_ERROR) when row_create_table_for_mysql() returns DB_DUPLICATE_KEY. rb://206 ------------------------------------------------------------------------ r6186 | vasil | 2009-11-17 16:48:14 +0200 (Tue, 17 Nov 2009) | 4 lines Changed paths: M /branches/zip/ChangeLog branches/zip: Add ChangeLog entry for r6185. ------------------------------------------------------------------------ r6189 | marko | 2009-11-18 11:36:18 +0200 (Wed, 18 Nov 2009) | 5 lines Changed paths: M /branches/zip/ChangeLog M /branches/zip/handler/handler0alter.cc branches/zip: ha_innobase::add_index(): When creating the primary key and the table is being locked by another transaction, do not attempt to drop the table. (Bug #48782) Approved by Sunny Bains over IM ------------------------------------------------------------------------ r6194 | vasil | 2009-11-19 09:24:45 +0200 (Thu, 19 Nov 2009) | 5 lines Changed paths: M /branches/zip/include/univ.i branches/zip: Increment version number from 1.0.5 to 1.0.6 since 1.0.5 was just released by MySQL and we will soon release 1.0.6. ------------------------------------------------------------------------ r6197 | calvin | 2009-11-19 09:32:55 +0200 (Thu, 19 Nov 2009) | 6 lines Changed paths: M /branches/zip/CMakeLists.txt branches/zip: merge the fix of bug#48317 (CMake file) Due to MySQL changes to the CMake, it is no longer able to build InnoDB plugin as a static library on Windows. The fix is proposed by Vlad of MySQL. ------------------------------------------------------------------------ r6198 | vasil | 2009-11-19 09:44:31 +0200 (Thu, 19 Nov 2009) | 4 lines Changed paths: M /branches/zip/ChangeLog branches/zip: Add ChangeLog entry for r6197. ------------------------------------------------------------------------ r6199 | vasil | 2009-11-19 12:10:12 +0200 (Thu, 19 Nov 2009) | 31 lines Changed paths: M /branches/zip/ChangeLog M /branches/zip/btr/btr0btr.c M /branches/zip/data/data0type.c branches/zip: Merge r6159:6198 from branches/5.1: ------------------------------------------------------------------------ r6187 | jyang | 2009-11-18 05:27:30 +0200 (Wed, 18 Nov 2009) | 9 lines Changed paths: M /branches/5.1/btr/btr0btr.c branches/5.1: Fix bug #48469 "when innodb tablespace is configured too small, crash and corruption!". Function btr_create() did not check the return status of fseg_create(), and continue the index creation even there is no sufficient space. rb://205 Approved by Marko ------------------------------------------------------------------------ r6188 | jyang | 2009-11-18 07:14:23 +0200 (Wed, 18 Nov 2009) | 8 lines Changed paths: M /branches/5.1/data/data0type.c branches/5.1: Fix bug #48526 "Data type for float and double is incorrectly reported in InnoDB table monitor". Certain datatypes are not printed correctly in dtype_print(). rb://204 Approved by Marko. ------------------------------------------------------------------------ ------------------------------------------------------------------------ r6201 | marko | 2009-11-19 14:09:11 +0200 (Thu, 19 Nov 2009) | 2 lines Changed paths: M /branches/zip/handler/handler0alter.cc branches/zip: ha_innobase::add_index(): Clarify the comment on orphaned tables when creating a primary key. ------------------------------------------------------------------------ r6202 | jyang | 2009-11-19 15:01:00 +0200 (Thu, 19 Nov 2009) | 8 lines Changed paths: M /branches/zip/btr/btr0btr.c branches/zip: Function fseg_free() is no longer defined in branches/zip. To port fix for bug #48469 to zip, we can use btr_free_root() which frees the page, and also does not require mini-transaction. Approved by Marko. ------------------------------------------------------------------------ r6207 | vasil | 2009-11-20 10:19:14 +0200 (Fri, 20 Nov 2009) | 54 lines Changed paths: M /branches/zip/handler/ha_innodb.cc branches/zip: Merge r6198:6206 from branches/5.1: (r6203 was skipped as it is already in branches/zip) ------------------------------------------------------------------------ r6200 | vasil | 2009-11-19 12:14:23 +0200 (Thu, 19 Nov 2009) | 4 lines Changed paths: M /branches/5.1/btr/btr0btr.c branches/5.1: White space fixup - indent under the opening ( ------------------------------------------------------------------------ r6203 | jyang | 2009-11-19 15:12:22 +0200 (Thu, 19 Nov 2009) | 8 lines Changed paths: M /branches/5.1/btr/btr0btr.c branches/5.1: Use btr_free_root() instead of fseg_free() for the fix of bug #48469, because fseg_free() is not defined in the zip branch. And we could save one mini-trasaction started by fseg_free(). Approved by Marko. ------------------------------------------------------------------------ r6205 | jyang | 2009-11-20 07:55:48 +0200 (Fri, 20 Nov 2009) | 11 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Add a special case to handle the Duplicated Key error and return DB_ERROR instead. This is to avoid a possible SIGSEGV by mysql error handling re-entering the storage layer for dup key info without proper table handle. This is to prevent a server crash when error situation in bug #45961 "DDL on partitioned innodb tables leaves data dictionary in an inconsistent state" happens. rb://157 approved by Sunny Bains. ------------------------------------------------------------------------ r6206 | jyang | 2009-11-20 09:38:43 +0200 (Fri, 20 Nov 2009) | 5 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Fix a minor code formating issue for the parenthesis iplacement of the if condition in rename_table(). ------------------------------------------------------------------------ ------------------------------------------------------------------------ r6208 | vasil | 2009-11-20 10:49:24 +0200 (Fri, 20 Nov 2009) | 4 lines Changed paths: M /branches/zip/ChangeLog branches/zip: Add ChangeLog entry for c6207. ------------------------------------------------------------------------ r6210 | vasil | 2009-11-20 23:39:48 +0200 (Fri, 20 Nov 2009) | 3 lines Changed paths: M /branches/zip/trx/trx0i_s.c branches/zip: Whitespace fixup. ------------------------------------------------------------------------ r6248 | marko | 2009-11-30 12:19:50 +0200 (Mon, 30 Nov 2009) | 1 line Changed paths: M /branches/zip/ChangeLog branches/zip: ChangeLog: Document r4922 that was forgotten. ------------------------------------------------------------------------ r6252 | marko | 2009-11-30 12:50:11 +0200 (Mon, 30 Nov 2009) | 23 lines Changed paths: M /branches/zip/ChangeLog M /branches/zip/dict/dict0boot.c M /branches/zip/dict/dict0crea.c M /branches/zip/dict/dict0load.c M /branches/zip/dict/dict0mem.c M /branches/zip/fil/fil0fil.c M /branches/zip/handler/ha_innodb.cc M /branches/zip/include/dict0mem.h M /branches/zip/row/row0mysql.c branches/zip: Suppress errors about non-found temporary tables. Write the is_temp flag to SYS_TABLES.MIX_LEN. dict_table_t:🎏 Add a flag for is_temporary, DICT_TF2_TEMPORARY. Unlike other flags, this will not be written to the tablespace flags or SYS_TABLES.TYPE, but only to SYS_TABLES.MIX_LEN. dict_build_table_def_step(): Only pass DICT_TF_BITS to tablespaces. dict_check_tablespaces_and_store_max_id(), dict_load_table(): Suppress errors about temporary tables not being found. dict_create_sys_tables_tuple(): Write the DICT_TF2_TEMPORARY flag to SYS_TABLES.MIX_LEN. fil_space_create(), fil_create_new_single_table_tablespace(): Add assertions about space->flags. row_drop_table_for_mysql(): Do not complain about non-found temporary tables. rb://160 approved by Heikki Tuuri. This addresses the second part of Bug #41609 Crash recovery does not work for InnoDB temporary tables. ------------------------------------------------------------------------ r6263 | vasil | 2009-12-01 14:49:05 +0200 (Tue, 01 Dec 2009) | 4 lines Changed paths: M /branches/zip/include/univ.i branches/zip: Increment version number from 1.0.6 to 1.0.7 1.0.6 has been released ------------------------------------------------------------------------ r6264 | vasil | 2009-12-01 16:19:44 +0200 (Tue, 01 Dec 2009) | 1 line Changed paths: M /branches/zip/ChangeLog branches/zip: Add ChangeLog entry for the release of 1.0.6. ------------------------------------------------------------------------ r6269 | marko | 2009-12-02 11:35:22 +0200 (Wed, 02 Dec 2009) | 2 lines Changed paths: M /branches/zip/srv/srv0start.c branches/zip: innobase_start_or_create_for_mysql(): UNIV_IBUF_DEBUG should not break crash recovery, but UNIV_IBUF_COUNT_DEBUG will. ------------------------------------------------------------------------ r6270 | marko | 2009-12-02 11:36:47 +0200 (Wed, 02 Dec 2009) | 1 line Changed paths: M /branches/zip/srv/srv0start.c branches/zip: innobase_start_or_create_for_mysql(): Log the zlib version. ------------------------------------------------------------------------ r6271 | marko | 2009-12-02 11:43:49 +0200 (Wed, 02 Dec 2009) | 2 lines Changed paths: M /branches/zip/ChangeLog M /branches/zip/Makefile.am M /branches/zip/include/univ.i M /branches/zip/plug.in branches/zip: ChangeLog: Document that since r6270, the zlib version number will be displayed at start-up. ------------------------------------------------------------------------ r6272 | marko | 2009-12-02 11:46:05 +0200 (Wed, 02 Dec 2009) | 1 line Changed paths: M /branches/zip/Makefile.am M /branches/zip/include/univ.i M /branches/zip/plug.in branches/zip: Revert changes that were accidentally committed in r6271. ------------------------------------------------------------------------ r6274 | marko | 2009-12-03 14:47:12 +0200 (Thu, 03 Dec 2009) | 6 lines Changed paths: M /branches/zip/dict/dict0dict.c branches/zip: dict_table_check_for_dup_indexes(): Assert that the data dictionary mutex is being held while table->indexes is accessed. This is already the case. Currently, only dict_table_get_next_index() and dict_table_get_first_index() are being invoked without holding dict_sys->mutex. ------------------------------------------------------------------------ r6275 | pekka | 2009-12-03 18:32:47 +0200 (Thu, 03 Dec 2009) | 10 lines Changed paths: M /branches/zip/include/log0recv.h M /branches/zip/include/trx0sys.h M /branches/zip/log/log0recv.c M /branches/zip/trx/trx0sys.c branches/zip: Minor changes which allow build with UNIV_HOTBACKUP defined to succeed: include/trx0sys.h: Allow Hot Backup build to see some TRX_SYS_DOUBLEWRITE_... macros. trx/trx0sys.c: Exclude trx_sys_close() function from Hot Backup build. log/log0recv.[ch]: Exclude recv_sys_var_init() function from Hot Backup build. This change should not affect !UNIV_HOTBACKUP build. ------------------------------------------------------------------------ r6277 | marko | 2009-12-08 11:13:36 +0200 (Tue, 08 Dec 2009) | 1 line Changed paths: M /branches/zip/fsp/fsp0fsp.c branches/zip: fsp0fsp.c: Add some missing in/out and const qualifiers. ------------------------------------------------------------------------ r6285 | marko | 2009-12-09 09:24:50 +0200 (Wed, 09 Dec 2009) | 13 lines Changed paths: M /branches/zip/row/row0sel.c branches/zip: row_sel_fetch_columns(): Remove redundant code that was accidentally added in r1591, which introduced dfield_t::ext in order to make the merge sort of fast index creation support externally stored columns, Initially, I tried to allocate the bit for dfield_t::ext from dfield_t::len by making the length 31 bits and mapping UNIV_SQL_NULL to something that would fit in it. Then I decided that it would be too risky. The redundant check was part of the mapping. The condition may have been dfield_is_null() initially. This redundant code was noticed by Sergey Petrunya on the MySQL internals list. ------------------------------------------------------------------------ r6288 | marko | 2009-12-09 09:51:00 +0200 (Wed, 09 Dec 2009) | 15 lines Changed paths: M /branches/zip/row/row0upd.c branches/zip: row_upd_copy_columns(): Remove redundant code that was accidentally added in r1591, which introduced dfield_t::ext in order to make the merge sort of fast index creation support externally stored columns. Initially, I tried to allocate the bit for dfield_t::ext from dfield_t::len by making the length 31 bits and mapping UNIV_SQL_NULL to something that would fit in it. Then I decided that it would be too risky. The redundant check was part of the mapping. The condition may have been dfield_is_null() initially. This is similar to the redundant code in row_sel_fetch_columns() that was noticed by Sergey Petrunya on the MySQL internals list and removed in r6285. As far as I can tell, there are no redundant UNIV_SQL_NULL assignments remaining after this change. ------------------------------------------------------------------------ r6305 | marko | 2009-12-14 13:03:57 +0200 (Mon, 14 Dec 2009) | 2 lines Changed paths: M /branches/zip/row/row0umod.c branches/zip: row_undo_mod_del_unmark_sec_and_undo_update(): Add a missing const qualifier. ------------------------------------------------------------------------ r6309 | marko | 2009-12-15 14:05:50 +0200 (Tue, 15 Dec 2009) | 3 lines Changed paths: M /branches/zip/lock/lock0lock.c branches/zip: lock_rec_insert_check_and_lock(): Avoid casting away constness. Use page_rec_get_next_const() instead. This silences a gcc 4.2.4 warning. Reported by Sunny Bains. ------------------------------------------------------------------------ r6312 | marko | 2009-12-16 10:10:36 +0200 (Wed, 16 Dec 2009) | 6 lines Changed paths: M /branches/zip/fil/fil0fil.c branches/zip: fil_close(): Add #ifndef UNIV_HOTBACKUP around a debug assertion on mutex.magic_n. InnoDB Hot Backup is a single-threaded program and does not contain mutexes. This change allows InnoDB Hot Backup to be compiled with UNIV_DEBUG. Suggested by Michael Izioumtchenko. ------------------------------------------------------------------------ r6321 | marko | 2009-12-16 16:16:33 +0200 (Wed, 16 Dec 2009) | 4 lines Changed paths: M /branches/zip/row/row0merge.c branches/zip: row_merge_drop_temp_indexes(): Revert a hack to transaction isolation level that was made unnecessary by r5826 (Issue #337). When this function is called, any active data dictionary transaction should have been rolled back. ------------------------------------------------------------------------ r6345 | marko | 2009-12-21 10:46:14 +0200 (Mon, 21 Dec 2009) | 7 lines Changed paths: M /branches/zip/log/log0recv.c branches/zip: recv_scan_log_recs(): Non-functional change: Replace a debug assertion ut_ad(len > 0) with ut_ad(len >= OS_FILE_LOG_BLOCK_SIZE). This change is only for readability, for Issue #428. Another assertion on len being an integer multiple of OS_FILE_LOG_BLOCK_SIZE already ensured together with the old ut_ad(len > 0) that actually len must be at least OS_FILE_LOG_BLOCK_SIZE. ------------------------------------------------------------------------ r6346 | marko | 2009-12-21 12:03:25 +0200 (Mon, 21 Dec 2009) | 2 lines Changed paths: M /branches/zip/log/log0recv.c branches/zip: recv_recovery_from_checkpoint_finish(): Revert a change that was accidentally committed in r6345. ------------------------------------------------------------------------ r6348 | marko | 2009-12-22 11:04:34 +0200 (Tue, 22 Dec 2009) | 37 lines Changed paths: M /branches/zip/handler/ha_innodb.cc M /branches/zip/include/ha_prototypes.h M /branches/zip/include/trx0trx.h M /branches/zip/lock/lock0lock.c M /branches/zip/trx/trx0i_s.c M /branches/zip/trx/trx0trx.c branches/zip: Merge a change from MySQL: ------------------------------------------------------------ revno: 3236 committer: Satya B <satya.bn@sun.com> branch nick: mysql-5.1-bugteam timestamp: Tue 2009-12-01 17:48:57 +0530 message: merge to mysql-5.1-bugteam ------------------------------------------------------------ revno: 3234.1.1 committer: Gleb Shchepa <gshchepa@mysql.com> branch nick: mysql-5.1-bugteam timestamp: Tue 2009-12-01 14:38:40 +0400 message: Bug #38883 (reopened): thd_security_context is not thread safe, crashes? manual merge 5.0-->5.1, updating InnoDB plugin. ------------------------------------------------------------ revno: 1810.3968.13 committer: Gleb Shchepa <gshchepa@mysql.com> branch nick: mysql-5.0-bugteam timestamp: Tue 2009-12-01 14:24:44 +0400 message: Bug #38883 (reopened): thd_security_context is not thread safe, crashes? The bug 38816 changed the lock that protects THD::query from LOCK_thread_count to LOCK_thd_data, but didn't update the associated InnoDB functions. 1. The innobase_mysql_prepare_print_arbitrary_thd and the innobase_mysql_end_print_arbitrary_thd InnoDB functions have been removed, since now we have a per-thread mutex: now we don't need to wrap several inter-thread access tries to THD::query with a single global LOCK_thread_count lock, so we can simplify the code. 2. The innobase_mysql_print_thd function has been modified to lock LOCK_thd_data in direct way. ------------------------------------------------------------------------ r6351 | marko | 2009-12-22 11:11:18 +0200 (Tue, 22 Dec 2009) | 1 line Changed paths: M /branches/zip/handler/ha_innodb.cc branches/zip: Remove an obsolete declaration of LOCK_thread_count. ------------------------------------------------------------------------ r6352 | marko | 2009-12-22 12:33:01 +0200 (Tue, 22 Dec 2009) | 104 lines Changed paths: M /branches/zip/handler/ha_innodb.cc M /branches/zip/include/lock0lock.h M /branches/zip/include/srv0srv.h M /branches/zip/lock/lock0lock.c M /branches/zip/log/log0log.c M /branches/zip/mysql-test/innodb-autoinc.result M /branches/zip/mysql-test/innodb-autoinc.test M /branches/zip/row/row0sel.c M /branches/zip/srv/srv0srv.c M /branches/zip/srv/srv0start.c branches/zip: Merge revisions 6206:6350 from branches/5.1, except r6347, r6349, r6350 which were committed separately to both branches, and r6310, which was backported from zip to 5.1. ------------------------------------------------------------------------ r6206 | jyang | 2009-11-20 09:38:43 +0200 (Fri, 20 Nov 2009) | 3 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Non-functional change, fix formatting. ------------------------------------------------------------------------ r6230 | sunny | 2009-11-24 23:52:43 +0200 (Tue, 24 Nov 2009) | 3 lines Changed paths: M /branches/5.1/mysql-test/innodb-autoinc.result branches/5.1: Fix autoinc failing test results. (this should be skipped when merging 5.1 into zip) ------------------------------------------------------------------------ r6231 | sunny | 2009-11-25 10:26:27 +0200 (Wed, 25 Nov 2009) | 7 lines Changed paths: M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0sel.c branches/5.1: Fix BUG#49032 - auto_increment field does not initialize to last value in InnoDB Storage Engine. We use the appropriate function to read the column value for non-integer autoinc column types, namely float and double. rb://208. Approved by Marko. ------------------------------------------------------------------------ r6232 | sunny | 2009-11-25 10:27:39 +0200 (Wed, 25 Nov 2009) | 2 lines Changed paths: M /branches/5.1/row/row0sel.c branches/5.1: This is an interim fix, fix white space errors. ------------------------------------------------------------------------ r6233 | sunny | 2009-11-25 10:28:35 +0200 (Wed, 25 Nov 2009) | 2 lines Changed paths: M /branches/5.1/include/mach0data.h M /branches/5.1/include/mach0data.ic M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test M /branches/5.1/row/row0sel.c branches/5.1: This is an interim fix, fix tests and make read float/double arg const. ------------------------------------------------------------------------ r6234 | sunny | 2009-11-25 10:29:03 +0200 (Wed, 25 Nov 2009) | 2 lines Changed paths: M /branches/5.1/row/row0sel.c branches/5.1: This is an interim fix, fix whitepsace issues. ------------------------------------------------------------------------ r6235 | sunny | 2009-11-26 01:14:42 +0200 (Thu, 26 Nov 2009) | 9 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test branches/5.1: Fix Bug#47720 - REPLACE INTO Autoincrement column with negative values. This bug is similiar to the negative autoinc filter patch from earlier, with the additional handling of filtering out the negative column values set explicitly by the user. rb://184 Approved by Heikki. ------------------------------------------------------------------------ r6242 | vasil | 2009-11-27 22:07:12 +0200 (Fri, 27 Nov 2009) | 4 lines Changed paths: M /branches/5.1/export.sh branches/5.1: Minor changes to support plugin snapshots. ------------------------------------------------------------------------ r6306 | calvin | 2009-12-14 15:12:46 +0200 (Mon, 14 Dec 2009) | 5 lines Changed paths: M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test branches/5.1: fix bug#49267: innodb-autoinc.test fails on windows because of different case mode There is no change to the InnoDB code, only to fix test case by changing "T1" to "t1". ------------------------------------------------------------------------ r6324 | jyang | 2009-12-17 06:54:24 +0200 (Thu, 17 Dec 2009) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/lock0lock.h M /branches/5.1/include/srv0srv.h M /branches/5.1/lock/lock0lock.c M /branches/5.1/log/log0log.c M /branches/5.1/srv/srv0srv.c M /branches/5.1/srv/srv0start.c branches/5.1: Fix bug #47814 - Diagnostics are frequently not printed after a long lock wait in InnoDB. Separate out the lock wait timeout check thread from monitor information printing thread. rb://200 Approved by Marko. ------------------------------------------------------------------------ ------------------------------------------------------------------------ r6364 | marko | 2009-12-26 21:06:31 +0200 (Sat, 26 Dec 2009) | 4 lines Changed paths: M /branches/zip/ibuf/ibuf0ibuf.c branches/zip: ibuf_bitmap_get_map_page(): Define a wrapper macro that passes __FILE__, __LINE__ of the caller to buf_page_get_gen(). This will ease the diagnosis of the likes of Issue #135. ------------------------------------------------------------------------
4310 lines
120 KiB
C
4310 lines
120 KiB
C
/*****************************************************************************
|
|
|
|
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
|
|
|
|
This program is free software; you can redistribute it and/or modify it under
|
|
the terms of the GNU General Public License as published by the Free Software
|
|
Foundation; version 2 of the License.
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
|
Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*****************************************************************************/
|
|
|
|
/******************************************************************//**
|
|
@file fsp/fsp0fsp.c
|
|
File space management
|
|
|
|
Created 11/29/1995 Heikki Tuuri
|
|
***********************************************************************/
|
|
|
|
#include "fsp0fsp.h"
|
|
|
|
#ifdef UNIV_NONINL
|
|
#include "fsp0fsp.ic"
|
|
#endif
|
|
|
|
#include "buf0buf.h"
|
|
#include "fil0fil.h"
|
|
#include "mtr0log.h"
|
|
#include "ut0byte.h"
|
|
#include "page0page.h"
|
|
#include "page0zip.h"
|
|
#ifdef UNIV_HOTBACKUP
|
|
# include "fut0lst.h"
|
|
#else /* UNIV_HOTBACKUP */
|
|
# include "sync0sync.h"
|
|
# include "fut0fut.h"
|
|
# include "srv0srv.h"
|
|
# include "ibuf0ibuf.h"
|
|
# include "btr0btr.h"
|
|
# include "btr0sea.h"
|
|
# include "dict0boot.h"
|
|
# include "log0log.h"
|
|
#endif /* UNIV_HOTBACKUP */
|
|
#include "dict0mem.h"
|
|
|
|
|
|
#define FSP_HEADER_OFFSET FIL_PAGE_DATA /* Offset of the space header
|
|
within a file page */
|
|
|
|
/* The data structures in files are defined just as byte strings in C */
|
|
typedef byte fsp_header_t;
|
|
typedef byte xdes_t;
|
|
|
|
/* SPACE HEADER
|
|
============
|
|
|
|
File space header data structure: this data structure is contained in the
|
|
first page of a space. The space for this header is reserved in every extent
|
|
descriptor page, but used only in the first. */
|
|
|
|
/*-------------------------------------*/
|
|
#define FSP_SPACE_ID 0 /* space id */
|
|
#define FSP_NOT_USED 4 /* this field contained a value up to
|
|
which we know that the modifications
|
|
in the database have been flushed to
|
|
the file space; not used now */
|
|
#define FSP_SIZE 8 /* Current size of the space in
|
|
pages */
|
|
#define FSP_FREE_LIMIT 12 /* Minimum page number for which the
|
|
free list has not been initialized:
|
|
the pages >= this limit are, by
|
|
definition, free; note that in a
|
|
single-table tablespace where size
|
|
< 64 pages, this number is 64, i.e.,
|
|
we have initialized the space
|
|
about the first extent, but have not
|
|
physically allocted those pages to the
|
|
file */
|
|
#define FSP_SPACE_FLAGS 16 /* table->flags & ~DICT_TF_COMPACT */
|
|
#define FSP_FRAG_N_USED 20 /* number of used pages in the
|
|
FSP_FREE_FRAG list */
|
|
#define FSP_FREE 24 /* list of free extents */
|
|
#define FSP_FREE_FRAG (24 + FLST_BASE_NODE_SIZE)
|
|
/* list of partially free extents not
|
|
belonging to any segment */
|
|
#define FSP_FULL_FRAG (24 + 2 * FLST_BASE_NODE_SIZE)
|
|
/* list of full extents not belonging
|
|
to any segment */
|
|
#define FSP_SEG_ID (24 + 3 * FLST_BASE_NODE_SIZE)
|
|
/* 8 bytes which give the first unused
|
|
segment id */
|
|
#define FSP_SEG_INODES_FULL (32 + 3 * FLST_BASE_NODE_SIZE)
|
|
/* list of pages containing segment
|
|
headers, where all the segment inode
|
|
slots are reserved */
|
|
#define FSP_SEG_INODES_FREE (32 + 4 * FLST_BASE_NODE_SIZE)
|
|
/* list of pages containing segment
|
|
headers, where not all the segment
|
|
header slots are reserved */
|
|
/*-------------------------------------*/
|
|
/* File space header size */
|
|
#define FSP_HEADER_SIZE (32 + 5 * FLST_BASE_NODE_SIZE)
|
|
|
|
#define FSP_FREE_ADD 4 /* this many free extents are added
|
|
to the free list from above
|
|
FSP_FREE_LIMIT at a time */
|
|
|
|
/* FILE SEGMENT INODE
|
|
==================
|
|
|
|
Segment inode which is created for each segment in a tablespace. NOTE: in
|
|
purge we assume that a segment having only one currently used page can be
|
|
freed in a few steps, so that the freeing cannot fill the file buffer with
|
|
bufferfixed file pages. */
|
|
|
|
typedef byte fseg_inode_t;
|
|
|
|
#define FSEG_INODE_PAGE_NODE FSEG_PAGE_DATA
|
|
/* the list node for linking
|
|
segment inode pages */
|
|
|
|
#define FSEG_ARR_OFFSET (FSEG_PAGE_DATA + FLST_NODE_SIZE)
|
|
/*-------------------------------------*/
|
|
#define FSEG_ID 0 /* 8 bytes of segment id: if this is
|
|
ut_dulint_zero, it means that the
|
|
header is unused */
|
|
#define FSEG_NOT_FULL_N_USED 8
|
|
/* number of used segment pages in
|
|
the FSEG_NOT_FULL list */
|
|
#define FSEG_FREE 12
|
|
/* list of free extents of this
|
|
segment */
|
|
#define FSEG_NOT_FULL (12 + FLST_BASE_NODE_SIZE)
|
|
/* list of partially free extents */
|
|
#define FSEG_FULL (12 + 2 * FLST_BASE_NODE_SIZE)
|
|
/* list of full extents */
|
|
#define FSEG_MAGIC_N (12 + 3 * FLST_BASE_NODE_SIZE)
|
|
/* magic number used in debugging */
|
|
#define FSEG_FRAG_ARR (16 + 3 * FLST_BASE_NODE_SIZE)
|
|
/* array of individual pages
|
|
belonging to this segment in fsp
|
|
fragment extent lists */
|
|
#define FSEG_FRAG_ARR_N_SLOTS (FSP_EXTENT_SIZE / 2)
|
|
/* number of slots in the array for
|
|
the fragment pages */
|
|
#define FSEG_FRAG_SLOT_SIZE 4 /* a fragment page slot contains its
|
|
page number within space, FIL_NULL
|
|
means that the slot is not in use */
|
|
/*-------------------------------------*/
|
|
#define FSEG_INODE_SIZE \
|
|
(16 + 3 * FLST_BASE_NODE_SIZE \
|
|
+ FSEG_FRAG_ARR_N_SLOTS * FSEG_FRAG_SLOT_SIZE)
|
|
|
|
#define FSP_SEG_INODES_PER_PAGE(zip_size) \
|
|
(((zip_size ? zip_size : UNIV_PAGE_SIZE) \
|
|
- FSEG_ARR_OFFSET - 10) / FSEG_INODE_SIZE)
|
|
/* Number of segment inodes which fit on a
|
|
single page */
|
|
|
|
#define FSEG_MAGIC_N_VALUE 97937874
|
|
|
|
#define FSEG_FILLFACTOR 8 /* If this value is x, then if
|
|
the number of unused but reserved
|
|
pages in a segment is less than
|
|
reserved pages * 1/x, and there are
|
|
at least FSEG_FRAG_LIMIT used pages,
|
|
then we allow a new empty extent to
|
|
be added to the segment in
|
|
fseg_alloc_free_page. Otherwise, we
|
|
use unused pages of the segment. */
|
|
|
|
#define FSEG_FRAG_LIMIT FSEG_FRAG_ARR_N_SLOTS
|
|
/* If the segment has >= this many
|
|
used pages, it may be expanded by
|
|
allocating extents to the segment;
|
|
until that only individual fragment
|
|
pages are allocated from the space */
|
|
|
|
#define FSEG_FREE_LIST_LIMIT 40 /* If the reserved size of a segment
|
|
is at least this many extents, we
|
|
allow extents to be put to the free
|
|
list of the extent: at most
|
|
FSEG_FREE_LIST_MAX_LEN many */
|
|
#define FSEG_FREE_LIST_MAX_LEN 4
|
|
|
|
|
|
/* EXTENT DESCRIPTOR
|
|
=================
|
|
|
|
File extent descriptor data structure: contains bits to tell which pages in
|
|
the extent are free and which contain old tuple version to clean. */
|
|
|
|
/*-------------------------------------*/
|
|
#define XDES_ID 0 /* The identifier of the segment
|
|
to which this extent belongs */
|
|
#define XDES_FLST_NODE 8 /* The list node data structure
|
|
for the descriptors */
|
|
#define XDES_STATE (FLST_NODE_SIZE + 8)
|
|
/* contains state information
|
|
of the extent */
|
|
#define XDES_BITMAP (FLST_NODE_SIZE + 12)
|
|
/* Descriptor bitmap of the pages
|
|
in the extent */
|
|
/*-------------------------------------*/
|
|
|
|
#define XDES_BITS_PER_PAGE 2 /* How many bits are there per page */
|
|
#define XDES_FREE_BIT 0 /* Index of the bit which tells if
|
|
the page is free */
|
|
#define XDES_CLEAN_BIT 1 /* NOTE: currently not used!
|
|
Index of the bit which tells if
|
|
there are old versions of tuples
|
|
on the page */
|
|
/* States of a descriptor */
|
|
#define XDES_FREE 1 /* extent is in free list of space */
|
|
#define XDES_FREE_FRAG 2 /* extent is in free fragment list of
|
|
space */
|
|
#define XDES_FULL_FRAG 3 /* extent is in full fragment list of
|
|
space */
|
|
#define XDES_FSEG 4 /* extent belongs to a segment */
|
|
|
|
/* File extent data structure size in bytes. */
|
|
#define XDES_SIZE \
|
|
(XDES_BITMAP + UT_BITS_IN_BYTES(FSP_EXTENT_SIZE * XDES_BITS_PER_PAGE))
|
|
|
|
/* Offset of the descriptor array on a descriptor page */
|
|
#define XDES_ARR_OFFSET (FSP_HEADER_OFFSET + FSP_HEADER_SIZE)
|
|
|
|
#ifndef UNIV_HOTBACKUP
|
|
/* Flag to indicate if we have printed the tablespace full error. */
|
|
static ibool fsp_tbs_full_error_printed = FALSE;
|
|
|
|
/**********************************************************************//**
|
|
Returns an extent to the free list of a space. */
|
|
static
|
|
void
|
|
fsp_free_extent(
|
|
/*============*/
|
|
ulint space, /*!< in: space id */
|
|
ulint zip_size,/*!< in: compressed page size in bytes
|
|
or 0 for uncompressed pages */
|
|
ulint page, /*!< in: page offset in the extent */
|
|
mtr_t* mtr); /*!< in: mtr */
|
|
/**********************************************************************//**
|
|
Frees an extent of a segment to the space free list. */
|
|
static
|
|
void
|
|
fseg_free_extent(
|
|
/*=============*/
|
|
fseg_inode_t* seg_inode, /*!< in: segment inode */
|
|
ulint space, /*!< in: space id */
|
|
ulint zip_size,/*!< in: compressed page size in bytes
|
|
or 0 for uncompressed pages */
|
|
ulint page, /*!< in: page offset in the extent */
|
|
mtr_t* mtr); /*!< in: mtr handle */
|
|
/**********************************************************************//**
|
|
Calculates the number of pages reserved by a segment, and how
|
|
many pages are currently used.
|
|
@return number of reserved pages */
|
|
static
|
|
ulint
|
|
fseg_n_reserved_pages_low(
|
|
/*======================*/
|
|
fseg_inode_t* header, /*!< in: segment inode */
|
|
ulint* used, /*!< out: number of pages used (not
|
|
more than reserved) */
|
|
mtr_t* mtr); /*!< in: mtr handle */
|
|
/********************************************************************//**
|
|
Marks a page used. The page must reside within the extents of the given
|
|
segment. */
|
|
static
|
|
void
|
|
fseg_mark_page_used(
|
|
/*================*/
|
|
fseg_inode_t* seg_inode,/*!< in: segment inode */
|
|
ulint space, /*!< in: space id */
|
|
ulint zip_size,/*!< in: compressed page size in bytes
|
|
or 0 for uncompressed pages */
|
|
ulint page, /*!< in: page offset */
|
|
mtr_t* mtr); /*!< in: mtr */
|
|
/**********************************************************************//**
|
|
Returns the first extent descriptor for a segment. We think of the extent
|
|
lists of the segment catenated in the order FSEG_FULL -> FSEG_NOT_FULL
|
|
-> FSEG_FREE.
|
|
@return the first extent descriptor, or NULL if none */
|
|
static
|
|
xdes_t*
|
|
fseg_get_first_extent(
|
|
/*==================*/
|
|
fseg_inode_t* inode, /*!< in: segment inode */
|
|
ulint space, /*!< in: space id */
|
|
ulint zip_size,/*!< in: compressed page size in bytes
|
|
or 0 for uncompressed pages */
|
|
mtr_t* mtr); /*!< in: mtr */
|
|
/**********************************************************************//**
|
|
Puts new extents to the free list if
|
|
there are free extents above the free limit. If an extent happens
|
|
to contain an extent descriptor page, the extent is put to
|
|
the FSP_FREE_FRAG list with the page marked as used. */
|
|
static
|
|
void
|
|
fsp_fill_free_list(
|
|
/*===============*/
|
|
ibool init_space, /*!< in: TRUE if this is a single-table
|
|
tablespace and we are only initing
|
|
the tablespace's first extent
|
|
descriptor page and ibuf bitmap page;
|
|
then we do not allocate more extents */
|
|
ulint space, /*!< in: space */
|
|
fsp_header_t* header, /*!< in: space header */
|
|
mtr_t* mtr); /*!< in: mtr */
|
|
/**********************************************************************//**
|
|
Allocates a single free page from a segment. This function implements
|
|
the intelligent allocation strategy which tries to minimize file space
|
|
fragmentation.
|
|
@return the allocated page number, FIL_NULL if no page could be allocated */
|
|
static
|
|
ulint
|
|
fseg_alloc_free_page_low(
|
|
/*=====================*/
|
|
ulint space, /*!< in: space */
|
|
ulint zip_size,/*!< in: compressed page size in bytes
|
|
or 0 for uncompressed pages */
|
|
fseg_inode_t* seg_inode, /*!< in: segment inode */
|
|
ulint hint, /*!< in: hint of which page would be desirable */
|
|
byte direction, /*!< in: if the new page is needed because
|
|
of an index page split, and records are
|
|
inserted there in order, into which
|
|
direction they go alphabetically: FSP_DOWN,
|
|
FSP_UP, FSP_NO_DIR */
|
|
mtr_t* mtr); /*!< in: mtr handle */
|
|
#endif /* !UNIV_HOTBACKUP */
|
|
|
|
/**********************************************************************//**
|
|
Reads the file space size stored in the header page.
|
|
@return tablespace size stored in the space header */
|
|
UNIV_INTERN
|
|
ulint
|
|
fsp_get_size_low(
|
|
/*=============*/
|
|
page_t* page) /*!< in: header page (page 0 in the tablespace) */
|
|
{
|
|
return(mach_read_from_4(page + FSP_HEADER_OFFSET + FSP_SIZE));
|
|
}
|
|
|
|
#ifndef UNIV_HOTBACKUP
|
|
/**********************************************************************//**
|
|
Gets a pointer to the space header and x-locks its page.
|
|
@return pointer to the space header, page x-locked */
|
|
UNIV_INLINE
|
|
fsp_header_t*
|
|
fsp_get_space_header(
|
|
/*=================*/
|
|
ulint id, /*!< in: space id */
|
|
ulint zip_size,/*!< in: compressed page size in bytes
|
|
or 0 for uncompressed pages */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
buf_block_t* block;
|
|
fsp_header_t* header;
|
|
|
|
ut_ad(ut_is_2pow(zip_size));
|
|
ut_ad(zip_size <= UNIV_PAGE_SIZE);
|
|
ut_ad(!zip_size || zip_size >= PAGE_ZIP_MIN_SIZE);
|
|
ut_ad(id || !zip_size);
|
|
|
|
block = buf_page_get(id, zip_size, 0, RW_X_LATCH, mtr);
|
|
header = FSP_HEADER_OFFSET + buf_block_get_frame(block);
|
|
buf_block_dbg_add_level(block, SYNC_FSP_PAGE);
|
|
|
|
ut_ad(id == mach_read_from_4(FSP_SPACE_ID + header));
|
|
ut_ad(zip_size == dict_table_flags_to_zip_size(
|
|
mach_read_from_4(FSP_SPACE_FLAGS + header)));
|
|
return(header);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Gets a descriptor bit of a page.
|
|
@return TRUE if free */
|
|
UNIV_INLINE
|
|
ibool
|
|
xdes_get_bit(
|
|
/*=========*/
|
|
const xdes_t* descr, /*!< in: descriptor */
|
|
ulint bit, /*!< in: XDES_FREE_BIT or XDES_CLEAN_BIT */
|
|
ulint offset, /*!< in: page offset within extent:
|
|
0 ... FSP_EXTENT_SIZE - 1 */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
ulint index;
|
|
ulint byte_index;
|
|
ulint bit_index;
|
|
|
|
ut_ad(mtr_memo_contains_page(mtr, descr, MTR_MEMO_PAGE_X_FIX));
|
|
ut_ad((bit == XDES_FREE_BIT) || (bit == XDES_CLEAN_BIT));
|
|
ut_ad(offset < FSP_EXTENT_SIZE);
|
|
|
|
index = bit + XDES_BITS_PER_PAGE * offset;
|
|
|
|
byte_index = index / 8;
|
|
bit_index = index % 8;
|
|
|
|
return(ut_bit_get_nth(mtr_read_ulint(descr + XDES_BITMAP + byte_index,
|
|
MLOG_1BYTE, mtr),
|
|
bit_index));
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Sets a descriptor bit of a page. */
|
|
UNIV_INLINE
|
|
void
|
|
xdes_set_bit(
|
|
/*=========*/
|
|
xdes_t* descr, /*!< in: descriptor */
|
|
ulint bit, /*!< in: XDES_FREE_BIT or XDES_CLEAN_BIT */
|
|
ulint offset, /*!< in: page offset within extent:
|
|
0 ... FSP_EXTENT_SIZE - 1 */
|
|
ibool val, /*!< in: bit value */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
ulint index;
|
|
ulint byte_index;
|
|
ulint bit_index;
|
|
ulint descr_byte;
|
|
|
|
ut_ad(mtr_memo_contains_page(mtr, descr, MTR_MEMO_PAGE_X_FIX));
|
|
ut_ad((bit == XDES_FREE_BIT) || (bit == XDES_CLEAN_BIT));
|
|
ut_ad(offset < FSP_EXTENT_SIZE);
|
|
|
|
index = bit + XDES_BITS_PER_PAGE * offset;
|
|
|
|
byte_index = index / 8;
|
|
bit_index = index % 8;
|
|
|
|
descr_byte = mtr_read_ulint(descr + XDES_BITMAP + byte_index,
|
|
MLOG_1BYTE, mtr);
|
|
descr_byte = ut_bit_set_nth(descr_byte, bit_index, val);
|
|
|
|
mlog_write_ulint(descr + XDES_BITMAP + byte_index, descr_byte,
|
|
MLOG_1BYTE, mtr);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Looks for a descriptor bit having the desired value. Starts from hint
|
|
and scans upward; at the end of the extent the search is wrapped to
|
|
the start of the extent.
|
|
@return bit index of the bit, ULINT_UNDEFINED if not found */
|
|
UNIV_INLINE
|
|
ulint
|
|
xdes_find_bit(
|
|
/*==========*/
|
|
xdes_t* descr, /*!< in: descriptor */
|
|
ulint bit, /*!< in: XDES_FREE_BIT or XDES_CLEAN_BIT */
|
|
ibool val, /*!< in: desired bit value */
|
|
ulint hint, /*!< in: hint of which bit position would be desirable */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
ulint i;
|
|
|
|
ut_ad(descr && mtr);
|
|
ut_ad(val <= TRUE);
|
|
ut_ad(hint < FSP_EXTENT_SIZE);
|
|
ut_ad(mtr_memo_contains_page(mtr, descr, MTR_MEMO_PAGE_X_FIX));
|
|
for (i = hint; i < FSP_EXTENT_SIZE; i++) {
|
|
if (val == xdes_get_bit(descr, bit, i, mtr)) {
|
|
|
|
return(i);
|
|
}
|
|
}
|
|
|
|
for (i = 0; i < hint; i++) {
|
|
if (val == xdes_get_bit(descr, bit, i, mtr)) {
|
|
|
|
return(i);
|
|
}
|
|
}
|
|
|
|
return(ULINT_UNDEFINED);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Looks for a descriptor bit having the desired value. Scans the extent in
|
|
a direction opposite to xdes_find_bit.
|
|
@return bit index of the bit, ULINT_UNDEFINED if not found */
|
|
UNIV_INLINE
|
|
ulint
|
|
xdes_find_bit_downward(
|
|
/*===================*/
|
|
xdes_t* descr, /*!< in: descriptor */
|
|
ulint bit, /*!< in: XDES_FREE_BIT or XDES_CLEAN_BIT */
|
|
ibool val, /*!< in: desired bit value */
|
|
ulint hint, /*!< in: hint of which bit position would be desirable */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
ulint i;
|
|
|
|
ut_ad(descr && mtr);
|
|
ut_ad(val <= TRUE);
|
|
ut_ad(hint < FSP_EXTENT_SIZE);
|
|
ut_ad(mtr_memo_contains_page(mtr, descr, MTR_MEMO_PAGE_X_FIX));
|
|
for (i = hint + 1; i > 0; i--) {
|
|
if (val == xdes_get_bit(descr, bit, i - 1, mtr)) {
|
|
|
|
return(i - 1);
|
|
}
|
|
}
|
|
|
|
for (i = FSP_EXTENT_SIZE - 1; i > hint; i--) {
|
|
if (val == xdes_get_bit(descr, bit, i, mtr)) {
|
|
|
|
return(i);
|
|
}
|
|
}
|
|
|
|
return(ULINT_UNDEFINED);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Returns the number of used pages in a descriptor.
|
|
@return number of pages used */
|
|
UNIV_INLINE
|
|
ulint
|
|
xdes_get_n_used(
|
|
/*============*/
|
|
const xdes_t* descr, /*!< in: descriptor */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
ulint i;
|
|
ulint count = 0;
|
|
|
|
ut_ad(descr && mtr);
|
|
ut_ad(mtr_memo_contains_page(mtr, descr, MTR_MEMO_PAGE_X_FIX));
|
|
for (i = 0; i < FSP_EXTENT_SIZE; i++) {
|
|
if (FALSE == xdes_get_bit(descr, XDES_FREE_BIT, i, mtr)) {
|
|
count++;
|
|
}
|
|
}
|
|
|
|
return(count);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Returns true if extent contains no used pages.
|
|
@return TRUE if totally free */
|
|
UNIV_INLINE
|
|
ibool
|
|
xdes_is_free(
|
|
/*=========*/
|
|
const xdes_t* descr, /*!< in: descriptor */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
if (0 == xdes_get_n_used(descr, mtr)) {
|
|
|
|
return(TRUE);
|
|
}
|
|
|
|
return(FALSE);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Returns true if extent contains no free pages.
|
|
@return TRUE if full */
|
|
UNIV_INLINE
|
|
ibool
|
|
xdes_is_full(
|
|
/*=========*/
|
|
const xdes_t* descr, /*!< in: descriptor */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
if (FSP_EXTENT_SIZE == xdes_get_n_used(descr, mtr)) {
|
|
|
|
return(TRUE);
|
|
}
|
|
|
|
return(FALSE);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Sets the state of an xdes. */
|
|
UNIV_INLINE
|
|
void
|
|
xdes_set_state(
|
|
/*===========*/
|
|
xdes_t* descr, /*!< in/out: descriptor */
|
|
ulint state, /*!< in: state to set */
|
|
mtr_t* mtr) /*!< in: mtr handle */
|
|
{
|
|
ut_ad(descr && mtr);
|
|
ut_ad(state >= XDES_FREE);
|
|
ut_ad(state <= XDES_FSEG);
|
|
ut_ad(mtr_memo_contains_page(mtr, descr, MTR_MEMO_PAGE_X_FIX));
|
|
|
|
mlog_write_ulint(descr + XDES_STATE, state, MLOG_4BYTES, mtr);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Gets the state of an xdes.
|
|
@return state */
|
|
UNIV_INLINE
|
|
ulint
|
|
xdes_get_state(
|
|
/*===========*/
|
|
const xdes_t* descr, /*!< in: descriptor */
|
|
mtr_t* mtr) /*!< in: mtr handle */
|
|
{
|
|
ulint state;
|
|
|
|
ut_ad(descr && mtr);
|
|
ut_ad(mtr_memo_contains_page(mtr, descr, MTR_MEMO_PAGE_X_FIX));
|
|
|
|
state = mtr_read_ulint(descr + XDES_STATE, MLOG_4BYTES, mtr);
|
|
ut_ad(state - 1 < XDES_FSEG);
|
|
return(state);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Inits an extent descriptor to the free and clean state. */
|
|
UNIV_INLINE
|
|
void
|
|
xdes_init(
|
|
/*======*/
|
|
xdes_t* descr, /*!< in: descriptor */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
ulint i;
|
|
|
|
ut_ad(descr && mtr);
|
|
ut_ad(mtr_memo_contains_page(mtr, descr, MTR_MEMO_PAGE_X_FIX));
|
|
ut_ad((XDES_SIZE - XDES_BITMAP) % 4 == 0);
|
|
|
|
for (i = XDES_BITMAP; i < XDES_SIZE; i += 4) {
|
|
mlog_write_ulint(descr + i, 0xFFFFFFFFUL, MLOG_4BYTES, mtr);
|
|
}
|
|
|
|
xdes_set_state(descr, XDES_FREE, mtr);
|
|
}
|
|
|
|
/********************************************************************//**
|
|
Calculates the page where the descriptor of a page resides.
|
|
@return descriptor page offset */
|
|
UNIV_INLINE
|
|
ulint
|
|
xdes_calc_descriptor_page(
|
|
/*======================*/
|
|
ulint zip_size, /*!< in: compressed page size in bytes;
|
|
0 for uncompressed pages */
|
|
ulint offset) /*!< in: page offset */
|
|
{
|
|
#ifndef DOXYGEN /* Doxygen gets confused of these */
|
|
# if UNIV_PAGE_SIZE <= XDES_ARR_OFFSET \
|
|
+ (UNIV_PAGE_SIZE / FSP_EXTENT_SIZE) * XDES_SIZE
|
|
# error
|
|
# endif
|
|
# if PAGE_ZIP_MIN_SIZE <= XDES_ARR_OFFSET \
|
|
+ (PAGE_ZIP_MIN_SIZE / FSP_EXTENT_SIZE) * XDES_SIZE
|
|
# error
|
|
# endif
|
|
#endif /* !DOXYGEN */
|
|
ut_ad(ut_is_2pow(zip_size));
|
|
|
|
if (!zip_size) {
|
|
return(ut_2pow_round(offset, UNIV_PAGE_SIZE));
|
|
} else {
|
|
ut_ad(zip_size > XDES_ARR_OFFSET
|
|
+ (zip_size / FSP_EXTENT_SIZE) * XDES_SIZE);
|
|
return(ut_2pow_round(offset, zip_size));
|
|
}
|
|
}
|
|
|
|
/********************************************************************//**
|
|
Calculates the descriptor index within a descriptor page.
|
|
@return descriptor index */
|
|
UNIV_INLINE
|
|
ulint
|
|
xdes_calc_descriptor_index(
|
|
/*=======================*/
|
|
ulint zip_size, /*!< in: compressed page size in bytes;
|
|
0 for uncompressed pages */
|
|
ulint offset) /*!< in: page offset */
|
|
{
|
|
ut_ad(ut_is_2pow(zip_size));
|
|
|
|
if (!zip_size) {
|
|
return(ut_2pow_remainder(offset, UNIV_PAGE_SIZE)
|
|
/ FSP_EXTENT_SIZE);
|
|
} else {
|
|
return(ut_2pow_remainder(offset, zip_size) / FSP_EXTENT_SIZE);
|
|
}
|
|
}
|
|
|
|
/********************************************************************//**
|
|
Gets pointer to a the extent descriptor of a page. The page where the extent
|
|
descriptor resides is x-locked. If the page offset is equal to the free limit
|
|
of the space, adds new extents from above the free limit to the space free
|
|
list, if not free limit == space size. This adding is necessary to make the
|
|
descriptor defined, as they are uninitialized above the free limit.
|
|
@return pointer to the extent descriptor, NULL if the page does not
|
|
exist in the space or if the offset exceeds the free limit */
|
|
UNIV_INLINE
|
|
xdes_t*
|
|
xdes_get_descriptor_with_space_hdr(
|
|
/*===============================*/
|
|
fsp_header_t* sp_header,/*!< in/out: space header, x-latched */
|
|
ulint space, /*!< in: space id */
|
|
ulint offset, /*!< in: page offset;
|
|
if equal to the free limit,
|
|
we try to add new extents to
|
|
the space free list */
|
|
mtr_t* mtr) /*!< in: mtr handle */
|
|
{
|
|
ulint limit;
|
|
ulint size;
|
|
ulint zip_size;
|
|
ulint descr_page_no;
|
|
page_t* descr_page;
|
|
|
|
ut_ad(mtr);
|
|
ut_ad(mtr_memo_contains(mtr, fil_space_get_latch(space, NULL),
|
|
MTR_MEMO_X_LOCK));
|
|
ut_ad(mtr_memo_contains_page(mtr, sp_header, MTR_MEMO_PAGE_S_FIX)
|
|
|| mtr_memo_contains_page(mtr, sp_header, MTR_MEMO_PAGE_X_FIX));
|
|
ut_ad(page_offset(sp_header) == FSP_HEADER_OFFSET);
|
|
/* Read free limit and space size */
|
|
limit = mach_read_from_4(sp_header + FSP_FREE_LIMIT);
|
|
size = mach_read_from_4(sp_header + FSP_SIZE);
|
|
zip_size = dict_table_flags_to_zip_size(
|
|
mach_read_from_4(sp_header + FSP_SPACE_FLAGS));
|
|
|
|
/* If offset is >= size or > limit, return NULL */
|
|
|
|
if ((offset >= size) || (offset > limit)) {
|
|
|
|
return(NULL);
|
|
}
|
|
|
|
/* If offset is == limit, fill free list of the space. */
|
|
|
|
if (offset == limit) {
|
|
fsp_fill_free_list(FALSE, space, sp_header, mtr);
|
|
}
|
|
|
|
descr_page_no = xdes_calc_descriptor_page(zip_size, offset);
|
|
|
|
if (descr_page_no == 0) {
|
|
/* It is on the space header page */
|
|
|
|
descr_page = page_align(sp_header);
|
|
} else {
|
|
buf_block_t* block;
|
|
|
|
block = buf_page_get(space, zip_size, descr_page_no,
|
|
RW_X_LATCH, mtr);
|
|
buf_block_dbg_add_level(block, SYNC_FSP_PAGE);
|
|
|
|
descr_page = buf_block_get_frame(block);
|
|
}
|
|
|
|
return(descr_page + XDES_ARR_OFFSET
|
|
+ XDES_SIZE * xdes_calc_descriptor_index(zip_size, offset));
|
|
}
|
|
|
|
/********************************************************************//**
|
|
Gets pointer to a the extent descriptor of a page. The page where the
|
|
extent descriptor resides is x-locked. If the page offset is equal to
|
|
the free limit of the space, adds new extents from above the free limit
|
|
to the space free list, if not free limit == space size. This adding
|
|
is necessary to make the descriptor defined, as they are uninitialized
|
|
above the free limit.
|
|
@return pointer to the extent descriptor, NULL if the page does not
|
|
exist in the space or if the offset exceeds the free limit */
|
|
static
|
|
xdes_t*
|
|
xdes_get_descriptor(
|
|
/*================*/
|
|
ulint space, /*!< in: space id */
|
|
ulint zip_size,/*!< in: compressed page size in bytes
|
|
or 0 for uncompressed pages */
|
|
ulint offset, /*!< in: page offset; if equal to the free limit,
|
|
we try to add new extents to the space free list */
|
|
mtr_t* mtr) /*!< in: mtr handle */
|
|
{
|
|
buf_block_t* block;
|
|
fsp_header_t* sp_header;
|
|
|
|
block = buf_page_get(space, zip_size, 0, RW_X_LATCH, mtr);
|
|
buf_block_dbg_add_level(block, SYNC_FSP_PAGE);
|
|
|
|
sp_header = FSP_HEADER_OFFSET + buf_block_get_frame(block);
|
|
return(xdes_get_descriptor_with_space_hdr(sp_header, space, offset,
|
|
mtr));
|
|
}
|
|
|
|
/********************************************************************//**
|
|
Gets pointer to a the extent descriptor if the file address
|
|
of the descriptor list node is known. The page where the
|
|
extent descriptor resides is x-locked.
|
|
@return pointer to the extent descriptor */
|
|
UNIV_INLINE
|
|
xdes_t*
|
|
xdes_lst_get_descriptor(
|
|
/*====================*/
|
|
ulint space, /*!< in: space id */
|
|
ulint zip_size,/*!< in: compressed page size in bytes
|
|
or 0 for uncompressed pages */
|
|
fil_addr_t lst_node,/*!< in: file address of the list node
|
|
contained in the descriptor */
|
|
mtr_t* mtr) /*!< in: mtr handle */
|
|
{
|
|
xdes_t* descr;
|
|
|
|
ut_ad(mtr);
|
|
ut_ad(mtr_memo_contains(mtr, fil_space_get_latch(space, NULL),
|
|
MTR_MEMO_X_LOCK));
|
|
descr = fut_get_ptr(space, zip_size, lst_node, RW_X_LATCH, mtr)
|
|
- XDES_FLST_NODE;
|
|
|
|
return(descr);
|
|
}
|
|
|
|
/********************************************************************//**
|
|
Returns page offset of the first page in extent described by a descriptor.
|
|
@return offset of the first page in extent */
|
|
UNIV_INLINE
|
|
ulint
|
|
xdes_get_offset(
|
|
/*============*/
|
|
xdes_t* descr) /*!< in: extent descriptor */
|
|
{
|
|
ut_ad(descr);
|
|
|
|
return(page_get_page_no(page_align(descr))
|
|
+ ((page_offset(descr) - XDES_ARR_OFFSET) / XDES_SIZE)
|
|
* FSP_EXTENT_SIZE);
|
|
}
|
|
#endif /* !UNIV_HOTBACKUP */
|
|
|
|
/***********************************************************//**
|
|
Inits a file page whose prior contents should be ignored. */
|
|
static
|
|
void
|
|
fsp_init_file_page_low(
|
|
/*===================*/
|
|
buf_block_t* block) /*!< in: pointer to a page */
|
|
{
|
|
page_t* page = buf_block_get_frame(block);
|
|
page_zip_des_t* page_zip= buf_block_get_page_zip(block);
|
|
|
|
#ifndef UNIV_HOTBACKUP
|
|
block->check_index_page_at_flush = FALSE;
|
|
#endif /* !UNIV_HOTBACKUP */
|
|
|
|
if (UNIV_LIKELY_NULL(page_zip)) {
|
|
memset(page, 0, UNIV_PAGE_SIZE);
|
|
memset(page_zip->data, 0, page_zip_get_size(page_zip));
|
|
mach_write_to_4(page + FIL_PAGE_OFFSET,
|
|
buf_block_get_page_no(block));
|
|
mach_write_to_4(page
|
|
+ FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID,
|
|
buf_block_get_space(block));
|
|
memcpy(page_zip->data + FIL_PAGE_OFFSET,
|
|
page + FIL_PAGE_OFFSET, 4);
|
|
memcpy(page_zip->data + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID,
|
|
page + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID, 4);
|
|
return;
|
|
}
|
|
|
|
#ifdef UNIV_BASIC_LOG_DEBUG
|
|
memset(page, 0xff, UNIV_PAGE_SIZE);
|
|
#endif
|
|
mach_write_to_4(page + FIL_PAGE_OFFSET, buf_block_get_page_no(block));
|
|
memset(page + FIL_PAGE_LSN, 0, 8);
|
|
mach_write_to_4(page + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID,
|
|
buf_block_get_space(block));
|
|
memset(page + UNIV_PAGE_SIZE - FIL_PAGE_END_LSN_OLD_CHKSUM, 0, 8);
|
|
}
|
|
|
|
#ifndef UNIV_HOTBACKUP
|
|
/***********************************************************//**
|
|
Inits a file page whose prior contents should be ignored. */
|
|
static
|
|
void
|
|
fsp_init_file_page(
|
|
/*===============*/
|
|
buf_block_t* block, /*!< in: pointer to a page */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
fsp_init_file_page_low(block);
|
|
|
|
mlog_write_initial_log_record(buf_block_get_frame(block),
|
|
MLOG_INIT_FILE_PAGE, mtr);
|
|
}
|
|
#endif /* !UNIV_HOTBACKUP */
|
|
|
|
/***********************************************************//**
|
|
Parses a redo log record of a file page init.
|
|
@return end of log record or NULL */
|
|
UNIV_INTERN
|
|
byte*
|
|
fsp_parse_init_file_page(
|
|
/*=====================*/
|
|
byte* ptr, /*!< in: buffer */
|
|
byte* end_ptr __attribute__((unused)), /*!< in: buffer end */
|
|
buf_block_t* block) /*!< in: block or NULL */
|
|
{
|
|
ut_ad(ptr && end_ptr);
|
|
|
|
if (block) {
|
|
fsp_init_file_page_low(block);
|
|
}
|
|
|
|
return(ptr);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Initializes the fsp system. */
|
|
UNIV_INTERN
|
|
void
|
|
fsp_init(void)
|
|
/*==========*/
|
|
{
|
|
/* Does nothing at the moment */
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Writes the space id and compressed page size to a tablespace header.
|
|
This function is used past the buffer pool when we in fil0fil.c create
|
|
a new single-table tablespace. */
|
|
UNIV_INTERN
|
|
void
|
|
fsp_header_init_fields(
|
|
/*===================*/
|
|
page_t* page, /*!< in/out: first page in the space */
|
|
ulint space_id, /*!< in: space id */
|
|
ulint flags) /*!< in: tablespace flags (FSP_SPACE_FLAGS):
|
|
0, or table->flags if newer than COMPACT */
|
|
{
|
|
/* The tablespace flags (FSP_SPACE_FLAGS) should be 0 for
|
|
ROW_FORMAT=COMPACT (table->flags == DICT_TF_COMPACT) and
|
|
ROW_FORMAT=REDUNDANT (table->flags == 0). For any other
|
|
format, the tablespace flags should equal table->flags. */
|
|
ut_a(flags != DICT_TF_COMPACT);
|
|
|
|
mach_write_to_4(FSP_HEADER_OFFSET + FSP_SPACE_ID + page,
|
|
space_id);
|
|
mach_write_to_4(FSP_HEADER_OFFSET + FSP_SPACE_FLAGS + page,
|
|
flags);
|
|
}
|
|
|
|
#ifndef UNIV_HOTBACKUP
|
|
/**********************************************************************//**
|
|
Initializes the space header of a new created space and creates also the
|
|
insert buffer tree root if space == 0. */
|
|
UNIV_INTERN
|
|
void
|
|
fsp_header_init(
|
|
/*============*/
|
|
ulint space, /*!< in: space id */
|
|
ulint size, /*!< in: current size in blocks */
|
|
mtr_t* mtr) /*!< in: mini-transaction handle */
|
|
{
|
|
fsp_header_t* header;
|
|
buf_block_t* block;
|
|
page_t* page;
|
|
ulint flags;
|
|
ulint zip_size;
|
|
|
|
ut_ad(mtr);
|
|
|
|
mtr_x_lock(fil_space_get_latch(space, &flags), mtr);
|
|
|
|
zip_size = dict_table_flags_to_zip_size(flags);
|
|
block = buf_page_create(space, 0, zip_size, mtr);
|
|
buf_page_get(space, zip_size, 0, RW_X_LATCH, mtr);
|
|
buf_block_dbg_add_level(block, SYNC_FSP_PAGE);
|
|
|
|
/* The prior contents of the file page should be ignored */
|
|
|
|
fsp_init_file_page(block, mtr);
|
|
page = buf_block_get_frame(block);
|
|
|
|
mlog_write_ulint(page + FIL_PAGE_TYPE, FIL_PAGE_TYPE_FSP_HDR,
|
|
MLOG_2BYTES, mtr);
|
|
|
|
header = FSP_HEADER_OFFSET + page;
|
|
|
|
mlog_write_ulint(header + FSP_SPACE_ID, space, MLOG_4BYTES, mtr);
|
|
mlog_write_ulint(header + FSP_NOT_USED, 0, MLOG_4BYTES, mtr);
|
|
|
|
mlog_write_ulint(header + FSP_SIZE, size, MLOG_4BYTES, mtr);
|
|
mlog_write_ulint(header + FSP_FREE_LIMIT, 0, MLOG_4BYTES, mtr);
|
|
mlog_write_ulint(header + FSP_SPACE_FLAGS, flags,
|
|
MLOG_4BYTES, mtr);
|
|
mlog_write_ulint(header + FSP_FRAG_N_USED, 0, MLOG_4BYTES, mtr);
|
|
|
|
flst_init(header + FSP_FREE, mtr);
|
|
flst_init(header + FSP_FREE_FRAG, mtr);
|
|
flst_init(header + FSP_FULL_FRAG, mtr);
|
|
flst_init(header + FSP_SEG_INODES_FULL, mtr);
|
|
flst_init(header + FSP_SEG_INODES_FREE, mtr);
|
|
|
|
mlog_write_dulint(header + FSP_SEG_ID, ut_dulint_create(0, 1), mtr);
|
|
if (space == 0) {
|
|
fsp_fill_free_list(FALSE, space, header, mtr);
|
|
btr_create(DICT_CLUSTERED | DICT_UNIVERSAL | DICT_IBUF,
|
|
0, 0, ut_dulint_add(DICT_IBUF_ID_MIN, space),
|
|
dict_ind_redundant, mtr);
|
|
} else {
|
|
fsp_fill_free_list(TRUE, space, header, mtr);
|
|
}
|
|
}
|
|
#endif /* !UNIV_HOTBACKUP */
|
|
|
|
/**********************************************************************//**
|
|
Reads the space id from the first page of a tablespace.
|
|
@return space id, ULINT UNDEFINED if error */
|
|
UNIV_INTERN
|
|
ulint
|
|
fsp_header_get_space_id(
|
|
/*====================*/
|
|
const page_t* page) /*!< in: first page of a tablespace */
|
|
{
|
|
ulint fsp_id;
|
|
ulint id;
|
|
|
|
fsp_id = mach_read_from_4(FSP_HEADER_OFFSET + page + FSP_SPACE_ID);
|
|
|
|
id = mach_read_from_4(page + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID);
|
|
|
|
if (id != fsp_id) {
|
|
fprintf(stderr,
|
|
"InnoDB: Error: space id in fsp header %lu,"
|
|
" but in the page header %lu\n",
|
|
(ulong) fsp_id, (ulong) id);
|
|
|
|
return(ULINT_UNDEFINED);
|
|
}
|
|
|
|
return(id);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Reads the space flags from the first page of a tablespace.
|
|
@return flags */
|
|
UNIV_INTERN
|
|
ulint
|
|
fsp_header_get_flags(
|
|
/*=================*/
|
|
const page_t* page) /*!< in: first page of a tablespace */
|
|
{
|
|
ut_ad(!page_offset(page));
|
|
|
|
return(mach_read_from_4(FSP_HEADER_OFFSET + FSP_SPACE_FLAGS + page));
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Reads the compressed page size from the first page of a tablespace.
|
|
@return compressed page size in bytes, or 0 if uncompressed */
|
|
UNIV_INTERN
|
|
ulint
|
|
fsp_header_get_zip_size(
|
|
/*====================*/
|
|
const page_t* page) /*!< in: first page of a tablespace */
|
|
{
|
|
ulint flags = fsp_header_get_flags(page);
|
|
|
|
return(dict_table_flags_to_zip_size(flags));
|
|
}
|
|
|
|
#ifndef UNIV_HOTBACKUP
|
|
/**********************************************************************//**
|
|
Increases the space size field of a space. */
|
|
UNIV_INTERN
|
|
void
|
|
fsp_header_inc_size(
|
|
/*================*/
|
|
ulint space, /*!< in: space id */
|
|
ulint size_inc,/*!< in: size increment in pages */
|
|
mtr_t* mtr) /*!< in: mini-transaction handle */
|
|
{
|
|
fsp_header_t* header;
|
|
ulint size;
|
|
ulint flags;
|
|
|
|
ut_ad(mtr);
|
|
|
|
mtr_x_lock(fil_space_get_latch(space, &flags), mtr);
|
|
|
|
header = fsp_get_space_header(space,
|
|
dict_table_flags_to_zip_size(flags),
|
|
mtr);
|
|
|
|
size = mtr_read_ulint(header + FSP_SIZE, MLOG_4BYTES, mtr);
|
|
|
|
mlog_write_ulint(header + FSP_SIZE, size + size_inc, MLOG_4BYTES,
|
|
mtr);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Gets the current free limit of the system tablespace. The free limit
|
|
means the place of the first page which has never been put to the
|
|
free list for allocation. The space above that address is initialized
|
|
to zero. Sets also the global variable log_fsp_current_free_limit.
|
|
@return free limit in megabytes */
|
|
UNIV_INTERN
|
|
ulint
|
|
fsp_header_get_free_limit(void)
|
|
/*===========================*/
|
|
{
|
|
fsp_header_t* header;
|
|
ulint limit;
|
|
mtr_t mtr;
|
|
|
|
mtr_start(&mtr);
|
|
|
|
mtr_x_lock(fil_space_get_latch(0, NULL), &mtr);
|
|
|
|
header = fsp_get_space_header(0, 0, &mtr);
|
|
|
|
limit = mtr_read_ulint(header + FSP_FREE_LIMIT, MLOG_4BYTES, &mtr);
|
|
|
|
limit /= ((1024 * 1024) / UNIV_PAGE_SIZE);
|
|
|
|
log_fsp_current_free_limit_set_and_checkpoint(limit);
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
return(limit);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Gets the size of the system tablespace from the tablespace header. If
|
|
we do not have an auto-extending data file, this should be equal to
|
|
the size of the data files. If there is an auto-extending data file,
|
|
this can be smaller.
|
|
@return size in pages */
|
|
UNIV_INTERN
|
|
ulint
|
|
fsp_header_get_tablespace_size(void)
|
|
/*================================*/
|
|
{
|
|
fsp_header_t* header;
|
|
ulint size;
|
|
mtr_t mtr;
|
|
|
|
mtr_start(&mtr);
|
|
|
|
mtr_x_lock(fil_space_get_latch(0, NULL), &mtr);
|
|
|
|
header = fsp_get_space_header(0, 0, &mtr);
|
|
|
|
size = mtr_read_ulint(header + FSP_SIZE, MLOG_4BYTES, &mtr);
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
return(size);
|
|
}
|
|
|
|
/***********************************************************************//**
|
|
Tries to extend a single-table tablespace so that a page would fit in the
|
|
data file.
|
|
@return TRUE if success */
|
|
static
|
|
ibool
|
|
fsp_try_extend_data_file_with_pages(
|
|
/*================================*/
|
|
ulint space, /*!< in: space */
|
|
ulint page_no, /*!< in: page number */
|
|
fsp_header_t* header, /*!< in: space header */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
ibool success;
|
|
ulint actual_size;
|
|
ulint size;
|
|
|
|
ut_a(space != 0);
|
|
|
|
size = mtr_read_ulint(header + FSP_SIZE, MLOG_4BYTES, mtr);
|
|
|
|
ut_a(page_no >= size);
|
|
|
|
success = fil_extend_space_to_desired_size(&actual_size, space,
|
|
page_no + 1);
|
|
/* actual_size now has the space size in pages; it may be less than
|
|
we wanted if we ran out of disk space */
|
|
|
|
mlog_write_ulint(header + FSP_SIZE, actual_size, MLOG_4BYTES, mtr);
|
|
|
|
return(success);
|
|
}
|
|
|
|
/***********************************************************************//**
|
|
Tries to extend the last data file of a tablespace if it is auto-extending.
|
|
@return FALSE if not auto-extending */
|
|
static
|
|
ibool
|
|
fsp_try_extend_data_file(
|
|
/*=====================*/
|
|
ulint* actual_increase,/*!< out: actual increase in pages, where
|
|
we measure the tablespace size from
|
|
what the header field says; it may be
|
|
the actual file size rounded down to
|
|
megabyte */
|
|
ulint space, /*!< in: space */
|
|
fsp_header_t* header, /*!< in: space header */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
ulint size;
|
|
ulint zip_size;
|
|
ulint new_size;
|
|
ulint old_size;
|
|
ulint size_increase;
|
|
ulint actual_size;
|
|
ibool success;
|
|
|
|
*actual_increase = 0;
|
|
|
|
if (space == 0 && !srv_auto_extend_last_data_file) {
|
|
|
|
/* We print the error message only once to avoid
|
|
spamming the error log. Note that we don't need
|
|
to reset the flag to FALSE as dealing with this
|
|
error requires server restart. */
|
|
if (fsp_tbs_full_error_printed == FALSE) {
|
|
fprintf(stderr,
|
|
"InnoDB: Error: Data file(s) ran"
|
|
" out of space.\n"
|
|
"Please add another data file or"
|
|
" use \'autoextend\' for the last"
|
|
" data file.\n");
|
|
fsp_tbs_full_error_printed = TRUE;
|
|
}
|
|
return(FALSE);
|
|
}
|
|
|
|
size = mtr_read_ulint(header + FSP_SIZE, MLOG_4BYTES, mtr);
|
|
zip_size = dict_table_flags_to_zip_size(
|
|
mach_read_from_4(header + FSP_SPACE_FLAGS));
|
|
|
|
old_size = size;
|
|
|
|
if (space == 0) {
|
|
if (!srv_last_file_size_max) {
|
|
size_increase = SRV_AUTO_EXTEND_INCREMENT;
|
|
} else {
|
|
if (srv_last_file_size_max
|
|
< srv_data_file_sizes[srv_n_data_files - 1]) {
|
|
|
|
fprintf(stderr,
|
|
"InnoDB: Error: Last data file size"
|
|
" is %lu, max size allowed %lu\n",
|
|
(ulong) srv_data_file_sizes[
|
|
srv_n_data_files - 1],
|
|
(ulong) srv_last_file_size_max);
|
|
}
|
|
|
|
size_increase = srv_last_file_size_max
|
|
- srv_data_file_sizes[srv_n_data_files - 1];
|
|
if (size_increase > SRV_AUTO_EXTEND_INCREMENT) {
|
|
size_increase = SRV_AUTO_EXTEND_INCREMENT;
|
|
}
|
|
}
|
|
} else {
|
|
/* We extend single-table tablespaces first one extent
|
|
at a time, but for bigger tablespaces more. It is not
|
|
enough to extend always by one extent, because some
|
|
extents are frag page extents. */
|
|
ulint extent_size; /*!< one megabyte, in pages */
|
|
|
|
if (!zip_size) {
|
|
extent_size = FSP_EXTENT_SIZE;
|
|
} else {
|
|
extent_size = FSP_EXTENT_SIZE
|
|
* UNIV_PAGE_SIZE / zip_size;
|
|
}
|
|
|
|
if (size < extent_size) {
|
|
/* Let us first extend the file to extent_size */
|
|
success = fsp_try_extend_data_file_with_pages(
|
|
space, extent_size - 1, header, mtr);
|
|
if (!success) {
|
|
new_size = mtr_read_ulint(header + FSP_SIZE,
|
|
MLOG_4BYTES, mtr);
|
|
|
|
*actual_increase = new_size - old_size;
|
|
|
|
return(FALSE);
|
|
}
|
|
|
|
size = extent_size;
|
|
}
|
|
|
|
if (size < 32 * extent_size) {
|
|
size_increase = extent_size;
|
|
} else {
|
|
/* Below in fsp_fill_free_list() we assume
|
|
that we add at most FSP_FREE_ADD extents at
|
|
a time */
|
|
size_increase = FSP_FREE_ADD * extent_size;
|
|
}
|
|
}
|
|
|
|
if (size_increase == 0) {
|
|
|
|
return(TRUE);
|
|
}
|
|
|
|
success = fil_extend_space_to_desired_size(&actual_size, space,
|
|
size + size_increase);
|
|
/* We ignore any fragments of a full megabyte when storing the size
|
|
to the space header */
|
|
|
|
if (!zip_size) {
|
|
new_size = ut_calc_align_down(actual_size,
|
|
(1024 * 1024) / UNIV_PAGE_SIZE);
|
|
} else {
|
|
new_size = ut_calc_align_down(actual_size,
|
|
(1024 * 1024) / zip_size);
|
|
}
|
|
mlog_write_ulint(header + FSP_SIZE, new_size, MLOG_4BYTES, mtr);
|
|
|
|
*actual_increase = new_size - old_size;
|
|
|
|
return(TRUE);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Puts new extents to the free list if there are free extents above the free
|
|
limit. If an extent happens to contain an extent descriptor page, the extent
|
|
is put to the FSP_FREE_FRAG list with the page marked as used. */
|
|
static
|
|
void
|
|
fsp_fill_free_list(
|
|
/*===============*/
|
|
ibool init_space, /*!< in: TRUE if this is a single-table
|
|
tablespace and we are only initing
|
|
the tablespace's first extent
|
|
descriptor page and ibuf bitmap page;
|
|
then we do not allocate more extents */
|
|
ulint space, /*!< in: space */
|
|
fsp_header_t* header, /*!< in/out: space header */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
ulint limit;
|
|
ulint size;
|
|
ulint zip_size;
|
|
xdes_t* descr;
|
|
ulint count = 0;
|
|
ulint frag_n_used;
|
|
ulint actual_increase;
|
|
ulint i;
|
|
mtr_t ibuf_mtr;
|
|
|
|
ut_ad(header && mtr);
|
|
ut_ad(page_offset(header) == FSP_HEADER_OFFSET);
|
|
|
|
/* Check if we can fill free list from above the free list limit */
|
|
size = mtr_read_ulint(header + FSP_SIZE, MLOG_4BYTES, mtr);
|
|
limit = mtr_read_ulint(header + FSP_FREE_LIMIT, MLOG_4BYTES, mtr);
|
|
|
|
zip_size = dict_table_flags_to_zip_size(
|
|
mach_read_from_4(FSP_SPACE_FLAGS + header));
|
|
ut_a(ut_is_2pow(zip_size));
|
|
ut_a(zip_size <= UNIV_PAGE_SIZE);
|
|
ut_a(!zip_size || zip_size >= PAGE_ZIP_MIN_SIZE);
|
|
|
|
if (space == 0 && srv_auto_extend_last_data_file
|
|
&& size < limit + FSP_EXTENT_SIZE * FSP_FREE_ADD) {
|
|
|
|
/* Try to increase the last data file size */
|
|
fsp_try_extend_data_file(&actual_increase, space, header, mtr);
|
|
size = mtr_read_ulint(header + FSP_SIZE, MLOG_4BYTES, mtr);
|
|
}
|
|
|
|
if (space != 0 && !init_space
|
|
&& size < limit + FSP_EXTENT_SIZE * FSP_FREE_ADD) {
|
|
|
|
/* Try to increase the .ibd file size */
|
|
fsp_try_extend_data_file(&actual_increase, space, header, mtr);
|
|
size = mtr_read_ulint(header + FSP_SIZE, MLOG_4BYTES, mtr);
|
|
}
|
|
|
|
i = limit;
|
|
|
|
while ((init_space && i < 1)
|
|
|| ((i + FSP_EXTENT_SIZE <= size) && (count < FSP_FREE_ADD))) {
|
|
|
|
ibool init_xdes;
|
|
if (zip_size) {
|
|
init_xdes = ut_2pow_remainder(i, zip_size) == 0;
|
|
} else {
|
|
init_xdes = ut_2pow_remainder(i, UNIV_PAGE_SIZE) == 0;
|
|
}
|
|
|
|
mlog_write_ulint(header + FSP_FREE_LIMIT, i + FSP_EXTENT_SIZE,
|
|
MLOG_4BYTES, mtr);
|
|
|
|
/* Update the free limit info in the log system and make
|
|
a checkpoint */
|
|
if (space == 0) {
|
|
ut_a(!zip_size);
|
|
log_fsp_current_free_limit_set_and_checkpoint(
|
|
(i + FSP_EXTENT_SIZE)
|
|
/ ((1024 * 1024) / UNIV_PAGE_SIZE));
|
|
}
|
|
|
|
if (UNIV_UNLIKELY(init_xdes)) {
|
|
|
|
buf_block_t* block;
|
|
|
|
/* We are going to initialize a new descriptor page
|
|
and a new ibuf bitmap page: the prior contents of the
|
|
pages should be ignored. */
|
|
|
|
if (i > 0) {
|
|
block = buf_page_create(
|
|
space, i, zip_size, mtr);
|
|
buf_page_get(space, zip_size, i,
|
|
RW_X_LATCH, mtr);
|
|
buf_block_dbg_add_level(block,
|
|
SYNC_FSP_PAGE);
|
|
|
|
fsp_init_file_page(block, mtr);
|
|
mlog_write_ulint(buf_block_get_frame(block)
|
|
+ FIL_PAGE_TYPE,
|
|
FIL_PAGE_TYPE_XDES,
|
|
MLOG_2BYTES, mtr);
|
|
}
|
|
|
|
/* Initialize the ibuf bitmap page in a separate
|
|
mini-transaction because it is low in the latching
|
|
order, and we must be able to release its latch
|
|
before returning from the fsp routine */
|
|
|
|
mtr_start(&ibuf_mtr);
|
|
|
|
block = buf_page_create(space,
|
|
i + FSP_IBUF_BITMAP_OFFSET,
|
|
zip_size, &ibuf_mtr);
|
|
buf_page_get(space, zip_size,
|
|
i + FSP_IBUF_BITMAP_OFFSET,
|
|
RW_X_LATCH, &ibuf_mtr);
|
|
buf_block_dbg_add_level(block, SYNC_FSP_PAGE);
|
|
|
|
fsp_init_file_page(block, &ibuf_mtr);
|
|
|
|
ibuf_bitmap_page_init(block, &ibuf_mtr);
|
|
|
|
mtr_commit(&ibuf_mtr);
|
|
}
|
|
|
|
descr = xdes_get_descriptor_with_space_hdr(header, space, i,
|
|
mtr);
|
|
xdes_init(descr, mtr);
|
|
|
|
#if UNIV_PAGE_SIZE % FSP_EXTENT_SIZE
|
|
# error "UNIV_PAGE_SIZE % FSP_EXTENT_SIZE != 0"
|
|
#endif
|
|
#if PAGE_ZIP_MIN_SIZE % FSP_EXTENT_SIZE
|
|
# error "PAGE_ZIP_MIN_SIZE % FSP_EXTENT_SIZE != 0"
|
|
#endif
|
|
|
|
if (UNIV_UNLIKELY(init_xdes)) {
|
|
|
|
/* The first page in the extent is a descriptor page
|
|
and the second is an ibuf bitmap page: mark them
|
|
used */
|
|
|
|
xdes_set_bit(descr, XDES_FREE_BIT, 0, FALSE, mtr);
|
|
xdes_set_bit(descr, XDES_FREE_BIT,
|
|
FSP_IBUF_BITMAP_OFFSET, FALSE, mtr);
|
|
xdes_set_state(descr, XDES_FREE_FRAG, mtr);
|
|
|
|
flst_add_last(header + FSP_FREE_FRAG,
|
|
descr + XDES_FLST_NODE, mtr);
|
|
frag_n_used = mtr_read_ulint(header + FSP_FRAG_N_USED,
|
|
MLOG_4BYTES, mtr);
|
|
mlog_write_ulint(header + FSP_FRAG_N_USED,
|
|
frag_n_used + 2, MLOG_4BYTES, mtr);
|
|
} else {
|
|
flst_add_last(header + FSP_FREE,
|
|
descr + XDES_FLST_NODE, mtr);
|
|
count++;
|
|
}
|
|
|
|
i += FSP_EXTENT_SIZE;
|
|
}
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Allocates a new free extent.
|
|
@return extent descriptor, NULL if cannot be allocated */
|
|
static
|
|
xdes_t*
|
|
fsp_alloc_free_extent(
|
|
/*==================*/
|
|
ulint space, /*!< in: space id */
|
|
ulint zip_size,/*!< in: compressed page size in bytes
|
|
or 0 for uncompressed pages */
|
|
ulint hint, /*!< in: hint of which extent would be desirable: any
|
|
page offset in the extent goes; the hint must not
|
|
be > FSP_FREE_LIMIT */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
fsp_header_t* header;
|
|
fil_addr_t first;
|
|
xdes_t* descr;
|
|
|
|
ut_ad(mtr);
|
|
|
|
header = fsp_get_space_header(space, zip_size, mtr);
|
|
|
|
descr = xdes_get_descriptor_with_space_hdr(header, space, hint, mtr);
|
|
|
|
if (descr && (xdes_get_state(descr, mtr) == XDES_FREE)) {
|
|
/* Ok, we can take this extent */
|
|
} else {
|
|
/* Take the first extent in the free list */
|
|
first = flst_get_first(header + FSP_FREE, mtr);
|
|
|
|
if (fil_addr_is_null(first)) {
|
|
fsp_fill_free_list(FALSE, space, header, mtr);
|
|
|
|
first = flst_get_first(header + FSP_FREE, mtr);
|
|
}
|
|
|
|
if (fil_addr_is_null(first)) {
|
|
|
|
return(NULL); /* No free extents left */
|
|
}
|
|
|
|
descr = xdes_lst_get_descriptor(space, zip_size, first, mtr);
|
|
}
|
|
|
|
flst_remove(header + FSP_FREE, descr + XDES_FLST_NODE, mtr);
|
|
|
|
return(descr);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Allocates a single free page from a space. The page is marked as used.
|
|
@return the page offset, FIL_NULL if no page could be allocated */
|
|
static
|
|
ulint
|
|
fsp_alloc_free_page(
|
|
/*================*/
|
|
ulint space, /*!< in: space id */
|
|
ulint zip_size,/*!< in: compressed page size in bytes
|
|
or 0 for uncompressed pages */
|
|
ulint hint, /*!< in: hint of which page would be desirable */
|
|
mtr_t* mtr) /*!< in: mtr handle */
|
|
{
|
|
fsp_header_t* header;
|
|
fil_addr_t first;
|
|
xdes_t* descr;
|
|
buf_block_t* block;
|
|
ulint free;
|
|
ulint frag_n_used;
|
|
ulint page_no;
|
|
ulint space_size;
|
|
ibool success;
|
|
|
|
ut_ad(mtr);
|
|
|
|
header = fsp_get_space_header(space, zip_size, mtr);
|
|
|
|
/* Get the hinted descriptor */
|
|
descr = xdes_get_descriptor_with_space_hdr(header, space, hint, mtr);
|
|
|
|
if (descr && (xdes_get_state(descr, mtr) == XDES_FREE_FRAG)) {
|
|
/* Ok, we can take this extent */
|
|
} else {
|
|
/* Else take the first extent in free_frag list */
|
|
first = flst_get_first(header + FSP_FREE_FRAG, mtr);
|
|
|
|
if (fil_addr_is_null(first)) {
|
|
/* There are no partially full fragments: allocate
|
|
a free extent and add it to the FREE_FRAG list. NOTE
|
|
that the allocation may have as a side-effect that an
|
|
extent containing a descriptor page is added to the
|
|
FREE_FRAG list. But we will allocate our page from the
|
|
the free extent anyway. */
|
|
|
|
descr = fsp_alloc_free_extent(space, zip_size,
|
|
hint, mtr);
|
|
|
|
if (descr == NULL) {
|
|
/* No free space left */
|
|
|
|
return(FIL_NULL);
|
|
}
|
|
|
|
xdes_set_state(descr, XDES_FREE_FRAG, mtr);
|
|
flst_add_last(header + FSP_FREE_FRAG,
|
|
descr + XDES_FLST_NODE, mtr);
|
|
} else {
|
|
descr = xdes_lst_get_descriptor(space, zip_size,
|
|
first, mtr);
|
|
}
|
|
|
|
/* Reset the hint */
|
|
hint = 0;
|
|
}
|
|
|
|
/* Now we have in descr an extent with at least one free page. Look
|
|
for a free page in the extent. */
|
|
|
|
free = xdes_find_bit(descr, XDES_FREE_BIT, TRUE,
|
|
hint % FSP_EXTENT_SIZE, mtr);
|
|
if (free == ULINT_UNDEFINED) {
|
|
|
|
ut_print_buf(stderr, ((byte*)descr) - 500, 1000);
|
|
putc('\n', stderr);
|
|
|
|
ut_error;
|
|
}
|
|
|
|
page_no = xdes_get_offset(descr) + free;
|
|
|
|
space_size = mtr_read_ulint(header + FSP_SIZE, MLOG_4BYTES, mtr);
|
|
|
|
if (space_size <= page_no) {
|
|
/* It must be that we are extending a single-table tablespace
|
|
whose size is still < 64 pages */
|
|
|
|
ut_a(space != 0);
|
|
if (page_no >= FSP_EXTENT_SIZE) {
|
|
fprintf(stderr,
|
|
"InnoDB: Error: trying to extend a"
|
|
" single-table tablespace %lu\n"
|
|
"InnoDB: by single page(s) though the"
|
|
" space size %lu. Page no %lu.\n",
|
|
(ulong) space, (ulong) space_size,
|
|
(ulong) page_no);
|
|
return(FIL_NULL);
|
|
}
|
|
success = fsp_try_extend_data_file_with_pages(space, page_no,
|
|
header, mtr);
|
|
if (!success) {
|
|
/* No disk space left */
|
|
return(FIL_NULL);
|
|
}
|
|
}
|
|
|
|
xdes_set_bit(descr, XDES_FREE_BIT, free, FALSE, mtr);
|
|
|
|
/* Update the FRAG_N_USED field */
|
|
frag_n_used = mtr_read_ulint(header + FSP_FRAG_N_USED, MLOG_4BYTES,
|
|
mtr);
|
|
frag_n_used++;
|
|
mlog_write_ulint(header + FSP_FRAG_N_USED, frag_n_used, MLOG_4BYTES,
|
|
mtr);
|
|
if (xdes_is_full(descr, mtr)) {
|
|
/* The fragment is full: move it to another list */
|
|
flst_remove(header + FSP_FREE_FRAG, descr + XDES_FLST_NODE,
|
|
mtr);
|
|
xdes_set_state(descr, XDES_FULL_FRAG, mtr);
|
|
|
|
flst_add_last(header + FSP_FULL_FRAG, descr + XDES_FLST_NODE,
|
|
mtr);
|
|
mlog_write_ulint(header + FSP_FRAG_N_USED,
|
|
frag_n_used - FSP_EXTENT_SIZE, MLOG_4BYTES,
|
|
mtr);
|
|
}
|
|
|
|
/* Initialize the allocated page to the buffer pool, so that it can
|
|
be obtained immediately with buf_page_get without need for a disk
|
|
read. */
|
|
|
|
buf_page_create(space, page_no, zip_size, mtr);
|
|
|
|
block = buf_page_get(space, zip_size, page_no, RW_X_LATCH, mtr);
|
|
buf_block_dbg_add_level(block, SYNC_FSP_PAGE);
|
|
|
|
/* Prior contents of the page should be ignored */
|
|
fsp_init_file_page(block, mtr);
|
|
|
|
return(page_no);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Frees a single page of a space. The page is marked as free and clean. */
|
|
static
|
|
void
|
|
fsp_free_page(
|
|
/*==========*/
|
|
ulint space, /*!< in: space id */
|
|
ulint zip_size,/*!< in: compressed page size in bytes
|
|
or 0 for uncompressed pages */
|
|
ulint page, /*!< in: page offset */
|
|
mtr_t* mtr) /*!< in: mtr handle */
|
|
{
|
|
fsp_header_t* header;
|
|
xdes_t* descr;
|
|
ulint state;
|
|
ulint frag_n_used;
|
|
|
|
ut_ad(mtr);
|
|
|
|
/* fprintf(stderr, "Freeing page %lu in space %lu\n", page, space); */
|
|
|
|
header = fsp_get_space_header(space, zip_size, mtr);
|
|
|
|
descr = xdes_get_descriptor_with_space_hdr(header, space, page, mtr);
|
|
|
|
state = xdes_get_state(descr, mtr);
|
|
|
|
if (state != XDES_FREE_FRAG && state != XDES_FULL_FRAG) {
|
|
fprintf(stderr,
|
|
"InnoDB: Error: File space extent descriptor"
|
|
" of page %lu has state %lu\n",
|
|
(ulong) page,
|
|
(ulong) state);
|
|
fputs("InnoDB: Dump of descriptor: ", stderr);
|
|
ut_print_buf(stderr, ((byte*)descr) - 50, 200);
|
|
putc('\n', stderr);
|
|
|
|
if (state == XDES_FREE) {
|
|
/* We put here some fault tolerance: if the page
|
|
is already free, return without doing anything! */
|
|
|
|
return;
|
|
}
|
|
|
|
ut_error;
|
|
}
|
|
|
|
if (xdes_get_bit(descr, XDES_FREE_BIT, page % FSP_EXTENT_SIZE, mtr)) {
|
|
fprintf(stderr,
|
|
"InnoDB: Error: File space extent descriptor"
|
|
" of page %lu says it is free\n"
|
|
"InnoDB: Dump of descriptor: ", (ulong) page);
|
|
ut_print_buf(stderr, ((byte*)descr) - 50, 200);
|
|
putc('\n', stderr);
|
|
|
|
/* We put here some fault tolerance: if the page
|
|
is already free, return without doing anything! */
|
|
|
|
return;
|
|
}
|
|
|
|
xdes_set_bit(descr, XDES_FREE_BIT, page % FSP_EXTENT_SIZE, TRUE, mtr);
|
|
xdes_set_bit(descr, XDES_CLEAN_BIT, page % FSP_EXTENT_SIZE, TRUE, mtr);
|
|
|
|
frag_n_used = mtr_read_ulint(header + FSP_FRAG_N_USED, MLOG_4BYTES,
|
|
mtr);
|
|
if (state == XDES_FULL_FRAG) {
|
|
/* The fragment was full: move it to another list */
|
|
flst_remove(header + FSP_FULL_FRAG, descr + XDES_FLST_NODE,
|
|
mtr);
|
|
xdes_set_state(descr, XDES_FREE_FRAG, mtr);
|
|
flst_add_last(header + FSP_FREE_FRAG, descr + XDES_FLST_NODE,
|
|
mtr);
|
|
mlog_write_ulint(header + FSP_FRAG_N_USED,
|
|
frag_n_used + FSP_EXTENT_SIZE - 1,
|
|
MLOG_4BYTES, mtr);
|
|
} else {
|
|
ut_a(frag_n_used > 0);
|
|
mlog_write_ulint(header + FSP_FRAG_N_USED, frag_n_used - 1,
|
|
MLOG_4BYTES, mtr);
|
|
}
|
|
|
|
if (xdes_is_free(descr, mtr)) {
|
|
/* The extent has become free: move it to another list */
|
|
flst_remove(header + FSP_FREE_FRAG, descr + XDES_FLST_NODE,
|
|
mtr);
|
|
fsp_free_extent(space, zip_size, page, mtr);
|
|
}
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Returns an extent to the free list of a space. */
|
|
static
|
|
void
|
|
fsp_free_extent(
|
|
/*============*/
|
|
ulint space, /*!< in: space id */
|
|
ulint zip_size,/*!< in: compressed page size in bytes
|
|
or 0 for uncompressed pages */
|
|
ulint page, /*!< in: page offset in the extent */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
fsp_header_t* header;
|
|
xdes_t* descr;
|
|
|
|
ut_ad(mtr);
|
|
|
|
header = fsp_get_space_header(space, zip_size, mtr);
|
|
|
|
descr = xdes_get_descriptor_with_space_hdr(header, space, page, mtr);
|
|
|
|
if (xdes_get_state(descr, mtr) == XDES_FREE) {
|
|
|
|
ut_print_buf(stderr, (byte*)descr - 500, 1000);
|
|
putc('\n', stderr);
|
|
|
|
ut_error;
|
|
}
|
|
|
|
xdes_init(descr, mtr);
|
|
|
|
flst_add_last(header + FSP_FREE, descr + XDES_FLST_NODE, mtr);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Returns the nth inode slot on an inode page.
|
|
@return segment inode */
|
|
UNIV_INLINE
|
|
fseg_inode_t*
|
|
fsp_seg_inode_page_get_nth_inode(
|
|
/*=============================*/
|
|
page_t* page, /*!< in: segment inode page */
|
|
ulint i, /*!< in: inode index on page */
|
|
ulint zip_size __attribute__((unused)),
|
|
/*!< in: compressed page size, or 0 */
|
|
mtr_t* mtr __attribute__((unused)))
|
|
/*!< in: mini-transaction handle */
|
|
{
|
|
ut_ad(i < FSP_SEG_INODES_PER_PAGE(zip_size));
|
|
ut_ad(mtr_memo_contains_page(mtr, page, MTR_MEMO_PAGE_X_FIX));
|
|
|
|
return(page + FSEG_ARR_OFFSET + FSEG_INODE_SIZE * i);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Looks for a used segment inode on a segment inode page.
|
|
@return segment inode index, or ULINT_UNDEFINED if not found */
|
|
static
|
|
ulint
|
|
fsp_seg_inode_page_find_used(
|
|
/*=========================*/
|
|
page_t* page, /*!< in: segment inode page */
|
|
ulint zip_size,/*!< in: compressed page size, or 0 */
|
|
mtr_t* mtr) /*!< in: mini-transaction handle */
|
|
{
|
|
ulint i;
|
|
fseg_inode_t* inode;
|
|
|
|
for (i = 0; i < FSP_SEG_INODES_PER_PAGE(zip_size); i++) {
|
|
|
|
inode = fsp_seg_inode_page_get_nth_inode(
|
|
page, i, zip_size, mtr);
|
|
|
|
if (!ut_dulint_is_zero(mach_read_from_8(inode + FSEG_ID))) {
|
|
/* This is used */
|
|
|
|
ut_ad(mach_read_from_4(inode + FSEG_MAGIC_N)
|
|
== FSEG_MAGIC_N_VALUE);
|
|
return(i);
|
|
}
|
|
}
|
|
|
|
return(ULINT_UNDEFINED);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Looks for an unused segment inode on a segment inode page.
|
|
@return segment inode index, or ULINT_UNDEFINED if not found */
|
|
static
|
|
ulint
|
|
fsp_seg_inode_page_find_free(
|
|
/*=========================*/
|
|
page_t* page, /*!< in: segment inode page */
|
|
ulint i, /*!< in: search forward starting from this index */
|
|
ulint zip_size,/*!< in: compressed page size, or 0 */
|
|
mtr_t* mtr) /*!< in: mini-transaction handle */
|
|
{
|
|
fseg_inode_t* inode;
|
|
|
|
for (; i < FSP_SEG_INODES_PER_PAGE(zip_size); i++) {
|
|
|
|
inode = fsp_seg_inode_page_get_nth_inode(
|
|
page, i, zip_size, mtr);
|
|
|
|
if (ut_dulint_is_zero(mach_read_from_8(inode + FSEG_ID))) {
|
|
/* This is unused */
|
|
|
|
return(i);
|
|
}
|
|
|
|
ut_ad(mach_read_from_4(inode + FSEG_MAGIC_N)
|
|
== FSEG_MAGIC_N_VALUE);
|
|
}
|
|
|
|
return(ULINT_UNDEFINED);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Allocates a new file segment inode page.
|
|
@return TRUE if could be allocated */
|
|
static
|
|
ibool
|
|
fsp_alloc_seg_inode_page(
|
|
/*=====================*/
|
|
fsp_header_t* space_header, /*!< in: space header */
|
|
mtr_t* mtr) /*!< in: mini-transaction handle */
|
|
{
|
|
fseg_inode_t* inode;
|
|
buf_block_t* block;
|
|
page_t* page;
|
|
ulint page_no;
|
|
ulint space;
|
|
ulint zip_size;
|
|
ulint i;
|
|
|
|
ut_ad(page_offset(space_header) == FSP_HEADER_OFFSET);
|
|
|
|
space = page_get_space_id(page_align(space_header));
|
|
zip_size = dict_table_flags_to_zip_size(
|
|
mach_read_from_4(FSP_SPACE_FLAGS + space_header));
|
|
|
|
page_no = fsp_alloc_free_page(space, zip_size, 0, mtr);
|
|
|
|
if (page_no == FIL_NULL) {
|
|
|
|
return(FALSE);
|
|
}
|
|
|
|
block = buf_page_get(space, zip_size, page_no, RW_X_LATCH, mtr);
|
|
buf_block_dbg_add_level(block, SYNC_FSP_PAGE);
|
|
|
|
block->check_index_page_at_flush = FALSE;
|
|
|
|
page = buf_block_get_frame(block);
|
|
|
|
mlog_write_ulint(page + FIL_PAGE_TYPE, FIL_PAGE_INODE,
|
|
MLOG_2BYTES, mtr);
|
|
|
|
for (i = 0; i < FSP_SEG_INODES_PER_PAGE(zip_size); i++) {
|
|
|
|
inode = fsp_seg_inode_page_get_nth_inode(page, i,
|
|
zip_size, mtr);
|
|
|
|
mlog_write_dulint(inode + FSEG_ID, ut_dulint_zero, mtr);
|
|
}
|
|
|
|
flst_add_last(space_header + FSP_SEG_INODES_FREE,
|
|
page + FSEG_INODE_PAGE_NODE, mtr);
|
|
return(TRUE);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Allocates a new file segment inode.
|
|
@return segment inode, or NULL if not enough space */
|
|
static
|
|
fseg_inode_t*
|
|
fsp_alloc_seg_inode(
|
|
/*================*/
|
|
fsp_header_t* space_header, /*!< in: space header */
|
|
mtr_t* mtr) /*!< in: mini-transaction handle */
|
|
{
|
|
ulint page_no;
|
|
buf_block_t* block;
|
|
page_t* page;
|
|
fseg_inode_t* inode;
|
|
ibool success;
|
|
ulint zip_size;
|
|
ulint n;
|
|
|
|
ut_ad(page_offset(space_header) == FSP_HEADER_OFFSET);
|
|
|
|
if (flst_get_len(space_header + FSP_SEG_INODES_FREE, mtr) == 0) {
|
|
/* Allocate a new segment inode page */
|
|
|
|
success = fsp_alloc_seg_inode_page(space_header, mtr);
|
|
|
|
if (!success) {
|
|
|
|
return(NULL);
|
|
}
|
|
}
|
|
|
|
page_no = flst_get_first(space_header + FSP_SEG_INODES_FREE, mtr).page;
|
|
|
|
zip_size = dict_table_flags_to_zip_size(
|
|
mach_read_from_4(FSP_SPACE_FLAGS + space_header));
|
|
block = buf_page_get(page_get_space_id(page_align(space_header)),
|
|
zip_size, page_no, RW_X_LATCH, mtr);
|
|
buf_block_dbg_add_level(block, SYNC_FSP_PAGE);
|
|
|
|
page = buf_block_get_frame(block);
|
|
|
|
n = fsp_seg_inode_page_find_free(page, 0, zip_size, mtr);
|
|
|
|
ut_a(n != ULINT_UNDEFINED);
|
|
|
|
inode = fsp_seg_inode_page_get_nth_inode(page, n, zip_size, mtr);
|
|
|
|
if (ULINT_UNDEFINED == fsp_seg_inode_page_find_free(page, n + 1,
|
|
zip_size, mtr)) {
|
|
/* There are no other unused headers left on the page: move it
|
|
to another list */
|
|
|
|
flst_remove(space_header + FSP_SEG_INODES_FREE,
|
|
page + FSEG_INODE_PAGE_NODE, mtr);
|
|
|
|
flst_add_last(space_header + FSP_SEG_INODES_FULL,
|
|
page + FSEG_INODE_PAGE_NODE, mtr);
|
|
}
|
|
|
|
ut_ad(ut_dulint_is_zero(mach_read_from_8(inode + FSEG_ID))
|
|
|| mach_read_from_4(inode + FSEG_MAGIC_N) == FSEG_MAGIC_N_VALUE);
|
|
return(inode);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Frees a file segment inode. */
|
|
static
|
|
void
|
|
fsp_free_seg_inode(
|
|
/*===============*/
|
|
ulint space, /*!< in: space id */
|
|
ulint zip_size,/*!< in: compressed page size in bytes
|
|
or 0 for uncompressed pages */
|
|
fseg_inode_t* inode, /*!< in: segment inode */
|
|
mtr_t* mtr) /*!< in: mini-transaction handle */
|
|
{
|
|
page_t* page;
|
|
fsp_header_t* space_header;
|
|
|
|
page = page_align(inode);
|
|
|
|
space_header = fsp_get_space_header(space, zip_size, mtr);
|
|
|
|
ut_ad(mach_read_from_4(inode + FSEG_MAGIC_N) == FSEG_MAGIC_N_VALUE);
|
|
|
|
if (ULINT_UNDEFINED
|
|
== fsp_seg_inode_page_find_free(page, 0, zip_size, mtr)) {
|
|
|
|
/* Move the page to another list */
|
|
|
|
flst_remove(space_header + FSP_SEG_INODES_FULL,
|
|
page + FSEG_INODE_PAGE_NODE, mtr);
|
|
|
|
flst_add_last(space_header + FSP_SEG_INODES_FREE,
|
|
page + FSEG_INODE_PAGE_NODE, mtr);
|
|
}
|
|
|
|
mlog_write_dulint(inode + FSEG_ID, ut_dulint_zero, mtr);
|
|
mlog_write_ulint(inode + FSEG_MAGIC_N, 0xfa051ce3, MLOG_4BYTES, mtr);
|
|
|
|
if (ULINT_UNDEFINED
|
|
== fsp_seg_inode_page_find_used(page, zip_size, mtr)) {
|
|
|
|
/* There are no other used headers left on the page: free it */
|
|
|
|
flst_remove(space_header + FSP_SEG_INODES_FREE,
|
|
page + FSEG_INODE_PAGE_NODE, mtr);
|
|
|
|
fsp_free_page(space, zip_size, page_get_page_no(page), mtr);
|
|
}
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Returns the file segment inode, page x-latched.
|
|
@return segment inode, page x-latched; NULL if the inode is free */
|
|
static
|
|
fseg_inode_t*
|
|
fseg_inode_try_get(
|
|
/*===============*/
|
|
fseg_header_t* header, /*!< in: segment header */
|
|
ulint space, /*!< in: space id */
|
|
ulint zip_size,/*!< in: compressed page size in bytes
|
|
or 0 for uncompressed pages */
|
|
mtr_t* mtr) /*!< in: mtr handle */
|
|
{
|
|
fil_addr_t inode_addr;
|
|
fseg_inode_t* inode;
|
|
|
|
inode_addr.page = mach_read_from_4(header + FSEG_HDR_PAGE_NO);
|
|
inode_addr.boffset = mach_read_from_2(header + FSEG_HDR_OFFSET);
|
|
ut_ad(space == mach_read_from_4(header + FSEG_HDR_SPACE));
|
|
|
|
inode = fut_get_ptr(space, zip_size, inode_addr, RW_X_LATCH, mtr);
|
|
|
|
if (UNIV_UNLIKELY
|
|
(ut_dulint_is_zero(mach_read_from_8(inode + FSEG_ID)))) {
|
|
|
|
inode = NULL;
|
|
} else {
|
|
ut_ad(mach_read_from_4(inode + FSEG_MAGIC_N)
|
|
== FSEG_MAGIC_N_VALUE);
|
|
}
|
|
|
|
return(inode);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Returns the file segment inode, page x-latched.
|
|
@return segment inode, page x-latched */
|
|
static
|
|
fseg_inode_t*
|
|
fseg_inode_get(
|
|
/*===========*/
|
|
fseg_header_t* header, /*!< in: segment header */
|
|
ulint space, /*!< in: space id */
|
|
ulint zip_size,/*!< in: compressed page size in bytes
|
|
or 0 for uncompressed pages */
|
|
mtr_t* mtr) /*!< in: mtr handle */
|
|
{
|
|
fseg_inode_t* inode
|
|
= fseg_inode_try_get(header, space, zip_size, mtr);
|
|
ut_a(inode);
|
|
return(inode);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Gets the page number from the nth fragment page slot.
|
|
@return page number, FIL_NULL if not in use */
|
|
UNIV_INLINE
|
|
ulint
|
|
fseg_get_nth_frag_page_no(
|
|
/*======================*/
|
|
fseg_inode_t* inode, /*!< in: segment inode */
|
|
ulint n, /*!< in: slot index */
|
|
mtr_t* mtr __attribute__((unused))) /*!< in: mtr handle */
|
|
{
|
|
ut_ad(inode && mtr);
|
|
ut_ad(n < FSEG_FRAG_ARR_N_SLOTS);
|
|
ut_ad(mtr_memo_contains_page(mtr, inode, MTR_MEMO_PAGE_X_FIX));
|
|
ut_ad(mach_read_from_4(inode + FSEG_MAGIC_N) == FSEG_MAGIC_N_VALUE);
|
|
return(mach_read_from_4(inode + FSEG_FRAG_ARR
|
|
+ n * FSEG_FRAG_SLOT_SIZE));
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Sets the page number in the nth fragment page slot. */
|
|
UNIV_INLINE
|
|
void
|
|
fseg_set_nth_frag_page_no(
|
|
/*======================*/
|
|
fseg_inode_t* inode, /*!< in: segment inode */
|
|
ulint n, /*!< in: slot index */
|
|
ulint page_no,/*!< in: page number to set */
|
|
mtr_t* mtr) /*!< in: mtr handle */
|
|
{
|
|
ut_ad(inode && mtr);
|
|
ut_ad(n < FSEG_FRAG_ARR_N_SLOTS);
|
|
ut_ad(mtr_memo_contains_page(mtr, inode, MTR_MEMO_PAGE_X_FIX));
|
|
ut_ad(mach_read_from_4(inode + FSEG_MAGIC_N) == FSEG_MAGIC_N_VALUE);
|
|
|
|
mlog_write_ulint(inode + FSEG_FRAG_ARR + n * FSEG_FRAG_SLOT_SIZE,
|
|
page_no, MLOG_4BYTES, mtr);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Finds a fragment page slot which is free.
|
|
@return slot index; ULINT_UNDEFINED if none found */
|
|
static
|
|
ulint
|
|
fseg_find_free_frag_page_slot(
|
|
/*==========================*/
|
|
fseg_inode_t* inode, /*!< in: segment inode */
|
|
mtr_t* mtr) /*!< in: mtr handle */
|
|
{
|
|
ulint i;
|
|
ulint page_no;
|
|
|
|
ut_ad(inode && mtr);
|
|
|
|
for (i = 0; i < FSEG_FRAG_ARR_N_SLOTS; i++) {
|
|
page_no = fseg_get_nth_frag_page_no(inode, i, mtr);
|
|
|
|
if (page_no == FIL_NULL) {
|
|
|
|
return(i);
|
|
}
|
|
}
|
|
|
|
return(ULINT_UNDEFINED);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Finds a fragment page slot which is used and last in the array.
|
|
@return slot index; ULINT_UNDEFINED if none found */
|
|
static
|
|
ulint
|
|
fseg_find_last_used_frag_page_slot(
|
|
/*===============================*/
|
|
fseg_inode_t* inode, /*!< in: segment inode */
|
|
mtr_t* mtr) /*!< in: mtr handle */
|
|
{
|
|
ulint i;
|
|
ulint page_no;
|
|
|
|
ut_ad(inode && mtr);
|
|
|
|
for (i = 0; i < FSEG_FRAG_ARR_N_SLOTS; i++) {
|
|
page_no = fseg_get_nth_frag_page_no(
|
|
inode, FSEG_FRAG_ARR_N_SLOTS - i - 1, mtr);
|
|
|
|
if (page_no != FIL_NULL) {
|
|
|
|
return(FSEG_FRAG_ARR_N_SLOTS - i - 1);
|
|
}
|
|
}
|
|
|
|
return(ULINT_UNDEFINED);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Calculates reserved fragment page slots.
|
|
@return number of fragment pages */
|
|
static
|
|
ulint
|
|
fseg_get_n_frag_pages(
|
|
/*==================*/
|
|
fseg_inode_t* inode, /*!< in: segment inode */
|
|
mtr_t* mtr) /*!< in: mtr handle */
|
|
{
|
|
ulint i;
|
|
ulint count = 0;
|
|
|
|
ut_ad(inode && mtr);
|
|
|
|
for (i = 0; i < FSEG_FRAG_ARR_N_SLOTS; i++) {
|
|
if (FIL_NULL != fseg_get_nth_frag_page_no(inode, i, mtr)) {
|
|
count++;
|
|
}
|
|
}
|
|
|
|
return(count);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Creates a new segment.
|
|
@return the block where the segment header is placed, x-latched, NULL
|
|
if could not create segment because of lack of space */
|
|
UNIV_INTERN
|
|
buf_block_t*
|
|
fseg_create_general(
|
|
/*================*/
|
|
ulint space, /*!< in: space id */
|
|
ulint page, /*!< in: page where the segment header is placed: if
|
|
this is != 0, the page must belong to another segment,
|
|
if this is 0, a new page will be allocated and it
|
|
will belong to the created segment */
|
|
ulint byte_offset, /*!< in: byte offset of the created segment header
|
|
on the page */
|
|
ibool has_done_reservation, /*!< in: TRUE if the caller has already
|
|
done the reservation for the pages with
|
|
fsp_reserve_free_extents (at least 2 extents: one for
|
|
the inode and the other for the segment) then there is
|
|
no need to do the check for this individual
|
|
operation */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
ulint flags;
|
|
ulint zip_size;
|
|
fsp_header_t* space_header;
|
|
fseg_inode_t* inode;
|
|
dulint seg_id;
|
|
buf_block_t* block = 0; /* remove warning */
|
|
fseg_header_t* header = 0; /* remove warning */
|
|
rw_lock_t* latch;
|
|
ibool success;
|
|
ulint n_reserved;
|
|
ulint i;
|
|
|
|
ut_ad(mtr);
|
|
ut_ad(byte_offset + FSEG_HEADER_SIZE
|
|
<= UNIV_PAGE_SIZE - FIL_PAGE_DATA_END);
|
|
|
|
latch = fil_space_get_latch(space, &flags);
|
|
zip_size = dict_table_flags_to_zip_size(flags);
|
|
|
|
if (page != 0) {
|
|
block = buf_page_get(space, zip_size, page, RW_X_LATCH, mtr);
|
|
header = byte_offset + buf_block_get_frame(block);
|
|
}
|
|
|
|
ut_ad(!mutex_own(&kernel_mutex)
|
|
|| mtr_memo_contains(mtr, latch, MTR_MEMO_X_LOCK));
|
|
|
|
mtr_x_lock(latch, mtr);
|
|
|
|
if (rw_lock_get_x_lock_count(latch) == 1) {
|
|
/* This thread did not own the latch before this call: free
|
|
excess pages from the insert buffer free list */
|
|
|
|
if (space == IBUF_SPACE_ID) {
|
|
ibuf_free_excess_pages();
|
|
}
|
|
}
|
|
|
|
if (!has_done_reservation) {
|
|
success = fsp_reserve_free_extents(&n_reserved, space, 2,
|
|
FSP_NORMAL, mtr);
|
|
if (!success) {
|
|
return(NULL);
|
|
}
|
|
}
|
|
|
|
space_header = fsp_get_space_header(space, zip_size, mtr);
|
|
|
|
inode = fsp_alloc_seg_inode(space_header, mtr);
|
|
|
|
if (inode == NULL) {
|
|
|
|
goto funct_exit;
|
|
}
|
|
|
|
/* Read the next segment id from space header and increment the
|
|
value in space header */
|
|
|
|
seg_id = mtr_read_dulint(space_header + FSP_SEG_ID, mtr);
|
|
|
|
mlog_write_dulint(space_header + FSP_SEG_ID, ut_dulint_add(seg_id, 1),
|
|
mtr);
|
|
|
|
mlog_write_dulint(inode + FSEG_ID, seg_id, mtr);
|
|
mlog_write_ulint(inode + FSEG_NOT_FULL_N_USED, 0, MLOG_4BYTES, mtr);
|
|
|
|
flst_init(inode + FSEG_FREE, mtr);
|
|
flst_init(inode + FSEG_NOT_FULL, mtr);
|
|
flst_init(inode + FSEG_FULL, mtr);
|
|
|
|
mlog_write_ulint(inode + FSEG_MAGIC_N, FSEG_MAGIC_N_VALUE,
|
|
MLOG_4BYTES, mtr);
|
|
for (i = 0; i < FSEG_FRAG_ARR_N_SLOTS; i++) {
|
|
fseg_set_nth_frag_page_no(inode, i, FIL_NULL, mtr);
|
|
}
|
|
|
|
if (page == 0) {
|
|
page = fseg_alloc_free_page_low(space, zip_size,
|
|
inode, 0, FSP_UP, mtr);
|
|
|
|
if (page == FIL_NULL) {
|
|
|
|
fsp_free_seg_inode(space, zip_size, inode, mtr);
|
|
|
|
goto funct_exit;
|
|
}
|
|
|
|
block = buf_page_get(space, zip_size, page, RW_X_LATCH, mtr);
|
|
header = byte_offset + buf_block_get_frame(block);
|
|
mlog_write_ulint(header - byte_offset + FIL_PAGE_TYPE,
|
|
FIL_PAGE_TYPE_SYS, MLOG_2BYTES, mtr);
|
|
}
|
|
|
|
mlog_write_ulint(header + FSEG_HDR_OFFSET,
|
|
page_offset(inode), MLOG_2BYTES, mtr);
|
|
|
|
mlog_write_ulint(header + FSEG_HDR_PAGE_NO,
|
|
page_get_page_no(page_align(inode)),
|
|
MLOG_4BYTES, mtr);
|
|
|
|
mlog_write_ulint(header + FSEG_HDR_SPACE, space, MLOG_4BYTES, mtr);
|
|
|
|
funct_exit:
|
|
if (!has_done_reservation) {
|
|
|
|
fil_space_release_free_extents(space, n_reserved);
|
|
}
|
|
|
|
return(block);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Creates a new segment.
|
|
@return the block where the segment header is placed, x-latched, NULL
|
|
if could not create segment because of lack of space */
|
|
UNIV_INTERN
|
|
buf_block_t*
|
|
fseg_create(
|
|
/*========*/
|
|
ulint space, /*!< in: space id */
|
|
ulint page, /*!< in: page where the segment header is placed: if
|
|
this is != 0, the page must belong to another segment,
|
|
if this is 0, a new page will be allocated and it
|
|
will belong to the created segment */
|
|
ulint byte_offset, /*!< in: byte offset of the created segment header
|
|
on the page */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
return(fseg_create_general(space, page, byte_offset, FALSE, mtr));
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Calculates the number of pages reserved by a segment, and how many pages are
|
|
currently used.
|
|
@return number of reserved pages */
|
|
static
|
|
ulint
|
|
fseg_n_reserved_pages_low(
|
|
/*======================*/
|
|
fseg_inode_t* inode, /*!< in: segment inode */
|
|
ulint* used, /*!< out: number of pages used (not
|
|
more than reserved) */
|
|
mtr_t* mtr) /*!< in: mtr handle */
|
|
{
|
|
ulint ret;
|
|
|
|
ut_ad(inode && used && mtr);
|
|
ut_ad(mtr_memo_contains_page(mtr, inode, MTR_MEMO_PAGE_X_FIX));
|
|
|
|
*used = mtr_read_ulint(inode + FSEG_NOT_FULL_N_USED, MLOG_4BYTES, mtr)
|
|
+ FSP_EXTENT_SIZE * flst_get_len(inode + FSEG_FULL, mtr)
|
|
+ fseg_get_n_frag_pages(inode, mtr);
|
|
|
|
ret = fseg_get_n_frag_pages(inode, mtr)
|
|
+ FSP_EXTENT_SIZE * flst_get_len(inode + FSEG_FREE, mtr)
|
|
+ FSP_EXTENT_SIZE * flst_get_len(inode + FSEG_NOT_FULL, mtr)
|
|
+ FSP_EXTENT_SIZE * flst_get_len(inode + FSEG_FULL, mtr);
|
|
|
|
return(ret);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Calculates the number of pages reserved by a segment, and how many pages are
|
|
currently used.
|
|
@return number of reserved pages */
|
|
UNIV_INTERN
|
|
ulint
|
|
fseg_n_reserved_pages(
|
|
/*==================*/
|
|
fseg_header_t* header, /*!< in: segment header */
|
|
ulint* used, /*!< out: number of pages used (<= reserved) */
|
|
mtr_t* mtr) /*!< in: mtr handle */
|
|
{
|
|
ulint ret;
|
|
fseg_inode_t* inode;
|
|
ulint space;
|
|
ulint flags;
|
|
ulint zip_size;
|
|
rw_lock_t* latch;
|
|
|
|
space = page_get_space_id(page_align(header));
|
|
latch = fil_space_get_latch(space, &flags);
|
|
zip_size = dict_table_flags_to_zip_size(flags);
|
|
|
|
ut_ad(!mutex_own(&kernel_mutex)
|
|
|| mtr_memo_contains(mtr, latch, MTR_MEMO_X_LOCK));
|
|
|
|
mtr_x_lock(latch, mtr);
|
|
|
|
inode = fseg_inode_get(header, space, zip_size, mtr);
|
|
|
|
ret = fseg_n_reserved_pages_low(inode, used, mtr);
|
|
|
|
return(ret);
|
|
}
|
|
|
|
/*********************************************************************//**
|
|
Tries to fill the free list of a segment with consecutive free extents.
|
|
This happens if the segment is big enough to allow extents in the free list,
|
|
the free list is empty, and the extents can be allocated consecutively from
|
|
the hint onward. */
|
|
static
|
|
void
|
|
fseg_fill_free_list(
|
|
/*================*/
|
|
fseg_inode_t* inode, /*!< in: segment inode */
|
|
ulint space, /*!< in: space id */
|
|
ulint zip_size,/*!< in: compressed page size in bytes
|
|
or 0 for uncompressed pages */
|
|
ulint hint, /*!< in: hint which extent would be good as
|
|
the first extent */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
xdes_t* descr;
|
|
ulint i;
|
|
dulint seg_id;
|
|
ulint reserved;
|
|
ulint used;
|
|
|
|
ut_ad(inode && mtr);
|
|
ut_ad(!((page_offset(inode) - FSEG_ARR_OFFSET) % FSEG_INODE_SIZE));
|
|
|
|
reserved = fseg_n_reserved_pages_low(inode, &used, mtr);
|
|
|
|
if (reserved < FSEG_FREE_LIST_LIMIT * FSP_EXTENT_SIZE) {
|
|
|
|
/* The segment is too small to allow extents in free list */
|
|
|
|
return;
|
|
}
|
|
|
|
if (flst_get_len(inode + FSEG_FREE, mtr) > 0) {
|
|
/* Free list is not empty */
|
|
|
|
return;
|
|
}
|
|
|
|
for (i = 0; i < FSEG_FREE_LIST_MAX_LEN; i++) {
|
|
descr = xdes_get_descriptor(space, zip_size, hint, mtr);
|
|
|
|
if ((descr == NULL)
|
|
|| (XDES_FREE != xdes_get_state(descr, mtr))) {
|
|
|
|
/* We cannot allocate the desired extent: stop */
|
|
|
|
return;
|
|
}
|
|
|
|
descr = fsp_alloc_free_extent(space, zip_size, hint, mtr);
|
|
|
|
xdes_set_state(descr, XDES_FSEG, mtr);
|
|
|
|
seg_id = mtr_read_dulint(inode + FSEG_ID, mtr);
|
|
ut_ad(mach_read_from_4(inode + FSEG_MAGIC_N)
|
|
== FSEG_MAGIC_N_VALUE);
|
|
mlog_write_dulint(descr + XDES_ID, seg_id, mtr);
|
|
|
|
flst_add_last(inode + FSEG_FREE, descr + XDES_FLST_NODE, mtr);
|
|
hint += FSP_EXTENT_SIZE;
|
|
}
|
|
}
|
|
|
|
/*********************************************************************//**
|
|
Allocates a free extent for the segment: looks first in the free list of the
|
|
segment, then tries to allocate from the space free list. NOTE that the extent
|
|
returned still resides in the segment free list, it is not yet taken off it!
|
|
@return allocated extent, still placed in the segment free list, NULL
|
|
if could not be allocated */
|
|
static
|
|
xdes_t*
|
|
fseg_alloc_free_extent(
|
|
/*===================*/
|
|
fseg_inode_t* inode, /*!< in: segment inode */
|
|
ulint space, /*!< in: space id */
|
|
ulint zip_size,/*!< in: compressed page size in bytes
|
|
or 0 for uncompressed pages */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
xdes_t* descr;
|
|
dulint seg_id;
|
|
fil_addr_t first;
|
|
|
|
ut_ad(!((page_offset(inode) - FSEG_ARR_OFFSET) % FSEG_INODE_SIZE));
|
|
ut_ad(mach_read_from_4(inode + FSEG_MAGIC_N) == FSEG_MAGIC_N_VALUE);
|
|
|
|
if (flst_get_len(inode + FSEG_FREE, mtr) > 0) {
|
|
/* Segment free list is not empty, allocate from it */
|
|
|
|
first = flst_get_first(inode + FSEG_FREE, mtr);
|
|
|
|
descr = xdes_lst_get_descriptor(space, zip_size, first, mtr);
|
|
} else {
|
|
/* Segment free list was empty, allocate from space */
|
|
descr = fsp_alloc_free_extent(space, zip_size, 0, mtr);
|
|
|
|
if (descr == NULL) {
|
|
|
|
return(NULL);
|
|
}
|
|
|
|
seg_id = mtr_read_dulint(inode + FSEG_ID, mtr);
|
|
|
|
xdes_set_state(descr, XDES_FSEG, mtr);
|
|
mlog_write_dulint(descr + XDES_ID, seg_id, mtr);
|
|
flst_add_last(inode + FSEG_FREE, descr + XDES_FLST_NODE, mtr);
|
|
|
|
/* Try to fill the segment free list */
|
|
fseg_fill_free_list(inode, space, zip_size,
|
|
xdes_get_offset(descr) + FSP_EXTENT_SIZE,
|
|
mtr);
|
|
}
|
|
|
|
return(descr);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Allocates a single free page from a segment. This function implements
|
|
the intelligent allocation strategy which tries to minimize file space
|
|
fragmentation.
|
|
@return the allocated page number, FIL_NULL if no page could be allocated */
|
|
static
|
|
ulint
|
|
fseg_alloc_free_page_low(
|
|
/*=====================*/
|
|
ulint space, /*!< in: space */
|
|
ulint zip_size,/*!< in: compressed page size in bytes
|
|
or 0 for uncompressed pages */
|
|
fseg_inode_t* seg_inode, /*!< in: segment inode */
|
|
ulint hint, /*!< in: hint of which page would be desirable */
|
|
byte direction, /*!< in: if the new page is needed because
|
|
of an index page split, and records are
|
|
inserted there in order, into which
|
|
direction they go alphabetically: FSP_DOWN,
|
|
FSP_UP, FSP_NO_DIR */
|
|
mtr_t* mtr) /*!< in: mtr handle */
|
|
{
|
|
fsp_header_t* space_header;
|
|
ulint space_size;
|
|
dulint seg_id;
|
|
ulint used;
|
|
ulint reserved;
|
|
xdes_t* descr; /*!< extent of the hinted page */
|
|
ulint ret_page; /*!< the allocated page offset, FIL_NULL
|
|
if could not be allocated */
|
|
xdes_t* ret_descr; /*!< the extent of the allocated page */
|
|
ibool frag_page_allocated = FALSE;
|
|
ibool success;
|
|
ulint n;
|
|
|
|
ut_ad(mtr);
|
|
ut_ad((direction >= FSP_UP) && (direction <= FSP_NO_DIR));
|
|
ut_ad(mach_read_from_4(seg_inode + FSEG_MAGIC_N)
|
|
== FSEG_MAGIC_N_VALUE);
|
|
ut_ad(!((page_offset(seg_inode) - FSEG_ARR_OFFSET) % FSEG_INODE_SIZE));
|
|
seg_id = mtr_read_dulint(seg_inode + FSEG_ID, mtr);
|
|
|
|
ut_ad(!ut_dulint_is_zero(seg_id));
|
|
|
|
reserved = fseg_n_reserved_pages_low(seg_inode, &used, mtr);
|
|
|
|
space_header = fsp_get_space_header(space, zip_size, mtr);
|
|
|
|
descr = xdes_get_descriptor_with_space_hdr(space_header, space,
|
|
hint, mtr);
|
|
if (descr == NULL) {
|
|
/* Hint outside space or too high above free limit: reset
|
|
hint */
|
|
hint = 0;
|
|
descr = xdes_get_descriptor(space, zip_size, hint, mtr);
|
|
}
|
|
|
|
/* In the big if-else below we look for ret_page and ret_descr */
|
|
/*-------------------------------------------------------------*/
|
|
if ((xdes_get_state(descr, mtr) == XDES_FSEG)
|
|
&& (0 == ut_dulint_cmp(mtr_read_dulint(descr + XDES_ID,
|
|
mtr), seg_id))
|
|
&& (xdes_get_bit(descr, XDES_FREE_BIT,
|
|
hint % FSP_EXTENT_SIZE, mtr) == TRUE)) {
|
|
|
|
/* 1. We can take the hinted page
|
|
=================================*/
|
|
ret_descr = descr;
|
|
ret_page = hint;
|
|
/*-----------------------------------------------------------*/
|
|
} else if ((xdes_get_state(descr, mtr) == XDES_FREE)
|
|
&& ((reserved - used) < reserved / FSEG_FILLFACTOR)
|
|
&& (used >= FSEG_FRAG_LIMIT)) {
|
|
|
|
/* 2. We allocate the free extent from space and can take
|
|
=========================================================
|
|
the hinted page
|
|
===============*/
|
|
ret_descr = fsp_alloc_free_extent(space, zip_size, hint, mtr);
|
|
|
|
ut_a(ret_descr == descr);
|
|
|
|
xdes_set_state(ret_descr, XDES_FSEG, mtr);
|
|
mlog_write_dulint(ret_descr + XDES_ID, seg_id, mtr);
|
|
flst_add_last(seg_inode + FSEG_FREE,
|
|
ret_descr + XDES_FLST_NODE, mtr);
|
|
|
|
/* Try to fill the segment free list */
|
|
fseg_fill_free_list(seg_inode, space, zip_size,
|
|
hint + FSP_EXTENT_SIZE, mtr);
|
|
ret_page = hint;
|
|
/*-----------------------------------------------------------*/
|
|
} else if ((direction != FSP_NO_DIR)
|
|
&& ((reserved - used) < reserved / FSEG_FILLFACTOR)
|
|
&& (used >= FSEG_FRAG_LIMIT)
|
|
&& (!!(ret_descr
|
|
= fseg_alloc_free_extent(seg_inode,
|
|
space, zip_size, mtr)))) {
|
|
|
|
/* 3. We take any free extent (which was already assigned above
|
|
===============================================================
|
|
in the if-condition to ret_descr) and take the lowest or
|
|
========================================================
|
|
highest page in it, depending on the direction
|
|
==============================================*/
|
|
ret_page = xdes_get_offset(ret_descr);
|
|
|
|
if (direction == FSP_DOWN) {
|
|
ret_page += FSP_EXTENT_SIZE - 1;
|
|
}
|
|
/*-----------------------------------------------------------*/
|
|
} else if ((xdes_get_state(descr, mtr) == XDES_FSEG)
|
|
&& (0 == ut_dulint_cmp(mtr_read_dulint(descr + XDES_ID,
|
|
mtr), seg_id))
|
|
&& (!xdes_is_full(descr, mtr))) {
|
|
|
|
/* 4. We can take the page from the same extent as the
|
|
======================================================
|
|
hinted page (and the extent already belongs to the
|
|
==================================================
|
|
segment)
|
|
========*/
|
|
ret_descr = descr;
|
|
ret_page = xdes_get_offset(ret_descr)
|
|
+ xdes_find_bit(ret_descr, XDES_FREE_BIT, TRUE,
|
|
hint % FSP_EXTENT_SIZE, mtr);
|
|
/*-----------------------------------------------------------*/
|
|
} else if (reserved - used > 0) {
|
|
/* 5. We take any unused page from the segment
|
|
==============================================*/
|
|
fil_addr_t first;
|
|
|
|
if (flst_get_len(seg_inode + FSEG_NOT_FULL, mtr) > 0) {
|
|
first = flst_get_first(seg_inode + FSEG_NOT_FULL,
|
|
mtr);
|
|
} else if (flst_get_len(seg_inode + FSEG_FREE, mtr) > 0) {
|
|
first = flst_get_first(seg_inode + FSEG_FREE, mtr);
|
|
} else {
|
|
ut_error;
|
|
return(FIL_NULL);
|
|
}
|
|
|
|
ret_descr = xdes_lst_get_descriptor(space, zip_size,
|
|
first, mtr);
|
|
ret_page = xdes_get_offset(ret_descr)
|
|
+ xdes_find_bit(ret_descr, XDES_FREE_BIT, TRUE,
|
|
0, mtr);
|
|
/*-----------------------------------------------------------*/
|
|
} else if (used < FSEG_FRAG_LIMIT) {
|
|
/* 6. We allocate an individual page from the space
|
|
===================================================*/
|
|
ret_page = fsp_alloc_free_page(space, zip_size, hint, mtr);
|
|
ret_descr = NULL;
|
|
|
|
frag_page_allocated = TRUE;
|
|
|
|
if (ret_page != FIL_NULL) {
|
|
/* Put the page in the fragment page array of the
|
|
segment */
|
|
n = fseg_find_free_frag_page_slot(seg_inode, mtr);
|
|
ut_a(n != FIL_NULL);
|
|
|
|
fseg_set_nth_frag_page_no(seg_inode, n, ret_page,
|
|
mtr);
|
|
}
|
|
/*-----------------------------------------------------------*/
|
|
} else {
|
|
/* 7. We allocate a new extent and take its first page
|
|
======================================================*/
|
|
ret_descr = fseg_alloc_free_extent(seg_inode,
|
|
space, zip_size, mtr);
|
|
|
|
if (ret_descr == NULL) {
|
|
ret_page = FIL_NULL;
|
|
} else {
|
|
ret_page = xdes_get_offset(ret_descr);
|
|
}
|
|
}
|
|
|
|
if (ret_page == FIL_NULL) {
|
|
/* Page could not be allocated */
|
|
|
|
return(FIL_NULL);
|
|
}
|
|
|
|
if (space != 0) {
|
|
space_size = fil_space_get_size(space);
|
|
|
|
if (space_size <= ret_page) {
|
|
/* It must be that we are extending a single-table
|
|
tablespace whose size is still < 64 pages */
|
|
|
|
if (ret_page >= FSP_EXTENT_SIZE) {
|
|
fprintf(stderr,
|
|
"InnoDB: Error (2): trying to extend"
|
|
" a single-table tablespace %lu\n"
|
|
"InnoDB: by single page(s) though"
|
|
" the space size %lu. Page no %lu.\n",
|
|
(ulong) space, (ulong) space_size,
|
|
(ulong) ret_page);
|
|
return(FIL_NULL);
|
|
}
|
|
|
|
success = fsp_try_extend_data_file_with_pages(
|
|
space, ret_page, space_header, mtr);
|
|
if (!success) {
|
|
/* No disk space left */
|
|
return(FIL_NULL);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!frag_page_allocated) {
|
|
/* Initialize the allocated page to buffer pool, so that it
|
|
can be obtained immediately with buf_page_get without need
|
|
for a disk read */
|
|
buf_block_t* block;
|
|
ulint zip_size = dict_table_flags_to_zip_size(
|
|
mach_read_from_4(FSP_SPACE_FLAGS + space_header));
|
|
|
|
block = buf_page_create(space, ret_page, zip_size, mtr);
|
|
buf_block_dbg_add_level(block, SYNC_FSP_PAGE);
|
|
|
|
if (UNIV_UNLIKELY(block != buf_page_get(space, zip_size,
|
|
ret_page, RW_X_LATCH,
|
|
mtr))) {
|
|
ut_error;
|
|
}
|
|
|
|
/* The prior contents of the page should be ignored */
|
|
fsp_init_file_page(block, mtr);
|
|
|
|
/* At this point we know the extent and the page offset.
|
|
The extent is still in the appropriate list (FSEG_NOT_FULL
|
|
or FSEG_FREE), and the page is not yet marked as used. */
|
|
|
|
ut_ad(xdes_get_descriptor(space, zip_size, ret_page, mtr)
|
|
== ret_descr);
|
|
ut_ad(xdes_get_bit(ret_descr, XDES_FREE_BIT,
|
|
ret_page % FSP_EXTENT_SIZE, mtr) == TRUE);
|
|
|
|
fseg_mark_page_used(seg_inode, space, zip_size, ret_page, mtr);
|
|
}
|
|
|
|
buf_reset_check_index_page_at_flush(space, ret_page);
|
|
|
|
return(ret_page);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Allocates a single free page from a segment. This function implements
|
|
the intelligent allocation strategy which tries to minimize file space
|
|
fragmentation.
|
|
@return allocated page offset, FIL_NULL if no page could be allocated */
|
|
UNIV_INTERN
|
|
ulint
|
|
fseg_alloc_free_page_general(
|
|
/*=========================*/
|
|
fseg_header_t* seg_header,/*!< in: segment header */
|
|
ulint hint, /*!< in: hint of which page would be desirable */
|
|
byte direction,/*!< in: if the new page is needed because
|
|
of an index page split, and records are
|
|
inserted there in order, into which
|
|
direction they go alphabetically: FSP_DOWN,
|
|
FSP_UP, FSP_NO_DIR */
|
|
ibool has_done_reservation, /*!< in: TRUE if the caller has
|
|
already done the reservation for the page
|
|
with fsp_reserve_free_extents, then there
|
|
is no need to do the check for this individual
|
|
page */
|
|
mtr_t* mtr) /*!< in: mtr handle */
|
|
{
|
|
fseg_inode_t* inode;
|
|
ulint space;
|
|
ulint flags;
|
|
ulint zip_size;
|
|
rw_lock_t* latch;
|
|
ibool success;
|
|
ulint page_no;
|
|
ulint n_reserved;
|
|
|
|
space = page_get_space_id(page_align(seg_header));
|
|
|
|
latch = fil_space_get_latch(space, &flags);
|
|
|
|
zip_size = dict_table_flags_to_zip_size(flags);
|
|
|
|
ut_ad(!mutex_own(&kernel_mutex)
|
|
|| mtr_memo_contains(mtr, latch, MTR_MEMO_X_LOCK));
|
|
|
|
mtr_x_lock(latch, mtr);
|
|
|
|
if (rw_lock_get_x_lock_count(latch) == 1) {
|
|
/* This thread did not own the latch before this call: free
|
|
excess pages from the insert buffer free list */
|
|
|
|
if (space == IBUF_SPACE_ID) {
|
|
ibuf_free_excess_pages();
|
|
}
|
|
}
|
|
|
|
inode = fseg_inode_get(seg_header, space, zip_size, mtr);
|
|
|
|
if (!has_done_reservation) {
|
|
success = fsp_reserve_free_extents(&n_reserved, space, 2,
|
|
FSP_NORMAL, mtr);
|
|
if (!success) {
|
|
return(FIL_NULL);
|
|
}
|
|
}
|
|
|
|
page_no = fseg_alloc_free_page_low(space, zip_size,
|
|
inode, hint, direction, mtr);
|
|
if (!has_done_reservation) {
|
|
fil_space_release_free_extents(space, n_reserved);
|
|
}
|
|
|
|
return(page_no);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Allocates a single free page from a segment. This function implements
|
|
the intelligent allocation strategy which tries to minimize file space
|
|
fragmentation.
|
|
@return allocated page offset, FIL_NULL if no page could be allocated */
|
|
UNIV_INTERN
|
|
ulint
|
|
fseg_alloc_free_page(
|
|
/*=================*/
|
|
fseg_header_t* seg_header,/*!< in: segment header */
|
|
ulint hint, /*!< in: hint of which page would be desirable */
|
|
byte direction,/*!< in: if the new page is needed because
|
|
of an index page split, and records are
|
|
inserted there in order, into which
|
|
direction they go alphabetically: FSP_DOWN,
|
|
FSP_UP, FSP_NO_DIR */
|
|
mtr_t* mtr) /*!< in: mtr handle */
|
|
{
|
|
return(fseg_alloc_free_page_general(seg_header, hint, direction,
|
|
FALSE, mtr));
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Checks that we have at least 2 frag pages free in the first extent of a
|
|
single-table tablespace, and they are also physically initialized to the data
|
|
file. That is we have already extended the data file so that those pages are
|
|
inside the data file. If not, this function extends the tablespace with
|
|
pages.
|
|
@return TRUE if there were >= 3 free pages, or we were able to extend */
|
|
static
|
|
ibool
|
|
fsp_reserve_free_pages(
|
|
/*===================*/
|
|
ulint space, /*!< in: space id, must be != 0 */
|
|
fsp_header_t* space_header, /*!< in: header of that space,
|
|
x-latched */
|
|
ulint size, /*!< in: size of the tablespace in pages,
|
|
must be < FSP_EXTENT_SIZE / 2 */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
xdes_t* descr;
|
|
ulint n_used;
|
|
|
|
ut_a(space != 0);
|
|
ut_a(size < FSP_EXTENT_SIZE / 2);
|
|
|
|
descr = xdes_get_descriptor_with_space_hdr(space_header, space, 0,
|
|
mtr);
|
|
n_used = xdes_get_n_used(descr, mtr);
|
|
|
|
ut_a(n_used <= size);
|
|
|
|
if (size >= n_used + 2) {
|
|
|
|
return(TRUE);
|
|
}
|
|
|
|
return(fsp_try_extend_data_file_with_pages(space, n_used + 1,
|
|
space_header, mtr));
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Reserves free pages from a tablespace. All mini-transactions which may
|
|
use several pages from the tablespace should call this function beforehand
|
|
and reserve enough free extents so that they certainly will be able
|
|
to do their operation, like a B-tree page split, fully. Reservations
|
|
must be released with function fil_space_release_free_extents!
|
|
|
|
The alloc_type below has the following meaning: FSP_NORMAL means an
|
|
operation which will probably result in more space usage, like an
|
|
insert in a B-tree; FSP_UNDO means allocation to undo logs: if we are
|
|
deleting rows, then this allocation will in the long run result in
|
|
less space usage (after a purge); FSP_CLEANING means allocation done
|
|
in a physical record delete (like in a purge) or other cleaning operation
|
|
which will result in less space usage in the long run. We prefer the latter
|
|
two types of allocation: when space is scarce, FSP_NORMAL allocations
|
|
will not succeed, but the latter two allocations will succeed, if possible.
|
|
The purpose is to avoid dead end where the database is full but the
|
|
user cannot free any space because these freeing operations temporarily
|
|
reserve some space.
|
|
|
|
Single-table tablespaces whose size is < 32 pages are a special case. In this
|
|
function we would liberally reserve several 64 page extents for every page
|
|
split or merge in a B-tree. But we do not want to waste disk space if the table
|
|
only occupies < 32 pages. That is why we apply different rules in that special
|
|
case, just ensuring that there are 3 free pages available.
|
|
@return TRUE if we were able to make the reservation */
|
|
UNIV_INTERN
|
|
ibool
|
|
fsp_reserve_free_extents(
|
|
/*=====================*/
|
|
ulint* n_reserved,/*!< out: number of extents actually reserved; if we
|
|
return TRUE and the tablespace size is < 64 pages,
|
|
then this can be 0, otherwise it is n_ext */
|
|
ulint space, /*!< in: space id */
|
|
ulint n_ext, /*!< in: number of extents to reserve */
|
|
ulint alloc_type,/*!< in: FSP_NORMAL, FSP_UNDO, or FSP_CLEANING */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
fsp_header_t* space_header;
|
|
rw_lock_t* latch;
|
|
ulint n_free_list_ext;
|
|
ulint free_limit;
|
|
ulint size;
|
|
ulint flags;
|
|
ulint zip_size;
|
|
ulint n_free;
|
|
ulint n_free_up;
|
|
ulint reserve;
|
|
ibool success;
|
|
ulint n_pages_added;
|
|
|
|
ut_ad(mtr);
|
|
*n_reserved = n_ext;
|
|
|
|
latch = fil_space_get_latch(space, &flags);
|
|
zip_size = dict_table_flags_to_zip_size(flags);
|
|
|
|
ut_ad(!mutex_own(&kernel_mutex)
|
|
|| mtr_memo_contains(mtr, latch, MTR_MEMO_X_LOCK));
|
|
|
|
mtr_x_lock(latch, mtr);
|
|
|
|
space_header = fsp_get_space_header(space, zip_size, mtr);
|
|
try_again:
|
|
size = mtr_read_ulint(space_header + FSP_SIZE, MLOG_4BYTES, mtr);
|
|
|
|
if (size < FSP_EXTENT_SIZE / 2) {
|
|
/* Use different rules for small single-table tablespaces */
|
|
*n_reserved = 0;
|
|
return(fsp_reserve_free_pages(space, space_header, size, mtr));
|
|
}
|
|
|
|
n_free_list_ext = flst_get_len(space_header + FSP_FREE, mtr);
|
|
|
|
free_limit = mtr_read_ulint(space_header + FSP_FREE_LIMIT,
|
|
MLOG_4BYTES, mtr);
|
|
|
|
/* Below we play safe when counting free extents above the free limit:
|
|
some of them will contain extent descriptor pages, and therefore
|
|
will not be free extents */
|
|
|
|
n_free_up = (size - free_limit) / FSP_EXTENT_SIZE;
|
|
|
|
if (n_free_up > 0) {
|
|
n_free_up--;
|
|
if (!zip_size) {
|
|
n_free_up -= n_free_up
|
|
/ (UNIV_PAGE_SIZE / FSP_EXTENT_SIZE);
|
|
} else {
|
|
n_free_up -= n_free_up
|
|
/ (zip_size / FSP_EXTENT_SIZE);
|
|
}
|
|
}
|
|
|
|
n_free = n_free_list_ext + n_free_up;
|
|
|
|
if (alloc_type == FSP_NORMAL) {
|
|
/* We reserve 1 extent + 0.5 % of the space size to undo logs
|
|
and 1 extent + 0.5 % to cleaning operations; NOTE: this source
|
|
code is duplicated in the function below! */
|
|
|
|
reserve = 2 + ((size / FSP_EXTENT_SIZE) * 2) / 200;
|
|
|
|
if (n_free <= reserve + n_ext) {
|
|
|
|
goto try_to_extend;
|
|
}
|
|
} else if (alloc_type == FSP_UNDO) {
|
|
/* We reserve 0.5 % of the space size to cleaning operations */
|
|
|
|
reserve = 1 + ((size / FSP_EXTENT_SIZE) * 1) / 200;
|
|
|
|
if (n_free <= reserve + n_ext) {
|
|
|
|
goto try_to_extend;
|
|
}
|
|
} else {
|
|
ut_a(alloc_type == FSP_CLEANING);
|
|
}
|
|
|
|
success = fil_space_reserve_free_extents(space, n_free, n_ext);
|
|
|
|
if (success) {
|
|
return(TRUE);
|
|
}
|
|
try_to_extend:
|
|
success = fsp_try_extend_data_file(&n_pages_added, space,
|
|
space_header, mtr);
|
|
if (success && n_pages_added > 0) {
|
|
|
|
goto try_again;
|
|
}
|
|
|
|
return(FALSE);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
This function should be used to get information on how much we still
|
|
will be able to insert new data to the database without running out the
|
|
tablespace. Only free extents are taken into account and we also subtract
|
|
the safety margin required by the above function fsp_reserve_free_extents.
|
|
@return available space in kB */
|
|
UNIV_INTERN
|
|
ullint
|
|
fsp_get_available_space_in_free_extents(
|
|
/*====================================*/
|
|
ulint space) /*!< in: space id */
|
|
{
|
|
fsp_header_t* space_header;
|
|
ulint n_free_list_ext;
|
|
ulint free_limit;
|
|
ulint size;
|
|
ulint flags;
|
|
ulint zip_size;
|
|
ulint n_free;
|
|
ulint n_free_up;
|
|
ulint reserve;
|
|
rw_lock_t* latch;
|
|
mtr_t mtr;
|
|
|
|
ut_ad(!mutex_own(&kernel_mutex));
|
|
|
|
mtr_start(&mtr);
|
|
|
|
latch = fil_space_get_latch(space, &flags);
|
|
zip_size = dict_table_flags_to_zip_size(flags);
|
|
|
|
mtr_x_lock(latch, &mtr);
|
|
|
|
space_header = fsp_get_space_header(space, zip_size, &mtr);
|
|
|
|
size = mtr_read_ulint(space_header + FSP_SIZE, MLOG_4BYTES, &mtr);
|
|
|
|
n_free_list_ext = flst_get_len(space_header + FSP_FREE, &mtr);
|
|
|
|
free_limit = mtr_read_ulint(space_header + FSP_FREE_LIMIT,
|
|
MLOG_4BYTES, &mtr);
|
|
mtr_commit(&mtr);
|
|
|
|
if (size < FSP_EXTENT_SIZE) {
|
|
ut_a(space != 0); /* This must be a single-table
|
|
tablespace */
|
|
|
|
return(0); /* TODO: count free frag pages and
|
|
return a value based on that */
|
|
}
|
|
|
|
/* Below we play safe when counting free extents above the free limit:
|
|
some of them will contain extent descriptor pages, and therefore
|
|
will not be free extents */
|
|
|
|
n_free_up = (size - free_limit) / FSP_EXTENT_SIZE;
|
|
|
|
if (n_free_up > 0) {
|
|
n_free_up--;
|
|
if (!zip_size) {
|
|
n_free_up -= n_free_up
|
|
/ (UNIV_PAGE_SIZE / FSP_EXTENT_SIZE);
|
|
} else {
|
|
n_free_up -= n_free_up
|
|
/ (zip_size / FSP_EXTENT_SIZE);
|
|
}
|
|
}
|
|
|
|
n_free = n_free_list_ext + n_free_up;
|
|
|
|
/* We reserve 1 extent + 0.5 % of the space size to undo logs
|
|
and 1 extent + 0.5 % to cleaning operations; NOTE: this source
|
|
code is duplicated in the function above! */
|
|
|
|
reserve = 2 + ((size / FSP_EXTENT_SIZE) * 2) / 200;
|
|
|
|
if (reserve > n_free) {
|
|
return(0);
|
|
}
|
|
|
|
if (!zip_size) {
|
|
return((ullint) (n_free - reserve)
|
|
* FSP_EXTENT_SIZE
|
|
* (UNIV_PAGE_SIZE / 1024));
|
|
} else {
|
|
return((ullint) (n_free - reserve)
|
|
* FSP_EXTENT_SIZE
|
|
* (zip_size / 1024));
|
|
}
|
|
}
|
|
|
|
/********************************************************************//**
|
|
Marks a page used. The page must reside within the extents of the given
|
|
segment. */
|
|
static
|
|
void
|
|
fseg_mark_page_used(
|
|
/*================*/
|
|
fseg_inode_t* seg_inode,/*!< in: segment inode */
|
|
ulint space, /*!< in: space id */
|
|
ulint zip_size,/*!< in: compressed page size in bytes
|
|
or 0 for uncompressed pages */
|
|
ulint page, /*!< in: page offset */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
xdes_t* descr;
|
|
ulint not_full_n_used;
|
|
|
|
ut_ad(seg_inode && mtr);
|
|
ut_ad(!((page_offset(seg_inode) - FSEG_ARR_OFFSET) % FSEG_INODE_SIZE));
|
|
ut_ad(mach_read_from_4(seg_inode + FSEG_MAGIC_N)
|
|
== FSEG_MAGIC_N_VALUE);
|
|
|
|
descr = xdes_get_descriptor(space, zip_size, page, mtr);
|
|
|
|
ut_ad(mtr_read_ulint(seg_inode + FSEG_ID, MLOG_4BYTES, mtr)
|
|
== mtr_read_ulint(descr + XDES_ID, MLOG_4BYTES, mtr));
|
|
|
|
if (xdes_is_free(descr, mtr)) {
|
|
/* We move the extent from the free list to the
|
|
NOT_FULL list */
|
|
flst_remove(seg_inode + FSEG_FREE, descr + XDES_FLST_NODE,
|
|
mtr);
|
|
flst_add_last(seg_inode + FSEG_NOT_FULL,
|
|
descr + XDES_FLST_NODE, mtr);
|
|
}
|
|
|
|
ut_ad(xdes_get_bit(descr, XDES_FREE_BIT, page % FSP_EXTENT_SIZE, mtr)
|
|
== TRUE);
|
|
/* We mark the page as used */
|
|
xdes_set_bit(descr, XDES_FREE_BIT, page % FSP_EXTENT_SIZE, FALSE, mtr);
|
|
|
|
not_full_n_used = mtr_read_ulint(seg_inode + FSEG_NOT_FULL_N_USED,
|
|
MLOG_4BYTES, mtr);
|
|
not_full_n_used++;
|
|
mlog_write_ulint(seg_inode + FSEG_NOT_FULL_N_USED, not_full_n_used,
|
|
MLOG_4BYTES, mtr);
|
|
if (xdes_is_full(descr, mtr)) {
|
|
/* We move the extent from the NOT_FULL list to the
|
|
FULL list */
|
|
flst_remove(seg_inode + FSEG_NOT_FULL,
|
|
descr + XDES_FLST_NODE, mtr);
|
|
flst_add_last(seg_inode + FSEG_FULL,
|
|
descr + XDES_FLST_NODE, mtr);
|
|
|
|
mlog_write_ulint(seg_inode + FSEG_NOT_FULL_N_USED,
|
|
not_full_n_used - FSP_EXTENT_SIZE,
|
|
MLOG_4BYTES, mtr);
|
|
}
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Frees a single page of a segment. */
|
|
static
|
|
void
|
|
fseg_free_page_low(
|
|
/*===============*/
|
|
fseg_inode_t* seg_inode, /*!< in: segment inode */
|
|
ulint space, /*!< in: space id */
|
|
ulint zip_size,/*!< in: compressed page size in bytes
|
|
or 0 for uncompressed pages */
|
|
ulint page, /*!< in: page offset */
|
|
mtr_t* mtr) /*!< in: mtr handle */
|
|
{
|
|
xdes_t* descr;
|
|
ulint not_full_n_used;
|
|
ulint state;
|
|
dulint descr_id;
|
|
dulint seg_id;
|
|
ulint i;
|
|
|
|
ut_ad(seg_inode && mtr);
|
|
ut_ad(mach_read_from_4(seg_inode + FSEG_MAGIC_N)
|
|
== FSEG_MAGIC_N_VALUE);
|
|
ut_ad(!((page_offset(seg_inode) - FSEG_ARR_OFFSET) % FSEG_INODE_SIZE));
|
|
|
|
/* Drop search system page hash index if the page is found in
|
|
the pool and is hashed */
|
|
|
|
btr_search_drop_page_hash_when_freed(space, zip_size, page);
|
|
|
|
descr = xdes_get_descriptor(space, zip_size, page, mtr);
|
|
|
|
ut_a(descr);
|
|
if (xdes_get_bit(descr, XDES_FREE_BIT, page % FSP_EXTENT_SIZE, mtr)) {
|
|
fputs("InnoDB: Dump of the tablespace extent descriptor: ",
|
|
stderr);
|
|
ut_print_buf(stderr, descr, 40);
|
|
|
|
fprintf(stderr, "\n"
|
|
"InnoDB: Serious error! InnoDB is trying to"
|
|
" free page %lu\n"
|
|
"InnoDB: though it is already marked as free"
|
|
" in the tablespace!\n"
|
|
"InnoDB: The tablespace free space info is corrupt.\n"
|
|
"InnoDB: You may need to dump your"
|
|
" InnoDB tables and recreate the whole\n"
|
|
"InnoDB: database!\n", (ulong) page);
|
|
crash:
|
|
fputs("InnoDB: Please refer to\n"
|
|
"InnoDB: " REFMAN "forcing-recovery.html\n"
|
|
"InnoDB: about forcing recovery.\n", stderr);
|
|
ut_error;
|
|
}
|
|
|
|
state = xdes_get_state(descr, mtr);
|
|
|
|
if (state != XDES_FSEG) {
|
|
/* The page is in the fragment pages of the segment */
|
|
|
|
for (i = 0;; i++) {
|
|
if (fseg_get_nth_frag_page_no(seg_inode, i, mtr)
|
|
== page) {
|
|
|
|
fseg_set_nth_frag_page_no(seg_inode, i,
|
|
FIL_NULL, mtr);
|
|
break;
|
|
}
|
|
}
|
|
|
|
fsp_free_page(space, zip_size, page, mtr);
|
|
|
|
return;
|
|
}
|
|
|
|
/* If we get here, the page is in some extent of the segment */
|
|
|
|
descr_id = mtr_read_dulint(descr + XDES_ID, mtr);
|
|
seg_id = mtr_read_dulint(seg_inode + FSEG_ID, mtr);
|
|
#if 0
|
|
fprintf(stderr,
|
|
"InnoDB: InnoDB is freeing space %lu page %lu,\n"
|
|
"InnoDB: which belongs to descr seg %lu %lu\n"
|
|
"InnoDB: segment %lu %lu.\n",
|
|
(ulong) space, (ulong) page,
|
|
(ulong) ut_dulint_get_high(descr_id),
|
|
(ulong) ut_dulint_get_low(descr_id),
|
|
(ulong) ut_dulint_get_high(seg_id),
|
|
(ulong) ut_dulint_get_low(seg_id));
|
|
#endif /* 0 */
|
|
if (0 != ut_dulint_cmp(descr_id, seg_id)) {
|
|
fputs("InnoDB: Dump of the tablespace extent descriptor: ",
|
|
stderr);
|
|
ut_print_buf(stderr, descr, 40);
|
|
fputs("\nInnoDB: Dump of the segment inode: ", stderr);
|
|
ut_print_buf(stderr, seg_inode, 40);
|
|
putc('\n', stderr);
|
|
|
|
fprintf(stderr,
|
|
"InnoDB: Serious error: InnoDB is trying to"
|
|
" free space %lu page %lu,\n"
|
|
"InnoDB: which does not belong to"
|
|
" segment %lu %lu but belongs\n"
|
|
"InnoDB: to segment %lu %lu.\n",
|
|
(ulong) space, (ulong) page,
|
|
(ulong) ut_dulint_get_high(descr_id),
|
|
(ulong) ut_dulint_get_low(descr_id),
|
|
(ulong) ut_dulint_get_high(seg_id),
|
|
(ulong) ut_dulint_get_low(seg_id));
|
|
goto crash;
|
|
}
|
|
|
|
not_full_n_used = mtr_read_ulint(seg_inode + FSEG_NOT_FULL_N_USED,
|
|
MLOG_4BYTES, mtr);
|
|
if (xdes_is_full(descr, mtr)) {
|
|
/* The fragment is full: move it to another list */
|
|
flst_remove(seg_inode + FSEG_FULL,
|
|
descr + XDES_FLST_NODE, mtr);
|
|
flst_add_last(seg_inode + FSEG_NOT_FULL,
|
|
descr + XDES_FLST_NODE, mtr);
|
|
mlog_write_ulint(seg_inode + FSEG_NOT_FULL_N_USED,
|
|
not_full_n_used + FSP_EXTENT_SIZE - 1,
|
|
MLOG_4BYTES, mtr);
|
|
} else {
|
|
ut_a(not_full_n_used > 0);
|
|
mlog_write_ulint(seg_inode + FSEG_NOT_FULL_N_USED,
|
|
not_full_n_used - 1, MLOG_4BYTES, mtr);
|
|
}
|
|
|
|
xdes_set_bit(descr, XDES_FREE_BIT, page % FSP_EXTENT_SIZE, TRUE, mtr);
|
|
xdes_set_bit(descr, XDES_CLEAN_BIT, page % FSP_EXTENT_SIZE, TRUE, mtr);
|
|
|
|
if (xdes_is_free(descr, mtr)) {
|
|
/* The extent has become free: free it to space */
|
|
flst_remove(seg_inode + FSEG_NOT_FULL,
|
|
descr + XDES_FLST_NODE, mtr);
|
|
fsp_free_extent(space, zip_size, page, mtr);
|
|
}
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Frees a single page of a segment. */
|
|
UNIV_INTERN
|
|
void
|
|
fseg_free_page(
|
|
/*===========*/
|
|
fseg_header_t* seg_header, /*!< in: segment header */
|
|
ulint space, /*!< in: space id */
|
|
ulint page, /*!< in: page offset */
|
|
mtr_t* mtr) /*!< in: mtr handle */
|
|
{
|
|
ulint flags;
|
|
ulint zip_size;
|
|
fseg_inode_t* seg_inode;
|
|
rw_lock_t* latch;
|
|
|
|
latch = fil_space_get_latch(space, &flags);
|
|
zip_size = dict_table_flags_to_zip_size(flags);
|
|
|
|
ut_ad(!mutex_own(&kernel_mutex)
|
|
|| mtr_memo_contains(mtr, latch, MTR_MEMO_X_LOCK));
|
|
|
|
mtr_x_lock(latch, mtr);
|
|
|
|
seg_inode = fseg_inode_get(seg_header, space, zip_size, mtr);
|
|
|
|
fseg_free_page_low(seg_inode, space, zip_size, page, mtr);
|
|
|
|
#ifdef UNIV_DEBUG_FILE_ACCESSES
|
|
buf_page_set_file_page_was_freed(space, page);
|
|
#endif
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Frees an extent of a segment to the space free list. */
|
|
static
|
|
void
|
|
fseg_free_extent(
|
|
/*=============*/
|
|
fseg_inode_t* seg_inode, /*!< in: segment inode */
|
|
ulint space, /*!< in: space id */
|
|
ulint zip_size,/*!< in: compressed page size in bytes
|
|
or 0 for uncompressed pages */
|
|
ulint page, /*!< in: a page in the extent */
|
|
mtr_t* mtr) /*!< in: mtr handle */
|
|
{
|
|
ulint first_page_in_extent;
|
|
xdes_t* descr;
|
|
ulint not_full_n_used;
|
|
ulint descr_n_used;
|
|
ulint i;
|
|
|
|
ut_ad(seg_inode && mtr);
|
|
|
|
descr = xdes_get_descriptor(space, zip_size, page, mtr);
|
|
|
|
ut_a(xdes_get_state(descr, mtr) == XDES_FSEG);
|
|
ut_a(0 == ut_dulint_cmp(mtr_read_dulint(descr + XDES_ID, mtr),
|
|
mtr_read_dulint(seg_inode + FSEG_ID, mtr)));
|
|
ut_ad(mach_read_from_4(seg_inode + FSEG_MAGIC_N)
|
|
== FSEG_MAGIC_N_VALUE);
|
|
|
|
first_page_in_extent = page - (page % FSP_EXTENT_SIZE);
|
|
|
|
for (i = 0; i < FSP_EXTENT_SIZE; i++) {
|
|
if (FALSE == xdes_get_bit(descr, XDES_FREE_BIT, i, mtr)) {
|
|
|
|
/* Drop search system page hash index if the page is
|
|
found in the pool and is hashed */
|
|
|
|
btr_search_drop_page_hash_when_freed(
|
|
space, zip_size, first_page_in_extent + i);
|
|
}
|
|
}
|
|
|
|
if (xdes_is_full(descr, mtr)) {
|
|
flst_remove(seg_inode + FSEG_FULL,
|
|
descr + XDES_FLST_NODE, mtr);
|
|
} else if (xdes_is_free(descr, mtr)) {
|
|
flst_remove(seg_inode + FSEG_FREE,
|
|
descr + XDES_FLST_NODE, mtr);
|
|
} else {
|
|
flst_remove(seg_inode + FSEG_NOT_FULL,
|
|
descr + XDES_FLST_NODE, mtr);
|
|
|
|
not_full_n_used = mtr_read_ulint(
|
|
seg_inode + FSEG_NOT_FULL_N_USED, MLOG_4BYTES, mtr);
|
|
|
|
descr_n_used = xdes_get_n_used(descr, mtr);
|
|
ut_a(not_full_n_used >= descr_n_used);
|
|
mlog_write_ulint(seg_inode + FSEG_NOT_FULL_N_USED,
|
|
not_full_n_used - descr_n_used,
|
|
MLOG_4BYTES, mtr);
|
|
}
|
|
|
|
fsp_free_extent(space, zip_size, page, mtr);
|
|
|
|
#ifdef UNIV_DEBUG_FILE_ACCESSES
|
|
for (i = 0; i < FSP_EXTENT_SIZE; i++) {
|
|
|
|
buf_page_set_file_page_was_freed(space,
|
|
first_page_in_extent + i);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Frees part of a segment. This function can be used to free a segment by
|
|
repeatedly calling this function in different mini-transactions. Doing
|
|
the freeing in a single mini-transaction might result in too big a
|
|
mini-transaction.
|
|
@return TRUE if freeing completed */
|
|
UNIV_INTERN
|
|
ibool
|
|
fseg_free_step(
|
|
/*===========*/
|
|
fseg_header_t* header, /*!< in, own: segment header; NOTE: if the header
|
|
resides on the first page of the frag list
|
|
of the segment, this pointer becomes obsolete
|
|
after the last freeing step */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
ulint n;
|
|
ulint page;
|
|
xdes_t* descr;
|
|
fseg_inode_t* inode;
|
|
ulint space;
|
|
ulint flags;
|
|
ulint zip_size;
|
|
ulint header_page;
|
|
rw_lock_t* latch;
|
|
|
|
space = page_get_space_id(page_align(header));
|
|
header_page = page_get_page_no(page_align(header));
|
|
|
|
latch = fil_space_get_latch(space, &flags);
|
|
zip_size = dict_table_flags_to_zip_size(flags);
|
|
|
|
ut_ad(!mutex_own(&kernel_mutex)
|
|
|| mtr_memo_contains(mtr, latch, MTR_MEMO_X_LOCK));
|
|
|
|
mtr_x_lock(latch, mtr);
|
|
|
|
descr = xdes_get_descriptor(space, zip_size, header_page, mtr);
|
|
|
|
/* Check that the header resides on a page which has not been
|
|
freed yet */
|
|
|
|
ut_a(descr);
|
|
ut_a(xdes_get_bit(descr, XDES_FREE_BIT,
|
|
header_page % FSP_EXTENT_SIZE, mtr) == FALSE);
|
|
inode = fseg_inode_try_get(header, space, zip_size, mtr);
|
|
|
|
if (UNIV_UNLIKELY(inode == NULL)) {
|
|
fprintf(stderr, "double free of inode from %u:%u\n",
|
|
(unsigned) space, (unsigned) header_page);
|
|
return(TRUE);
|
|
}
|
|
|
|
descr = fseg_get_first_extent(inode, space, zip_size, mtr);
|
|
|
|
if (descr != NULL) {
|
|
/* Free the extent held by the segment */
|
|
page = xdes_get_offset(descr);
|
|
|
|
fseg_free_extent(inode, space, zip_size, page, mtr);
|
|
|
|
return(FALSE);
|
|
}
|
|
|
|
/* Free a frag page */
|
|
n = fseg_find_last_used_frag_page_slot(inode, mtr);
|
|
|
|
if (n == ULINT_UNDEFINED) {
|
|
/* Freeing completed: free the segment inode */
|
|
fsp_free_seg_inode(space, zip_size, inode, mtr);
|
|
|
|
return(TRUE);
|
|
}
|
|
|
|
fseg_free_page_low(inode, space, zip_size,
|
|
fseg_get_nth_frag_page_no(inode, n, mtr), mtr);
|
|
|
|
n = fseg_find_last_used_frag_page_slot(inode, mtr);
|
|
|
|
if (n == ULINT_UNDEFINED) {
|
|
/* Freeing completed: free the segment inode */
|
|
fsp_free_seg_inode(space, zip_size, inode, mtr);
|
|
|
|
return(TRUE);
|
|
}
|
|
|
|
return(FALSE);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Frees part of a segment. Differs from fseg_free_step because this function
|
|
leaves the header page unfreed.
|
|
@return TRUE if freeing completed, except the header page */
|
|
UNIV_INTERN
|
|
ibool
|
|
fseg_free_step_not_header(
|
|
/*======================*/
|
|
fseg_header_t* header, /*!< in: segment header which must reside on
|
|
the first fragment page of the segment */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
ulint n;
|
|
ulint page;
|
|
xdes_t* descr;
|
|
fseg_inode_t* inode;
|
|
ulint space;
|
|
ulint flags;
|
|
ulint zip_size;
|
|
ulint page_no;
|
|
rw_lock_t* latch;
|
|
|
|
space = page_get_space_id(page_align(header));
|
|
|
|
latch = fil_space_get_latch(space, &flags);
|
|
zip_size = dict_table_flags_to_zip_size(flags);
|
|
|
|
ut_ad(!mutex_own(&kernel_mutex)
|
|
|| mtr_memo_contains(mtr, latch, MTR_MEMO_X_LOCK));
|
|
|
|
mtr_x_lock(latch, mtr);
|
|
|
|
inode = fseg_inode_get(header, space, zip_size, mtr);
|
|
|
|
descr = fseg_get_first_extent(inode, space, zip_size, mtr);
|
|
|
|
if (descr != NULL) {
|
|
/* Free the extent held by the segment */
|
|
page = xdes_get_offset(descr);
|
|
|
|
fseg_free_extent(inode, space, zip_size, page, mtr);
|
|
|
|
return(FALSE);
|
|
}
|
|
|
|
/* Free a frag page */
|
|
|
|
n = fseg_find_last_used_frag_page_slot(inode, mtr);
|
|
|
|
if (n == ULINT_UNDEFINED) {
|
|
ut_error;
|
|
}
|
|
|
|
page_no = fseg_get_nth_frag_page_no(inode, n, mtr);
|
|
|
|
if (page_no == page_get_page_no(page_align(header))) {
|
|
|
|
return(TRUE);
|
|
}
|
|
|
|
fseg_free_page_low(inode, space, zip_size, page_no, mtr);
|
|
|
|
return(FALSE);
|
|
}
|
|
|
|
/**********************************************************************//**
|
|
Returns the first extent descriptor for a segment. We think of the extent
|
|
lists of the segment catenated in the order FSEG_FULL -> FSEG_NOT_FULL
|
|
-> FSEG_FREE.
|
|
@return the first extent descriptor, or NULL if none */
|
|
static
|
|
xdes_t*
|
|
fseg_get_first_extent(
|
|
/*==================*/
|
|
fseg_inode_t* inode, /*!< in: segment inode */
|
|
ulint space, /*!< in: space id */
|
|
ulint zip_size,/*!< in: compressed page size in bytes
|
|
or 0 for uncompressed pages */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
fil_addr_t first;
|
|
xdes_t* descr;
|
|
|
|
ut_ad(inode && mtr);
|
|
|
|
ut_ad(space == page_get_space_id(page_align(inode)));
|
|
ut_ad(mach_read_from_4(inode + FSEG_MAGIC_N) == FSEG_MAGIC_N_VALUE);
|
|
|
|
first = fil_addr_null;
|
|
|
|
if (flst_get_len(inode + FSEG_FULL, mtr) > 0) {
|
|
|
|
first = flst_get_first(inode + FSEG_FULL, mtr);
|
|
|
|
} else if (flst_get_len(inode + FSEG_NOT_FULL, mtr) > 0) {
|
|
|
|
first = flst_get_first(inode + FSEG_NOT_FULL, mtr);
|
|
|
|
} else if (flst_get_len(inode + FSEG_FREE, mtr) > 0) {
|
|
|
|
first = flst_get_first(inode + FSEG_FREE, mtr);
|
|
}
|
|
|
|
if (first.page == FIL_NULL) {
|
|
|
|
return(NULL);
|
|
}
|
|
descr = xdes_lst_get_descriptor(space, zip_size, first, mtr);
|
|
|
|
return(descr);
|
|
}
|
|
|
|
/*******************************************************************//**
|
|
Validates a segment.
|
|
@return TRUE if ok */
|
|
static
|
|
ibool
|
|
fseg_validate_low(
|
|
/*==============*/
|
|
fseg_inode_t* inode, /*!< in: segment inode */
|
|
mtr_t* mtr2) /*!< in: mtr */
|
|
{
|
|
ulint space;
|
|
dulint seg_id;
|
|
mtr_t mtr;
|
|
xdes_t* descr;
|
|
fil_addr_t node_addr;
|
|
ulint n_used = 0;
|
|
ulint n_used2 = 0;
|
|
|
|
ut_ad(mtr_memo_contains_page(mtr2, inode, MTR_MEMO_PAGE_X_FIX));
|
|
ut_ad(mach_read_from_4(inode + FSEG_MAGIC_N) == FSEG_MAGIC_N_VALUE);
|
|
|
|
space = page_get_space_id(page_align(inode));
|
|
|
|
seg_id = mtr_read_dulint(inode + FSEG_ID, mtr2);
|
|
n_used = mtr_read_ulint(inode + FSEG_NOT_FULL_N_USED,
|
|
MLOG_4BYTES, mtr2);
|
|
flst_validate(inode + FSEG_FREE, mtr2);
|
|
flst_validate(inode + FSEG_NOT_FULL, mtr2);
|
|
flst_validate(inode + FSEG_FULL, mtr2);
|
|
|
|
/* Validate FSEG_FREE list */
|
|
node_addr = flst_get_first(inode + FSEG_FREE, mtr2);
|
|
|
|
while (!fil_addr_is_null(node_addr)) {
|
|
ulint flags;
|
|
ulint zip_size;
|
|
|
|
mtr_start(&mtr);
|
|
mtr_x_lock(fil_space_get_latch(space, &flags), &mtr);
|
|
zip_size = dict_table_flags_to_zip_size(flags);
|
|
|
|
descr = xdes_lst_get_descriptor(space, zip_size,
|
|
node_addr, &mtr);
|
|
|
|
ut_a(xdes_get_n_used(descr, &mtr) == 0);
|
|
ut_a(xdes_get_state(descr, &mtr) == XDES_FSEG);
|
|
ut_a(!ut_dulint_cmp(mtr_read_dulint(descr + XDES_ID, &mtr),
|
|
seg_id));
|
|
|
|
node_addr = flst_get_next_addr(descr + XDES_FLST_NODE, &mtr);
|
|
mtr_commit(&mtr);
|
|
}
|
|
|
|
/* Validate FSEG_NOT_FULL list */
|
|
|
|
node_addr = flst_get_first(inode + FSEG_NOT_FULL, mtr2);
|
|
|
|
while (!fil_addr_is_null(node_addr)) {
|
|
ulint flags;
|
|
ulint zip_size;
|
|
|
|
mtr_start(&mtr);
|
|
mtr_x_lock(fil_space_get_latch(space, &flags), &mtr);
|
|
zip_size = dict_table_flags_to_zip_size(flags);
|
|
|
|
descr = xdes_lst_get_descriptor(space, zip_size,
|
|
node_addr, &mtr);
|
|
|
|
ut_a(xdes_get_n_used(descr, &mtr) > 0);
|
|
ut_a(xdes_get_n_used(descr, &mtr) < FSP_EXTENT_SIZE);
|
|
ut_a(xdes_get_state(descr, &mtr) == XDES_FSEG);
|
|
ut_a(!ut_dulint_cmp(mtr_read_dulint(descr + XDES_ID, &mtr),
|
|
seg_id));
|
|
|
|
n_used2 += xdes_get_n_used(descr, &mtr);
|
|
|
|
node_addr = flst_get_next_addr(descr + XDES_FLST_NODE, &mtr);
|
|
mtr_commit(&mtr);
|
|
}
|
|
|
|
/* Validate FSEG_FULL list */
|
|
|
|
node_addr = flst_get_first(inode + FSEG_FULL, mtr2);
|
|
|
|
while (!fil_addr_is_null(node_addr)) {
|
|
ulint flags;
|
|
ulint zip_size;
|
|
|
|
mtr_start(&mtr);
|
|
mtr_x_lock(fil_space_get_latch(space, &flags), &mtr);
|
|
zip_size = dict_table_flags_to_zip_size(flags);
|
|
|
|
descr = xdes_lst_get_descriptor(space, zip_size,
|
|
node_addr, &mtr);
|
|
|
|
ut_a(xdes_get_n_used(descr, &mtr) == FSP_EXTENT_SIZE);
|
|
ut_a(xdes_get_state(descr, &mtr) == XDES_FSEG);
|
|
ut_a(!ut_dulint_cmp(mtr_read_dulint(descr + XDES_ID, &mtr),
|
|
seg_id));
|
|
|
|
node_addr = flst_get_next_addr(descr + XDES_FLST_NODE, &mtr);
|
|
mtr_commit(&mtr);
|
|
}
|
|
|
|
ut_a(n_used == n_used2);
|
|
|
|
return(TRUE);
|
|
}
|
|
|
|
#ifdef UNIV_DEBUG
|
|
/*******************************************************************//**
|
|
Validates a segment.
|
|
@return TRUE if ok */
|
|
UNIV_INTERN
|
|
ibool
|
|
fseg_validate(
|
|
/*==========*/
|
|
fseg_header_t* header, /*!< in: segment header */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
fseg_inode_t* inode;
|
|
ibool ret;
|
|
ulint space;
|
|
ulint flags;
|
|
ulint zip_size;
|
|
|
|
space = page_get_space_id(page_align(header));
|
|
|
|
mtr_x_lock(fil_space_get_latch(space, &flags), mtr);
|
|
zip_size = dict_table_flags_to_zip_size(flags);
|
|
|
|
inode = fseg_inode_get(header, space, zip_size, mtr);
|
|
|
|
ret = fseg_validate_low(inode, mtr);
|
|
|
|
return(ret);
|
|
}
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
/*******************************************************************//**
|
|
Writes info of a segment. */
|
|
static
|
|
void
|
|
fseg_print_low(
|
|
/*===========*/
|
|
fseg_inode_t* inode, /*!< in: segment inode */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
ulint space;
|
|
ulint seg_id_low;
|
|
ulint seg_id_high;
|
|
ulint n_used;
|
|
ulint n_frag;
|
|
ulint n_free;
|
|
ulint n_not_full;
|
|
ulint n_full;
|
|
ulint reserved;
|
|
ulint used;
|
|
ulint page_no;
|
|
dulint d_var;
|
|
|
|
ut_ad(mtr_memo_contains_page(mtr, inode, MTR_MEMO_PAGE_X_FIX));
|
|
space = page_get_space_id(page_align(inode));
|
|
page_no = page_get_page_no(page_align(inode));
|
|
|
|
reserved = fseg_n_reserved_pages_low(inode, &used, mtr);
|
|
|
|
d_var = mtr_read_dulint(inode + FSEG_ID, mtr);
|
|
|
|
seg_id_low = ut_dulint_get_low(d_var);
|
|
seg_id_high = ut_dulint_get_high(d_var);
|
|
|
|
n_used = mtr_read_ulint(inode + FSEG_NOT_FULL_N_USED,
|
|
MLOG_4BYTES, mtr);
|
|
n_frag = fseg_get_n_frag_pages(inode, mtr);
|
|
n_free = flst_get_len(inode + FSEG_FREE, mtr);
|
|
n_not_full = flst_get_len(inode + FSEG_NOT_FULL, mtr);
|
|
n_full = flst_get_len(inode + FSEG_FULL, mtr);
|
|
|
|
fprintf(stderr,
|
|
"SEGMENT id %lu %lu space %lu; page %lu;"
|
|
" res %lu used %lu; full ext %lu\n"
|
|
"fragm pages %lu; free extents %lu;"
|
|
" not full extents %lu: pages %lu\n",
|
|
(ulong) seg_id_high, (ulong) seg_id_low,
|
|
(ulong) space, (ulong) page_no,
|
|
(ulong) reserved, (ulong) used, (ulong) n_full,
|
|
(ulong) n_frag, (ulong) n_free, (ulong) n_not_full,
|
|
(ulong) n_used);
|
|
ut_ad(mach_read_from_4(inode + FSEG_MAGIC_N) == FSEG_MAGIC_N_VALUE);
|
|
}
|
|
|
|
#ifdef UNIV_BTR_PRINT
|
|
/*******************************************************************//**
|
|
Writes info of a segment. */
|
|
UNIV_INTERN
|
|
void
|
|
fseg_print(
|
|
/*=======*/
|
|
fseg_header_t* header, /*!< in: segment header */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
fseg_inode_t* inode;
|
|
ulint space;
|
|
ulint flags;
|
|
ulint zip_size;
|
|
|
|
space = page_get_space_id(page_align(header));
|
|
|
|
mtr_x_lock(fil_space_get_latch(space, &flags), mtr);
|
|
zip_size = dict_table_flags_to_zip_size(flags);
|
|
|
|
inode = fseg_inode_get(header, space, zip_size, mtr);
|
|
|
|
fseg_print_low(inode, mtr);
|
|
}
|
|
#endif /* UNIV_BTR_PRINT */
|
|
|
|
/*******************************************************************//**
|
|
Validates the file space system and its segments.
|
|
@return TRUE if ok */
|
|
UNIV_INTERN
|
|
ibool
|
|
fsp_validate(
|
|
/*=========*/
|
|
ulint space) /*!< in: space id */
|
|
{
|
|
fsp_header_t* header;
|
|
fseg_inode_t* seg_inode;
|
|
page_t* seg_inode_page;
|
|
rw_lock_t* latch;
|
|
ulint size;
|
|
ulint flags;
|
|
ulint zip_size;
|
|
ulint free_limit;
|
|
ulint frag_n_used;
|
|
mtr_t mtr;
|
|
mtr_t mtr2;
|
|
xdes_t* descr;
|
|
fil_addr_t node_addr;
|
|
fil_addr_t next_node_addr;
|
|
ulint descr_count = 0;
|
|
ulint n_used = 0;
|
|
ulint n_used2 = 0;
|
|
ulint n_full_frag_pages;
|
|
ulint n;
|
|
ulint seg_inode_len_free;
|
|
ulint seg_inode_len_full;
|
|
|
|
latch = fil_space_get_latch(space, &flags);
|
|
zip_size = dict_table_flags_to_zip_size(flags);
|
|
ut_a(ut_is_2pow(zip_size));
|
|
ut_a(zip_size <= UNIV_PAGE_SIZE);
|
|
ut_a(!zip_size || zip_size >= PAGE_ZIP_MIN_SIZE);
|
|
|
|
/* Start first a mini-transaction mtr2 to lock out all other threads
|
|
from the fsp system */
|
|
mtr_start(&mtr2);
|
|
mtr_x_lock(latch, &mtr2);
|
|
|
|
mtr_start(&mtr);
|
|
mtr_x_lock(latch, &mtr);
|
|
|
|
header = fsp_get_space_header(space, zip_size, &mtr);
|
|
|
|
size = mtr_read_ulint(header + FSP_SIZE, MLOG_4BYTES, &mtr);
|
|
free_limit = mtr_read_ulint(header + FSP_FREE_LIMIT,
|
|
MLOG_4BYTES, &mtr);
|
|
frag_n_used = mtr_read_ulint(header + FSP_FRAG_N_USED,
|
|
MLOG_4BYTES, &mtr);
|
|
|
|
n_full_frag_pages = FSP_EXTENT_SIZE
|
|
* flst_get_len(header + FSP_FULL_FRAG, &mtr);
|
|
|
|
if (UNIV_UNLIKELY(free_limit > size)) {
|
|
|
|
ut_a(space != 0);
|
|
ut_a(size < FSP_EXTENT_SIZE);
|
|
}
|
|
|
|
flst_validate(header + FSP_FREE, &mtr);
|
|
flst_validate(header + FSP_FREE_FRAG, &mtr);
|
|
flst_validate(header + FSP_FULL_FRAG, &mtr);
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
/* Validate FSP_FREE list */
|
|
mtr_start(&mtr);
|
|
mtr_x_lock(latch, &mtr);
|
|
|
|
header = fsp_get_space_header(space, zip_size, &mtr);
|
|
node_addr = flst_get_first(header + FSP_FREE, &mtr);
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
while (!fil_addr_is_null(node_addr)) {
|
|
mtr_start(&mtr);
|
|
mtr_x_lock(latch, &mtr);
|
|
|
|
descr_count++;
|
|
descr = xdes_lst_get_descriptor(space, zip_size,
|
|
node_addr, &mtr);
|
|
|
|
ut_a(xdes_get_n_used(descr, &mtr) == 0);
|
|
ut_a(xdes_get_state(descr, &mtr) == XDES_FREE);
|
|
|
|
node_addr = flst_get_next_addr(descr + XDES_FLST_NODE, &mtr);
|
|
mtr_commit(&mtr);
|
|
}
|
|
|
|
/* Validate FSP_FREE_FRAG list */
|
|
mtr_start(&mtr);
|
|
mtr_x_lock(latch, &mtr);
|
|
|
|
header = fsp_get_space_header(space, zip_size, &mtr);
|
|
node_addr = flst_get_first(header + FSP_FREE_FRAG, &mtr);
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
while (!fil_addr_is_null(node_addr)) {
|
|
mtr_start(&mtr);
|
|
mtr_x_lock(latch, &mtr);
|
|
|
|
descr_count++;
|
|
descr = xdes_lst_get_descriptor(space, zip_size,
|
|
node_addr, &mtr);
|
|
|
|
ut_a(xdes_get_n_used(descr, &mtr) > 0);
|
|
ut_a(xdes_get_n_used(descr, &mtr) < FSP_EXTENT_SIZE);
|
|
ut_a(xdes_get_state(descr, &mtr) == XDES_FREE_FRAG);
|
|
|
|
n_used += xdes_get_n_used(descr, &mtr);
|
|
node_addr = flst_get_next_addr(descr + XDES_FLST_NODE, &mtr);
|
|
|
|
mtr_commit(&mtr);
|
|
}
|
|
|
|
/* Validate FSP_FULL_FRAG list */
|
|
mtr_start(&mtr);
|
|
mtr_x_lock(latch, &mtr);
|
|
|
|
header = fsp_get_space_header(space, zip_size, &mtr);
|
|
node_addr = flst_get_first(header + FSP_FULL_FRAG, &mtr);
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
while (!fil_addr_is_null(node_addr)) {
|
|
mtr_start(&mtr);
|
|
mtr_x_lock(latch, &mtr);
|
|
|
|
descr_count++;
|
|
descr = xdes_lst_get_descriptor(space, zip_size,
|
|
node_addr, &mtr);
|
|
|
|
ut_a(xdes_get_n_used(descr, &mtr) == FSP_EXTENT_SIZE);
|
|
ut_a(xdes_get_state(descr, &mtr) == XDES_FULL_FRAG);
|
|
|
|
node_addr = flst_get_next_addr(descr + XDES_FLST_NODE, &mtr);
|
|
mtr_commit(&mtr);
|
|
}
|
|
|
|
/* Validate segments */
|
|
mtr_start(&mtr);
|
|
mtr_x_lock(latch, &mtr);
|
|
|
|
header = fsp_get_space_header(space, zip_size, &mtr);
|
|
|
|
node_addr = flst_get_first(header + FSP_SEG_INODES_FULL, &mtr);
|
|
|
|
seg_inode_len_full = flst_get_len(header + FSP_SEG_INODES_FULL, &mtr);
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
while (!fil_addr_is_null(node_addr)) {
|
|
|
|
n = 0;
|
|
do {
|
|
mtr_start(&mtr);
|
|
mtr_x_lock(latch, &mtr);
|
|
|
|
seg_inode_page = fut_get_ptr(
|
|
space, zip_size, node_addr, RW_X_LATCH, &mtr)
|
|
- FSEG_INODE_PAGE_NODE;
|
|
|
|
seg_inode = fsp_seg_inode_page_get_nth_inode(
|
|
seg_inode_page, n, zip_size, &mtr);
|
|
ut_a(!ut_dulint_is_zero(
|
|
mach_read_from_8(seg_inode + FSEG_ID)));
|
|
fseg_validate_low(seg_inode, &mtr);
|
|
|
|
descr_count += flst_get_len(seg_inode + FSEG_FREE,
|
|
&mtr);
|
|
descr_count += flst_get_len(seg_inode + FSEG_FULL,
|
|
&mtr);
|
|
descr_count += flst_get_len(seg_inode + FSEG_NOT_FULL,
|
|
&mtr);
|
|
|
|
n_used2 += fseg_get_n_frag_pages(seg_inode, &mtr);
|
|
|
|
next_node_addr = flst_get_next_addr(
|
|
seg_inode_page + FSEG_INODE_PAGE_NODE, &mtr);
|
|
mtr_commit(&mtr);
|
|
} while (++n < FSP_SEG_INODES_PER_PAGE(zip_size));
|
|
|
|
node_addr = next_node_addr;
|
|
}
|
|
|
|
mtr_start(&mtr);
|
|
mtr_x_lock(latch, &mtr);
|
|
|
|
header = fsp_get_space_header(space, zip_size, &mtr);
|
|
|
|
node_addr = flst_get_first(header + FSP_SEG_INODES_FREE, &mtr);
|
|
|
|
seg_inode_len_free = flst_get_len(header + FSP_SEG_INODES_FREE, &mtr);
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
while (!fil_addr_is_null(node_addr)) {
|
|
|
|
n = 0;
|
|
|
|
do {
|
|
mtr_start(&mtr);
|
|
mtr_x_lock(latch, &mtr);
|
|
|
|
seg_inode_page = fut_get_ptr(
|
|
space, zip_size, node_addr, RW_X_LATCH, &mtr)
|
|
- FSEG_INODE_PAGE_NODE;
|
|
|
|
seg_inode = fsp_seg_inode_page_get_nth_inode(
|
|
seg_inode_page, n, zip_size, &mtr);
|
|
if (!ut_dulint_is_zero(
|
|
mach_read_from_8(seg_inode + FSEG_ID))) {
|
|
fseg_validate_low(seg_inode, &mtr);
|
|
|
|
descr_count += flst_get_len(
|
|
seg_inode + FSEG_FREE, &mtr);
|
|
descr_count += flst_get_len(
|
|
seg_inode + FSEG_FULL, &mtr);
|
|
descr_count += flst_get_len(
|
|
seg_inode + FSEG_NOT_FULL, &mtr);
|
|
n_used2 += fseg_get_n_frag_pages(
|
|
seg_inode, &mtr);
|
|
}
|
|
|
|
next_node_addr = flst_get_next_addr(
|
|
seg_inode_page + FSEG_INODE_PAGE_NODE, &mtr);
|
|
mtr_commit(&mtr);
|
|
} while (++n < FSP_SEG_INODES_PER_PAGE(zip_size));
|
|
|
|
node_addr = next_node_addr;
|
|
}
|
|
|
|
ut_a(descr_count * FSP_EXTENT_SIZE == free_limit);
|
|
if (!zip_size) {
|
|
ut_a(n_used + n_full_frag_pages
|
|
== n_used2 + 2 * ((free_limit + (UNIV_PAGE_SIZE - 1))
|
|
/ UNIV_PAGE_SIZE)
|
|
+ seg_inode_len_full + seg_inode_len_free);
|
|
} else {
|
|
ut_a(n_used + n_full_frag_pages
|
|
== n_used2 + 2 * ((free_limit + (zip_size - 1))
|
|
/ zip_size)
|
|
+ seg_inode_len_full + seg_inode_len_free);
|
|
}
|
|
ut_a(frag_n_used == n_used);
|
|
|
|
mtr_commit(&mtr2);
|
|
|
|
return(TRUE);
|
|
}
|
|
|
|
/*******************************************************************//**
|
|
Prints info of a file space. */
|
|
UNIV_INTERN
|
|
void
|
|
fsp_print(
|
|
/*======*/
|
|
ulint space) /*!< in: space id */
|
|
{
|
|
fsp_header_t* header;
|
|
fseg_inode_t* seg_inode;
|
|
page_t* seg_inode_page;
|
|
rw_lock_t* latch;
|
|
ulint flags;
|
|
ulint zip_size;
|
|
ulint size;
|
|
ulint free_limit;
|
|
ulint frag_n_used;
|
|
fil_addr_t node_addr;
|
|
fil_addr_t next_node_addr;
|
|
ulint n_free;
|
|
ulint n_free_frag;
|
|
ulint n_full_frag;
|
|
ulint seg_id_low;
|
|
ulint seg_id_high;
|
|
ulint n;
|
|
ulint n_segs = 0;
|
|
dulint d_var;
|
|
mtr_t mtr;
|
|
mtr_t mtr2;
|
|
|
|
latch = fil_space_get_latch(space, &flags);
|
|
zip_size = dict_table_flags_to_zip_size(flags);
|
|
|
|
/* Start first a mini-transaction mtr2 to lock out all other threads
|
|
from the fsp system */
|
|
|
|
mtr_start(&mtr2);
|
|
|
|
mtr_x_lock(latch, &mtr2);
|
|
|
|
mtr_start(&mtr);
|
|
|
|
mtr_x_lock(latch, &mtr);
|
|
|
|
header = fsp_get_space_header(space, zip_size, &mtr);
|
|
|
|
size = mtr_read_ulint(header + FSP_SIZE, MLOG_4BYTES, &mtr);
|
|
|
|
free_limit = mtr_read_ulint(header + FSP_FREE_LIMIT, MLOG_4BYTES,
|
|
&mtr);
|
|
frag_n_used = mtr_read_ulint(header + FSP_FRAG_N_USED, MLOG_4BYTES,
|
|
&mtr);
|
|
n_free = flst_get_len(header + FSP_FREE, &mtr);
|
|
n_free_frag = flst_get_len(header + FSP_FREE_FRAG, &mtr);
|
|
n_full_frag = flst_get_len(header + FSP_FULL_FRAG, &mtr);
|
|
|
|
d_var = mtr_read_dulint(header + FSP_SEG_ID, &mtr);
|
|
|
|
seg_id_low = ut_dulint_get_low(d_var);
|
|
seg_id_high = ut_dulint_get_high(d_var);
|
|
|
|
fprintf(stderr,
|
|
"FILE SPACE INFO: id %lu\n"
|
|
"size %lu, free limit %lu, free extents %lu\n"
|
|
"not full frag extents %lu: used pages %lu,"
|
|
" full frag extents %lu\n"
|
|
"first seg id not used %lu %lu\n",
|
|
(ulong) space,
|
|
(ulong) size, (ulong) free_limit, (ulong) n_free,
|
|
(ulong) n_free_frag, (ulong) frag_n_used, (ulong) n_full_frag,
|
|
(ulong) seg_id_high, (ulong) seg_id_low);
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
/* Print segments */
|
|
|
|
mtr_start(&mtr);
|
|
mtr_x_lock(latch, &mtr);
|
|
|
|
header = fsp_get_space_header(space, zip_size, &mtr);
|
|
|
|
node_addr = flst_get_first(header + FSP_SEG_INODES_FULL, &mtr);
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
while (!fil_addr_is_null(node_addr)) {
|
|
|
|
n = 0;
|
|
|
|
do {
|
|
|
|
mtr_start(&mtr);
|
|
mtr_x_lock(latch, &mtr);
|
|
|
|
seg_inode_page = fut_get_ptr(
|
|
space, zip_size, node_addr, RW_X_LATCH, &mtr)
|
|
- FSEG_INODE_PAGE_NODE;
|
|
|
|
seg_inode = fsp_seg_inode_page_get_nth_inode(
|
|
seg_inode_page, n, zip_size, &mtr);
|
|
ut_a(!ut_dulint_is_zero(
|
|
mach_read_from_8(seg_inode + FSEG_ID)));
|
|
fseg_print_low(seg_inode, &mtr);
|
|
|
|
n_segs++;
|
|
|
|
next_node_addr = flst_get_next_addr(
|
|
seg_inode_page + FSEG_INODE_PAGE_NODE, &mtr);
|
|
mtr_commit(&mtr);
|
|
} while (++n < FSP_SEG_INODES_PER_PAGE(zip_size));
|
|
|
|
node_addr = next_node_addr;
|
|
}
|
|
|
|
mtr_start(&mtr);
|
|
mtr_x_lock(latch, &mtr);
|
|
|
|
header = fsp_get_space_header(space, zip_size, &mtr);
|
|
|
|
node_addr = flst_get_first(header + FSP_SEG_INODES_FREE, &mtr);
|
|
|
|
mtr_commit(&mtr);
|
|
|
|
while (!fil_addr_is_null(node_addr)) {
|
|
|
|
n = 0;
|
|
|
|
do {
|
|
|
|
mtr_start(&mtr);
|
|
mtr_x_lock(latch, &mtr);
|
|
|
|
seg_inode_page = fut_get_ptr(
|
|
space, zip_size, node_addr, RW_X_LATCH, &mtr)
|
|
- FSEG_INODE_PAGE_NODE;
|
|
|
|
seg_inode = fsp_seg_inode_page_get_nth_inode(
|
|
seg_inode_page, n, zip_size, &mtr);
|
|
if (!ut_dulint_is_zero(
|
|
mach_read_from_8(seg_inode + FSEG_ID))) {
|
|
|
|
fseg_print_low(seg_inode, &mtr);
|
|
n_segs++;
|
|
}
|
|
|
|
next_node_addr = flst_get_next_addr(
|
|
seg_inode_page + FSEG_INODE_PAGE_NODE, &mtr);
|
|
mtr_commit(&mtr);
|
|
} while (++n < FSP_SEG_INODES_PER_PAGE(zip_size));
|
|
|
|
node_addr = next_node_addr;
|
|
}
|
|
|
|
mtr_commit(&mtr2);
|
|
|
|
fprintf(stderr, "NUMBER of file segments: %lu\n", (ulong) n_segs);
|
|
}
|
|
#endif /* !UNIV_HOTBACKUP */
|