MySQL 9.1.0
Source Code Documentation
fil_space_t Struct Reference

Tablespace or log data space. More...

#include <fil0fil.h>

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

void release_free_extents (ulint n_reserved)
 Release the reserved free extents. More...
 
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...
 
void initialize () noexcept
 Initializes fields. 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 ()
 
bool initialize_while_extending ()
 
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...
 
fil_node_tget_file_node (page_no_t *page_no) noexcept
 Get the file node corresponding to the given page number of the tablespace. 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 size {}
 Tablespace file size in pages; 0 if not known yet. More...
 
page_no_t size_in_header {}
 FSP_SIZE in the tablespace header; 0 if not known yet. More...
 
uint64_t autoextend_size_in_bytes {}
 Autoextend size. More...
 
uint32_t free_len {}
 Length of the FSP_FREE list. More...
 
page_no_t free_limit {}
 Contents of FSP_FREE_LIMIT. 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_ts_sys_space
 System tablespace. 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...
 

Detailed Description

Tablespace or log data space.

Member Typedef Documentation

◆ Files

◆ Flush_observers

◆ List_node

◆ Observer

Member Function Documentation

◆ begin_bulk_operation()

void fil_space_t::begin_bulk_operation ( uint64_t  extend_size)
inline

Begin bulk operation on the space.

Parameters
[in]extend_sizespace extension size for bulk operation

◆ bump_version()

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.

◆ can_encrypt()

bool fil_space_t::can_encrypt ( ) const
inlinenoexcept

Check if the encryption details, like the encryption key, type and other details, that are needed to carry out encryption are available.

Returns
true if encryption can be done, false otherwise.

◆ dec_ref()

void fil_space_t::dec_ref ( )
inlinenoexcept

Decrement the page reference count.

◆ end_bulk_operation()

void fil_space_t::end_bulk_operation ( )
inline

End bulk operation on the space.

◆ get_auto_extend_size()

uint64_t fil_space_t::get_auto_extend_size ( )
Returns
automatic extension size for space.

◆ get_current_version()

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.

◆ get_file_node()

fil_node_t * fil_space_t::get_file_node ( page_no_t page_no)
noexcept

Get the file node corresponding to the given page number of the tablespace.

Parameters
[in,out]page_noCaller 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.
Returns
the file node object.

◆ get_recent_version()

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.

◆ get_reference_count()

size_t fil_space_t::get_reference_count ( ) const
Returns
Current number of references to the space. This method should be called only while shutting down the server. Only when there is no background nor user session activity the returned value will be valid.

◆ has_no_references()

bool fil_space_t::has_no_references ( ) const
Returns
true if this space does not have any more references. Guarantees the result only if true was returned.

◆ inc_ref()

void fil_space_t::inc_ref ( )
inlinenoexcept

Increment the page reference count.

◆ initialize()

void fil_space_t::initialize ( )
inlinenoexcept

Initializes fields.

This could be replaced by a constructor if SunPro is compiling it correctly.

◆ initialize_while_extending()

bool fil_space_t::initialize_while_extending ( )
Returns
true if added space should be initialized while extending space.

◆ is_bulk_operation_in_progress()

bool fil_space_t::is_bulk_operation_in_progress ( ) const
inline
Returns
true, if bulk operation in progress.

◆ is_compressed()

bool fil_space_t::is_compressed ( ) const
inlinenoexcept

Check if the tablespace is compressed.

Returns
true if compressed, false otherwise.

◆ is_deleted()

bool fil_space_t::is_deleted ( ) const
Returns
true if the instance is queued for deletion. Guarantees the space is not deleted as long as the fil_shard mutex is not released.

◆ is_encrypted()

bool fil_space_t::is_encrypted ( ) const
inlinenoexcept

Check if the tablespace is encrypted.

Returns
true if encrypted, false otherwise.

◆ print_xdes_pages() [1/2]

void fil_space_t::print_xdes_pages ( const char *  filename) const

Print the extent descriptor pages of this tablespace into the given file.

Parameters
[in]filenamethe output file name.

◆ print_xdes_pages() [2/2]

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.

Parameters
[in]outthe output stream.
Returns
the output stream.

◆ release_free_extents()

void fil_space_t::release_free_extents ( ulint  n_reserved)

Release the reserved free extents.

Parameters
[in]n_reservednumber of reserved extents

◆ set_deleted()

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.

◆ was_not_deleted()

bool fil_space_t::was_not_deleted ( ) const
Returns
true if the instance was not queued for deletion. It does not guarantee it is not queued for deletion at the moment.

