2014-02-26 19:11:54 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
|
2017-01-04 14:34:38 +05:30
|
|
|
Copyright (c) 1995, 2017, Oracle and/or its affiliates. All Rights Reserved.
|
2018-01-15 15:26:02 +02:00
|
|
|
Copyright (c) 2013, 2018, MariaDB Corporation.
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
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.,
|
|
|
|
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
|
|
|
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/**************************************************//**
|
|
|
|
@file include/fil0fil.h
|
|
|
|
The low-level file system
|
|
|
|
|
|
|
|
Created 10/25/1995 Heikki Tuuri
|
|
|
|
*******************************************************/
|
|
|
|
|
|
|
|
#ifndef fil0fil_h
|
|
|
|
#define fil0fil_h
|
|
|
|
|
|
|
|
#ifndef UNIV_INNOCHECKSUM
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
#include "log0recv.h"
|
2014-02-26 19:11:54 +01:00
|
|
|
#include "dict0types.h"
|
2016-08-12 11:17:45 +03:00
|
|
|
#include "page0size.h"
|
2014-02-26 19:11:54 +01:00
|
|
|
#include "ibuf0types.h"
|
|
|
|
|
|
|
|
#include <list>
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
// Forward declaration
|
2018-03-09 21:25:20 +02:00
|
|
|
extern ibool srv_use_doublewrite_buf;
|
|
|
|
extern struct buf_dblwr_t* buf_dblwr;
|
2016-08-12 11:17:45 +03:00
|
|
|
class page_id_t;
|
2018-10-18 18:23:12 +03:00
|
|
|
struct trx_t;
|
2016-08-12 11:17:45 +03:00
|
|
|
class truncate_t;
|
2016-09-06 09:43:16 +03:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
typedef std::list<char*, ut_allocator<char*> > space_name_list_t;
|
|
|
|
|
2017-03-30 12:48:42 +02:00
|
|
|
/** Structure containing encryption specification */
|
|
|
|
struct fil_space_crypt_t;
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** File types */
|
|
|
|
enum fil_type_t {
|
|
|
|
/** temporary tablespace (temporary undo log or tables) */
|
|
|
|
FIL_TYPE_TEMPORARY,
|
|
|
|
/** a tablespace that is being imported (no logging until finished) */
|
|
|
|
FIL_TYPE_IMPORT,
|
|
|
|
/** persistent tablespace (for system, undo log or tables) */
|
|
|
|
FIL_TYPE_TABLESPACE,
|
|
|
|
/** redo log covering changes to files of FIL_TYPE_TABLESPACE */
|
|
|
|
FIL_TYPE_LOG
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Check if fil_type is any of FIL_TYPE_TEMPORARY, FIL_TYPE_IMPORT
|
|
|
|
or FIL_TYPE_TABLESPACE.
|
|
|
|
@param[in] type variable of type fil_type_t
|
|
|
|
@return true if any of FIL_TYPE_TEMPORARY, FIL_TYPE_IMPORT
|
|
|
|
or FIL_TYPE_TABLESPACE */
|
|
|
|
inline
|
|
|
|
bool
|
|
|
|
fil_type_is_data(
|
|
|
|
fil_type_t type)
|
|
|
|
{
|
|
|
|
return(type == FIL_TYPE_TEMPORARY
|
|
|
|
|| type == FIL_TYPE_IMPORT
|
|
|
|
|| type == FIL_TYPE_TABLESPACE);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct fil_node_t;
|
|
|
|
|
|
|
|
/** Tablespace or log data space */
|
|
|
|
struct fil_space_t {
|
|
|
|
ulint id; /*!< space id */
|
2019-01-17 11:24:38 +02:00
|
|
|
hash_node_t hash; /*!< hash chain node */
|
|
|
|
char* name; /*!< Tablespace name */
|
|
|
|
hash_node_t name_hash;/*!< hash chain the name_hash table */
|
2016-08-12 11:17:45 +03:00
|
|
|
lsn_t max_lsn;
|
|
|
|
/*!< LSN of the most recent
|
|
|
|
fil_names_write_if_was_clean().
|
|
|
|
Reset to 0 by fil_names_clear().
|
|
|
|
Protected by log_sys->mutex.
|
|
|
|
If and only if this is nonzero, the
|
|
|
|
tablespace will be in named_spaces. */
|
|
|
|
bool stop_new_ops;
|
|
|
|
/*!< we set this true when we start
|
|
|
|
deleting a single-table tablespace.
|
|
|
|
When this is set following new ops
|
|
|
|
are not allowed:
|
|
|
|
* read IO request
|
|
|
|
* ibuf merge
|
|
|
|
* file flush
|
|
|
|
Note that we can still possibly have
|
|
|
|
new write operations because we don't
|
|
|
|
check this flag when doing flush
|
|
|
|
batches. */
|
MDEV-13564 Mariabackup does not work with TRUNCATE
Implement undo tablespace truncation via normal redo logging.
Implement TRUNCATE TABLE as a combination of RENAME to #sql-ib name,
CREATE, and DROP.
Note: Orphan #sql-ib*.ibd may be left behind if MariaDB Server 10.2
is killed before the DROP operation is committed. If MariaDB Server 10.2
is killed during TRUNCATE, it is also possible that the old table
was renamed to #sql-ib*.ibd but the data dictionary will refer to the
table using the original name.
In MariaDB Server 10.3, RENAME inside InnoDB is transactional,
and #sql-* tables will be dropped on startup. So, this new TRUNCATE
will be fully crash-safe in 10.3.
ha_mroonga::wrapper_truncate(): Pass table options to the underlying
storage engine, now that ha_innobase::truncate() will need them.
rpl_slave_state::truncate_state_table(): Before truncating
mysql.gtid_slave_pos, evict any cached table handles from
the table definition cache, so that there will be no stale
references to the old table after truncating.
== TRUNCATE TABLE ==
WL#6501 in MySQL 5.7 introduced separate log files for implementing
atomic and crash-safe TRUNCATE TABLE, instead of using the InnoDB
undo and redo log. Some convoluted logic was added to the InnoDB
crash recovery, and some extra synchronization (including a redo log
checkpoint) was introduced to make this work. This synchronization
has caused performance problems and race conditions, and the extra
log files cannot be copied or applied by external backup programs.
In order to support crash-upgrade from MariaDB 10.2, we will keep
the logic for parsing and applying the extra log files, but we will
no longer generate those files in TRUNCATE TABLE.
A prerequisite for crash-safe TRUNCATE is a crash-safe RENAME TABLE
(with full redo and undo logging and proper rollback). This will
be implemented in MDEV-14717.
ha_innobase::truncate(): Invoke RENAME, create(), delete_table().
Because RENAME cannot be fully rolled back before MariaDB 10.3
due to missing undo logging, add some explicit rename-back in
case the operation fails.
ha_innobase::delete(): Introduce a variant that takes sqlcom as
a parameter. In TRUNCATE TABLE, we do not want to touch any
FOREIGN KEY constraints.
ha_innobase::create(): Add the parameters file_per_table, trx.
In TRUNCATE, the new table must be created in the same transaction
that renames the old table.
create_table_info_t::create_table_info_t(): Add the parameters
file_per_table, trx.
row_drop_table_for_mysql(): Replace a bool parameter with sqlcom.
row_drop_table_after_create_fail(): New function, wrapping
row_drop_table_for_mysql().
dict_truncate_index_tree_in_mem(), fil_truncate_tablespace(),
fil_prepare_for_truncate(), fil_reinit_space_header_for_table(),
row_truncate_table_for_mysql(), TruncateLogger,
row_truncate_prepare(), row_truncate_rollback(),
row_truncate_complete(), row_truncate_fts(),
row_truncate_update_system_tables(),
row_truncate_foreign_key_checks(), row_truncate_sanity_checks():
Remove.
row_upd_check_references_constraints(): Remove a check for
TRUNCATE, now that the table is no longer truncated in place.
The new test innodb.truncate_foreign uses DEBUG_SYNC to cover some
race-condition like scenarios. The test innodb-innodb.truncate does
not use any synchronization.
We add a redo log subformat to indicate backup-friendly format.
MariaDB 10.4 will remove support for the old TRUNCATE logging,
so crash-upgrade from old 10.2 or 10.3 to 10.4 will involve
limitations.
== Undo tablespace truncation ==
MySQL 5.7 implements undo tablespace truncation. It is only
possible when innodb_undo_tablespaces is set to at least 2.
The logging is implemented similar to the WL#6501 TRUNCATE,
that is, using separate log files and a redo log checkpoint.
We can simply implement undo tablespace truncation within
a single mini-transaction that reinitializes the undo log
tablespace file. Unfortunately, due to the redo log format
of some operations, currently, the total redo log written by
undo tablespace truncation will be more than the combined size
of the truncated undo tablespace. It should be acceptable
to have a little more than 1 megabyte of log in a single
mini-transaction. This will be fixed in MDEV-17138 in
MariaDB Server 10.4.
recv_sys_t: Add truncated_undo_spaces[] to remember for which undo
tablespaces a MLOG_FILE_CREATE2 record was seen.
namespace undo: Remove some unnecessary declarations.
fil_space_t::is_being_truncated: Document that this flag now
only applies to undo tablespaces. Remove some references.
fil_space_t::is_stopping(): Do not refer to is_being_truncated.
This check is for tablespaces of tables. Potentially used
tablespaces are never truncated any more.
buf_dblwr_process(): Suppress the out-of-bounds warning
for undo tablespaces.
fil_truncate_log(): Write a MLOG_FILE_CREATE2 with a nonzero
page number (new size of the tablespace in pages) to inform
crash recovery that the undo tablespace size has been reduced.
fil_op_write_log(): Relax assertions, so that MLOG_FILE_CREATE2
can be written for undo tablespaces (without .ibd file suffix)
for a nonzero page number.
os_file_truncate(): Add the parameter allow_shrink=false
so that undo tablespaces can actually be shrunk using this function.
fil_name_parse(): For undo tablespace truncation,
buffer MLOG_FILE_CREATE2 in truncated_undo_spaces[].
recv_read_in_area(): Avoid reading pages for which no redo log
records remain buffered, after recv_addr_trim() removed them.
trx_rseg_header_create(): Add a FIXME comment that we could write
much less redo log.
trx_undo_truncate_tablespace(): Reinitialize the undo tablespace
in a single mini-transaction, which will be flushed to the redo log
before the file size is trimmed.
recv_addr_trim(): Discard any redo logs for pages that were
logged after the new end of a file, before the truncation LSN.
If the rec_list becomes empty, reduce n_addrs. After removing
any affected records, actually truncate the file.
recv_apply_hashed_log_recs(): Invoke recv_addr_trim() right before
applying any log records. The undo tablespace files must be open
at this point.
buf_flush_or_remove_pages(), buf_flush_dirty_pages(),
buf_LRU_flush_or_remove_pages(): Add a parameter for specifying
the number of the first page to flush or remove (default 0).
trx_purge_initiate_truncate(): Remove the log checkpoints, the
extra logging, and some unnecessary crash points. Merge the code
from trx_undo_truncate_tablespace(). First, flush all to-be-discarded
pages (beyond the new end of the file), then trim the space->size
to make the page allocation deterministic. At the only remaining
crash injection point, flush the redo log, so that the recovery
can be tested.
2018-08-28 13:43:06 +03:00
|
|
|
/** whether undo tablespace truncation is in progress */
|
2016-08-12 11:17:45 +03:00
|
|
|
bool is_being_truncated;
|
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
ulint redo_skipped_count;
|
|
|
|
/*!< reference count for operations who want
|
|
|
|
to skip redo log in the file space in order
|
|
|
|
to make fsp_space_modify_check pass. */
|
|
|
|
#endif
|
|
|
|
fil_type_t purpose;/*!< purpose */
|
|
|
|
UT_LIST_BASE_NODE_T(fil_node_t) chain;
|
|
|
|
/*!< base node for the file chain */
|
|
|
|
ulint size; /*!< tablespace file size in pages;
|
|
|
|
0 if not known yet */
|
|
|
|
ulint size_in_header;
|
|
|
|
/* FSP_SIZE in the tablespace header;
|
|
|
|
0 if not known yet */
|
|
|
|
ulint free_len;
|
|
|
|
/*!< length of the FSP_FREE list */
|
|
|
|
ulint free_limit;
|
|
|
|
/*!< contents of FSP_FREE_LIMIT */
|
2016-12-30 13:48:22 +02:00
|
|
|
ulint recv_size;
|
|
|
|
/*!< recovered tablespace size in pages;
|
|
|
|
0 if no size change was read from the redo log,
|
|
|
|
or if the size change was implemented */
|
2017-01-19 12:06:13 +02:00
|
|
|
ulint flags; /*!< FSP_SPACE_FLAGS and FSP_FLAGS_MEM_ flags;
|
|
|
|
see fsp0types.h,
|
2016-08-12 11:17:45 +03:00
|
|
|
fsp_flags_is_valid(),
|
|
|
|
page_size_t(ulint) (constructor) */
|
|
|
|
ulint n_reserved_extents;
|
|
|
|
/*!< number of reserved free extents for
|
|
|
|
ongoing operations like B-tree page split */
|
|
|
|
ulint n_pending_flushes; /*!< this is positive when flushing
|
|
|
|
the tablespace to disk; dropping of the
|
|
|
|
tablespace is forbidden if this is positive */
|
2017-04-28 12:23:35 +03:00
|
|
|
/** Number of pending buffer pool operations accessing the tablespace
|
|
|
|
without holding a table lock or dict_operation_lock S-latch
|
|
|
|
that would prevent the table (and tablespace) from being
|
|
|
|
dropped. An example is change buffer merge.
|
|
|
|
The tablespace cannot be dropped while this is nonzero,
|
|
|
|
or while fil_node_t::n_pending is nonzero.
|
|
|
|
Protected by fil_system->mutex. */
|
|
|
|
ulint n_pending_ops;
|
|
|
|
/** Number of pending block read or write operations
|
|
|
|
(when a write is imminent or a read has recently completed).
|
|
|
|
The tablespace object cannot be freed while this is nonzero,
|
|
|
|
but it can be detached from fil_system.
|
|
|
|
Note that fil_node_t::n_pending tracks actual pending I/O requests.
|
|
|
|
Protected by fil_system->mutex. */
|
|
|
|
ulint n_pending_ios;
|
2016-08-12 11:17:45 +03:00
|
|
|
rw_lock_t latch; /*!< latch protecting the file space storage
|
|
|
|
allocation */
|
|
|
|
UT_LIST_NODE_T(fil_space_t) unflushed_spaces;
|
|
|
|
/*!< list of spaces with at least one unflushed
|
|
|
|
file we have written to */
|
|
|
|
UT_LIST_NODE_T(fil_space_t) named_spaces;
|
|
|
|
/*!< list of spaces for which MLOG_FILE_NAME
|
|
|
|
records have been issued */
|
2019-01-25 15:23:57 +02:00
|
|
|
/** Checks that this tablespace in a list of unflushed tablespaces.
|
|
|
|
@return true if in a list */
|
|
|
|
bool is_in_unflushed_spaces() const;
|
2016-08-12 11:17:45 +03:00
|
|
|
UT_LIST_NODE_T(fil_space_t) space_list;
|
|
|
|
/*!< list of all spaces */
|
2017-03-30 12:48:42 +02:00
|
|
|
/** other tablespaces needing key rotation */
|
|
|
|
UT_LIST_NODE_T(fil_space_t) rotation_list;
|
2019-01-25 15:23:57 +02:00
|
|
|
/** Checks that this tablespace needs key rotation.
|
|
|
|
@return true if in a rotation list */
|
|
|
|
bool is_in_rotation_list() const;
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2016-09-06 09:43:16 +03:00
|
|
|
/** MariaDB encryption data */
|
2017-03-30 12:48:42 +02:00
|
|
|
fil_space_crypt_t* crypt_data;
|
2016-09-06 09:43:16 +03:00
|
|
|
|
2017-03-30 12:48:42 +02:00
|
|
|
/** True if the device this filespace is on supports atomic writes */
|
|
|
|
bool atomic_write_supported;
|
2016-12-31 15:11:52 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** Release the reserved free extents.
|
|
|
|
@param[in] n_reserved number of reserved extents */
|
|
|
|
void release_free_extents(ulint n_reserved);
|
|
|
|
|
MDEV-11254: innodb-use-trim has no effect in 10.2
Problem was that implementation merged from 10.1 was incompatible
with InnoDB 5.7.
buf0buf.cc: Add functions to return should we punch hole and
how big.
buf0flu.cc: Add written page to IORequest
fil0fil.cc: Remove unneeded status call and add test is
sparse files and punch hole supported by file system when
tablespace is created. Add call to get file system
block size. Used file node is added to IORequest. Added
functions to check is punch hole supported and setting
punch hole.
ha_innodb.cc: Remove unneeded status variables (trim512-32768)
and trim_op_saved. Deprecate innodb_use_trim and
set it ON by default. Add function to set innodb-use-trim
dynamically.
dberr.h: Add error code DB_IO_NO_PUNCH_HOLE
if punch hole operation fails.
fil0fil.h: Add punch_hole variable to fil_space_t and
block size to fil_node_t.
os0api.h: Header to helper functions on buf0buf.cc and
fil0fil.cc for os0file.h
os0file.h: Remove unneeded m_block_size from IORequest
and add bpage to IORequest to know actual size of
the block and m_fil_node to know tablespace file
system block size and does it support punch hole.
os0file.cc: Add function punch_hole() to IORequest
to do punch_hole operation,
get the file system block size and determine
does file system support sparse files (for punch hole).
page0size.h: remove implicit copy disable and
use this implicit copy to implement copy_from()
function.
buf0dblwr.cc, buf0flu.cc, buf0rea.cc, fil0fil.cc, fil0fil.h,
os0file.h, os0file.cc, log0log.cc, log0recv.cc:
Remove unneeded write_size parameter from fil_io
calls.
srv0mon.h, srv0srv.h, srv0mon.cc: Remove unneeded
trim512-trim32678 status variables. Removed
these from monitor tests.
2017-01-24 14:40:58 +02:00
|
|
|
/** True if file system storing this tablespace supports
|
|
|
|
punch hole */
|
|
|
|
bool punch_hole;
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
ulint magic_n;/*!< FIL_SPACE_MAGIC_N */
|
2017-03-30 12:48:42 +02:00
|
|
|
|
MDEV-13564 Mariabackup does not work with TRUNCATE
Implement undo tablespace truncation via normal redo logging.
Implement TRUNCATE TABLE as a combination of RENAME to #sql-ib name,
CREATE, and DROP.
Note: Orphan #sql-ib*.ibd may be left behind if MariaDB Server 10.2
is killed before the DROP operation is committed. If MariaDB Server 10.2
is killed during TRUNCATE, it is also possible that the old table
was renamed to #sql-ib*.ibd but the data dictionary will refer to the
table using the original name.
In MariaDB Server 10.3, RENAME inside InnoDB is transactional,
and #sql-* tables will be dropped on startup. So, this new TRUNCATE
will be fully crash-safe in 10.3.
ha_mroonga::wrapper_truncate(): Pass table options to the underlying
storage engine, now that ha_innobase::truncate() will need them.
rpl_slave_state::truncate_state_table(): Before truncating
mysql.gtid_slave_pos, evict any cached table handles from
the table definition cache, so that there will be no stale
references to the old table after truncating.
== TRUNCATE TABLE ==
WL#6501 in MySQL 5.7 introduced separate log files for implementing
atomic and crash-safe TRUNCATE TABLE, instead of using the InnoDB
undo and redo log. Some convoluted logic was added to the InnoDB
crash recovery, and some extra synchronization (including a redo log
checkpoint) was introduced to make this work. This synchronization
has caused performance problems and race conditions, and the extra
log files cannot be copied or applied by external backup programs.
In order to support crash-upgrade from MariaDB 10.2, we will keep
the logic for parsing and applying the extra log files, but we will
no longer generate those files in TRUNCATE TABLE.
A prerequisite for crash-safe TRUNCATE is a crash-safe RENAME TABLE
(with full redo and undo logging and proper rollback). This will
be implemented in MDEV-14717.
ha_innobase::truncate(): Invoke RENAME, create(), delete_table().
Because RENAME cannot be fully rolled back before MariaDB 10.3
due to missing undo logging, add some explicit rename-back in
case the operation fails.
ha_innobase::delete(): Introduce a variant that takes sqlcom as
a parameter. In TRUNCATE TABLE, we do not want to touch any
FOREIGN KEY constraints.
ha_innobase::create(): Add the parameters file_per_table, trx.
In TRUNCATE, the new table must be created in the same transaction
that renames the old table.
create_table_info_t::create_table_info_t(): Add the parameters
file_per_table, trx.
row_drop_table_for_mysql(): Replace a bool parameter with sqlcom.
row_drop_table_after_create_fail(): New function, wrapping
row_drop_table_for_mysql().
dict_truncate_index_tree_in_mem(), fil_truncate_tablespace(),
fil_prepare_for_truncate(), fil_reinit_space_header_for_table(),
row_truncate_table_for_mysql(), TruncateLogger,
row_truncate_prepare(), row_truncate_rollback(),
row_truncate_complete(), row_truncate_fts(),
row_truncate_update_system_tables(),
row_truncate_foreign_key_checks(), row_truncate_sanity_checks():
Remove.
row_upd_check_references_constraints(): Remove a check for
TRUNCATE, now that the table is no longer truncated in place.
The new test innodb.truncate_foreign uses DEBUG_SYNC to cover some
race-condition like scenarios. The test innodb-innodb.truncate does
not use any synchronization.
We add a redo log subformat to indicate backup-friendly format.
MariaDB 10.4 will remove support for the old TRUNCATE logging,
so crash-upgrade from old 10.2 or 10.3 to 10.4 will involve
limitations.
== Undo tablespace truncation ==
MySQL 5.7 implements undo tablespace truncation. It is only
possible when innodb_undo_tablespaces is set to at least 2.
The logging is implemented similar to the WL#6501 TRUNCATE,
that is, using separate log files and a redo log checkpoint.
We can simply implement undo tablespace truncation within
a single mini-transaction that reinitializes the undo log
tablespace file. Unfortunately, due to the redo log format
of some operations, currently, the total redo log written by
undo tablespace truncation will be more than the combined size
of the truncated undo tablespace. It should be acceptable
to have a little more than 1 megabyte of log in a single
mini-transaction. This will be fixed in MDEV-17138 in
MariaDB Server 10.4.
recv_sys_t: Add truncated_undo_spaces[] to remember for which undo
tablespaces a MLOG_FILE_CREATE2 record was seen.
namespace undo: Remove some unnecessary declarations.
fil_space_t::is_being_truncated: Document that this flag now
only applies to undo tablespaces. Remove some references.
fil_space_t::is_stopping(): Do not refer to is_being_truncated.
This check is for tablespaces of tables. Potentially used
tablespaces are never truncated any more.
buf_dblwr_process(): Suppress the out-of-bounds warning
for undo tablespaces.
fil_truncate_log(): Write a MLOG_FILE_CREATE2 with a nonzero
page number (new size of the tablespace in pages) to inform
crash recovery that the undo tablespace size has been reduced.
fil_op_write_log(): Relax assertions, so that MLOG_FILE_CREATE2
can be written for undo tablespaces (without .ibd file suffix)
for a nonzero page number.
os_file_truncate(): Add the parameter allow_shrink=false
so that undo tablespaces can actually be shrunk using this function.
fil_name_parse(): For undo tablespace truncation,
buffer MLOG_FILE_CREATE2 in truncated_undo_spaces[].
recv_read_in_area(): Avoid reading pages for which no redo log
records remain buffered, after recv_addr_trim() removed them.
trx_rseg_header_create(): Add a FIXME comment that we could write
much less redo log.
trx_undo_truncate_tablespace(): Reinitialize the undo tablespace
in a single mini-transaction, which will be flushed to the redo log
before the file size is trimmed.
recv_addr_trim(): Discard any redo logs for pages that were
logged after the new end of a file, before the truncation LSN.
If the rec_list becomes empty, reduce n_addrs. After removing
any affected records, actually truncate the file.
recv_apply_hashed_log_recs(): Invoke recv_addr_trim() right before
applying any log records. The undo tablespace files must be open
at this point.
buf_flush_or_remove_pages(), buf_flush_dirty_pages(),
buf_LRU_flush_or_remove_pages(): Add a parameter for specifying
the number of the first page to flush or remove (default 0).
trx_purge_initiate_truncate(): Remove the log checkpoints, the
extra logging, and some unnecessary crash points. Merge the code
from trx_undo_truncate_tablespace(). First, flush all to-be-discarded
pages (beyond the new end of the file), then trim the space->size
to make the page allocation deterministic. At the only remaining
crash injection point, flush the redo log, so that the recovery
can be tested.
2018-08-28 13:43:06 +03:00
|
|
|
/** @return whether the tablespace is about to be dropped */
|
|
|
|
bool is_stopping() const { return stop_new_ops; }
|
2018-03-09 21:25:20 +02:00
|
|
|
|
|
|
|
/** @return whether doublewrite buffering is needed */
|
|
|
|
bool use_doublewrite() const
|
|
|
|
{
|
|
|
|
return !atomic_write_supported
|
|
|
|
&& srv_use_doublewrite_buf && buf_dblwr;
|
|
|
|
}
|
2018-11-27 14:49:20 +02:00
|
|
|
|
|
|
|
/** Append a file to the chain of files of a space.
|
|
|
|
@param[in] name file name of a file that is not open
|
|
|
|
@param[in] handle file handle, or OS_FILE_CLOSED
|
|
|
|
@param[in] size file size in entire database pages
|
|
|
|
@param[in] is_raw whether this is a raw device
|
|
|
|
@param[in] atomic_write true if atomic write could be enabled
|
|
|
|
@param[in] max_pages maximum number of pages in file,
|
|
|
|
or ULINT_MAX for unlimited
|
|
|
|
@return file object */
|
|
|
|
fil_node_t* add(const char* name, pfs_os_file_t handle,
|
|
|
|
ulint size, bool is_raw, bool atomic_write,
|
|
|
|
ulint max_pages = ULINT_MAX);
|
2016-08-12 11:17:45 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Value of fil_space_t::magic_n */
|
|
|
|
#define FIL_SPACE_MAGIC_N 89472
|
|
|
|
|
|
|
|
/** File node of a tablespace or the log data space */
|
|
|
|
struct fil_node_t {
|
2016-09-06 09:43:16 +03:00
|
|
|
/** tablespace containing this file */
|
|
|
|
fil_space_t* space;
|
|
|
|
/** file name; protected by fil_system->mutex and log_sys->mutex. */
|
|
|
|
char* name;
|
|
|
|
/** file handle (valid if is_open) */
|
2017-05-23 11:09:47 +03:00
|
|
|
pfs_os_file_t handle;
|
2016-09-06 09:43:16 +03:00
|
|
|
/** whether the file actually is a raw device or disk partition */
|
|
|
|
bool is_raw_disk;
|
|
|
|
/** size of the file in database pages (0 if not known yet);
|
|
|
|
the possible last incomplete megabyte may be ignored
|
|
|
|
if space->id == 0 */
|
|
|
|
ulint size;
|
|
|
|
/** initial size of the file in database pages;
|
|
|
|
FIL_IBD_FILE_INITIAL_SIZE by default */
|
2016-08-12 11:17:45 +03:00
|
|
|
ulint init_size;
|
2016-09-06 09:43:16 +03:00
|
|
|
/** maximum size of the file in database pages (0 if unlimited) */
|
2016-08-12 11:17:45 +03:00
|
|
|
ulint max_size;
|
2016-09-06 09:43:16 +03:00
|
|
|
/** count of pending i/o's; is_open must be true if nonzero */
|
2016-08-12 11:17:45 +03:00
|
|
|
ulint n_pending;
|
2016-09-06 09:43:16 +03:00
|
|
|
/** count of pending flushes; is_open must be true if nonzero */
|
2016-08-12 11:17:45 +03:00
|
|
|
ulint n_pending_flushes;
|
2016-09-06 09:43:16 +03:00
|
|
|
/** whether the file is currently being extended */
|
2016-08-12 11:17:45 +03:00
|
|
|
bool being_extended;
|
2019-01-25 15:23:57 +02:00
|
|
|
/** whether this file had writes after lasy fsync() */
|
|
|
|
bool needs_flush;
|
2016-09-06 09:43:16 +03:00
|
|
|
/** link to other files in this tablespace */
|
2016-08-12 11:17:45 +03:00
|
|
|
UT_LIST_NODE_T(fil_node_t) chain;
|
2016-09-06 09:43:16 +03:00
|
|
|
/** link to the fil_system->LRU list (keeping track of open files) */
|
2016-08-12 11:17:45 +03:00
|
|
|
UT_LIST_NODE_T(fil_node_t) LRU;
|
|
|
|
|
2016-12-31 15:11:52 +01:00
|
|
|
/** whether this file could use atomic write (data file) */
|
2016-08-12 11:17:45 +03:00
|
|
|
bool atomic_write;
|
2016-09-06 09:43:16 +03:00
|
|
|
|
MDEV-11254: innodb-use-trim has no effect in 10.2
Problem was that implementation merged from 10.1 was incompatible
with InnoDB 5.7.
buf0buf.cc: Add functions to return should we punch hole and
how big.
buf0flu.cc: Add written page to IORequest
fil0fil.cc: Remove unneeded status call and add test is
sparse files and punch hole supported by file system when
tablespace is created. Add call to get file system
block size. Used file node is added to IORequest. Added
functions to check is punch hole supported and setting
punch hole.
ha_innodb.cc: Remove unneeded status variables (trim512-32768)
and trim_op_saved. Deprecate innodb_use_trim and
set it ON by default. Add function to set innodb-use-trim
dynamically.
dberr.h: Add error code DB_IO_NO_PUNCH_HOLE
if punch hole operation fails.
fil0fil.h: Add punch_hole variable to fil_space_t and
block size to fil_node_t.
os0api.h: Header to helper functions on buf0buf.cc and
fil0fil.cc for os0file.h
os0file.h: Remove unneeded m_block_size from IORequest
and add bpage to IORequest to know actual size of
the block and m_fil_node to know tablespace file
system block size and does it support punch hole.
os0file.cc: Add function punch_hole() to IORequest
to do punch_hole operation,
get the file system block size and determine
does file system support sparse files (for punch hole).
page0size.h: remove implicit copy disable and
use this implicit copy to implement copy_from()
function.
buf0dblwr.cc, buf0flu.cc, buf0rea.cc, fil0fil.cc, fil0fil.h,
os0file.h, os0file.cc, log0log.cc, log0recv.cc:
Remove unneeded write_size parameter from fil_io
calls.
srv0mon.h, srv0srv.h, srv0mon.cc: Remove unneeded
trim512-trim32678 status variables. Removed
these from monitor tests.
2017-01-24 14:40:58 +02:00
|
|
|
/** Filesystem block size */
|
|
|
|
ulint block_size;
|
|
|
|
|
2016-09-06 09:43:16 +03:00
|
|
|
/** FIL_NODE_MAGIC_N */
|
|
|
|
ulint magic_n;
|
2017-01-25 15:59:37 +02:00
|
|
|
|
|
|
|
/** @return whether this file is open */
|
|
|
|
bool is_open() const
|
|
|
|
{
|
|
|
|
return(handle != OS_FILE_CLOSED);
|
|
|
|
}
|
2018-11-27 14:49:20 +02:00
|
|
|
|
|
|
|
/** Read the first page of a data file.
|
|
|
|
@param[in] first whether this is the very first read
|
|
|
|
@return whether the page was found valid */
|
|
|
|
bool read_page0(bool first);
|
2016-08-12 11:17:45 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Value of fil_node_t::magic_n */
|
|
|
|
#define FIL_NODE_MAGIC_N 89389
|
|
|
|
|
|
|
|
/** Common InnoDB file extentions */
|
|
|
|
enum ib_extention {
|
|
|
|
NO_EXT = 0,
|
|
|
|
IBD = 1,
|
|
|
|
ISL = 2,
|
2017-01-16 11:11:14 +02:00
|
|
|
CFG = 3
|
2016-08-12 11:17:45 +03:00
|
|
|
};
|
|
|
|
extern const char* dot_ext[];
|
|
|
|
#define DOT_IBD dot_ext[IBD]
|
|
|
|
#define DOT_ISL dot_ext[ISL]
|
|
|
|
#define DOT_CFG dot_ext[CFG]
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/** When mysqld is run, the default directory "." is the mysqld datadir,
|
2014-09-11 10:13:35 +02:00
|
|
|
but in the MySQL Embedded Server Library and mysqlbackup it is not the default
|
2014-02-26 19:11:54 +01:00
|
|
|
directory, and we must set the base file path explicitly */
|
|
|
|
extern const char* fil_path_to_mysql_datadir;
|
|
|
|
|
|
|
|
/* Space address data type; this is intended to be used when
|
|
|
|
addresses accurate to a byte are stored in file pages. If the page part
|
|
|
|
of the address is FIL_NULL, the address is considered undefined. */
|
|
|
|
|
|
|
|
typedef byte fil_faddr_t; /*!< 'type' definition in C: an address
|
|
|
|
stored in a file page is a string of bytes */
|
2017-08-04 13:57:26 +03:00
|
|
|
#endif /* !UNIV_INNOCHECKSUM */
|
|
|
|
|
|
|
|
/** Initial size of a single-table tablespace in pages */
|
|
|
|
#define FIL_IBD_FILE_INITIAL_SIZE 4
|
|
|
|
|
|
|
|
/** 'null' (undefined) page offset in the context of file spaces */
|
|
|
|
#define FIL_NULL ULINT32_UNDEFINED
|
|
|
|
|
2015-01-19 12:39:17 +02:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
#define FIL_ADDR_PAGE 0 /* first in address is the page offset */
|
|
|
|
#define FIL_ADDR_BYTE 4 /* then comes 2-byte byte offset within page*/
|
|
|
|
#define FIL_ADDR_SIZE 6 /* address size is 6 bytes */
|
|
|
|
|
2015-01-19 12:39:17 +02:00
|
|
|
#ifndef UNIV_INNOCHECKSUM
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/** File space address */
|
2016-08-12 11:17:45 +03:00
|
|
|
struct fil_addr_t {
|
2014-02-26 19:11:54 +01:00
|
|
|
ulint page; /*!< page number within a space */
|
|
|
|
ulint boffset; /*!< byte offset within the page */
|
|
|
|
};
|
|
|
|
|
|
|
|
/** The null file address */
|
|
|
|
extern fil_addr_t fil_addr_null;
|
|
|
|
|
|
|
|
#endif /* !UNIV_INNOCHECKSUM */
|
|
|
|
|
|
|
|
/** The byte offsets on a file page for various variables @{ */
|
|
|
|
#define FIL_PAGE_SPACE_OR_CHKSUM 0 /*!< in < MySQL-4.0.14 space id the
|
|
|
|
page belongs to (== 0) but in later
|
|
|
|
versions the 'new' checksum of the
|
|
|
|
page */
|
|
|
|
#define FIL_PAGE_OFFSET 4 /*!< page offset inside space */
|
|
|
|
#define FIL_PAGE_PREV 8 /*!< if there is a 'natural'
|
|
|
|
predecessor of the page, its
|
|
|
|
offset. Otherwise FIL_NULL.
|
|
|
|
This field is not set on BLOB
|
|
|
|
pages, which are stored as a
|
|
|
|
singly-linked list. See also
|
|
|
|
FIL_PAGE_NEXT. */
|
|
|
|
#define FIL_PAGE_NEXT 12 /*!< if there is a 'natural' successor
|
|
|
|
of the page, its offset.
|
|
|
|
Otherwise FIL_NULL.
|
|
|
|
B-tree index pages
|
|
|
|
(FIL_PAGE_TYPE contains FIL_PAGE_INDEX)
|
|
|
|
on the same PAGE_LEVEL are maintained
|
|
|
|
as a doubly linked list via
|
|
|
|
FIL_PAGE_PREV and FIL_PAGE_NEXT
|
|
|
|
in the collation order of the
|
|
|
|
smallest user record on each page. */
|
|
|
|
#define FIL_PAGE_LSN 16 /*!< lsn of the end of the newest
|
|
|
|
modification log record to the page */
|
|
|
|
#define FIL_PAGE_TYPE 24 /*!< file page type: FIL_PAGE_INDEX,...,
|
|
|
|
2 bytes.
|
|
|
|
|
|
|
|
The contents of this field can only
|
|
|
|
be trusted in the following case:
|
|
|
|
if the page is an uncompressed
|
|
|
|
B-tree index page, then it is
|
|
|
|
guaranteed that the value is
|
|
|
|
FIL_PAGE_INDEX.
|
|
|
|
The opposite does not hold.
|
|
|
|
|
|
|
|
In tablespaces created by
|
|
|
|
MySQL/InnoDB 5.1.7 or later, the
|
|
|
|
contents of this field is valid
|
|
|
|
for all uncompressed pages. */
|
2014-12-22 16:53:17 +02:00
|
|
|
#define FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION 26 /*!< for the first page
|
|
|
|
in a system tablespace data file
|
|
|
|
(ibdata*, not *.ibd): the file has
|
|
|
|
been flushed to disk at least up
|
|
|
|
to this lsn
|
|
|
|
for other pages: a 32-bit key version
|
|
|
|
used to encrypt the page + 32-bit checksum
|
|
|
|
or 64 bits of zero if no encryption
|
|
|
|
*/
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** This overloads FIL_PAGE_FILE_FLUSH_LSN for RTREE Split Sequence Number */
|
|
|
|
#define FIL_RTREE_SPLIT_SEQ_NUM FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION
|
|
|
|
|
|
|
|
/** starting from 4.1.x this contains the space id of the page */
|
|
|
|
#define FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID 34
|
|
|
|
|
2014-05-05 18:20:28 +02:00
|
|
|
#define FIL_PAGE_SPACE_ID FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
#define FIL_PAGE_DATA 38U /*!< start of the data on the page */
|
2016-09-06 09:43:16 +03:00
|
|
|
|
2013-12-19 14:36:38 +02:00
|
|
|
/* Following are used when page compression is used */
|
|
|
|
#define FIL_PAGE_COMPRESSED_SIZE 2 /*!< Number of bytes used to store
|
2015-06-03 13:10:18 +03:00
|
|
|
actual payload data size on
|
|
|
|
compressed pages. */
|
|
|
|
#define FIL_PAGE_COMPRESSION_METHOD_SIZE 2
|
|
|
|
/*!< Number of bytes used to store
|
|
|
|
actual compression method. */
|
2014-02-26 19:11:54 +01:00
|
|
|
/* @} */
|
|
|
|
/** File page trailer @{ */
|
|
|
|
#define FIL_PAGE_END_LSN_OLD_CHKSUM 8 /*!< the low 4 bytes of this are used
|
|
|
|
to store the page checksum, the
|
|
|
|
last 4 bytes should be identical
|
|
|
|
to the last 4 bytes of FIL_PAGE_LSN */
|
|
|
|
#define FIL_PAGE_DATA_END 8 /*!< size of the page trailer */
|
|
|
|
/* @} */
|
|
|
|
|
|
|
|
/** File page types (values of FIL_PAGE_TYPE) @{ */
|
2015-06-03 13:10:18 +03:00
|
|
|
#define FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED 37401 /*!< Page is compressed and
|
|
|
|
then encrypted */
|
2013-12-19 14:36:38 +02:00
|
|
|
#define FIL_PAGE_PAGE_COMPRESSED 34354 /*!< page compressed page */
|
2014-02-26 19:11:54 +01:00
|
|
|
#define FIL_PAGE_INDEX 17855 /*!< B-tree node */
|
2016-08-12 11:17:45 +03:00
|
|
|
#define FIL_PAGE_RTREE 17854 /*!< B-tree node */
|
2014-02-26 19:11:54 +01:00
|
|
|
#define FIL_PAGE_UNDO_LOG 2 /*!< Undo log page */
|
|
|
|
#define FIL_PAGE_INODE 3 /*!< Index node */
|
|
|
|
#define FIL_PAGE_IBUF_FREE_LIST 4 /*!< Insert buffer free list */
|
|
|
|
/* File page types introduced in MySQL/InnoDB 5.1.7 */
|
|
|
|
#define FIL_PAGE_TYPE_ALLOCATED 0 /*!< Freshly allocated page */
|
|
|
|
#define FIL_PAGE_IBUF_BITMAP 5 /*!< Insert buffer bitmap */
|
|
|
|
#define FIL_PAGE_TYPE_SYS 6 /*!< System page */
|
|
|
|
#define FIL_PAGE_TYPE_TRX_SYS 7 /*!< Transaction system data */
|
|
|
|
#define FIL_PAGE_TYPE_FSP_HDR 8 /*!< File space header */
|
|
|
|
#define FIL_PAGE_TYPE_XDES 9 /*!< Extent descriptor page */
|
|
|
|
#define FIL_PAGE_TYPE_BLOB 10 /*!< Uncompressed BLOB page */
|
|
|
|
#define FIL_PAGE_TYPE_ZBLOB 11 /*!< First compressed BLOB page */
|
|
|
|
#define FIL_PAGE_TYPE_ZBLOB2 12 /*!< Subsequent compressed BLOB page */
|
2016-08-12 11:17:45 +03:00
|
|
|
#define FIL_PAGE_TYPE_UNKNOWN 13 /*!< In old tablespaces, garbage
|
|
|
|
in FIL_PAGE_TYPE is replaced with this
|
|
|
|
value when flushing pages. */
|
2017-01-16 14:03:36 +02:00
|
|
|
|
|
|
|
/* File page types introduced in MySQL 5.7, not supported in MariaDB */
|
|
|
|
//#define FIL_PAGE_COMPRESSED 14
|
|
|
|
//#define FIL_PAGE_ENCRYPTED 15
|
|
|
|
//#define FIL_PAGE_COMPRESSED_AND_ENCRYPTED 16
|
|
|
|
//#define FIL_PAGE_ENCRYPTED_RTREE 17
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** Used by i_s.cc to index into the text description. */
|
|
|
|
#define FIL_PAGE_TYPE_LAST FIL_PAGE_TYPE_UNKNOWN
|
2014-02-26 19:11:54 +01:00
|
|
|
/*!< Last page type */
|
|
|
|
/* @} */
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** macro to check whether the page type is index (Btree or Rtree) type */
|
|
|
|
#define fil_page_type_is_index(page_type) \
|
|
|
|
(page_type == FIL_PAGE_INDEX || page_type == FIL_PAGE_RTREE)
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** Check whether the page is index page (either regular Btree index or Rtree
|
|
|
|
index */
|
|
|
|
#define fil_page_index_page_check(page) \
|
|
|
|
fil_page_type_is_index(fil_page_get_type(page))
|
2015-01-19 12:39:17 +02:00
|
|
|
|
2017-03-14 12:56:01 +02:00
|
|
|
/** Enum values for encryption table option */
|
|
|
|
enum fil_encryption_t {
|
|
|
|
/** Encrypted if innodb_encrypt_tables=ON (srv_encrypt_tables) */
|
|
|
|
FIL_ENCRYPTION_DEFAULT,
|
|
|
|
/** Encrypted */
|
|
|
|
FIL_ENCRYPTION_ON,
|
|
|
|
/** Not encrypted */
|
|
|
|
FIL_ENCRYPTION_OFF
|
|
|
|
};
|
2015-04-01 11:50:21 +03:00
|
|
|
|
2018-11-29 12:53:44 +02:00
|
|
|
#ifndef UNIV_INNOCHECKSUM
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/** The number of fsyncs done to the log */
|
|
|
|
extern ulint fil_n_log_flushes;
|
|
|
|
|
|
|
|
/** Number of pending redo log flushes */
|
|
|
|
extern ulint fil_n_pending_log_flushes;
|
|
|
|
/** Number of pending tablespace flushes */
|
|
|
|
extern ulint fil_n_pending_tablespace_flushes;
|
|
|
|
|
2016-09-06 09:43:16 +03:00
|
|
|
/** Look up a tablespace.
|
|
|
|
The caller should hold an InnoDB table lock or a MDL that prevents
|
|
|
|
the tablespace from being dropped during the operation,
|
|
|
|
or the caller should be in single-threaded crash recovery mode
|
|
|
|
(no user connections that could drop tablespaces).
|
|
|
|
If this is not the case, fil_space_acquire() and fil_space_release()
|
|
|
|
should be used instead.
|
|
|
|
@param[in] id tablespace ID
|
|
|
|
@return tablespace, or NULL if not found */
|
|
|
|
fil_space_t*
|
|
|
|
fil_space_get(
|
|
|
|
ulint id)
|
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
|
|
|
|
2014-10-25 08:21:52 +03:00
|
|
|
/** The tablespace memory cache; also the totality of logs (the log
|
|
|
|
data space) is stored here; below we talk about tablespaces, but also
|
|
|
|
the ib_logfiles form a 'space' and it is handled here */
|
|
|
|
struct fil_system_t {
|
2016-08-12 11:17:45 +03:00
|
|
|
ib_mutex_t mutex; /*!< The mutex protecting the cache */
|
2014-10-25 08:21:52 +03:00
|
|
|
hash_table_t* spaces; /*!< The hash table of spaces in the
|
|
|
|
system; they are hashed on the space
|
|
|
|
id */
|
|
|
|
hash_table_t* name_hash; /*!< hash table based on the space
|
|
|
|
name */
|
|
|
|
UT_LIST_BASE_NODE_T(fil_node_t) LRU;
|
|
|
|
/*!< base node for the LRU list of the
|
|
|
|
most recently used open files with no
|
|
|
|
pending i/o's; if we start an i/o on
|
|
|
|
the file, we first remove it from this
|
|
|
|
list, and return it to the start of
|
|
|
|
the list when the i/o ends;
|
|
|
|
log files and the system tablespace are
|
|
|
|
not put to this list: they are opened
|
|
|
|
after the startup, and kept open until
|
|
|
|
shutdown */
|
|
|
|
UT_LIST_BASE_NODE_T(fil_space_t) unflushed_spaces;
|
|
|
|
/*!< base node for the list of those
|
|
|
|
tablespaces whose files contain
|
|
|
|
unflushed writes; those spaces have
|
|
|
|
at least one file node where
|
2019-01-25 15:23:57 +02:00
|
|
|
needs_flush == true */
|
2014-10-25 08:21:52 +03:00
|
|
|
ulint n_open; /*!< number of files currently open */
|
|
|
|
ulint max_n_open; /*!< n_open is not allowed to exceed
|
|
|
|
this */
|
|
|
|
ulint max_assigned_id;/*!< maximum space id in the existing
|
|
|
|
tables, or assigned during the time
|
|
|
|
mysqld has been up; at an InnoDB
|
|
|
|
startup we scan the data dictionary
|
|
|
|
and set here the maximum of the
|
|
|
|
space id's of the tables there */
|
|
|
|
UT_LIST_BASE_NODE_T(fil_space_t) space_list;
|
|
|
|
/*!< list of all file spaces */
|
2016-08-12 11:17:45 +03:00
|
|
|
UT_LIST_BASE_NODE_T(fil_space_t) named_spaces;
|
|
|
|
/*!< list of all file spaces
|
|
|
|
for which a MLOG_FILE_NAME
|
|
|
|
record has been written since
|
|
|
|
the latest redo log checkpoint.
|
|
|
|
Protected only by log_sys->mutex. */
|
2017-03-14 12:56:01 +02:00
|
|
|
UT_LIST_BASE_NODE_T(fil_space_t) rotation_list;
|
|
|
|
/*!< list of all file spaces needing
|
|
|
|
key rotation.*/
|
|
|
|
|
2014-10-25 08:21:52 +03:00
|
|
|
ibool space_id_reuse_warned;
|
|
|
|
/* !< TRUE if fil_space_create()
|
|
|
|
has issued a warning about
|
|
|
|
potential space_id reuse */
|
|
|
|
};
|
|
|
|
|
2016-09-06 09:43:16 +03:00
|
|
|
/** The tablespace memory cache. This variable is NULL before the module is
|
|
|
|
initialized. */
|
|
|
|
extern fil_system_t* fil_system;
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2016-09-06 09:43:16 +03:00
|
|
|
#include "fil0crypt.h"
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** Returns the latch of a file space.
|
|
|
|
@param[in] id space id
|
|
|
|
@param[out] flags tablespace flags
|
|
|
|
@return latch protecting storage allocation */
|
2014-02-26 19:11:54 +01:00
|
|
|
rw_lock_t*
|
|
|
|
fil_space_get_latch(
|
2016-08-12 11:17:45 +03:00
|
|
|
ulint id,
|
|
|
|
ulint* flags);
|
|
|
|
|
|
|
|
/** Gets the type of a file space.
|
|
|
|
@param[in] id tablespace identifier
|
|
|
|
@return file type */
|
|
|
|
fil_type_t
|
2014-02-26 19:11:54 +01:00
|
|
|
fil_space_get_type(
|
2016-08-12 11:17:45 +03:00
|
|
|
ulint id);
|
|
|
|
|
|
|
|
/** Note that a tablespace has been imported.
|
|
|
|
It is initially marked as FIL_TYPE_IMPORT so that no logging is
|
|
|
|
done during the import process when the space ID is stamped to each page.
|
|
|
|
Now we change it to FIL_SPACE_TABLESPACE to start redo and undo logging.
|
|
|
|
NOTE: temporary tablespaces are never imported.
|
|
|
|
@param[in] id tablespace identifier */
|
|
|
|
void
|
|
|
|
fil_space_set_imported(
|
|
|
|
ulint id);
|
2013-12-19 14:36:38 +02:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** Create a space memory object and put it to the fil_system hash table.
|
|
|
|
Error messages are issued to the server log.
|
2017-03-30 12:48:42 +02:00
|
|
|
@param[in] name tablespace name
|
|
|
|
@param[in] id tablespace identifier
|
|
|
|
@param[in] flags tablespace flags
|
|
|
|
@param[in] purpose tablespace purpose
|
|
|
|
@param[in,out] crypt_data encryption information
|
|
|
|
@param[in] mode encryption mode
|
2018-11-27 14:49:20 +02:00
|
|
|
@return pointer to created tablespace, to be filled in with fil_space_t::add()
|
2016-08-12 11:17:45 +03:00
|
|
|
@retval NULL on failure (such as when the same tablespace exists) */
|
|
|
|
fil_space_t*
|
2014-02-26 19:11:54 +01:00
|
|
|
fil_space_create(
|
2017-03-14 12:56:01 +02:00
|
|
|
const char* name,
|
|
|
|
ulint id,
|
|
|
|
ulint flags,
|
2017-03-30 12:48:42 +02:00
|
|
|
fil_type_t purpose,
|
2017-03-14 12:56:01 +02:00
|
|
|
fil_space_crypt_t* crypt_data,
|
2017-03-30 12:48:42 +02:00
|
|
|
fil_encryption_t mode = FIL_ENCRYPTION_DEFAULT)
|
2016-09-06 09:43:16 +03:00
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2014-12-22 16:53:17 +02:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/*******************************************************************//**
|
|
|
|
Assigns a new space id for a new single-table tablespace. This works simply by
|
|
|
|
incrementing the global counter. If 4 billion id's is not enough, we may need
|
|
|
|
to recycle id's.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return true if assigned, false if not */
|
|
|
|
bool
|
2014-02-26 19:11:54 +01:00
|
|
|
fil_assign_new_space_id(
|
|
|
|
/*====================*/
|
|
|
|
ulint* space_id); /*!< in/out: space id */
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** Frees a space object from the tablespace memory cache.
|
|
|
|
Closes the files in the chain but does not delete them.
|
|
|
|
There must not be any pending i/o's or flushes on the files.
|
|
|
|
@param[in] id tablespace identifier
|
|
|
|
@param[in] x_latched whether the caller holds X-mode space->latch
|
|
|
|
@return true if success */
|
|
|
|
bool
|
|
|
|
fil_space_free(
|
|
|
|
ulint id,
|
|
|
|
bool x_latched);
|
|
|
|
|
|
|
|
/** Returns the path from the first fil_node_t found with this space ID.
|
2014-02-26 19:11:54 +01:00
|
|
|
The caller is responsible for freeing the memory allocated here for the
|
|
|
|
value returned.
|
2016-08-12 11:17:45 +03:00
|
|
|
@param[in] id Tablespace ID
|
|
|
|
@return own: A copy of fil_node_t::path, NULL if space ID is zero
|
|
|
|
or not found. */
|
2014-02-26 19:11:54 +01:00
|
|
|
char*
|
|
|
|
fil_space_get_first_path(
|
2016-08-12 11:17:45 +03:00
|
|
|
ulint id);
|
|
|
|
|
MDEV-11556 InnoDB redo log apply fails to adjust data file sizes
fil_space_t::recv_size: New member: recovered tablespace size in pages;
0 if no size change was read from the redo log,
or if the size change was implemented.
fil_space_set_recv_size(): New function for setting space->recv_size.
innodb_data_file_size_debug: A debug parameter for setting the system
tablespace size in recovery even when the redo log does not contain
any size changes. It is hard to write a small test case that would
cause the system tablespace to be extended at the critical moment.
recv_parse_log_rec(): Note those tablespaces whose size is being changed
by the redo log, by invoking fil_space_set_recv_size().
innobase_init(): Correct an error message, and do not require a larger
innodb_buffer_pool_size when starting up with a smaller innodb_page_size.
innobase_start_or_create_for_mysql(): Allow startup with any initial
size of the ibdata1 file if the autoextend attribute is set. Require
the minimum size of fixed-size system tablespaces to be 640 pages,
not 10 megabytes. Implement innodb_data_file_size_debug.
open_or_create_data_files(): Round the system tablespace size down
to pages, not to full megabytes, (Our test truncates the system
tablespace to more than 800 pages with innodb_page_size=4k.
InnoDB should not imagine that it was truncated to 768 pages
and then overwrite good pages in the tablespace.)
fil_flush_low(): Refactored from fil_flush().
fil_space_extend_must_retry(): Refactored from
fil_extend_space_to_desired_size().
fil_mutex_enter_and_prepare_for_io(): Extend the tablespace if
fil_space_set_recv_size() was called.
The test case has been successfully run with all the
innodb_page_size values 4k, 8k, 16k, 32k, 64k.
2016-12-28 12:05:43 +02:00
|
|
|
/** Set the recovered size of a tablespace in pages.
|
|
|
|
@param id tablespace ID
|
|
|
|
@param size recovered size in pages */
|
|
|
|
UNIV_INTERN
|
|
|
|
void
|
|
|
|
fil_space_set_recv_size(ulint id, ulint size);
|
2014-02-26 19:11:54 +01:00
|
|
|
/*******************************************************************//**
|
|
|
|
Returns the size of the space in pages. The tablespace must be cached in the
|
|
|
|
memory cache.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return space size, 0 if space not found */
|
2014-02-26 19:11:54 +01:00
|
|
|
ulint
|
|
|
|
fil_space_get_size(
|
|
|
|
/*===============*/
|
|
|
|
ulint id); /*!< in: space id */
|
|
|
|
/*******************************************************************//**
|
|
|
|
Returns the flags of the space. The tablespace must be cached
|
|
|
|
in the memory cache.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return flags, ULINT_UNDEFINED if space not found */
|
2014-02-26 19:11:54 +01:00
|
|
|
ulint
|
|
|
|
fil_space_get_flags(
|
|
|
|
/*================*/
|
|
|
|
ulint id); /*!< in: space id */
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** Open each fil_node_t of a named fil_space_t if not already open.
|
|
|
|
@param[in] name Tablespace name
|
|
|
|
@return true if all file nodes are opened. */
|
|
|
|
bool
|
|
|
|
fil_space_open(
|
|
|
|
const char* name);
|
|
|
|
|
|
|
|
/** Close each fil_node_t of a named fil_space_t if open.
|
|
|
|
@param[in] name Tablespace name */
|
|
|
|
void
|
|
|
|
fil_space_close(
|
|
|
|
const char* name);
|
|
|
|
|
|
|
|
/** Returns the page size of the space and whether it is compressed or not.
|
|
|
|
The tablespace must be cached in the memory cache.
|
|
|
|
@param[in] id space id
|
|
|
|
@param[out] found true if tablespace was found
|
|
|
|
@return page size */
|
|
|
|
const page_size_t
|
|
|
|
fil_space_get_page_size(
|
|
|
|
ulint id,
|
|
|
|
bool* found);
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/****************************************************************//**
|
|
|
|
Initializes the tablespace memory cache. */
|
|
|
|
void
|
|
|
|
fil_init(
|
|
|
|
/*=====*/
|
|
|
|
ulint hash_size, /*!< in: hash table size */
|
|
|
|
ulint max_n_open); /*!< in: max number of open files */
|
|
|
|
/*******************************************************************//**
|
|
|
|
Initializes the tablespace memory cache. */
|
|
|
|
void
|
|
|
|
fil_close(void);
|
|
|
|
/*===========*/
|
|
|
|
/*******************************************************************//**
|
|
|
|
Opens all log files and system tablespace data files. They stay open until the
|
|
|
|
database server shutdown. This should be called at a server startup after the
|
|
|
|
space objects for the log and the system tablespace have been created. The
|
|
|
|
purpose of this operation is to make sure we never run out of file descriptors
|
|
|
|
if we need to read from the insert buffer or to write to the log. */
|
|
|
|
void
|
|
|
|
fil_open_log_and_system_tablespace_files(void);
|
|
|
|
/*==========================================*/
|
|
|
|
/*******************************************************************//**
|
|
|
|
Closes all open files. There must not be any pending i/o's or not flushed
|
|
|
|
modifications in the files. */
|
|
|
|
void
|
|
|
|
fil_close_all_files(void);
|
|
|
|
/*=====================*/
|
|
|
|
/*******************************************************************//**
|
|
|
|
Closes the redo log files. There must not be any pending i/o's or not
|
|
|
|
flushed modifications in the files. */
|
|
|
|
void
|
|
|
|
fil_close_log_files(
|
|
|
|
/*================*/
|
|
|
|
bool free); /*!< in: whether to free the memory object */
|
|
|
|
/*******************************************************************//**
|
|
|
|
Sets the max tablespace id counter if the given number is bigger than the
|
|
|
|
previous value. */
|
|
|
|
void
|
|
|
|
fil_set_max_space_id_if_bigger(
|
|
|
|
/*===========================*/
|
|
|
|
ulint max_id);/*!< in: maximum known id */
|
2016-09-06 09:43:16 +03:00
|
|
|
|
|
|
|
/** Write the flushed LSN to the page header of the first page in the
|
|
|
|
system tablespace.
|
|
|
|
@param[in] lsn flushed LSN
|
|
|
|
@return DB_SUCCESS or error number */
|
|
|
|
dberr_t
|
|
|
|
fil_write_flushed_lsn(
|
|
|
|
lsn_t lsn)
|
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** Acquire a tablespace when it could be dropped concurrently.
|
|
|
|
Used by background threads that do not necessarily hold proper locks
|
|
|
|
for concurrency control.
|
|
|
|
@param[in] id tablespace ID
|
MDEV-12253: Buffer pool blocks are accessed after they have been freed
Problem was that bpage was referenced after it was already freed
from LRU. Fixed by adding a new variable encrypted that is
passed down to buf_page_check_corrupt() and used in
buf_page_get_gen() to stop processing page read.
This patch should also address following test failures and
bugs:
MDEV-12419: IMPORT should not look up tablespace in
PageConverter::validate(). This is now removed.
MDEV-10099: encryption.innodb_onlinealter_encryption fails
sporadically in buildbot
MDEV-11420: encryption.innodb_encryption-page-compression
failed in buildbot
MDEV-11222: encryption.encrypt_and_grep failed in buildbot on P8
Removed dict_table_t::is_encrypted and dict_table_t::ibd_file_missing
and replaced these with dict_table_t::file_unreadable. Table
ibd file is missing if fil_get_space(space_id) returns NULL
and encrypted if not. Removed dict_table_t::is_corrupted field.
Ported FilSpace class from 10.2 and using that on buf_page_check_corrupt(),
buf_page_decrypt_after_read(), buf_page_encrypt_before_write(),
buf_dblwr_process(), buf_read_page(), dict_stats_save_defrag_stats().
Added test cases when enrypted page could be read while doing
redo log crash recovery. Also added test case for row compressed
blobs.
btr_cur_open_at_index_side_func(),
btr_cur_open_at_rnd_pos_func(): Avoid referencing block that is
NULL.
buf_page_get_zip(): Issue error if page read fails.
buf_page_get_gen(): Use dberr_t for error detection and
do not reference bpage after we hare freed it.
buf_mark_space_corrupt(): remove bpage from LRU also when
it is encrypted.
buf_page_check_corrupt(): @return DB_SUCCESS if page has
been read and is not corrupted,
DB_PAGE_CORRUPTED if page based on checksum check is corrupted,
DB_DECRYPTION_FAILED if page post encryption checksum matches but
after decryption normal page checksum does not match. In read
case only DB_SUCCESS is possible.
buf_page_io_complete(): use dberr_t for error handling.
buf_flush_write_block_low(),
buf_read_ahead_random(),
buf_read_page_async(),
buf_read_ahead_linear(),
buf_read_ibuf_merge_pages(),
buf_read_recv_pages(),
fil_aio_wait():
Issue error if page read fails.
btr_pcur_move_to_next_page(): Do not reference page if it is
NULL.
Introduced dict_table_t::is_readable() and dict_index_t::is_readable()
that will return true if tablespace exists and pages read from
tablespace are not corrupted or page decryption failed.
Removed buf_page_t::key_version. After page decryption the
key version is not removed from page frame. For unencrypted
pages, old key_version is removed at buf_page_encrypt_before_write()
dict_stats_update_transient_for_index(),
dict_stats_update_transient()
Do not continue if table decryption failed or table
is corrupted.
dict0stats.cc: Introduced a dict_stats_report_error function
to avoid code duplication.
fil_parse_write_crypt_data():
Check that key read from redo log entry is found from
encryption plugin and if it is not, refuse to start.
PageConverter::validate(): Removed access to fil_space_t as
tablespace is not available during import.
Fixed error code on innodb.innodb test.
Merged test cased innodb-bad-key-change5 and innodb-bad-key-shutdown
to innodb-bad-key-change2. Removed innodb-bad-key-change5 test.
Decreased unnecessary complexity on some long lasting tests.
Removed fil_inc_pending_ops(), fil_decr_pending_ops(),
fil_get_first_space(), fil_get_next_space(),
fil_get_first_space_safe(), fil_get_next_space_safe()
functions.
fil_space_verify_crypt_checksum(): Fixed bug found using ASAN
where FIL_PAGE_END_LSN_OLD_CHECKSUM field was incorrectly
accessed from row compressed tables. Fixed out of page frame
bug for row compressed tables in
fil_space_verify_crypt_checksum() found using ASAN. Incorrect
function was called for compressed table.
Added new tests for discard, rename table and drop (we should allow them
even when page decryption fails). Alter table rename is not allowed.
Added test for restart with innodb-force-recovery=1 when page read on
redo-recovery cant be decrypted. Added test for corrupted table where
both page data and FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION is corrupted.
Adjusted the test case innodb_bug14147491 so that it does not anymore
expect crash. Instead table is just mostly not usable.
fil0fil.h: fil_space_acquire_low is not visible function
and fil_space_acquire and fil_space_acquire_silent are
inline functions. FilSpace class uses fil_space_acquire_low
directly.
recv_apply_hashed_log_recs() does not return anything.
2017-04-26 15:19:16 +03:00
|
|
|
@param[in] silent whether to silently ignore missing tablespaces
|
2017-04-03 19:36:54 +03:00
|
|
|
@return the tablespace
|
|
|
|
@retval NULL if missing or being deleted or truncated */
|
MDEV-12253: Buffer pool blocks are accessed after they have been freed
Problem was that bpage was referenced after it was already freed
from LRU. Fixed by adding a new variable encrypted that is
passed down to buf_page_check_corrupt() and used in
buf_page_get_gen() to stop processing page read.
This patch should also address following test failures and
bugs:
MDEV-12419: IMPORT should not look up tablespace in
PageConverter::validate(). This is now removed.
MDEV-10099: encryption.innodb_onlinealter_encryption fails
sporadically in buildbot
MDEV-11420: encryption.innodb_encryption-page-compression
failed in buildbot
MDEV-11222: encryption.encrypt_and_grep failed in buildbot on P8
Removed dict_table_t::is_encrypted and dict_table_t::ibd_file_missing
and replaced these with dict_table_t::file_unreadable. Table
ibd file is missing if fil_get_space(space_id) returns NULL
and encrypted if not. Removed dict_table_t::is_corrupted field.
Ported FilSpace class from 10.2 and using that on buf_page_check_corrupt(),
buf_page_decrypt_after_read(), buf_page_encrypt_before_write(),
buf_dblwr_process(), buf_read_page(), dict_stats_save_defrag_stats().
Added test cases when enrypted page could be read while doing
redo log crash recovery. Also added test case for row compressed
blobs.
btr_cur_open_at_index_side_func(),
btr_cur_open_at_rnd_pos_func(): Avoid referencing block that is
NULL.
buf_page_get_zip(): Issue error if page read fails.
buf_page_get_gen(): Use dberr_t for error detection and
do not reference bpage after we hare freed it.
buf_mark_space_corrupt(): remove bpage from LRU also when
it is encrypted.
buf_page_check_corrupt(): @return DB_SUCCESS if page has
been read and is not corrupted,
DB_PAGE_CORRUPTED if page based on checksum check is corrupted,
DB_DECRYPTION_FAILED if page post encryption checksum matches but
after decryption normal page checksum does not match. In read
case only DB_SUCCESS is possible.
buf_page_io_complete(): use dberr_t for error handling.
buf_flush_write_block_low(),
buf_read_ahead_random(),
buf_read_page_async(),
buf_read_ahead_linear(),
buf_read_ibuf_merge_pages(),
buf_read_recv_pages(),
fil_aio_wait():
Issue error if page read fails.
btr_pcur_move_to_next_page(): Do not reference page if it is
NULL.
Introduced dict_table_t::is_readable() and dict_index_t::is_readable()
that will return true if tablespace exists and pages read from
tablespace are not corrupted or page decryption failed.
Removed buf_page_t::key_version. After page decryption the
key version is not removed from page frame. For unencrypted
pages, old key_version is removed at buf_page_encrypt_before_write()
dict_stats_update_transient_for_index(),
dict_stats_update_transient()
Do not continue if table decryption failed or table
is corrupted.
dict0stats.cc: Introduced a dict_stats_report_error function
to avoid code duplication.
fil_parse_write_crypt_data():
Check that key read from redo log entry is found from
encryption plugin and if it is not, refuse to start.
PageConverter::validate(): Removed access to fil_space_t as
tablespace is not available during import.
Fixed error code on innodb.innodb test.
Merged test cased innodb-bad-key-change5 and innodb-bad-key-shutdown
to innodb-bad-key-change2. Removed innodb-bad-key-change5 test.
Decreased unnecessary complexity on some long lasting tests.
Removed fil_inc_pending_ops(), fil_decr_pending_ops(),
fil_get_first_space(), fil_get_next_space(),
fil_get_first_space_safe(), fil_get_next_space_safe()
functions.
fil_space_verify_crypt_checksum(): Fixed bug found using ASAN
where FIL_PAGE_END_LSN_OLD_CHECKSUM field was incorrectly
accessed from row compressed tables. Fixed out of page frame
bug for row compressed tables in
fil_space_verify_crypt_checksum() found using ASAN. Incorrect
function was called for compressed table.
Added new tests for discard, rename table and drop (we should allow them
even when page decryption fails). Alter table rename is not allowed.
Added test for restart with innodb-force-recovery=1 when page read on
redo-recovery cant be decrypted. Added test for corrupted table where
both page data and FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION is corrupted.
Adjusted the test case innodb_bug14147491 so that it does not anymore
expect crash. Instead table is just mostly not usable.
fil0fil.h: fil_space_acquire_low is not visible function
and fil_space_acquire and fil_space_acquire_silent are
inline functions. FilSpace class uses fil_space_acquire_low
directly.
recv_apply_hashed_log_recs() does not return anything.
2017-04-26 15:19:16 +03:00
|
|
|
UNIV_INTERN
|
2016-08-12 11:17:45 +03:00
|
|
|
fil_space_t*
|
2017-05-05 10:25:29 +03:00
|
|
|
fil_space_acquire_low(ulint id, bool silent)
|
2016-09-06 09:43:16 +03:00
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2016-08-12 11:17:45 +03:00
|
|
|
|
MDEV-12253: Buffer pool blocks are accessed after they have been freed
Problem was that bpage was referenced after it was already freed
from LRU. Fixed by adding a new variable encrypted that is
passed down to buf_page_check_corrupt() and used in
buf_page_get_gen() to stop processing page read.
This patch should also address following test failures and
bugs:
MDEV-12419: IMPORT should not look up tablespace in
PageConverter::validate(). This is now removed.
MDEV-10099: encryption.innodb_onlinealter_encryption fails
sporadically in buildbot
MDEV-11420: encryption.innodb_encryption-page-compression
failed in buildbot
MDEV-11222: encryption.encrypt_and_grep failed in buildbot on P8
Removed dict_table_t::is_encrypted and dict_table_t::ibd_file_missing
and replaced these with dict_table_t::file_unreadable. Table
ibd file is missing if fil_get_space(space_id) returns NULL
and encrypted if not. Removed dict_table_t::is_corrupted field.
Ported FilSpace class from 10.2 and using that on buf_page_check_corrupt(),
buf_page_decrypt_after_read(), buf_page_encrypt_before_write(),
buf_dblwr_process(), buf_read_page(), dict_stats_save_defrag_stats().
Added test cases when enrypted page could be read while doing
redo log crash recovery. Also added test case for row compressed
blobs.
btr_cur_open_at_index_side_func(),
btr_cur_open_at_rnd_pos_func(): Avoid referencing block that is
NULL.
buf_page_get_zip(): Issue error if page read fails.
buf_page_get_gen(): Use dberr_t for error detection and
do not reference bpage after we hare freed it.
buf_mark_space_corrupt(): remove bpage from LRU also when
it is encrypted.
buf_page_check_corrupt(): @return DB_SUCCESS if page has
been read and is not corrupted,
DB_PAGE_CORRUPTED if page based on checksum check is corrupted,
DB_DECRYPTION_FAILED if page post encryption checksum matches but
after decryption normal page checksum does not match. In read
case only DB_SUCCESS is possible.
buf_page_io_complete(): use dberr_t for error handling.
buf_flush_write_block_low(),
buf_read_ahead_random(),
buf_read_page_async(),
buf_read_ahead_linear(),
buf_read_ibuf_merge_pages(),
buf_read_recv_pages(),
fil_aio_wait():
Issue error if page read fails.
btr_pcur_move_to_next_page(): Do not reference page if it is
NULL.
Introduced dict_table_t::is_readable() and dict_index_t::is_readable()
that will return true if tablespace exists and pages read from
tablespace are not corrupted or page decryption failed.
Removed buf_page_t::key_version. After page decryption the
key version is not removed from page frame. For unencrypted
pages, old key_version is removed at buf_page_encrypt_before_write()
dict_stats_update_transient_for_index(),
dict_stats_update_transient()
Do not continue if table decryption failed or table
is corrupted.
dict0stats.cc: Introduced a dict_stats_report_error function
to avoid code duplication.
fil_parse_write_crypt_data():
Check that key read from redo log entry is found from
encryption plugin and if it is not, refuse to start.
PageConverter::validate(): Removed access to fil_space_t as
tablespace is not available during import.
Fixed error code on innodb.innodb test.
Merged test cased innodb-bad-key-change5 and innodb-bad-key-shutdown
to innodb-bad-key-change2. Removed innodb-bad-key-change5 test.
Decreased unnecessary complexity on some long lasting tests.
Removed fil_inc_pending_ops(), fil_decr_pending_ops(),
fil_get_first_space(), fil_get_next_space(),
fil_get_first_space_safe(), fil_get_next_space_safe()
functions.
fil_space_verify_crypt_checksum(): Fixed bug found using ASAN
where FIL_PAGE_END_LSN_OLD_CHECKSUM field was incorrectly
accessed from row compressed tables. Fixed out of page frame
bug for row compressed tables in
fil_space_verify_crypt_checksum() found using ASAN. Incorrect
function was called for compressed table.
Added new tests for discard, rename table and drop (we should allow them
even when page decryption fails). Alter table rename is not allowed.
Added test for restart with innodb-force-recovery=1 when page read on
redo-recovery cant be decrypted. Added test for corrupted table where
both page data and FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION is corrupted.
Adjusted the test case innodb_bug14147491 so that it does not anymore
expect crash. Instead table is just mostly not usable.
fil0fil.h: fil_space_acquire_low is not visible function
and fil_space_acquire and fil_space_acquire_silent are
inline functions. FilSpace class uses fil_space_acquire_low
directly.
recv_apply_hashed_log_recs() does not return anything.
2017-04-26 15:19:16 +03:00
|
|
|
/** Acquire a tablespace when it could be dropped concurrently.
|
|
|
|
Used by background threads that do not necessarily hold proper locks
|
|
|
|
for concurrency control.
|
|
|
|
@param[in] id tablespace ID
|
|
|
|
@return the tablespace
|
|
|
|
@retval NULL if missing or being deleted or truncated */
|
|
|
|
inline
|
|
|
|
fil_space_t*
|
2017-05-05 10:25:29 +03:00
|
|
|
fil_space_acquire(ulint id)
|
MDEV-12253: Buffer pool blocks are accessed after they have been freed
Problem was that bpage was referenced after it was already freed
from LRU. Fixed by adding a new variable encrypted that is
passed down to buf_page_check_corrupt() and used in
buf_page_get_gen() to stop processing page read.
This patch should also address following test failures and
bugs:
MDEV-12419: IMPORT should not look up tablespace in
PageConverter::validate(). This is now removed.
MDEV-10099: encryption.innodb_onlinealter_encryption fails
sporadically in buildbot
MDEV-11420: encryption.innodb_encryption-page-compression
failed in buildbot
MDEV-11222: encryption.encrypt_and_grep failed in buildbot on P8
Removed dict_table_t::is_encrypted and dict_table_t::ibd_file_missing
and replaced these with dict_table_t::file_unreadable. Table
ibd file is missing if fil_get_space(space_id) returns NULL
and encrypted if not. Removed dict_table_t::is_corrupted field.
Ported FilSpace class from 10.2 and using that on buf_page_check_corrupt(),
buf_page_decrypt_after_read(), buf_page_encrypt_before_write(),
buf_dblwr_process(), buf_read_page(), dict_stats_save_defrag_stats().
Added test cases when enrypted page could be read while doing
redo log crash recovery. Also added test case for row compressed
blobs.
btr_cur_open_at_index_side_func(),
btr_cur_open_at_rnd_pos_func(): Avoid referencing block that is
NULL.
buf_page_get_zip(): Issue error if page read fails.
buf_page_get_gen(): Use dberr_t for error detection and
do not reference bpage after we hare freed it.
buf_mark_space_corrupt(): remove bpage from LRU also when
it is encrypted.
buf_page_check_corrupt(): @return DB_SUCCESS if page has
been read and is not corrupted,
DB_PAGE_CORRUPTED if page based on checksum check is corrupted,
DB_DECRYPTION_FAILED if page post encryption checksum matches but
after decryption normal page checksum does not match. In read
case only DB_SUCCESS is possible.
buf_page_io_complete(): use dberr_t for error handling.
buf_flush_write_block_low(),
buf_read_ahead_random(),
buf_read_page_async(),
buf_read_ahead_linear(),
buf_read_ibuf_merge_pages(),
buf_read_recv_pages(),
fil_aio_wait():
Issue error if page read fails.
btr_pcur_move_to_next_page(): Do not reference page if it is
NULL.
Introduced dict_table_t::is_readable() and dict_index_t::is_readable()
that will return true if tablespace exists and pages read from
tablespace are not corrupted or page decryption failed.
Removed buf_page_t::key_version. After page decryption the
key version is not removed from page frame. For unencrypted
pages, old key_version is removed at buf_page_encrypt_before_write()
dict_stats_update_transient_for_index(),
dict_stats_update_transient()
Do not continue if table decryption failed or table
is corrupted.
dict0stats.cc: Introduced a dict_stats_report_error function
to avoid code duplication.
fil_parse_write_crypt_data():
Check that key read from redo log entry is found from
encryption plugin and if it is not, refuse to start.
PageConverter::validate(): Removed access to fil_space_t as
tablespace is not available during import.
Fixed error code on innodb.innodb test.
Merged test cased innodb-bad-key-change5 and innodb-bad-key-shutdown
to innodb-bad-key-change2. Removed innodb-bad-key-change5 test.
Decreased unnecessary complexity on some long lasting tests.
Removed fil_inc_pending_ops(), fil_decr_pending_ops(),
fil_get_first_space(), fil_get_next_space(),
fil_get_first_space_safe(), fil_get_next_space_safe()
functions.
fil_space_verify_crypt_checksum(): Fixed bug found using ASAN
where FIL_PAGE_END_LSN_OLD_CHECKSUM field was incorrectly
accessed from row compressed tables. Fixed out of page frame
bug for row compressed tables in
fil_space_verify_crypt_checksum() found using ASAN. Incorrect
function was called for compressed table.
Added new tests for discard, rename table and drop (we should allow them
even when page decryption fails). Alter table rename is not allowed.
Added test for restart with innodb-force-recovery=1 when page read on
redo-recovery cant be decrypted. Added test for corrupted table where
both page data and FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION is corrupted.
Adjusted the test case innodb_bug14147491 so that it does not anymore
expect crash. Instead table is just mostly not usable.
fil0fil.h: fil_space_acquire_low is not visible function
and fil_space_acquire and fil_space_acquire_silent are
inline functions. FilSpace class uses fil_space_acquire_low
directly.
recv_apply_hashed_log_recs() does not return anything.
2017-04-26 15:19:16 +03:00
|
|
|
{
|
2017-05-05 10:25:29 +03:00
|
|
|
return (fil_space_acquire_low(id, false));
|
MDEV-12253: Buffer pool blocks are accessed after they have been freed
Problem was that bpage was referenced after it was already freed
from LRU. Fixed by adding a new variable encrypted that is
passed down to buf_page_check_corrupt() and used in
buf_page_get_gen() to stop processing page read.
This patch should also address following test failures and
bugs:
MDEV-12419: IMPORT should not look up tablespace in
PageConverter::validate(). This is now removed.
MDEV-10099: encryption.innodb_onlinealter_encryption fails
sporadically in buildbot
MDEV-11420: encryption.innodb_encryption-page-compression
failed in buildbot
MDEV-11222: encryption.encrypt_and_grep failed in buildbot on P8
Removed dict_table_t::is_encrypted and dict_table_t::ibd_file_missing
and replaced these with dict_table_t::file_unreadable. Table
ibd file is missing if fil_get_space(space_id) returns NULL
and encrypted if not. Removed dict_table_t::is_corrupted field.
Ported FilSpace class from 10.2 and using that on buf_page_check_corrupt(),
buf_page_decrypt_after_read(), buf_page_encrypt_before_write(),
buf_dblwr_process(), buf_read_page(), dict_stats_save_defrag_stats().
Added test cases when enrypted page could be read while doing
redo log crash recovery. Also added test case for row compressed
blobs.
btr_cur_open_at_index_side_func(),
btr_cur_open_at_rnd_pos_func(): Avoid referencing block that is
NULL.
buf_page_get_zip(): Issue error if page read fails.
buf_page_get_gen(): Use dberr_t for error detection and
do not reference bpage after we hare freed it.
buf_mark_space_corrupt(): remove bpage from LRU also when
it is encrypted.
buf_page_check_corrupt(): @return DB_SUCCESS if page has
been read and is not corrupted,
DB_PAGE_CORRUPTED if page based on checksum check is corrupted,
DB_DECRYPTION_FAILED if page post encryption checksum matches but
after decryption normal page checksum does not match. In read
case only DB_SUCCESS is possible.
buf_page_io_complete(): use dberr_t for error handling.
buf_flush_write_block_low(),
buf_read_ahead_random(),
buf_read_page_async(),
buf_read_ahead_linear(),
buf_read_ibuf_merge_pages(),
buf_read_recv_pages(),
fil_aio_wait():
Issue error if page read fails.
btr_pcur_move_to_next_page(): Do not reference page if it is
NULL.
Introduced dict_table_t::is_readable() and dict_index_t::is_readable()
that will return true if tablespace exists and pages read from
tablespace are not corrupted or page decryption failed.
Removed buf_page_t::key_version. After page decryption the
key version is not removed from page frame. For unencrypted
pages, old key_version is removed at buf_page_encrypt_before_write()
dict_stats_update_transient_for_index(),
dict_stats_update_transient()
Do not continue if table decryption failed or table
is corrupted.
dict0stats.cc: Introduced a dict_stats_report_error function
to avoid code duplication.
fil_parse_write_crypt_data():
Check that key read from redo log entry is found from
encryption plugin and if it is not, refuse to start.
PageConverter::validate(): Removed access to fil_space_t as
tablespace is not available during import.
Fixed error code on innodb.innodb test.
Merged test cased innodb-bad-key-change5 and innodb-bad-key-shutdown
to innodb-bad-key-change2. Removed innodb-bad-key-change5 test.
Decreased unnecessary complexity on some long lasting tests.
Removed fil_inc_pending_ops(), fil_decr_pending_ops(),
fil_get_first_space(), fil_get_next_space(),
fil_get_first_space_safe(), fil_get_next_space_safe()
functions.
fil_space_verify_crypt_checksum(): Fixed bug found using ASAN
where FIL_PAGE_END_LSN_OLD_CHECKSUM field was incorrectly
accessed from row compressed tables. Fixed out of page frame
bug for row compressed tables in
fil_space_verify_crypt_checksum() found using ASAN. Incorrect
function was called for compressed table.
Added new tests for discard, rename table and drop (we should allow them
even when page decryption fails). Alter table rename is not allowed.
Added test for restart with innodb-force-recovery=1 when page read on
redo-recovery cant be decrypted. Added test for corrupted table where
both page data and FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION is corrupted.
Adjusted the test case innodb_bug14147491 so that it does not anymore
expect crash. Instead table is just mostly not usable.
fil0fil.h: fil_space_acquire_low is not visible function
and fil_space_acquire and fil_space_acquire_silent are
inline functions. FilSpace class uses fil_space_acquire_low
directly.
recv_apply_hashed_log_recs() does not return anything.
2017-04-26 15:19:16 +03:00
|
|
|
}
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** Acquire a tablespace that may not exist.
|
|
|
|
Used by background threads that do not necessarily hold proper locks
|
|
|
|
for concurrency control.
|
|
|
|
@param[in] id tablespace ID
|
2017-04-03 19:36:54 +03:00
|
|
|
@return the tablespace
|
|
|
|
@retval NULL if missing or being deleted */
|
MDEV-12253: Buffer pool blocks are accessed after they have been freed
Problem was that bpage was referenced after it was already freed
from LRU. Fixed by adding a new variable encrypted that is
passed down to buf_page_check_corrupt() and used in
buf_page_get_gen() to stop processing page read.
This patch should also address following test failures and
bugs:
MDEV-12419: IMPORT should not look up tablespace in
PageConverter::validate(). This is now removed.
MDEV-10099: encryption.innodb_onlinealter_encryption fails
sporadically in buildbot
MDEV-11420: encryption.innodb_encryption-page-compression
failed in buildbot
MDEV-11222: encryption.encrypt_and_grep failed in buildbot on P8
Removed dict_table_t::is_encrypted and dict_table_t::ibd_file_missing
and replaced these with dict_table_t::file_unreadable. Table
ibd file is missing if fil_get_space(space_id) returns NULL
and encrypted if not. Removed dict_table_t::is_corrupted field.
Ported FilSpace class from 10.2 and using that on buf_page_check_corrupt(),
buf_page_decrypt_after_read(), buf_page_encrypt_before_write(),
buf_dblwr_process(), buf_read_page(), dict_stats_save_defrag_stats().
Added test cases when enrypted page could be read while doing
redo log crash recovery. Also added test case for row compressed
blobs.
btr_cur_open_at_index_side_func(),
btr_cur_open_at_rnd_pos_func(): Avoid referencing block that is
NULL.
buf_page_get_zip(): Issue error if page read fails.
buf_page_get_gen(): Use dberr_t for error detection and
do not reference bpage after we hare freed it.
buf_mark_space_corrupt(): remove bpage from LRU also when
it is encrypted.
buf_page_check_corrupt(): @return DB_SUCCESS if page has
been read and is not corrupted,
DB_PAGE_CORRUPTED if page based on checksum check is corrupted,
DB_DECRYPTION_FAILED if page post encryption checksum matches but
after decryption normal page checksum does not match. In read
case only DB_SUCCESS is possible.
buf_page_io_complete(): use dberr_t for error handling.
buf_flush_write_block_low(),
buf_read_ahead_random(),
buf_read_page_async(),
buf_read_ahead_linear(),
buf_read_ibuf_merge_pages(),
buf_read_recv_pages(),
fil_aio_wait():
Issue error if page read fails.
btr_pcur_move_to_next_page(): Do not reference page if it is
NULL.
Introduced dict_table_t::is_readable() and dict_index_t::is_readable()
that will return true if tablespace exists and pages read from
tablespace are not corrupted or page decryption failed.
Removed buf_page_t::key_version. After page decryption the
key version is not removed from page frame. For unencrypted
pages, old key_version is removed at buf_page_encrypt_before_write()
dict_stats_update_transient_for_index(),
dict_stats_update_transient()
Do not continue if table decryption failed or table
is corrupted.
dict0stats.cc: Introduced a dict_stats_report_error function
to avoid code duplication.
fil_parse_write_crypt_data():
Check that key read from redo log entry is found from
encryption plugin and if it is not, refuse to start.
PageConverter::validate(): Removed access to fil_space_t as
tablespace is not available during import.
Fixed error code on innodb.innodb test.
Merged test cased innodb-bad-key-change5 and innodb-bad-key-shutdown
to innodb-bad-key-change2. Removed innodb-bad-key-change5 test.
Decreased unnecessary complexity on some long lasting tests.
Removed fil_inc_pending_ops(), fil_decr_pending_ops(),
fil_get_first_space(), fil_get_next_space(),
fil_get_first_space_safe(), fil_get_next_space_safe()
functions.
fil_space_verify_crypt_checksum(): Fixed bug found using ASAN
where FIL_PAGE_END_LSN_OLD_CHECKSUM field was incorrectly
accessed from row compressed tables. Fixed out of page frame
bug for row compressed tables in
fil_space_verify_crypt_checksum() found using ASAN. Incorrect
function was called for compressed table.
Added new tests for discard, rename table and drop (we should allow them
even when page decryption fails). Alter table rename is not allowed.
Added test for restart with innodb-force-recovery=1 when page read on
redo-recovery cant be decrypted. Added test for corrupted table where
both page data and FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION is corrupted.
Adjusted the test case innodb_bug14147491 so that it does not anymore
expect crash. Instead table is just mostly not usable.
fil0fil.h: fil_space_acquire_low is not visible function
and fil_space_acquire and fil_space_acquire_silent are
inline functions. FilSpace class uses fil_space_acquire_low
directly.
recv_apply_hashed_log_recs() does not return anything.
2017-04-26 15:19:16 +03:00
|
|
|
inline
|
2016-08-12 11:17:45 +03:00
|
|
|
fil_space_t*
|
2017-04-03 19:36:54 +03:00
|
|
|
fil_space_acquire_silent(ulint id)
|
MDEV-12253: Buffer pool blocks are accessed after they have been freed
Problem was that bpage was referenced after it was already freed
from LRU. Fixed by adding a new variable encrypted that is
passed down to buf_page_check_corrupt() and used in
buf_page_get_gen() to stop processing page read.
This patch should also address following test failures and
bugs:
MDEV-12419: IMPORT should not look up tablespace in
PageConverter::validate(). This is now removed.
MDEV-10099: encryption.innodb_onlinealter_encryption fails
sporadically in buildbot
MDEV-11420: encryption.innodb_encryption-page-compression
failed in buildbot
MDEV-11222: encryption.encrypt_and_grep failed in buildbot on P8
Removed dict_table_t::is_encrypted and dict_table_t::ibd_file_missing
and replaced these with dict_table_t::file_unreadable. Table
ibd file is missing if fil_get_space(space_id) returns NULL
and encrypted if not. Removed dict_table_t::is_corrupted field.
Ported FilSpace class from 10.2 and using that on buf_page_check_corrupt(),
buf_page_decrypt_after_read(), buf_page_encrypt_before_write(),
buf_dblwr_process(), buf_read_page(), dict_stats_save_defrag_stats().
Added test cases when enrypted page could be read while doing
redo log crash recovery. Also added test case for row compressed
blobs.
btr_cur_open_at_index_side_func(),
btr_cur_open_at_rnd_pos_func(): Avoid referencing block that is
NULL.
buf_page_get_zip(): Issue error if page read fails.
buf_page_get_gen(): Use dberr_t for error detection and
do not reference bpage after we hare freed it.
buf_mark_space_corrupt(): remove bpage from LRU also when
it is encrypted.
buf_page_check_corrupt(): @return DB_SUCCESS if page has
been read and is not corrupted,
DB_PAGE_CORRUPTED if page based on checksum check is corrupted,
DB_DECRYPTION_FAILED if page post encryption checksum matches but
after decryption normal page checksum does not match. In read
case only DB_SUCCESS is possible.
buf_page_io_complete(): use dberr_t for error handling.
buf_flush_write_block_low(),
buf_read_ahead_random(),
buf_read_page_async(),
buf_read_ahead_linear(),
buf_read_ibuf_merge_pages(),
buf_read_recv_pages(),
fil_aio_wait():
Issue error if page read fails.
btr_pcur_move_to_next_page(): Do not reference page if it is
NULL.
Introduced dict_table_t::is_readable() and dict_index_t::is_readable()
that will return true if tablespace exists and pages read from
tablespace are not corrupted or page decryption failed.
Removed buf_page_t::key_version. After page decryption the
key version is not removed from page frame. For unencrypted
pages, old key_version is removed at buf_page_encrypt_before_write()
dict_stats_update_transient_for_index(),
dict_stats_update_transient()
Do not continue if table decryption failed or table
is corrupted.
dict0stats.cc: Introduced a dict_stats_report_error function
to avoid code duplication.
fil_parse_write_crypt_data():
Check that key read from redo log entry is found from
encryption plugin and if it is not, refuse to start.
PageConverter::validate(): Removed access to fil_space_t as
tablespace is not available during import.
Fixed error code on innodb.innodb test.
Merged test cased innodb-bad-key-change5 and innodb-bad-key-shutdown
to innodb-bad-key-change2. Removed innodb-bad-key-change5 test.
Decreased unnecessary complexity on some long lasting tests.
Removed fil_inc_pending_ops(), fil_decr_pending_ops(),
fil_get_first_space(), fil_get_next_space(),
fil_get_first_space_safe(), fil_get_next_space_safe()
functions.
fil_space_verify_crypt_checksum(): Fixed bug found using ASAN
where FIL_PAGE_END_LSN_OLD_CHECKSUM field was incorrectly
accessed from row compressed tables. Fixed out of page frame
bug for row compressed tables in
fil_space_verify_crypt_checksum() found using ASAN. Incorrect
function was called for compressed table.
Added new tests for discard, rename table and drop (we should allow them
even when page decryption fails). Alter table rename is not allowed.
Added test for restart with innodb-force-recovery=1 when page read on
redo-recovery cant be decrypted. Added test for corrupted table where
both page data and FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION is corrupted.
Adjusted the test case innodb_bug14147491 so that it does not anymore
expect crash. Instead table is just mostly not usable.
fil0fil.h: fil_space_acquire_low is not visible function
and fil_space_acquire and fil_space_acquire_silent are
inline functions. FilSpace class uses fil_space_acquire_low
directly.
recv_apply_hashed_log_recs() does not return anything.
2017-04-26 15:19:16 +03:00
|
|
|
{
|
2017-05-05 10:25:29 +03:00
|
|
|
return (fil_space_acquire_low(id, true));
|
MDEV-12253: Buffer pool blocks are accessed after they have been freed
Problem was that bpage was referenced after it was already freed
from LRU. Fixed by adding a new variable encrypted that is
passed down to buf_page_check_corrupt() and used in
buf_page_get_gen() to stop processing page read.
This patch should also address following test failures and
bugs:
MDEV-12419: IMPORT should not look up tablespace in
PageConverter::validate(). This is now removed.
MDEV-10099: encryption.innodb_onlinealter_encryption fails
sporadically in buildbot
MDEV-11420: encryption.innodb_encryption-page-compression
failed in buildbot
MDEV-11222: encryption.encrypt_and_grep failed in buildbot on P8
Removed dict_table_t::is_encrypted and dict_table_t::ibd_file_missing
and replaced these with dict_table_t::file_unreadable. Table
ibd file is missing if fil_get_space(space_id) returns NULL
and encrypted if not. Removed dict_table_t::is_corrupted field.
Ported FilSpace class from 10.2 and using that on buf_page_check_corrupt(),
buf_page_decrypt_after_read(), buf_page_encrypt_before_write(),
buf_dblwr_process(), buf_read_page(), dict_stats_save_defrag_stats().
Added test cases when enrypted page could be read while doing
redo log crash recovery. Also added test case for row compressed
blobs.
btr_cur_open_at_index_side_func(),
btr_cur_open_at_rnd_pos_func(): Avoid referencing block that is
NULL.
buf_page_get_zip(): Issue error if page read fails.
buf_page_get_gen(): Use dberr_t for error detection and
do not reference bpage after we hare freed it.
buf_mark_space_corrupt(): remove bpage from LRU also when
it is encrypted.
buf_page_check_corrupt(): @return DB_SUCCESS if page has
been read and is not corrupted,
DB_PAGE_CORRUPTED if page based on checksum check is corrupted,
DB_DECRYPTION_FAILED if page post encryption checksum matches but
after decryption normal page checksum does not match. In read
case only DB_SUCCESS is possible.
buf_page_io_complete(): use dberr_t for error handling.
buf_flush_write_block_low(),
buf_read_ahead_random(),
buf_read_page_async(),
buf_read_ahead_linear(),
buf_read_ibuf_merge_pages(),
buf_read_recv_pages(),
fil_aio_wait():
Issue error if page read fails.
btr_pcur_move_to_next_page(): Do not reference page if it is
NULL.
Introduced dict_table_t::is_readable() and dict_index_t::is_readable()
that will return true if tablespace exists and pages read from
tablespace are not corrupted or page decryption failed.
Removed buf_page_t::key_version. After page decryption the
key version is not removed from page frame. For unencrypted
pages, old key_version is removed at buf_page_encrypt_before_write()
dict_stats_update_transient_for_index(),
dict_stats_update_transient()
Do not continue if table decryption failed or table
is corrupted.
dict0stats.cc: Introduced a dict_stats_report_error function
to avoid code duplication.
fil_parse_write_crypt_data():
Check that key read from redo log entry is found from
encryption plugin and if it is not, refuse to start.
PageConverter::validate(): Removed access to fil_space_t as
tablespace is not available during import.
Fixed error code on innodb.innodb test.
Merged test cased innodb-bad-key-change5 and innodb-bad-key-shutdown
to innodb-bad-key-change2. Removed innodb-bad-key-change5 test.
Decreased unnecessary complexity on some long lasting tests.
Removed fil_inc_pending_ops(), fil_decr_pending_ops(),
fil_get_first_space(), fil_get_next_space(),
fil_get_first_space_safe(), fil_get_next_space_safe()
functions.
fil_space_verify_crypt_checksum(): Fixed bug found using ASAN
where FIL_PAGE_END_LSN_OLD_CHECKSUM field was incorrectly
accessed from row compressed tables. Fixed out of page frame
bug for row compressed tables in
fil_space_verify_crypt_checksum() found using ASAN. Incorrect
function was called for compressed table.
Added new tests for discard, rename table and drop (we should allow them
even when page decryption fails). Alter table rename is not allowed.
Added test for restart with innodb-force-recovery=1 when page read on
redo-recovery cant be decrypted. Added test for corrupted table where
both page data and FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION is corrupted.
Adjusted the test case innodb_bug14147491 so that it does not anymore
expect crash. Instead table is just mostly not usable.
fil0fil.h: fil_space_acquire_low is not visible function
and fil_space_acquire and fil_space_acquire_silent are
inline functions. FilSpace class uses fil_space_acquire_low
directly.
recv_apply_hashed_log_recs() does not return anything.
2017-04-26 15:19:16 +03:00
|
|
|
}
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** Release a tablespace acquired with fil_space_acquire().
|
|
|
|
@param[in,out] space tablespace to release */
|
|
|
|
void
|
2017-04-03 19:36:54 +03:00
|
|
|
fil_space_release(fil_space_t* space);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2017-04-28 12:23:35 +03:00
|
|
|
/** Acquire a tablespace for reading or writing a block,
|
|
|
|
when it could be dropped concurrently.
|
|
|
|
@param[in] id tablespace ID
|
|
|
|
@return the tablespace
|
|
|
|
@retval NULL if missing */
|
|
|
|
fil_space_t*
|
|
|
|
fil_space_acquire_for_io(ulint id);
|
|
|
|
|
|
|
|
/** Release a tablespace acquired with fil_space_acquire_for_io().
|
|
|
|
@param[in,out] space tablespace to release */
|
|
|
|
void
|
|
|
|
fil_space_release_for_io(fil_space_t* space);
|
|
|
|
|
2017-03-14 12:56:01 +02:00
|
|
|
/** Return the next fil_space_t.
|
|
|
|
Once started, the caller must keep calling this until it returns NULL.
|
|
|
|
fil_space_acquire() and fil_space_release() are invoked here which
|
|
|
|
blocks a concurrent operation from dropping the tablespace.
|
|
|
|
@param[in,out] prev_space Pointer to the previous fil_space_t.
|
|
|
|
If NULL, use the first fil_space_t on fil_system->space_list.
|
|
|
|
@return pointer to the next fil_space_t.
|
|
|
|
@retval NULL if this was the last */
|
|
|
|
fil_space_t*
|
|
|
|
fil_space_next(
|
|
|
|
fil_space_t* prev_space)
|
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
|
|
|
|
|
|
|
/** Return the next fil_space_t from key rotation list.
|
|
|
|
Once started, the caller must keep calling this until it returns NULL.
|
|
|
|
fil_space_acquire() and fil_space_release() are invoked here which
|
|
|
|
blocks a concurrent operation from dropping the tablespace.
|
|
|
|
@param[in,out] prev_space Pointer to the previous fil_space_t.
|
|
|
|
If NULL, use the first fil_space_t on fil_system->space_list.
|
|
|
|
@return pointer to the next fil_space_t.
|
|
|
|
@retval NULL if this was the last*/
|
|
|
|
fil_space_t*
|
|
|
|
fil_space_keyrotate_next(
|
|
|
|
fil_space_t* prev_space)
|
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** Wrapper with reference-counting for a fil_space_t. */
|
|
|
|
class FilSpace
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/** Default constructor: Use this when reference counting
|
|
|
|
is done outside this wrapper. */
|
|
|
|
FilSpace() : m_space(NULL) {}
|
|
|
|
|
|
|
|
/** Constructor: Look up the tablespace and increment the
|
2017-04-04 07:59:25 +03:00
|
|
|
reference count if found.
|
MDEV-12253: Buffer pool blocks are accessed after they have been freed
Problem was that bpage was referenced after it was already freed
from LRU. Fixed by adding a new variable encrypted that is
passed down to buf_page_check_corrupt() and used in
buf_page_get_gen() to stop processing page read.
This patch should also address following test failures and
bugs:
MDEV-12419: IMPORT should not look up tablespace in
PageConverter::validate(). This is now removed.
MDEV-10099: encryption.innodb_onlinealter_encryption fails
sporadically in buildbot
MDEV-11420: encryption.innodb_encryption-page-compression
failed in buildbot
MDEV-11222: encryption.encrypt_and_grep failed in buildbot on P8
Removed dict_table_t::is_encrypted and dict_table_t::ibd_file_missing
and replaced these with dict_table_t::file_unreadable. Table
ibd file is missing if fil_get_space(space_id) returns NULL
and encrypted if not. Removed dict_table_t::is_corrupted field.
Ported FilSpace class from 10.2 and using that on buf_page_check_corrupt(),
buf_page_decrypt_after_read(), buf_page_encrypt_before_write(),
buf_dblwr_process(), buf_read_page(), dict_stats_save_defrag_stats().
Added test cases when enrypted page could be read while doing
redo log crash recovery. Also added test case for row compressed
blobs.
btr_cur_open_at_index_side_func(),
btr_cur_open_at_rnd_pos_func(): Avoid referencing block that is
NULL.
buf_page_get_zip(): Issue error if page read fails.
buf_page_get_gen(): Use dberr_t for error detection and
do not reference bpage after we hare freed it.
buf_mark_space_corrupt(): remove bpage from LRU also when
it is encrypted.
buf_page_check_corrupt(): @return DB_SUCCESS if page has
been read and is not corrupted,
DB_PAGE_CORRUPTED if page based on checksum check is corrupted,
DB_DECRYPTION_FAILED if page post encryption checksum matches but
after decryption normal page checksum does not match. In read
case only DB_SUCCESS is possible.
buf_page_io_complete(): use dberr_t for error handling.
buf_flush_write_block_low(),
buf_read_ahead_random(),
buf_read_page_async(),
buf_read_ahead_linear(),
buf_read_ibuf_merge_pages(),
buf_read_recv_pages(),
fil_aio_wait():
Issue error if page read fails.
btr_pcur_move_to_next_page(): Do not reference page if it is
NULL.
Introduced dict_table_t::is_readable() and dict_index_t::is_readable()
that will return true if tablespace exists and pages read from
tablespace are not corrupted or page decryption failed.
Removed buf_page_t::key_version. After page decryption the
key version is not removed from page frame. For unencrypted
pages, old key_version is removed at buf_page_encrypt_before_write()
dict_stats_update_transient_for_index(),
dict_stats_update_transient()
Do not continue if table decryption failed or table
is corrupted.
dict0stats.cc: Introduced a dict_stats_report_error function
to avoid code duplication.
fil_parse_write_crypt_data():
Check that key read from redo log entry is found from
encryption plugin and if it is not, refuse to start.
PageConverter::validate(): Removed access to fil_space_t as
tablespace is not available during import.
Fixed error code on innodb.innodb test.
Merged test cased innodb-bad-key-change5 and innodb-bad-key-shutdown
to innodb-bad-key-change2. Removed innodb-bad-key-change5 test.
Decreased unnecessary complexity on some long lasting tests.
Removed fil_inc_pending_ops(), fil_decr_pending_ops(),
fil_get_first_space(), fil_get_next_space(),
fil_get_first_space_safe(), fil_get_next_space_safe()
functions.
fil_space_verify_crypt_checksum(): Fixed bug found using ASAN
where FIL_PAGE_END_LSN_OLD_CHECKSUM field was incorrectly
accessed from row compressed tables. Fixed out of page frame
bug for row compressed tables in
fil_space_verify_crypt_checksum() found using ASAN. Incorrect
function was called for compressed table.
Added new tests for discard, rename table and drop (we should allow them
even when page decryption fails). Alter table rename is not allowed.
Added test for restart with innodb-force-recovery=1 when page read on
redo-recovery cant be decrypted. Added test for corrupted table where
both page data and FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION is corrupted.
Adjusted the test case innodb_bug14147491 so that it does not anymore
expect crash. Instead table is just mostly not usable.
fil0fil.h: fil_space_acquire_low is not visible function
and fil_space_acquire and fil_space_acquire_silent are
inline functions. FilSpace class uses fil_space_acquire_low
directly.
recv_apply_hashed_log_recs() does not return anything.
2017-04-26 15:19:16 +03:00
|
|
|
@param[in] space_id tablespace ID
|
2017-05-05 10:25:29 +03:00
|
|
|
@param[in] silent whether not to display errors */
|
|
|
|
explicit FilSpace(ulint space_id, bool silent = false)
|
|
|
|
: m_space(fil_space_acquire_low(space_id, silent)) {}
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** Assignment operator: This assumes that fil_space_acquire()
|
|
|
|
has already been done for the fil_space_t. The caller must
|
|
|
|
assign NULL if it calls fil_space_release().
|
|
|
|
@param[in] space tablespace to assign */
|
2017-04-04 07:59:25 +03:00
|
|
|
class FilSpace& operator=(fil_space_t* space)
|
2016-08-12 11:17:45 +03:00
|
|
|
{
|
|
|
|
/* fil_space_acquire() must have been invoked. */
|
|
|
|
ut_ad(space == NULL || space->n_pending_ops > 0);
|
|
|
|
m_space = space;
|
|
|
|
return(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Destructor - Decrement the reference count if a fil_space_t
|
|
|
|
is still assigned. */
|
|
|
|
~FilSpace()
|
|
|
|
{
|
|
|
|
if (m_space != NULL) {
|
|
|
|
fil_space_release(m_space);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Implicit type conversion
|
|
|
|
@return the wrapped object */
|
|
|
|
operator const fil_space_t*() const
|
|
|
|
{
|
|
|
|
return(m_space);
|
|
|
|
}
|
|
|
|
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
/** Member accessor
|
|
|
|
@return the wrapped object */
|
|
|
|
const fil_space_t* operator->() const
|
|
|
|
{
|
|
|
|
return(m_space);
|
|
|
|
}
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** Explicit type conversion
|
|
|
|
@return the wrapped object */
|
|
|
|
const fil_space_t* operator()() const
|
|
|
|
{
|
|
|
|
return(m_space);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
/** The wrapped pointer */
|
|
|
|
fil_space_t* m_space;
|
|
|
|
};
|
|
|
|
|
|
|
|
/********************************************************//**
|
|
|
|
Creates the database directory for a table if it does not exist yet. */
|
|
|
|
void
|
|
|
|
fil_create_directory_for_tablename(
|
|
|
|
/*===============================*/
|
|
|
|
const char* name); /*!< in: name in the standard
|
|
|
|
'databasename/tablename' format */
|
2018-09-06 10:32:49 +03:00
|
|
|
/** Write redo log for renaming a file.
|
|
|
|
@param[in] space_id tablespace id
|
|
|
|
@param[in] old_name tablespace file name
|
|
|
|
@param[in] new_name tablespace file name after renaming */
|
|
|
|
void
|
|
|
|
fil_name_write_rename(
|
|
|
|
ulint space_id,
|
|
|
|
const char* old_name,
|
|
|
|
const char* new_name);
|
2016-08-12 11:17:45 +03:00
|
|
|
/********************************************************//**
|
|
|
|
Recreates table indexes by applying
|
|
|
|
TRUNCATE log record during recovery.
|
|
|
|
@return DB_SUCCESS or error code */
|
|
|
|
dberr_t
|
|
|
|
fil_recreate_table(
|
|
|
|
/*===============*/
|
|
|
|
ulint space_id, /*!< in: space id */
|
|
|
|
ulint format_flags, /*!< in: page format */
|
|
|
|
ulint flags, /*!< in: tablespace flags */
|
|
|
|
const char* name, /*!< in: table name */
|
|
|
|
truncate_t& truncate); /*!< in/out: The information of
|
|
|
|
TRUNCATE log record */
|
|
|
|
/********************************************************//**
|
|
|
|
Recreates the tablespace and table indexes by applying
|
|
|
|
TRUNCATE log record during recovery.
|
|
|
|
@return DB_SUCCESS or error code */
|
|
|
|
dberr_t
|
|
|
|
fil_recreate_tablespace(
|
|
|
|
/*====================*/
|
|
|
|
ulint space_id, /*!< in: space id */
|
|
|
|
ulint format_flags, /*!< in: page format */
|
|
|
|
ulint flags, /*!< in: tablespace flags */
|
|
|
|
const char* name, /*!< in: table name */
|
|
|
|
truncate_t& truncate, /*!< in/out: The information of
|
|
|
|
TRUNCATE log record */
|
|
|
|
lsn_t recv_lsn); /*!< in: the end LSN of
|
|
|
|
the log record */
|
|
|
|
/** Replay a file rename operation if possible.
|
|
|
|
@param[in] space_id tablespace identifier
|
|
|
|
@param[in] first_page_no first page number in the file
|
|
|
|
@param[in] name old file name
|
|
|
|
@param[in] new_name new file name
|
|
|
|
@return whether the operation was successfully applied
|
|
|
|
(the name did not exist, or new_name did not exist and
|
|
|
|
name was successfully renamed to new_name) */
|
|
|
|
bool
|
|
|
|
fil_op_replay_rename(
|
|
|
|
ulint space_id,
|
|
|
|
ulint first_page_no,
|
|
|
|
const char* name,
|
|
|
|
const char* new_name)
|
2016-09-06 09:43:16 +03:00
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2016-08-12 11:17:45 +03:00
|
|
|
|
2017-04-25 18:25:57 +03:00
|
|
|
/** Determine whether a table can be accessed in operations that are
|
|
|
|
not (necessarily) protected by meta-data locks.
|
|
|
|
(Rollback would generally be protected, but rollback of
|
|
|
|
FOREIGN KEY CASCADE/SET NULL is not protected by meta-data locks
|
MDEV-13564 Mariabackup does not work with TRUNCATE
Implement undo tablespace truncation via normal redo logging.
Implement TRUNCATE TABLE as a combination of RENAME to #sql-ib name,
CREATE, and DROP.
Note: Orphan #sql-ib*.ibd may be left behind if MariaDB Server 10.2
is killed before the DROP operation is committed. If MariaDB Server 10.2
is killed during TRUNCATE, it is also possible that the old table
was renamed to #sql-ib*.ibd but the data dictionary will refer to the
table using the original name.
In MariaDB Server 10.3, RENAME inside InnoDB is transactional,
and #sql-* tables will be dropped on startup. So, this new TRUNCATE
will be fully crash-safe in 10.3.
ha_mroonga::wrapper_truncate(): Pass table options to the underlying
storage engine, now that ha_innobase::truncate() will need them.
rpl_slave_state::truncate_state_table(): Before truncating
mysql.gtid_slave_pos, evict any cached table handles from
the table definition cache, so that there will be no stale
references to the old table after truncating.
== TRUNCATE TABLE ==
WL#6501 in MySQL 5.7 introduced separate log files for implementing
atomic and crash-safe TRUNCATE TABLE, instead of using the InnoDB
undo and redo log. Some convoluted logic was added to the InnoDB
crash recovery, and some extra synchronization (including a redo log
checkpoint) was introduced to make this work. This synchronization
has caused performance problems and race conditions, and the extra
log files cannot be copied or applied by external backup programs.
In order to support crash-upgrade from MariaDB 10.2, we will keep
the logic for parsing and applying the extra log files, but we will
no longer generate those files in TRUNCATE TABLE.
A prerequisite for crash-safe TRUNCATE is a crash-safe RENAME TABLE
(with full redo and undo logging and proper rollback). This will
be implemented in MDEV-14717.
ha_innobase::truncate(): Invoke RENAME, create(), delete_table().
Because RENAME cannot be fully rolled back before MariaDB 10.3
due to missing undo logging, add some explicit rename-back in
case the operation fails.
ha_innobase::delete(): Introduce a variant that takes sqlcom as
a parameter. In TRUNCATE TABLE, we do not want to touch any
FOREIGN KEY constraints.
ha_innobase::create(): Add the parameters file_per_table, trx.
In TRUNCATE, the new table must be created in the same transaction
that renames the old table.
create_table_info_t::create_table_info_t(): Add the parameters
file_per_table, trx.
row_drop_table_for_mysql(): Replace a bool parameter with sqlcom.
row_drop_table_after_create_fail(): New function, wrapping
row_drop_table_for_mysql().
dict_truncate_index_tree_in_mem(), fil_truncate_tablespace(),
fil_prepare_for_truncate(), fil_reinit_space_header_for_table(),
row_truncate_table_for_mysql(), TruncateLogger,
row_truncate_prepare(), row_truncate_rollback(),
row_truncate_complete(), row_truncate_fts(),
row_truncate_update_system_tables(),
row_truncate_foreign_key_checks(), row_truncate_sanity_checks():
Remove.
row_upd_check_references_constraints(): Remove a check for
TRUNCATE, now that the table is no longer truncated in place.
The new test innodb.truncate_foreign uses DEBUG_SYNC to cover some
race-condition like scenarios. The test innodb-innodb.truncate does
not use any synchronization.
We add a redo log subformat to indicate backup-friendly format.
MariaDB 10.4 will remove support for the old TRUNCATE logging,
so crash-upgrade from old 10.2 or 10.3 to 10.4 will involve
limitations.
== Undo tablespace truncation ==
MySQL 5.7 implements undo tablespace truncation. It is only
possible when innodb_undo_tablespaces is set to at least 2.
The logging is implemented similar to the WL#6501 TRUNCATE,
that is, using separate log files and a redo log checkpoint.
We can simply implement undo tablespace truncation within
a single mini-transaction that reinitializes the undo log
tablespace file. Unfortunately, due to the redo log format
of some operations, currently, the total redo log written by
undo tablespace truncation will be more than the combined size
of the truncated undo tablespace. It should be acceptable
to have a little more than 1 megabyte of log in a single
mini-transaction. This will be fixed in MDEV-17138 in
MariaDB Server 10.4.
recv_sys_t: Add truncated_undo_spaces[] to remember for which undo
tablespaces a MLOG_FILE_CREATE2 record was seen.
namespace undo: Remove some unnecessary declarations.
fil_space_t::is_being_truncated: Document that this flag now
only applies to undo tablespaces. Remove some references.
fil_space_t::is_stopping(): Do not refer to is_being_truncated.
This check is for tablespaces of tables. Potentially used
tablespaces are never truncated any more.
buf_dblwr_process(): Suppress the out-of-bounds warning
for undo tablespaces.
fil_truncate_log(): Write a MLOG_FILE_CREATE2 with a nonzero
page number (new size of the tablespace in pages) to inform
crash recovery that the undo tablespace size has been reduced.
fil_op_write_log(): Relax assertions, so that MLOG_FILE_CREATE2
can be written for undo tablespaces (without .ibd file suffix)
for a nonzero page number.
os_file_truncate(): Add the parameter allow_shrink=false
so that undo tablespaces can actually be shrunk using this function.
fil_name_parse(): For undo tablespace truncation,
buffer MLOG_FILE_CREATE2 in truncated_undo_spaces[].
recv_read_in_area(): Avoid reading pages for which no redo log
records remain buffered, after recv_addr_trim() removed them.
trx_rseg_header_create(): Add a FIXME comment that we could write
much less redo log.
trx_undo_truncate_tablespace(): Reinitialize the undo tablespace
in a single mini-transaction, which will be flushed to the redo log
before the file size is trimmed.
recv_addr_trim(): Discard any redo logs for pages that were
logged after the new end of a file, before the truncation LSN.
If the rec_list becomes empty, reduce n_addrs. After removing
any affected records, actually truncate the file.
recv_apply_hashed_log_recs(): Invoke recv_addr_trim() right before
applying any log records. The undo tablespace files must be open
at this point.
buf_flush_or_remove_pages(), buf_flush_dirty_pages(),
buf_LRU_flush_or_remove_pages(): Add a parameter for specifying
the number of the first page to flush or remove (default 0).
trx_purge_initiate_truncate(): Remove the log checkpoints, the
extra logging, and some unnecessary crash points. Merge the code
from trx_undo_truncate_tablespace(). First, flush all to-be-discarded
pages (beyond the new end of the file), then trim the space->size
to make the page allocation deterministic. At the only remaining
crash injection point, flush the redo log, so that the recovery
can be tested.
2018-08-28 13:43:06 +03:00
|
|
|
but only by InnoDB table locks, which may be broken by
|
|
|
|
lock_remove_all_on_table().)
|
2017-04-25 18:25:57 +03:00
|
|
|
@param[in] table persistent table
|
|
|
|
checked @return whether the table is accessible */
|
|
|
|
bool
|
|
|
|
fil_table_accessible(const dict_table_t* table)
|
|
|
|
MY_ATTRIBUTE((warn_unused_result, nonnull));
|
|
|
|
|
MDEV-13328 ALTER TABLE…DISCARD TABLESPACE takes a lot of time
With a big buffer pool that contains many data pages,
DISCARD TABLESPACE took a long time, because it would scan the
entire buffer pool to remove any pages that belong to the tablespace.
With a large buffer pool, this would take a lot of time, especially
when the table-to-discard is empty.
The minimum amount of work that DISCARD TABLESPACE must do is to
remove the pages of the to-be-discarded table from the
buf_pool->flush_list because any writes to the data file must be
prevented before the file is deleted.
If DISCARD TABLESPACE does not evict the pages from the buffer pool,
then IMPORT TABLESPACE must do it, because we must prevent pre-DISCARD,
not-yet-evicted pages from being mistaken for pages of the imported
tablespace.
It would not be a useful fix to simply move the buffer pool scan to
the IMPORT TABLESPACE step. What we can do is to actively evict those
pages that could be mistaken for imported pages. In this way, when
importing a small table into a big buffer pool, the import should
still run relatively fast.
Import is bypassing the buffer pool when reading pages for the
adjustment phase. In the adjustment phase, if a page exists in
the buffer pool, we could replace it with the page from the imported
file. Unfortunately I did not get this to work properly, so instead
we will simply evict any matching page from the buffer pool.
buf_page_get_gen(): Implement BUF_EVICT_IF_IN_POOL, a new mode
where the requested page will be evicted if it is found. There
must be no unwritten changes for the page.
buf_remove_t: Remove. Instead, use trx!=NULL to signify that a write
to file is desired, and use a separate parameter bool drop_ahi.
buf_LRU_flush_or_remove_pages(), fil_delete_tablespace():
Replace buf_remove_t.
buf_LRU_remove_pages(), buf_LRU_remove_all_pages(): Remove.
PageConverter::m_mtr: A dummy mini-transaction buffer
PageConverter::PageConverter(): Complete the member initialization list.
PageConverter::operator()(): Evict any 'shadow' pages from the
buffer pool so that pre-existing (garbage) pages cannot be mistaken
for pages that exist in the being-imported file.
row_discard_tablespace(): Remove a bogus comment that seems to
refer to IMPORT TABLESPACE, not DISCARD TABLESPACE.
2017-11-02 22:38:37 +02:00
|
|
|
/** Delete a tablespace and associated .ibd file.
|
|
|
|
@param[in] id tablespace identifier
|
|
|
|
@return DB_SUCCESS or error */
|
2014-02-26 19:11:54 +01:00
|
|
|
dberr_t
|
2018-01-15 15:26:02 +02:00
|
|
|
fil_delete_tablespace(
|
|
|
|
ulint id
|
|
|
|
#ifdef BTR_CUR_HASH_ADAPT
|
|
|
|
, bool drop_ahi = false /*!< whether to drop the adaptive hash index */
|
|
|
|
#endif /* BTR_CUR_HASH_ADAPT */
|
|
|
|
);
|
2016-08-12 11:17:45 +03:00
|
|
|
|
MDEV-13564 Mariabackup does not work with TRUNCATE
Implement undo tablespace truncation via normal redo logging.
Implement TRUNCATE TABLE as a combination of RENAME to #sql-ib name,
CREATE, and DROP.
Note: Orphan #sql-ib*.ibd may be left behind if MariaDB Server 10.2
is killed before the DROP operation is committed. If MariaDB Server 10.2
is killed during TRUNCATE, it is also possible that the old table
was renamed to #sql-ib*.ibd but the data dictionary will refer to the
table using the original name.
In MariaDB Server 10.3, RENAME inside InnoDB is transactional,
and #sql-* tables will be dropped on startup. So, this new TRUNCATE
will be fully crash-safe in 10.3.
ha_mroonga::wrapper_truncate(): Pass table options to the underlying
storage engine, now that ha_innobase::truncate() will need them.
rpl_slave_state::truncate_state_table(): Before truncating
mysql.gtid_slave_pos, evict any cached table handles from
the table definition cache, so that there will be no stale
references to the old table after truncating.
== TRUNCATE TABLE ==
WL#6501 in MySQL 5.7 introduced separate log files for implementing
atomic and crash-safe TRUNCATE TABLE, instead of using the InnoDB
undo and redo log. Some convoluted logic was added to the InnoDB
crash recovery, and some extra synchronization (including a redo log
checkpoint) was introduced to make this work. This synchronization
has caused performance problems and race conditions, and the extra
log files cannot be copied or applied by external backup programs.
In order to support crash-upgrade from MariaDB 10.2, we will keep
the logic for parsing and applying the extra log files, but we will
no longer generate those files in TRUNCATE TABLE.
A prerequisite for crash-safe TRUNCATE is a crash-safe RENAME TABLE
(with full redo and undo logging and proper rollback). This will
be implemented in MDEV-14717.
ha_innobase::truncate(): Invoke RENAME, create(), delete_table().
Because RENAME cannot be fully rolled back before MariaDB 10.3
due to missing undo logging, add some explicit rename-back in
case the operation fails.
ha_innobase::delete(): Introduce a variant that takes sqlcom as
a parameter. In TRUNCATE TABLE, we do not want to touch any
FOREIGN KEY constraints.
ha_innobase::create(): Add the parameters file_per_table, trx.
In TRUNCATE, the new table must be created in the same transaction
that renames the old table.
create_table_info_t::create_table_info_t(): Add the parameters
file_per_table, trx.
row_drop_table_for_mysql(): Replace a bool parameter with sqlcom.
row_drop_table_after_create_fail(): New function, wrapping
row_drop_table_for_mysql().
dict_truncate_index_tree_in_mem(), fil_truncate_tablespace(),
fil_prepare_for_truncate(), fil_reinit_space_header_for_table(),
row_truncate_table_for_mysql(), TruncateLogger,
row_truncate_prepare(), row_truncate_rollback(),
row_truncate_complete(), row_truncate_fts(),
row_truncate_update_system_tables(),
row_truncate_foreign_key_checks(), row_truncate_sanity_checks():
Remove.
row_upd_check_references_constraints(): Remove a check for
TRUNCATE, now that the table is no longer truncated in place.
The new test innodb.truncate_foreign uses DEBUG_SYNC to cover some
race-condition like scenarios. The test innodb-innodb.truncate does
not use any synchronization.
We add a redo log subformat to indicate backup-friendly format.
MariaDB 10.4 will remove support for the old TRUNCATE logging,
so crash-upgrade from old 10.2 or 10.3 to 10.4 will involve
limitations.
== Undo tablespace truncation ==
MySQL 5.7 implements undo tablespace truncation. It is only
possible when innodb_undo_tablespaces is set to at least 2.
The logging is implemented similar to the WL#6501 TRUNCATE,
that is, using separate log files and a redo log checkpoint.
We can simply implement undo tablespace truncation within
a single mini-transaction that reinitializes the undo log
tablespace file. Unfortunately, due to the redo log format
of some operations, currently, the total redo log written by
undo tablespace truncation will be more than the combined size
of the truncated undo tablespace. It should be acceptable
to have a little more than 1 megabyte of log in a single
mini-transaction. This will be fixed in MDEV-17138 in
MariaDB Server 10.4.
recv_sys_t: Add truncated_undo_spaces[] to remember for which undo
tablespaces a MLOG_FILE_CREATE2 record was seen.
namespace undo: Remove some unnecessary declarations.
fil_space_t::is_being_truncated: Document that this flag now
only applies to undo tablespaces. Remove some references.
fil_space_t::is_stopping(): Do not refer to is_being_truncated.
This check is for tablespaces of tables. Potentially used
tablespaces are never truncated any more.
buf_dblwr_process(): Suppress the out-of-bounds warning
for undo tablespaces.
fil_truncate_log(): Write a MLOG_FILE_CREATE2 with a nonzero
page number (new size of the tablespace in pages) to inform
crash recovery that the undo tablespace size has been reduced.
fil_op_write_log(): Relax assertions, so that MLOG_FILE_CREATE2
can be written for undo tablespaces (without .ibd file suffix)
for a nonzero page number.
os_file_truncate(): Add the parameter allow_shrink=false
so that undo tablespaces can actually be shrunk using this function.
fil_name_parse(): For undo tablespace truncation,
buffer MLOG_FILE_CREATE2 in truncated_undo_spaces[].
recv_read_in_area(): Avoid reading pages for which no redo log
records remain buffered, after recv_addr_trim() removed them.
trx_rseg_header_create(): Add a FIXME comment that we could write
much less redo log.
trx_undo_truncate_tablespace(): Reinitialize the undo tablespace
in a single mini-transaction, which will be flushed to the redo log
before the file size is trimmed.
recv_addr_trim(): Discard any redo logs for pages that were
logged after the new end of a file, before the truncation LSN.
If the rec_list becomes empty, reduce n_addrs. After removing
any affected records, actually truncate the file.
recv_apply_hashed_log_recs(): Invoke recv_addr_trim() right before
applying any log records. The undo tablespace files must be open
at this point.
buf_flush_or_remove_pages(), buf_flush_dirty_pages(),
buf_LRU_flush_or_remove_pages(): Add a parameter for specifying
the number of the first page to flush or remove (default 0).
trx_purge_initiate_truncate(): Remove the log checkpoints, the
extra logging, and some unnecessary crash points. Merge the code
from trx_undo_truncate_tablespace(). First, flush all to-be-discarded
pages (beyond the new end of the file), then trim the space->size
to make the page allocation deterministic. At the only remaining
crash injection point, flush the redo log, so that the recovery
can be tested.
2018-08-28 13:43:06 +03:00
|
|
|
/** Prepare to truncate an undo tablespace.
|
|
|
|
@param[in] space_id undo tablespace id
|
|
|
|
@return the tablespace
|
|
|
|
@retval NULL if the tablespace does not exist */
|
|
|
|
fil_space_t* fil_truncate_prepare(ulint space_id);
|
2017-01-04 14:34:38 +05:30
|
|
|
|
MDEV-13564 Mariabackup does not work with TRUNCATE
Implement undo tablespace truncation via normal redo logging.
Implement TRUNCATE TABLE as a combination of RENAME to #sql-ib name,
CREATE, and DROP.
Note: Orphan #sql-ib*.ibd may be left behind if MariaDB Server 10.2
is killed before the DROP operation is committed. If MariaDB Server 10.2
is killed during TRUNCATE, it is also possible that the old table
was renamed to #sql-ib*.ibd but the data dictionary will refer to the
table using the original name.
In MariaDB Server 10.3, RENAME inside InnoDB is transactional,
and #sql-* tables will be dropped on startup. So, this new TRUNCATE
will be fully crash-safe in 10.3.
ha_mroonga::wrapper_truncate(): Pass table options to the underlying
storage engine, now that ha_innobase::truncate() will need them.
rpl_slave_state::truncate_state_table(): Before truncating
mysql.gtid_slave_pos, evict any cached table handles from
the table definition cache, so that there will be no stale
references to the old table after truncating.
== TRUNCATE TABLE ==
WL#6501 in MySQL 5.7 introduced separate log files for implementing
atomic and crash-safe TRUNCATE TABLE, instead of using the InnoDB
undo and redo log. Some convoluted logic was added to the InnoDB
crash recovery, and some extra synchronization (including a redo log
checkpoint) was introduced to make this work. This synchronization
has caused performance problems and race conditions, and the extra
log files cannot be copied or applied by external backup programs.
In order to support crash-upgrade from MariaDB 10.2, we will keep
the logic for parsing and applying the extra log files, but we will
no longer generate those files in TRUNCATE TABLE.
A prerequisite for crash-safe TRUNCATE is a crash-safe RENAME TABLE
(with full redo and undo logging and proper rollback). This will
be implemented in MDEV-14717.
ha_innobase::truncate(): Invoke RENAME, create(), delete_table().
Because RENAME cannot be fully rolled back before MariaDB 10.3
due to missing undo logging, add some explicit rename-back in
case the operation fails.
ha_innobase::delete(): Introduce a variant that takes sqlcom as
a parameter. In TRUNCATE TABLE, we do not want to touch any
FOREIGN KEY constraints.
ha_innobase::create(): Add the parameters file_per_table, trx.
In TRUNCATE, the new table must be created in the same transaction
that renames the old table.
create_table_info_t::create_table_info_t(): Add the parameters
file_per_table, trx.
row_drop_table_for_mysql(): Replace a bool parameter with sqlcom.
row_drop_table_after_create_fail(): New function, wrapping
row_drop_table_for_mysql().
dict_truncate_index_tree_in_mem(), fil_truncate_tablespace(),
fil_prepare_for_truncate(), fil_reinit_space_header_for_table(),
row_truncate_table_for_mysql(), TruncateLogger,
row_truncate_prepare(), row_truncate_rollback(),
row_truncate_complete(), row_truncate_fts(),
row_truncate_update_system_tables(),
row_truncate_foreign_key_checks(), row_truncate_sanity_checks():
Remove.
row_upd_check_references_constraints(): Remove a check for
TRUNCATE, now that the table is no longer truncated in place.
The new test innodb.truncate_foreign uses DEBUG_SYNC to cover some
race-condition like scenarios. The test innodb-innodb.truncate does
not use any synchronization.
We add a redo log subformat to indicate backup-friendly format.
MariaDB 10.4 will remove support for the old TRUNCATE logging,
so crash-upgrade from old 10.2 or 10.3 to 10.4 will involve
limitations.
== Undo tablespace truncation ==
MySQL 5.7 implements undo tablespace truncation. It is only
possible when innodb_undo_tablespaces is set to at least 2.
The logging is implemented similar to the WL#6501 TRUNCATE,
that is, using separate log files and a redo log checkpoint.
We can simply implement undo tablespace truncation within
a single mini-transaction that reinitializes the undo log
tablespace file. Unfortunately, due to the redo log format
of some operations, currently, the total redo log written by
undo tablespace truncation will be more than the combined size
of the truncated undo tablespace. It should be acceptable
to have a little more than 1 megabyte of log in a single
mini-transaction. This will be fixed in MDEV-17138 in
MariaDB Server 10.4.
recv_sys_t: Add truncated_undo_spaces[] to remember for which undo
tablespaces a MLOG_FILE_CREATE2 record was seen.
namespace undo: Remove some unnecessary declarations.
fil_space_t::is_being_truncated: Document that this flag now
only applies to undo tablespaces. Remove some references.
fil_space_t::is_stopping(): Do not refer to is_being_truncated.
This check is for tablespaces of tables. Potentially used
tablespaces are never truncated any more.
buf_dblwr_process(): Suppress the out-of-bounds warning
for undo tablespaces.
fil_truncate_log(): Write a MLOG_FILE_CREATE2 with a nonzero
page number (new size of the tablespace in pages) to inform
crash recovery that the undo tablespace size has been reduced.
fil_op_write_log(): Relax assertions, so that MLOG_FILE_CREATE2
can be written for undo tablespaces (without .ibd file suffix)
for a nonzero page number.
os_file_truncate(): Add the parameter allow_shrink=false
so that undo tablespaces can actually be shrunk using this function.
fil_name_parse(): For undo tablespace truncation,
buffer MLOG_FILE_CREATE2 in truncated_undo_spaces[].
recv_read_in_area(): Avoid reading pages for which no redo log
records remain buffered, after recv_addr_trim() removed them.
trx_rseg_header_create(): Add a FIXME comment that we could write
much less redo log.
trx_undo_truncate_tablespace(): Reinitialize the undo tablespace
in a single mini-transaction, which will be flushed to the redo log
before the file size is trimmed.
recv_addr_trim(): Discard any redo logs for pages that were
logged after the new end of a file, before the truncation LSN.
If the rec_list becomes empty, reduce n_addrs. After removing
any affected records, actually truncate the file.
recv_apply_hashed_log_recs(): Invoke recv_addr_trim() right before
applying any log records. The undo tablespace files must be open
at this point.
buf_flush_or_remove_pages(), buf_flush_dirty_pages(),
buf_LRU_flush_or_remove_pages(): Add a parameter for specifying
the number of the first page to flush or remove (default 0).
trx_purge_initiate_truncate(): Remove the log checkpoints, the
extra logging, and some unnecessary crash points. Merge the code
from trx_undo_truncate_tablespace(). First, flush all to-be-discarded
pages (beyond the new end of the file), then trim the space->size
to make the page allocation deterministic. At the only remaining
crash injection point, flush the redo log, so that the recovery
can be tested.
2018-08-28 13:43:06 +03:00
|
|
|
/** Write log about an undo tablespace truncate operation. */
|
|
|
|
void fil_truncate_log(fil_space_t* space, ulint size, mtr_t* mtr)
|
|
|
|
MY_ATTRIBUTE((nonnull));
|
2017-01-04 14:34:38 +05:30
|
|
|
|
MDEV-13564: Implement innodb_unsafe_truncate=ON for compatibility
While MariaDB Server 10.2 is not really guaranteed to be compatible
with Percona XtraBackup 2.4 (for example, the MySQL 5.7 undo log format
change that could be present in XtraBackup, but was reverted from
MariaDB in MDEV-12289), we do not want to disrupt users who have
deployed xtrabackup and MariaDB Server 10.2 in their environments.
With this change, MariaDB 10.2 will continue to use the backup-unsafe
TRUNCATE TABLE code, so that neither the undo log nor the redo log
formats will change in an incompatible way.
Undo tablespace truncation will keep using the redo log only. Recovery
or backup with old code will fail to shrink the undo tablespace files,
but the contents will be recovered just fine.
In the MariaDB Server 10.2 series only, we introduce the configuration
parameter innodb_unsafe_truncate and make it ON by default. To allow
MariaDB Backup (mariabackup) to work properly with TRUNCATE TABLE
operations, use loose_innodb_unsafe_truncate=OFF.
MariaDB Server 10.3.10 and later releases will always use the
backup-safe TRUNCATE TABLE, and this parameter will not be
added there.
recv_recovery_rollback_active(): Skip row_mysql_drop_garbage_tables()
unless innodb_unsafe_truncate=OFF. It is too unsafe to drop orphan
tables if RENAME operations are not transactional within InnoDB.
LOG_HEADER_FORMAT_10_3: Replaces LOG_HEADER_FORMAT_CURRENT.
log_init(), log_group_file_header_flush(),
srv_prepare_to_delete_redo_log_files(),
innobase_start_or_create_for_mysql(): Choose the redo log format
and subformat based on the value of innodb_unsafe_truncate.
2018-10-10 19:19:29 +03:00
|
|
|
/** Truncate the tablespace to needed size.
|
|
|
|
@param[in] space_id id of tablespace to truncate
|
|
|
|
@param[in] size_in_pages truncate size.
|
|
|
|
@return true if truncate was successful. */
|
|
|
|
bool
|
|
|
|
fil_truncate_tablespace(
|
|
|
|
ulint space_id,
|
|
|
|
ulint size_in_pages);
|
|
|
|
|
|
|
|
/*******************************************************************//**
|
|
|
|
Prepare for truncating a single-table tablespace. The tablespace
|
|
|
|
must be cached in the memory cache.
|
|
|
|
1) Check pending operations on a tablespace;
|
|
|
|
2) Remove all insert buffer entries for the tablespace;
|
|
|
|
@return DB_SUCCESS or error */
|
|
|
|
dberr_t
|
|
|
|
fil_prepare_for_truncate(
|
|
|
|
/*=====================*/
|
|
|
|
ulint id); /*!< in: space id */
|
|
|
|
|
|
|
|
/** Reinitialize the original tablespace header with the same space id
|
|
|
|
for single tablespace
|
|
|
|
@param[in] table table belongs to the tablespace
|
|
|
|
@param[in] size size in blocks
|
|
|
|
@param[in] trx Transaction covering truncate */
|
|
|
|
void
|
|
|
|
fil_reinit_space_header_for_table(
|
|
|
|
dict_table_t* table,
|
|
|
|
ulint size,
|
|
|
|
trx_t* trx);
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/*******************************************************************//**
|
|
|
|
Closes a single-table tablespace. The tablespace must be cached in the
|
|
|
|
memory cache. Free all pages used by the tablespace.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return DB_SUCCESS or error */
|
2014-02-26 19:11:54 +01:00
|
|
|
dberr_t
|
|
|
|
fil_close_tablespace(
|
|
|
|
/*=================*/
|
|
|
|
trx_t* trx, /*!< in/out: Transaction covering the close */
|
|
|
|
ulint id); /*!< in: space id */
|
2016-12-30 15:04:10 +02:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/*******************************************************************//**
|
|
|
|
Discards a single-table tablespace. The tablespace must be cached in the
|
|
|
|
memory cache. Discarding is like deleting a tablespace, but
|
|
|
|
|
|
|
|
1. We do not drop the table from the data dictionary;
|
|
|
|
|
|
|
|
2. We remove all insert buffer entries for the tablespace immediately;
|
|
|
|
in DROP TABLE they are only removed gradually in the background;
|
|
|
|
|
|
|
|
3. When the user does IMPORT TABLESPACE, the tablespace will have the
|
|
|
|
same id as it originally had.
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
4. Free all the pages in use by the tablespace if rename=true.
|
|
|
|
@return DB_SUCCESS or error */
|
2014-02-26 19:11:54 +01:00
|
|
|
dberr_t
|
|
|
|
fil_discard_tablespace(
|
|
|
|
/*===================*/
|
|
|
|
ulint id) /*!< in: space id */
|
2016-06-21 14:21:03 +02:00
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2015-12-13 10:11:49 +01:00
|
|
|
|
|
|
|
/** Test if a tablespace file can be renamed to a new filepath by checking
|
|
|
|
if that the old filepath exists and the new filepath does not exist.
|
|
|
|
@param[in] space_id tablespace id
|
|
|
|
@param[in] old_path old filepath
|
|
|
|
@param[in] new_path new filepath
|
|
|
|
@param[in] is_discarded whether the tablespace is discarded
|
MDEV-17158 TRUNCATE is not atomic after MDEV-13564
It turned out that ha_innobase::truncate() would prematurely
commit the transaction already before the completion of the
ha_innobase::create(). All of this must be atomic.
innodb.truncate_crash: Use the correct DEBUG_SYNC point, and
tolerate non-truncation of the table, because the redo log
for the TRUNCATE transaction commit might be flushed due to
some InnoDB background activity.
dict_build_tablespace_for_table(): Merge to the function
dict_build_table_def_step().
dict_build_table_def_step(): If a table is being created during
an already started data dictionary transaction (such as TRUNCATE),
persistently write the table_id to the undo log header before
creating any file. In this way, the recovery of TRUNCATE will be
able to delete the new file before rolling back the rename of
the original table.
dict_table_rename_in_cache(): Add the parameter replace_new_file,
used as part of rolling back a TRUNCATE operation.
fil_rename_tablespace_check(): Add the parameter replace_new.
If the parameter is set and a file identified by new_path exists,
remove a possible tablespace and also the file.
create_table_info_t::create_table_def(): Remove some debug assertions
that no longer hold. During TRUNCATE, the transaction will already
have been started (and performed a rename operation) before the
table is created. Also, remove a call to dict_build_tablespace_for_table().
create_table_info_t::create_table(): Add the parameter create_fk=true.
During TRUNCATE TABLE, do not add FOREIGN KEY constraints to the
InnoDB data dictionary, because they will also not be removed.
row_table_add_foreign_constraints(): If trx=NULL, do not modify
the InnoDB data dictionary, but only load the FOREIGN KEY constraints
from the data dictionary.
ha_innobase::create(): Lock the InnoDB data dictionary cache only
if no transaction was passed by the caller. Unlock it in any case.
innobase_rename_table(): Add the parameter commit = true.
If !commit, do not lock or unlock the data dictionary cache.
ha_innobase::truncate(): Lock the data dictionary before invoking
rename or create, and let ha_innobase::create() unlock it and
also commit or roll back the transaction.
trx_undo_mark_as_dict(): Renamed from trx_undo_mark_as_dict_operation()
and declared global instead of static.
row_undo_ins_parse_undo_rec(): If table_id is set, this must
be rolling back the rename operation in TRUNCATE TABLE, and
therefore replace_new_file=true.
2018-09-10 14:59:58 +03:00
|
|
|
@param[in] replace_new whether to ignore the existence of new_path
|
2015-12-13 10:11:49 +01:00
|
|
|
@return innodb error code */
|
|
|
|
dberr_t
|
|
|
|
fil_rename_tablespace_check(
|
|
|
|
ulint space_id,
|
|
|
|
const char* old_path,
|
|
|
|
const char* new_path,
|
MDEV-17158 TRUNCATE is not atomic after MDEV-13564
It turned out that ha_innobase::truncate() would prematurely
commit the transaction already before the completion of the
ha_innobase::create(). All of this must be atomic.
innodb.truncate_crash: Use the correct DEBUG_SYNC point, and
tolerate non-truncation of the table, because the redo log
for the TRUNCATE transaction commit might be flushed due to
some InnoDB background activity.
dict_build_tablespace_for_table(): Merge to the function
dict_build_table_def_step().
dict_build_table_def_step(): If a table is being created during
an already started data dictionary transaction (such as TRUNCATE),
persistently write the table_id to the undo log header before
creating any file. In this way, the recovery of TRUNCATE will be
able to delete the new file before rolling back the rename of
the original table.
dict_table_rename_in_cache(): Add the parameter replace_new_file,
used as part of rolling back a TRUNCATE operation.
fil_rename_tablespace_check(): Add the parameter replace_new.
If the parameter is set and a file identified by new_path exists,
remove a possible tablespace and also the file.
create_table_info_t::create_table_def(): Remove some debug assertions
that no longer hold. During TRUNCATE, the transaction will already
have been started (and performed a rename operation) before the
table is created. Also, remove a call to dict_build_tablespace_for_table().
create_table_info_t::create_table(): Add the parameter create_fk=true.
During TRUNCATE TABLE, do not add FOREIGN KEY constraints to the
InnoDB data dictionary, because they will also not be removed.
row_table_add_foreign_constraints(): If trx=NULL, do not modify
the InnoDB data dictionary, but only load the FOREIGN KEY constraints
from the data dictionary.
ha_innobase::create(): Lock the InnoDB data dictionary cache only
if no transaction was passed by the caller. Unlock it in any case.
innobase_rename_table(): Add the parameter commit = true.
If !commit, do not lock or unlock the data dictionary cache.
ha_innobase::truncate(): Lock the data dictionary before invoking
rename or create, and let ha_innobase::create() unlock it and
also commit or roll back the transaction.
trx_undo_mark_as_dict(): Renamed from trx_undo_mark_as_dict_operation()
and declared global instead of static.
row_undo_ins_parse_undo_rec(): If table_id is set, this must
be rolling back the rename operation in TRUNCATE TABLE, and
therefore replace_new_file=true.
2018-09-10 14:59:58 +03:00
|
|
|
bool is_discarded,
|
|
|
|
bool replace_new = false);
|
2015-12-13 10:11:49 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** Rename a single-table tablespace.
|
|
|
|
The tablespace must exist in the memory cache.
|
|
|
|
@param[in] id tablespace identifier
|
|
|
|
@param[in] old_path old file name
|
|
|
|
@param[in] new_name new table name in the
|
|
|
|
databasename/tablename format
|
|
|
|
@param[in] new_path_in new file name,
|
|
|
|
or NULL if it is located in the normal data directory
|
|
|
|
@return true if success */
|
|
|
|
bool
|
2014-02-26 19:11:54 +01:00
|
|
|
fil_rename_tablespace(
|
2016-08-12 11:17:45 +03:00
|
|
|
ulint id,
|
|
|
|
const char* old_path,
|
|
|
|
const char* new_name,
|
|
|
|
const char* new_path_in);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/*******************************************************************//**
|
2016-08-12 11:17:45 +03:00
|
|
|
Allocates and builds a file name from a path, a table or tablespace name
|
|
|
|
and a suffix. The string must be freed by caller with ut_free().
|
|
|
|
@param[in] path NULL or the direcory path or the full path and filename.
|
|
|
|
@param[in] name NULL if path is full, or Table/Tablespace name
|
|
|
|
@param[in] suffix NULL or the file extention to use.
|
|
|
|
@return own: file name */
|
2014-02-26 19:11:54 +01:00
|
|
|
char*
|
2016-08-12 11:17:45 +03:00
|
|
|
fil_make_filepath(
|
|
|
|
const char* path,
|
|
|
|
const char* name,
|
|
|
|
ib_extention suffix,
|
|
|
|
bool strip_name);
|
2015-08-14 11:09:06 +03:00
|
|
|
|
2017-01-17 11:37:49 +02:00
|
|
|
/** Create a tablespace file.
|
2016-08-12 11:17:45 +03:00
|
|
|
@param[in] space_id Tablespace ID
|
|
|
|
@param[in] name Tablespace name in dbname/tablename format.
|
|
|
|
@param[in] path Path and filename of the datafile to create.
|
|
|
|
@param[in] flags Tablespace flags
|
|
|
|
@param[in] size Initial size of the tablespace file in pages,
|
|
|
|
must be >= FIL_IBD_FILE_INITIAL_SIZE
|
2017-01-17 11:37:49 +02:00
|
|
|
@param[in] mode MariaDB encryption mode
|
|
|
|
@param[in] key_id MariaDB encryption key_id
|
2016-08-12 11:17:45 +03:00
|
|
|
@return DB_SUCCESS or error code */
|
2014-02-26 19:11:54 +01:00
|
|
|
dberr_t
|
2016-08-12 11:17:45 +03:00
|
|
|
fil_ibd_create(
|
|
|
|
ulint space_id,
|
|
|
|
const char* name,
|
|
|
|
const char* path,
|
|
|
|
ulint flags,
|
|
|
|
ulint size,
|
2017-01-17 11:37:49 +02:00
|
|
|
fil_encryption_t mode,
|
2017-05-10 09:07:50 +03:00
|
|
|
uint32_t key_id)
|
2017-05-17 13:49:51 +03:00
|
|
|
MY_ATTRIBUTE((nonnull(2), warn_unused_result));
|
2016-08-12 11:17:45 +03:00
|
|
|
|
MDEV-11623 MariaDB 10.1 fails to start datadir created with
MariaDB 10.0/MySQL 5.6 using innodb-page-size!=16K
The storage format of FSP_SPACE_FLAGS was accidentally broken
already in MariaDB 10.1.0. This fix is bringing the format in
line with other MySQL and MariaDB release series.
Please refer to the comments that were added to fsp0fsp.h
for details.
This is an INCOMPATIBLE CHANGE that affects users of
page_compression and non-default innodb_page_size. Upgrading
to this release will correct the flags in the data files.
If you want to downgrade to earlier MariaDB 10.1.x, please refer
to the test innodb.101_compatibility how to reset the
FSP_SPACE_FLAGS in the files.
NOTE: MariaDB 10.1.0 to 10.1.20 can misinterpret
uncompressed data files with innodb_page_size=4k or 64k as
compressed innodb_page_size=16k files, and then probably fail
when trying to access the pages. See the comments in the
function fsp_flags_convert_from_101() for detailed analysis.
Move PAGE_COMPRESSION to FSP_SPACE_FLAGS bit position 16.
In this way, compressed innodb_page_size=16k tablespaces will not
be mistaken for uncompressed ones by MariaDB 10.1.0 to 10.1.20.
Derive PAGE_COMPRESSION_LEVEL, ATOMIC_WRITES and DATA_DIR from the
dict_table_t::flags when the table is available, in
fil_space_for_table_exists_in_mem() or fil_open_single_table_tablespace().
During crash recovery, fil_load_single_table_tablespace() will use
innodb_compression_level for the PAGE_COMPRESSION_LEVEL.
FSP_FLAGS_MEM_MASK: A bitmap of the memory-only fil_space_t::flags
that are not to be written to FSP_SPACE_FLAGS. Currently, these will
include PAGE_COMPRESSION_LEVEL, ATOMIC_WRITES and DATA_DIR.
Introduce the macro FSP_FLAGS_PAGE_SSIZE(). We only support
one innodb_page_size for the whole instance.
When creating a dummy tablespace for the redo log, use
fil_space_t::flags=0. The flags are never written to the redo log files.
Remove many FSP_FLAGS_SET_ macros.
dict_tf_verify_flags(): Remove. This is basically only duplicating
the logic of dict_tf_to_fsp_flags(), used in a debug assertion.
fil_space_t::mark: Remove. This flag was not used for anything.
fil_space_for_table_exists_in_mem(): Remove the unnecessary parameter
mark_space, and add a parameter for table flags. Check that
fil_space_t::flags match the table flags, and adjust the (memory-only)
flags based on the table flags.
fil_node_open_file(): Remove some redundant or unreachable conditions,
do not use stderr for output, and avoid unnecessary server aborts.
fil_user_tablespace_restore_page(): Convert the flags, so that the
correct page_size will be used when restoring a page from the
doublewrite buffer.
fil_space_get_page_compressed(), fsp_flags_is_page_compressed(): Remove.
It suffices to have fil_space_is_page_compressed().
FSP_FLAGS_WIDTH_DATA_DIR, FSP_FLAGS_WIDTH_PAGE_COMPRESSION_LEVEL,
FSP_FLAGS_WIDTH_ATOMIC_WRITES: Remove, because these flags do not
exist in the FSP_SPACE_FLAGS but only in memory.
fsp_flags_try_adjust(): New function, to adjust the FSP_SPACE_FLAGS
in page 0. Called by fil_open_single_table_tablespace(),
fil_space_for_table_exists_in_mem(), innobase_start_or_create_for_mysql()
except if --innodb-read-only is active.
fsp_flags_is_valid(ulint): Reimplement from the scratch, with
accurate comments. Do not display any details of detected
inconsistencies, because the output could be confusing when
dealing with MariaDB 10.1.x data files.
fsp_flags_convert_from_101(ulint): Convert flags from buggy
MariaDB 10.1.x format, or return ULINT_UNDEFINED if the flags
cannot be in MariaDB 10.1.x format.
fsp_flags_match(): Check the flags when probing files.
Implemented based on fsp_flags_is_valid()
and fsp_flags_convert_from_101().
dict_check_tablespaces_and_store_max_id(): Do not access the
page after committing the mini-transaction.
IMPORT TABLESPACE fixes:
AbstractCallback::init(): Convert the flags.
FetchIndexRootPages::operator(): Check that the tablespace flags match the
table flags. Do not attempt to convert tablespace flags to table flags,
because the conversion would necessarily be lossy.
PageConverter::update_header(): Write back the correct flags.
This takes care of the flags in IMPORT TABLESPACE.
2017-01-14 00:13:16 +02:00
|
|
|
/** Try to adjust FSP_SPACE_FLAGS if they differ from the expectations.
|
|
|
|
(Typically when upgrading from MariaDB 10.1.0..10.1.20.)
|
|
|
|
@param[in] space_id tablespace ID
|
|
|
|
@param[in] flags desired tablespace flags */
|
|
|
|
UNIV_INTERN
|
|
|
|
void
|
|
|
|
fsp_flags_try_adjust(ulint space_id, ulint flags);
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/********************************************************************//**
|
|
|
|
Tries to open a single-table tablespace and optionally checks the space id is
|
|
|
|
right in it. If does not succeed, prints an error message to the .err log. This
|
|
|
|
function is used to open a tablespace when we start up mysqld, and also in
|
|
|
|
IMPORT TABLESPACE.
|
|
|
|
NOTE that we assume this operation is used either at the database startup
|
|
|
|
or under the protection of the dictionary mutex, so that two users cannot
|
|
|
|
race here. This operation does not leave the file associated with the
|
|
|
|
tablespace open, but closes it after we have looked at the space id in it.
|
|
|
|
|
|
|
|
If the validate boolean is set, we read the first page of the file and
|
|
|
|
check that the space id in the file is what we expect. We assume that
|
|
|
|
this function runs much faster if no check is made, since accessing the
|
|
|
|
file inode probably is much faster (the OS caches them) than accessing
|
2016-08-12 11:17:45 +03:00
|
|
|
the first page of the file. This boolean may be initially false, but if
|
2014-02-26 19:11:54 +01:00
|
|
|
a remote tablespace is found it will be changed to true.
|
|
|
|
|
|
|
|
If the fix_dict boolean is set, then it is safe to use an internal SQL
|
|
|
|
statement to update the dictionary tables if they are incorrect.
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
@param[in] validate true if we should validate the tablespace
|
|
|
|
@param[in] fix_dict true if the dictionary is available to be fixed
|
|
|
|
@param[in] purpose FIL_TYPE_TABLESPACE or FIL_TYPE_TEMPORARY
|
|
|
|
@param[in] id tablespace ID
|
2017-01-19 12:06:13 +02:00
|
|
|
@param[in] flags expected FSP_SPACE_FLAGS
|
2016-08-12 11:17:45 +03:00
|
|
|
@param[in] space_name tablespace name of the datafile
|
|
|
|
If file-per-table, it is the table name in the databasename/tablename format
|
|
|
|
@param[in] path_in expected filepath, usually read from dictionary
|
|
|
|
@return DB_SUCCESS or error code */
|
2014-02-26 19:11:54 +01:00
|
|
|
dberr_t
|
2016-08-12 11:17:45 +03:00
|
|
|
fil_ibd_open(
|
|
|
|
bool validate,
|
|
|
|
bool fix_dict,
|
|
|
|
fil_type_t purpose,
|
|
|
|
ulint id,
|
|
|
|
ulint flags,
|
|
|
|
const char* tablename,
|
2017-06-15 14:35:51 +03:00
|
|
|
const char* path_in)
|
2016-09-06 09:43:16 +03:00
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
enum fil_load_status {
|
|
|
|
/** The tablespace file(s) were found and valid. */
|
|
|
|
FIL_LOAD_OK,
|
|
|
|
/** The name no longer matches space_id */
|
|
|
|
FIL_LOAD_ID_CHANGED,
|
|
|
|
/** The file(s) were not found */
|
|
|
|
FIL_LOAD_NOT_FOUND,
|
|
|
|
/** The file(s) were not valid */
|
|
|
|
FIL_LOAD_INVALID
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Open a single-file tablespace and add it to the InnoDB data structures.
|
|
|
|
@param[in] space_id tablespace ID
|
|
|
|
@param[in] filename path/to/databasename/tablename.ibd
|
|
|
|
@param[out] space the tablespace, or NULL on error
|
|
|
|
@return status of the operation */
|
|
|
|
enum fil_load_status
|
|
|
|
fil_ibd_load(
|
|
|
|
ulint space_id,
|
|
|
|
const char* filename,
|
|
|
|
fil_space_t*& space)
|
2016-09-06 09:43:16 +03:00
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/***********************************************************************//**
|
|
|
|
A fault-tolerant function that tries to read the next file name in the
|
|
|
|
directory. We retry 100 times if os_file_readdir_next_file() returns -1. The
|
|
|
|
idea is to read as much good data as we can and jump over bad data.
|
|
|
|
@return 0 if ok, -1 if error even after the retries, 1 if at the end
|
|
|
|
of the directory */
|
|
|
|
int
|
|
|
|
fil_file_readdir_next_file(
|
|
|
|
/*=======================*/
|
|
|
|
dberr_t* err, /*!< out: this is set to DB_ERROR if an error
|
|
|
|
was encountered, otherwise not changed */
|
|
|
|
const char* dirname,/*!< in: directory name or path */
|
|
|
|
os_file_dir_t dir, /*!< in: directory stream */
|
|
|
|
os_file_stat_t* info); /*!< in/out: buffer where the
|
|
|
|
info is returned */
|
2018-09-06 10:32:49 +03:00
|
|
|
/** Determine if a matching tablespace exists in the InnoDB tablespace
|
|
|
|
memory cache. Note that if we have not done a crash recovery at the database
|
|
|
|
startup, there may be many tablespaces which are not yet in the memory cache.
|
|
|
|
@param[in] id Tablespace ID
|
|
|
|
@param[in] name Tablespace name used in fil_space_create().
|
|
|
|
@param[in] print_error_if_does_not_exist
|
|
|
|
Print detailed error information to the
|
|
|
|
error log if a matching tablespace is not found from memory.
|
|
|
|
@param[in] heap Heap memory
|
|
|
|
@param[in] table_flags table flags
|
2016-08-12 11:17:45 +03:00
|
|
|
@return true if a matching tablespace exists in the memory cache */
|
|
|
|
bool
|
2014-02-26 19:11:54 +01:00
|
|
|
fil_space_for_table_exists_in_mem(
|
2018-09-06 10:32:49 +03:00
|
|
|
ulint id,
|
|
|
|
const char* name,
|
2016-08-12 11:17:45 +03:00
|
|
|
bool print_error_if_does_not_exist,
|
2018-09-06 10:32:49 +03:00
|
|
|
mem_heap_t* heap,
|
|
|
|
ulint table_flags);
|
2016-12-30 15:04:10 +02:00
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** Try to extend a tablespace if it is smaller than the specified size.
|
|
|
|
@param[in,out] space tablespace
|
|
|
|
@param[in] size desired size in pages
|
|
|
|
@return whether the tablespace is at least as big as requested */
|
|
|
|
bool
|
|
|
|
fil_space_extend(
|
|
|
|
fil_space_t* space,
|
|
|
|
ulint size);
|
2014-02-26 19:11:54 +01:00
|
|
|
/*******************************************************************//**
|
|
|
|
Tries to reserve free extents in a file space.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return true if succeed */
|
|
|
|
bool
|
2014-02-26 19:11:54 +01:00
|
|
|
fil_space_reserve_free_extents(
|
|
|
|
/*===========================*/
|
|
|
|
ulint id, /*!< in: space id */
|
|
|
|
ulint n_free_now, /*!< in: number of free extents now */
|
|
|
|
ulint n_to_reserve); /*!< in: how many one wants to reserve */
|
|
|
|
/*******************************************************************//**
|
|
|
|
Releases free extents in a file space. */
|
|
|
|
void
|
|
|
|
fil_space_release_free_extents(
|
|
|
|
/*===========================*/
|
|
|
|
ulint id, /*!< in: space id */
|
|
|
|
ulint n_reserved); /*!< in: how many one reserved */
|
|
|
|
/*******************************************************************//**
|
|
|
|
Gets the number of reserved extents. If the database is silent, this number
|
|
|
|
should be zero. */
|
|
|
|
ulint
|
|
|
|
fil_space_get_n_reserved_extents(
|
|
|
|
/*=============================*/
|
|
|
|
ulint id); /*!< in: space id */
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
/** Reads or writes data. This operation could be asynchronous (aio).
|
|
|
|
|
|
|
|
@param[in] type IO context
|
|
|
|
@param[in] sync true if synchronous aio is desired
|
|
|
|
@param[in] page_id page id
|
|
|
|
@param[in] page_size page size
|
|
|
|
@param[in] byte_offset remainder of offset in bytes; in aio this
|
|
|
|
must be divisible by the OS block size
|
|
|
|
@param[in] len how many bytes to read or write; this must
|
|
|
|
not cross a file boundary; in aio this must
|
|
|
|
be a block size multiple
|
|
|
|
@param[in,out] buf buffer where to store read data or from where
|
|
|
|
to write; in aio this must be appropriately
|
|
|
|
aligned
|
|
|
|
@param[in] message message for aio handler if non-sync aio
|
|
|
|
used, else ignored
|
2017-05-11 11:15:37 +03:00
|
|
|
@param[in] ignore_missing_space true=ignore missing space during read
|
2016-08-12 11:17:45 +03:00
|
|
|
@return DB_SUCCESS, DB_TABLESPACE_DELETED or DB_TABLESPACE_TRUNCATED
|
|
|
|
if we are trying to do i/o on a tablespace which does not exist */
|
2014-02-26 19:11:54 +01:00
|
|
|
dberr_t
|
|
|
|
fil_io(
|
2016-08-12 11:17:45 +03:00
|
|
|
const IORequest& type,
|
|
|
|
bool sync,
|
2018-10-18 18:23:12 +03:00
|
|
|
const page_id_t page_id,
|
2016-08-12 11:17:45 +03:00
|
|
|
const page_size_t& page_size,
|
|
|
|
ulint byte_offset,
|
|
|
|
ulint len,
|
|
|
|
void* buf,
|
2017-05-11 11:15:37 +03:00
|
|
|
void* message,
|
|
|
|
bool ignore_missing_space = false);
|
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
/**********************************************************************//**
|
|
|
|
Waits for an aio operation to complete. This function is used to write the
|
|
|
|
handler for completed requests. The aio array of pending requests is divided
|
|
|
|
into segments (see os0file.cc for more info). The thread specifies which
|
|
|
|
segment it wants to wait for. */
|
|
|
|
void
|
|
|
|
fil_aio_wait(
|
|
|
|
/*=========*/
|
|
|
|
ulint segment); /*!< in: the number of the segment in the aio
|
|
|
|
array to wait for */
|
|
|
|
/**********************************************************************//**
|
|
|
|
Flushes to disk possible writes cached by the OS. If the space does not exist
|
|
|
|
or is being dropped, does not do anything. */
|
|
|
|
void
|
|
|
|
fil_flush(
|
|
|
|
/*======*/
|
|
|
|
ulint space_id); /*!< in: file space id (this can be a group of
|
|
|
|
log files or a tablespace of the database) */
|
2017-04-21 11:28:18 +03:00
|
|
|
/** Flush a tablespace.
|
|
|
|
@param[in,out] space tablespace to flush */
|
|
|
|
void
|
|
|
|
fil_flush(fil_space_t* space);
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/** Flush to disk the writes in file spaces of the given type
|
|
|
|
possibly cached by the OS.
|
|
|
|
@param[in] purpose FIL_TYPE_TABLESPACE or FIL_TYPE_LOG */
|
2014-02-26 19:11:54 +01:00
|
|
|
void
|
|
|
|
fil_flush_file_spaces(
|
2016-08-12 11:17:45 +03:00
|
|
|
fil_type_t purpose);
|
2014-02-26 19:11:54 +01:00
|
|
|
/******************************************************************//**
|
|
|
|
Checks the consistency of the tablespace cache.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return true if ok */
|
|
|
|
bool
|
2014-02-26 19:11:54 +01:00
|
|
|
fil_validate(void);
|
|
|
|
/*==============*/
|
|
|
|
/********************************************************************//**
|
2016-08-12 11:17:45 +03:00
|
|
|
Returns true if file address is undefined.
|
|
|
|
@return true if undefined */
|
|
|
|
bool
|
2014-02-26 19:11:54 +01:00
|
|
|
fil_addr_is_null(
|
|
|
|
/*=============*/
|
|
|
|
fil_addr_t addr); /*!< in: address */
|
|
|
|
/********************************************************************//**
|
|
|
|
Get the predecessor of a file page.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return FIL_PAGE_PREV */
|
2014-02-26 19:11:54 +01:00
|
|
|
ulint
|
|
|
|
fil_page_get_prev(
|
|
|
|
/*==============*/
|
|
|
|
const byte* page); /*!< in: file page */
|
|
|
|
/********************************************************************//**
|
|
|
|
Get the successor of a file page.
|
2016-08-12 11:17:45 +03:00
|
|
|
@return FIL_PAGE_NEXT */
|
2014-02-26 19:11:54 +01:00
|
|
|
ulint
|
|
|
|
fil_page_get_next(
|
|
|
|
/*==============*/
|
|
|
|
const byte* page); /*!< in: file page */
|
|
|
|
/*********************************************************************//**
|
|
|
|
Sets the file page type. */
|
|
|
|
void
|
|
|
|
fil_page_set_type(
|
|
|
|
/*==============*/
|
|
|
|
byte* page, /*!< in/out: file page */
|
|
|
|
ulint type); /*!< in: type */
|
2016-08-12 11:17:45 +03:00
|
|
|
|
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
/** Increase redo skipped of a tablespace.
|
|
|
|
@param[in] id space id */
|
|
|
|
void
|
|
|
|
fil_space_inc_redo_skipped_count(
|
|
|
|
ulint id);
|
|
|
|
|
|
|
|
/** Decrease redo skipped of a tablespace.
|
|
|
|
@param[in] id space id */
|
|
|
|
void
|
|
|
|
fil_space_dec_redo_skipped_count(
|
|
|
|
ulint id);
|
|
|
|
#endif
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/********************************************************************//**
|
|
|
|
Delete the tablespace file and any related files like .cfg.
|
|
|
|
This should not be called for temporary tables. */
|
|
|
|
void
|
|
|
|
fil_delete_file(
|
|
|
|
/*============*/
|
|
|
|
const char* path); /*!< in: filepath of the ibd tablespace */
|
|
|
|
|
2016-08-12 11:17:45 +03:00
|
|
|
/********************************************************************//**
|
|
|
|
Looks for a pre-existing fil_space_t with the given tablespace ID
|
|
|
|
and, if found, returns the name and filepath in newly allocated buffers that the caller must free.
|
|
|
|
@param[in] space_id The tablespace ID to search for.
|
|
|
|
@param[out] name Name of the tablespace found.
|
|
|
|
@param[out] fileapth The filepath of the first datafile for thtablespace found.
|
|
|
|
@return true if tablespace is found, false if not. */
|
|
|
|
bool
|
|
|
|
fil_space_read_name_and_filepath(
|
|
|
|
ulint space_id,
|
|
|
|
char** name,
|
|
|
|
char** filepath);
|
|
|
|
|
|
|
|
/** Convert a file name to a tablespace name.
|
|
|
|
@param[in] filename directory/databasename/tablename.ibd
|
|
|
|
@return database/tablename string, to be freed with ut_free() */
|
|
|
|
char*
|
|
|
|
fil_path_to_space_name(
|
|
|
|
const char* filename);
|
|
|
|
|
|
|
|
/** Returns the space ID based on the tablespace name.
|
|
|
|
The tablespace must be found in the tablespace memory cache.
|
|
|
|
This call is made from external to this module, so the mutex is not owned.
|
|
|
|
@param[in] tablespace Tablespace name
|
|
|
|
@return space ID if tablespace found, ULINT_UNDEFINED if space not. */
|
2014-02-26 19:11:54 +01:00
|
|
|
ulint
|
2016-08-12 11:17:45 +03:00
|
|
|
fil_space_get_id_by_name(
|
|
|
|
const char* tablespace);
|
2014-02-26 19:11:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
Iterate over all the spaces in the space list and fetch the
|
|
|
|
tablespace names. It will return a copy of the name that must be
|
|
|
|
freed by the caller using: delete[].
|
|
|
|
@return DB_SUCCESS if all OK. */
|
|
|
|
dberr_t
|
|
|
|
fil_get_space_names(
|
|
|
|
/*================*/
|
|
|
|
space_name_list_t& space_name_list)
|
|
|
|
/*!< in/out: Vector for collecting the names. */
|
2016-06-21 14:21:03 +02:00
|
|
|
MY_ATTRIBUTE((warn_unused_result));
|
2014-02-26 19:11:54 +01:00
|
|
|
|
2015-12-13 10:11:49 +01:00
|
|
|
/** Generate redo log for swapping two .ibd files
|
|
|
|
@param[in] old_table old table
|
|
|
|
@param[in] new_table new table
|
|
|
|
@param[in] tmp_name temporary table name
|
|
|
|
@param[in,out] mtr mini-transaction
|
2016-09-06 09:43:16 +03:00
|
|
|
@return innodb error code */
|
|
|
|
dberr_t
|
2014-02-26 19:11:54 +01:00
|
|
|
fil_mtr_rename_log(
|
2015-12-13 10:11:49 +01:00
|
|
|
const dict_table_t* old_table,
|
|
|
|
const dict_table_t* new_table,
|
|
|
|
const char* tmp_name,
|
|
|
|
mtr_t* mtr)
|
2017-04-28 12:22:32 +03:00
|
|
|
MY_ATTRIBUTE((nonnull, warn_unused_result));
|
2016-09-06 09:43:16 +03:00
|
|
|
|
2017-03-06 10:02:01 +02:00
|
|
|
/** Acquire the fil_system mutex. */
|
|
|
|
#define fil_system_enter() mutex_enter(&fil_system->mutex)
|
|
|
|
/** Release the fil_system mutex. */
|
|
|
|
#define fil_system_exit() mutex_exit(&fil_system->mutex)
|
2016-09-06 09:43:16 +03:00
|
|
|
|
|
|
|
/*******************************************************************//**
|
|
|
|
Returns the table space by a given id, NULL if not found. */
|
|
|
|
fil_space_t*
|
|
|
|
fil_space_get_by_id(
|
|
|
|
/*================*/
|
|
|
|
ulint id); /*!< in: space id */
|
|
|
|
|
MDEV-12548 Initial implementation of Mariabackup for MariaDB 10.2
InnoDB I/O and buffer pool interfaces and the redo log format
have been changed between MariaDB 10.1 and 10.2, and the backup
code has to be adjusted accordingly.
The code has been simplified, and many memory leaks have been fixed.
Instead of the file name xtrabackup_logfile, the file name ib_logfile0
is being used for the copy of the redo log. Unnecessary InnoDB startup and
shutdown and some unnecessary threads have been removed.
Some help was provided by Vladislav Vaintroub.
Parameters have been cleaned up and aligned with those of MariaDB 10.2.
The --dbug option has been added, so that in debug builds,
--dbug=d,ib_log can be specified to enable diagnostic messages
for processing redo log entries.
By default, innodb_doublewrite=OFF, so that --prepare works faster.
If more crash-safety for --prepare is needed, double buffering
can be enabled.
The parameter innodb_log_checksums=OFF can be used to ignore redo log
checksums in --backup.
Some messages have been cleaned up.
Unless --export is specified, Mariabackup will not deal with undo log.
The InnoDB mini-transaction redo log is not only about user-level
transactions; it is actually about mini-transactions. To avoid confusion,
call it the redo log, not transaction log.
We disable any undo log processing in --prepare.
Because MariaDB 10.2 supports indexed virtual columns, the
undo log processing would need to be able to evaluate virtual column
expressions. To reduce the amount of code dependencies, we will not
process any undo log in prepare.
This means that the --export option must be disabled for now.
This also means that the following options are redundant
and have been removed:
xtrabackup --apply-log-only
innobackupex --redo-only
In addition to disabling any undo log processing, we will disable any
further changes to data pages during --prepare, including the change
buffer merge. This means that restoring incremental backups should
reliably work even when change buffering is being used on the server.
Because of this, preparing a backup will not generate any further
redo log, and the redo log file can be safely deleted. (If the
--export option is enabled in the future, it must generate redo log
when processing undo logs and buffered changes.)
In --prepare, we cannot easily know if a partial backup was used,
especially when restoring a series of incremental backups. So, we
simply warn about any missing files, and ignore the redo log for them.
FIXME: Enable the --export option.
FIXME: Improve the handling of the MLOG_INDEX_LOAD record, and write
a test that initiates a backup while an ALGORITHM=INPLACE operation
is creating indexes or rebuilding a table. An error should be detected
when preparing the backup.
FIXME: In --incremental --prepare, xtrabackup_apply_delta() should
ensure that if FSP_SIZE is modified, the file size will be adjusted
accordingly.
2017-06-30 10:49:37 +03:00
|
|
|
/** Look up a tablespace.
|
|
|
|
@param[in] name tablespace name
|
|
|
|
@return tablespace
|
|
|
|
@retval NULL if not found */
|
|
|
|
fil_space_t*
|
|
|
|
fil_space_get_by_name(const char* name);
|
|
|
|
|
2016-09-06 09:43:16 +03:00
|
|
|
/*******************************************************************//**
|
2016-08-12 11:17:45 +03:00
|
|
|
by redo log.
|
|
|
|
@param[in,out] space tablespace */
|
|
|
|
void
|
|
|
|
fil_names_dirty(
|
|
|
|
fil_space_t* space);
|
|
|
|
|
|
|
|
/** Write MLOG_FILE_NAME records when a non-predefined persistent
|
|
|
|
tablespace was modified for the first time since the latest
|
|
|
|
fil_names_clear().
|
|
|
|
@param[in,out] space tablespace
|
|
|
|
@param[in,out] mtr mini-transaction */
|
|
|
|
void
|
|
|
|
fil_names_dirty_and_write(
|
|
|
|
fil_space_t* space,
|
|
|
|
mtr_t* mtr);
|
|
|
|
|
|
|
|
/** Write MLOG_FILE_NAME records if a persistent tablespace was modified
|
|
|
|
for the first time since the latest fil_names_clear().
|
|
|
|
@param[in,out] space tablespace
|
|
|
|
@param[in,out] mtr mini-transaction
|
|
|
|
@return whether any MLOG_FILE_NAME record was written */
|
2016-09-06 09:43:16 +03:00
|
|
|
inline MY_ATTRIBUTE((warn_unused_result))
|
2014-05-06 21:13:16 +02:00
|
|
|
bool
|
2016-08-12 11:17:45 +03:00
|
|
|
fil_names_write_if_was_clean(
|
|
|
|
fil_space_t* space,
|
|
|
|
mtr_t* mtr)
|
|
|
|
{
|
|
|
|
ut_ad(log_mutex_own());
|
|
|
|
|
|
|
|
if (space == NULL) {
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool was_clean = space->max_lsn == 0;
|
|
|
|
ut_ad(space->max_lsn <= log_sys->lsn);
|
|
|
|
space->max_lsn = log_sys->lsn;
|
|
|
|
|
|
|
|
if (was_clean) {
|
|
|
|
fil_names_dirty_and_write(space, mtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(was_clean);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern volatile bool recv_recovery_on;
|
|
|
|
|
|
|
|
/** During crash recovery, open a tablespace if it had not been opened
|
|
|
|
yet, to get valid size and flags.
|
|
|
|
@param[in,out] space tablespace */
|
|
|
|
inline
|
|
|
|
void
|
|
|
|
fil_space_open_if_needed(
|
|
|
|
fil_space_t* space)
|
|
|
|
{
|
|
|
|
ut_ad(recv_recovery_on);
|
|
|
|
|
|
|
|
if (space->size == 0) {
|
|
|
|
/* Initially, size and flags will be set to 0,
|
|
|
|
until the files are opened for the first time.
|
|
|
|
fil_space_get_size() will open the file
|
|
|
|
and adjust the size and flags. */
|
|
|
|
#ifdef UNIV_DEBUG
|
|
|
|
ulint size =
|
|
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
fil_space_get_size(space->id);
|
|
|
|
ut_ad(size == space->size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** On a log checkpoint, reset fil_names_dirty_and_write() flags
|
|
|
|
and write out MLOG_FILE_NAME and MLOG_CHECKPOINT if needed.
|
|
|
|
@param[in] lsn checkpoint LSN
|
|
|
|
@param[in] do_write whether to always write MLOG_CHECKPOINT
|
|
|
|
@return whether anything was written to the redo log
|
|
|
|
@retval false if no flags were set and nothing written
|
|
|
|
@retval true if anything was written to the redo log */
|
|
|
|
bool
|
|
|
|
fil_names_clear(
|
|
|
|
lsn_t lsn,
|
|
|
|
bool do_write);
|
|
|
|
|
|
|
|
#ifdef UNIV_ENABLE_UNIT_TEST_MAKE_FILEPATH
|
|
|
|
void test_make_filepath();
|
|
|
|
#endif /* UNIV_ENABLE_UNIT_TEST_MAKE_FILEPATH */
|
2014-05-06 21:13:16 +02:00
|
|
|
|
2017-04-21 11:28:18 +03:00
|
|
|
/** Determine the block size of the data file.
|
|
|
|
@param[in] space tablespace
|
|
|
|
@param[in] offset page number
|
2015-04-01 19:37:00 +03:00
|
|
|
@return block size */
|
|
|
|
UNIV_INTERN
|
|
|
|
ulint
|
2017-04-21 11:28:18 +03:00
|
|
|
fil_space_get_block_size(const fil_space_t* space, unsigned offset);
|
2014-07-31 11:31:39 +03:00
|
|
|
|
2015-04-01 11:50:21 +03:00
|
|
|
#include "fil0fil.ic"
|
2016-04-22 10:50:45 +02:00
|
|
|
#endif /* UNIV_INNOCHECKSUM */
|
2014-07-31 11:31:39 +03:00
|
|
|
|
2014-02-26 19:11:54 +01:00
|
|
|
#endif /* fil0fil_h */
|