![]() |
MySQL 26.7.0
Source Code Documentation
|
Tablespace or log data space. More...
#include <fil0fil.h>
Classes | |
| struct | fsp_cache |
| Structure to hold cached data for the FSP subsystem. More... | |
Public Types | |
| using | List_node = UT_LIST_NODE_T(fil_space_t) |
| using | Files = std::vector< fil_node_t, ut::allocator< fil_node_t > > |
| using | Observer = Flush_observer |
| using | Flush_observers = std::vector< Observer *, ut::allocator< Observer * > > |
Public Member Functions | |
| fil_space_t () | |
| ~fil_space_t () | |
| bool | is_deleted () const |
| bool | was_not_deleted () const |
| void | set_deleted () |
| Marks the space object for deletion. More... | |
| uint32_t | get_current_version () const |
| Returns current version of the space object. More... | |
| uint32_t | get_recent_version () const |
| Returns current version of the space object. More... | |
| void | bump_version () |
| Bumps the space object version and cause all pages in buffer pool that reference the current space object version to be stale and be freed on first encounter. More... | |
| bool | has_no_references () const |
| size_t | get_reference_count () const |
| void | inc_ref () noexcept |
| Increment the page reference count. More... | |
| void | dec_ref () noexcept |
| Decrement the page reference count. More... | |
| std::ostream & | print_xdes_pages (std::ostream &out) const |
| Print the extent descriptor pages of this tablespace into the given output stream. More... | |
| void | print_xdes_pages (const char *filename) const |
| Print the extent descriptor pages of this tablespace into the given file. More... | |
| fil_node_t * | get_node_for_page_no (page_no_t &page_no) noexcept |
| Get the file node corresponding to the given page number of the tablespace. More... | |
| const fil_node_t * | get_node_for_page_no (page_no_t &page_no) const noexcept |
| dberr_t | validate_to_dd (bool validate, bool old_space, bool &needs_reencryption) |
Checks if the space has encryption flag enabled in the tablespace flags or validate is true. More... | |
| dberr_t | validate_first_page () |
| Assures the FSP header of the tablespace is correct and fills the FSP-related data cache. More... | |
| void | declare_first_page_valid () |
| Sets the validation flag to true. More... | |
| bool | is_validated () const |
| Returns true iff the tablespace was already validated by checking the content of the first page. More... | |
| void | begin_bulk_operation (uint64_t extend_size) |
| Begin bulk operation on the space. More... | |
| void | end_bulk_operation () |
| End bulk operation on the space. More... | |
| bool | is_bulk_operation_in_progress () const |
| uint64_t | get_auto_extend_size () const |
| page_no_t | get_max_size_in_pages () const |
| bool | initialize_while_extending () const |
| bool | is_fsp_cache_valid () const |
| Returns true if the FSP-related cache is already filled in and valid. More... | |
| void | ensure_fsp_cache_valid () |
| Ensures the FSP-related cache is filled in and valid upon this call return. More... | |
| page_no_t | get_cached_fsp_size_in_header () const |
| void | set_cached_fsp_size_in_header (page_no_t new_size) |
| uint32_t | get_cached_fsp_free_len () const |
| Length of the FSP_FREE list. More... | |
| void | set_cached_fsp_free_len (uint32_t new_free_len) |
| void | inc_cached_fsp_free_len (uint32_t delta) |
| void | dec_cached_fsp_free_len () |
| page_no_t | get_cached_fsp_free_limit () const |
| Contents of FSP_FREE_LIMIT. More... | |
| void | set_cached_fsp_free_limit (page_no_t new_free_limit) |
| void | fill_fsp_cache (const byte *first_page) |
| Fills the cache of the FSP-related data that is stored in the first page of the tablespace header. More... | |
| bool | is_compressed () const noexcept |
| Check if the tablespace is compressed. More... | |
| bool | is_encrypted () const noexcept |
| Check if the tablespace is encrypted. More... | |
| bool | can_encrypt () const noexcept |
| Check if the encryption details, like the encryption key, type and other details, that are needed to carry out encryption are available. More... | |
Public Attributes | |
| ib::Timer | m_last_extended {} |
| When the tablespace was extended last. More... | |
| page_no_t | m_undo_extend {} |
| Extend undo tablespaces by so many pages. More... | |
| page_no_t | m_undo_initial {} |
| When an undo tablespace has been initialized with required header pages, that size is recorded here. More... | |
| char * | name {} |
| Tablespace name. More... | |
| space_id_t | id |
| Tablespace ID. More... | |
| bool | prevent_file_open {} |
| true if we want to rename the .ibd file of tablespace and want to temporarily prevent other threads from opening the file that is being renamed. More... | |
| ib::Throttler | m_prevent_file_open_wait_message_throttler |
| Throttles writing to log a message about long waiting for file to perform rename. More... | |
| bool | stop_new_ops {} |
| We set this true when we start deleting a single-table tablespace. More... | |
| 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. More... | |
| fil_type_t | purpose |
| Purpose. More... | |
| Files | files {} |
| Files attached to this tablespace. More... | |
| page_no_t | m_size_in_pages {} |
| Tablespace file size in pages; 0 if not known yet. More... | |
| uint64_t | autoextend_size_in_bytes {} |
| Autoextend size. More... | |
| uint32_t | flags {} |
| Tablespace flags; see fsp_flags_is_valid() and page_size_t(ulint) (constructor). More... | |
| uint32_t | n_reserved_extents {} |
| Number of reserved free extents for ongoing operations like B-tree page split. More... | |
| uint32_t | n_pending_flushes {} |
| This is positive when flushing the tablespace to disk; dropping of the tablespace is forbidden if this is positive. More... | |
| uint32_t | n_pending_ops {} |
| This is positive when we have pending operations against this tablespace. More... | |
| rw_lock_t | latch |
| Latch protecting the file space storage allocation. More... | |
| List_node | unflushed_spaces {} |
| List of spaces with at least one unflushed file we have written to. More... | |
| bool | is_in_unflushed_spaces {} |
| true if this space is currently in unflushed_spaces More... | |
| Compression::Type | compression_type {} |
| Compression algorithm. More... | |
| Encryption_metadata | m_encryption_metadata {} |
| Encryption metadata. More... | |
| Encryption::Progress | encryption_op_in_progress {Encryption::Progress::NONE} |
| Encryption is in progress. More... | |
| lsn_t | m_header_page_flush_lsn {} |
| Flush lsn of header page. More... | |
| ulint | magic_n |
| FIL_SPACE_MAGIC_N. More... | |
Static Public Attributes | |
| static fil_space_t * | s_sys_space |
| System tablespace. More... | |
Private Member Functions | |
| ut::Expected< ut::unique_ptr_aligned< byte[]> > | read_page_direct (page_no_t page_no) const |
Reads the specified page directly from the disk, without using fil_io or Buffer Pool caching. More... | |
Private Attributes | |
| std::atomic< uint32_t > | m_version {} |
| All pages in the buffer pool that reference this fil_space_t instance with version before this version can be lazily freed or reused as free pages. More... | |
| std::atomic_size_t | m_n_ref_count {} |
| Number of buf_page_t entries that point to this instance. More... | |
| std::atomic_bool | m_deleted {} |
| true if the tablespace is marked for deletion. More... | |
| std::atomic_bool | m_is_bulk {false} |
| true if bulk operation is in progress. More... | |
| std::atomic< uint64_t > | m_bulk_extend_size |
| true if bulk operation is in progress. More... | |
| bool | m_validated {} |
| struct fil_space_t::fsp_cache | m_fsp_cache |
Tablespace or log data space.
| using fil_space_t::Files = std::vector<fil_node_t, ut::allocator<fil_node_t> > |
| using fil_space_t::Flush_observers = std::vector<Observer *, ut::allocator<Observer *> > |
| using fil_space_t::Observer = Flush_observer |
| fil_space_t::fil_space_t | ( | ) |
| fil_space_t::~fil_space_t | ( | ) |
|
inline |
Begin bulk operation on the space.
| [in] | extend_size | space extension size for bulk operation |
| void fil_space_t::bump_version | ( | ) |
Bumps the space object version and cause all pages in buffer pool that reference the current space object version to be stale and be freed on first encounter.
|
inlinenoexcept |
Check if the encryption details, like the encryption key, type and other details, that are needed to carry out encryption are available.
| void fil_space_t::dec_cached_fsp_free_len | ( | ) |
|
inlinenoexcept |
Decrement the page reference count.
|
inline |
Sets the validation flag to true.
It should be called from places where we are certain the space header is valid, like in case we just filled it in or have just verified it is valid.
|
inline |
End bulk operation on the space.
| void fil_space_t::ensure_fsp_cache_valid | ( | ) |
Ensures the FSP-related cache is filled in and valid upon this call return.
| void fil_space_t::fill_fsp_cache | ( | const byte * | first_page | ) |
Fills the cache of the FSP-related data that is stored in the first page of the tablespace header.
| [in] | first_page | Pointer to buffer with the content of the first page. The buffer must be at least the length of the smallest page possible. |
| uint64_t fil_space_t::get_auto_extend_size | ( | ) | const |
| uint32_t fil_space_t::get_cached_fsp_free_len | ( | ) | const |
Length of the FSP_FREE list.
| page_no_t fil_space_t::get_cached_fsp_free_limit | ( | ) | const |
Contents of FSP_FREE_LIMIT.
| page_no_t fil_space_t::get_cached_fsp_size_in_header | ( | ) | const |
| uint32_t fil_space_t::get_current_version | ( | ) | const |
Returns current version of the space object.
It is being bumped when the space is truncated or deleted. Guarantees the version returned is up to date as long as fil_shard mutex is not released.
| page_no_t fil_space_t::get_max_size_in_pages | ( | ) | const |
|
noexcept |
|
noexcept |
Get the file node corresponding to the given page number of the tablespace.
Note that the size of nodes in tablespaces is rounded down to the extend size.
| [in,out] | page_no | Caller passes the page number within a tablespace. After return, it contains the page number within the returned file node. For tablespaces containing only one file, the given page_no will not change. |
nullptr if the file is not found or does not contain the page.This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
| uint32_t fil_space_t::get_recent_version | ( | ) | const |
Returns current version of the space object.
It is being bumped when the space is truncated or deleted. It does not guarantee the version is current one.
| size_t fil_space_t::get_reference_count | ( | ) | const |
| bool fil_space_t::has_no_references | ( | ) | const |
| void fil_space_t::inc_cached_fsp_free_len | ( | uint32_t | delta | ) |
|
inlinenoexcept |
Increment the page reference count.
| bool fil_space_t::initialize_while_extending | ( | ) | const |
|
inline |
|
inlinenoexcept |
Check if the tablespace is compressed.
| bool fil_space_t::is_deleted | ( | ) | const |
|
inlinenoexcept |
Check if the tablespace is encrypted.
| bool fil_space_t::is_fsp_cache_valid | ( | ) | const |
Returns true if the FSP-related cache is already filled in and valid.
|
inline |
Returns true iff the tablespace was already validated by checking the content of the first page.
| void fil_space_t::print_xdes_pages | ( | const char * | filename | ) | const |
Print the extent descriptor pages of this tablespace into the given file.
| [in] | filename | the output file name. |
| std::ostream & fil_space_t::print_xdes_pages | ( | std::ostream & | out | ) | const |
Print the extent descriptor pages of this tablespace into the given output stream.
| [in] | out | the output stream. |
|
private |
Reads the specified page directly from the disk, without using fil_io or Buffer Pool caching.
Requires the page to be located in the first file and requires this file to be already opened and prevented from being closed. The file can be prevented from being closed by calling prepare_file_for_io() on it or by having the shard's mutex. The returned buffer's length is page_size_t{flags}.physical().
| [in] | page_no | Page number to read from the disk. |
| void fil_space_t::set_cached_fsp_free_len | ( | uint32_t | new_free_len | ) |
| void fil_space_t::set_cached_fsp_free_limit | ( | page_no_t | new_free_limit | ) |
| void fil_space_t::set_cached_fsp_size_in_header | ( | page_no_t | new_size | ) |
| void fil_space_t::set_deleted | ( | ) |
Marks the space object for deletion.
It will bump the space object version and cause all pages in buffer pool that reference to the current space object version to be stale and be freed on first encounter.
| dberr_t fil_space_t::validate_first_page | ( | ) |
Assures the FSP header of the tablespace is correct and fills the FSP-related data cache.
If the tablespace was already validated, does nothing. The first node in the tablespace must be already opened and prevented from being closed - it will be used to read the first page directly from the storage of the first node. The file can be prevented from being closed by calling prepare_file_for_io() on it or by having the shard's mutex. The page will be read from the first node directly.
Add some tolerance when the tablespace is upgraded. If an empty general tablespace is created in 5.7, and then upgraded to 8.0, then its size changes from FIL_IBD_FILE_INITIAL_SIZE_5_7 pages to FIL_IBD_FILE_INITIAL_SIZE-1.
| dberr_t fil_space_t::validate_to_dd | ( | bool | validate, |
| bool | old_space, | ||
| bool & | needs_reencryption | ||
| ) |
Checks if the space has encryption flag enabled in the tablespace flags or validate is true.
If not, it just returns DB_SUCCESS. Otherwise opens the first node, reads the first page out of it, runs validation of data stored inside the tablespace header against the data used to construct this object, which should come from the DD, checks if the stored space version is correct. It checks if re-encryption is needed if the default master key ID was used to encrypt it.
| [in] | validate | Should the validation of the space ID and flags be performed? This is forced if the tablespace flags have the encryption flag even if false is passed. |
| [in] | old_space | If specified, the space version checks will not be performed. To be used for files from the MySQL Server 5.7 or older, during upgrade process only. |
| [out] | needs_reencryption | Is set to true if the tablespace re-encryption is required to be performed after this call ends and the space is added to the fil tablespaces mappings and fil_encryption_reencrypt requires the space to be present in these mappings. |
| bool fil_space_t::was_not_deleted | ( | ) | const |
| uint64_t fil_space_t::autoextend_size_in_bytes {} |
Autoextend size.
| Compression::Type fil_space_t::compression_type {} |
Compression algorithm.
| Encryption::Progress fil_space_t::encryption_op_in_progress {Encryption::Progress::NONE} |
Encryption is in progress.
| Files fil_space_t::files {} |
Files attached to this tablespace.
Note: Only the system tablespace can have multiple files, this is a legacy issue.
| uint32_t fil_space_t::flags {} |
Tablespace flags; see fsp_flags_is_valid() and page_size_t(ulint) (constructor).
This is protected by space->latch and tablespace MDL
| space_id_t fil_space_t::id |
Tablespace ID.
| bool fil_space_t::is_in_unflushed_spaces {} |
true if this space is currently in unflushed_spaces
| rw_lock_t fil_space_t::latch |
Latch protecting the file space storage allocation.
|
private |
true if bulk operation is in progress.
|
private |
true if the tablespace is marked for deletion.
| Encryption_metadata fil_space_t::m_encryption_metadata {} |
Encryption metadata.
|
private |
| lsn_t fil_space_t::m_header_page_flush_lsn {} |
Flush lsn of header page.
It is used only during recovery
|
private |
true if bulk operation is in progress.
| ib::Timer fil_space_t::m_last_extended {} |
When the tablespace was extended last.
|
private |
Number of buf_page_t entries that point to this instance.
This field is guarded by the Fil_shard mutex and the "reference count system". The reference count system here is allowing to take a "latch" on the space by incrementing the reference count, and release it by decrementing it.
The increments are possible from two places:
For decrementing the reference count is itself a latch allowing for the safe decrement.
The value is checked for being 0 in Fil_shard::checkpoint under the Fil_shard mutex, and only if the space is deleted. Observing m_n_ref_count==0 might trigger freeing the object. No other thread can be during the process of incrementing m_n_ref_count from 0 to 1 in parallel to this check. This is impossible for following reasons. Recall the only two places where we do increments listed above:
There is also an opposite race possible: while we check for ref count being zero, another thread may be decrementing it in parallel, and we might miss that if we check too soon. This is benign, as it will result in us not reclaiming the memory we could (but not have to) free, and will return to the check on next checkpoint.
| ib::Throttler fil_space_t::m_prevent_file_open_wait_message_throttler |
Throttles writing to log a message about long waiting for file to perform rename.
| page_no_t fil_space_t::m_size_in_pages {} |
Tablespace file size in pages; 0 if not known yet.
| page_no_t fil_space_t::m_undo_extend {} |
Extend undo tablespaces by so many pages.
| page_no_t fil_space_t::m_undo_initial {} |
When an undo tablespace has been initialized with required header pages, that size is recorded here.
Auto-truncation happens when the file size becomes bigger than both this and srv_max_undo_log_size.
|
private |
|
private |
All pages in the buffer pool that reference this fil_space_t instance with version before this version can be lazily freed or reused as free pages.
They should be rejected if there is an attempt to write them to disk.
Writes to m_version are guarded by the exclusive MDL/table lock latches acquired by the caller, as stated in docs. Note that the Fil_shard mutex seems to be latched in 2 of 3 usages only, so is not really an alternative.
Existence of the space object during reads is assured during these operations:
When reading the value for the page being created with buf_page_init_low we have the MDL latches on table that is in tablespace or the tablespace alone, so we won't be able to bump m_version until they are released, so we will read the current value of the version. When reading the value for the page validation with buf_page_t::is_stale(), we will either: a) have the MDL latches required in at least S mode in case we need to be certain if the page is stale, to use it in a query or in purge operation, or b) in case we don't not have the MDL latches, we may read an outdated value. This happens for pages that are seen during for example LRU or flush page scans. These pages are not needed for the query itself. The read is to decide if the page can be safely discarded. Reading incorrect value can lead to no action being executed. Reading incorrect value can't lead to page being incorrectly evicted.
| ulint fil_space_t::magic_n |
FIL_SPACE_MAGIC_N.
| uint32_t fil_space_t::n_pending_flushes {} |
This is positive when flushing the tablespace to disk; dropping of the tablespace is forbidden if this is positive.
| uint32_t fil_space_t::n_pending_ops {} |
This is positive when we have pending operations against this tablespace.
The pending operations can be ibuf merges or lock validation code trying to read a block. Dropping of the tablespace is forbidden if this is positive. Protected by Fil_shard::m_mutex.
| uint32_t fil_space_t::n_reserved_extents {} |
Number of reserved free extents for ongoing operations like B-tree page split.
| char* fil_space_t::name {} |
Tablespace name.
| bool fil_space_t::prevent_file_open {} |
true if we want to rename the .ibd file of tablespace and want to temporarily prevent other threads from opening the file that is being renamed.
| fil_type_t fil_space_t::purpose |
Purpose.
| ulint fil_space_t::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.
|
static |
System tablespace.
| bool fil_space_t::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.
| List_node fil_space_t::unflushed_spaces {} |
List of spaces with at least one unflushed file we have written to.