Member Data Documentation

◆ autoextend_size_in_bytes

uint64_t fil_space_t::autoextend_size_in_bytes {}

Autoextend size.

◆ compression_type

Compression::Type fil_space_t::compression_type

Compression algorithm.

◆ encryption_op_in_progress

Encryption::Progress fil_space_t::encryption_op_in_progress {Encryption::Progress::NONE}

Encryption is in progress.

◆ files

Files fil_space_t::files {}

Files attached to this tablespace.

Note: Only the system tablespace can have multiple files, this is a legacy issue.

◆ flags

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

◆ free_len

uint32_t fil_space_t::free_len {}

Length of the FSP_FREE list.

◆ free_limit

page_no_t fil_space_t::free_limit {}

Contents of FSP_FREE_LIMIT.

◆ id

space_id_t fil_space_t::id

Tablespace ID.

◆ is_in_unflushed_spaces

bool fil_space_t::is_in_unflushed_spaces {}

true if this space is currently in unflushed_spaces

◆ latch

rw_lock_t fil_space_t::latch

Latch protecting the file space storage allocation.

◆ m_bulk_extend_size

std::atomic<uint64_t> fil_space_t::m_bulk_extend_size
private

true if bulk operation is in progress.

◆ m_deleted

std::atomic_bool fil_space_t::m_deleted {}
private

true if the tablespace is marked for deletion.

◆ m_encryption_metadata

Encryption_metadata fil_space_t::m_encryption_metadata

Encryption metadata.

◆ m_header_page_flush_lsn

lsn_t fil_space_t::m_header_page_flush_lsn

Flush lsn of header page.

It is used only during recovery

◆ m_is_bulk

std::atomic_bool fil_space_t::m_is_bulk {false}
private

true if bulk operation is in progress.

◆ m_last_extended

ib::Timer fil_space_t::m_last_extended {}

When the tablespace was extended last.

◆ m_n_ref_count

std::atomic_size_t fil_space_t::m_n_ref_count {}
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:

  1. buf_page_init_low is covered by the existing MDL/table lock latches only and the fact that the space it is using is a current version of the space (the version itself is also guarded by these MDL/table lock latches). It implicitly acquires the "reference count system" latch after this operation.
  2. buf_page_t::buf_page_t(const buf_page_t&) copy constructor - increases the value, but it assumes the page being copied from has "reference count system" latch so the reference count is greater than 0 during this constructor call.

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:

  1. If the space is deleted, then MDL/table lock latches guarantee there are no users that would be able to see it as the current version of space and thus will not attempt to increase the reference value from 0.
  2. The buf_page_t copy constructor can increase it, but it assumes the page being copied from has "reference count system" latch so the reference count is greater than 0 during this constructor call.

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.

◆ m_prevent_file_open_wait_message_throttler

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.

◆ m_undo_extend

page_no_t fil_space_t::m_undo_extend {}

Extend undo tablespaces by so many pages.

◆ m_undo_initial

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.

◆ m_version

std::atomic<uint32_t> fil_space_t::m_version {}
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:

  1. when read by the buf_page_init_low on page read/creation - the caller must have acquired shared MDL/table lock latches.
  2. when read on buf_page_t::is_stale() on page access for a query or for purge operation. The caller must have acquired shared MDL/table lock latches.
  3. when read on buf_page_t::is_stale() on page access from LRU list, flush list or whatever else. Here, the fact that the page has latched the space using the reference counting system is what guards the space existence.

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.

◆ magic_n

ulint fil_space_t::magic_n

FIL_SPACE_MAGIC_N.

◆ n_pending_flushes

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.

◆ n_pending_ops

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.

◆ n_reserved_extents

uint32_t fil_space_t::n_reserved_extents {}

Number of reserved free extents for ongoing operations like B-tree page split.

◆ name

char* fil_space_t::name {}

Tablespace name.

◆ prevent_file_open

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.


◆ purpose

fil_type_t fil_space_t::purpose

Purpose.

◆ redo_skipped_count

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.

◆ s_sys_space

fil_space_t * fil_space_t::s_sys_space
static

System tablespace.

◆ size

page_no_t fil_space_t::size {}

Tablespace file size in pages; 0 if not known yet.

◆ size_in_header

page_no_t fil_space_t::size_in_header {}

FSP_SIZE in the tablespace header; 0 if not known yet.

◆ stop_new_ops

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.

◆ unflushed_spaces

List_node fil_space_t::unflushed_spaces

List of spaces with at least one unflushed file we have written to.


The documentation for this struct was generated from the following files: