MySQL 9.0.0
Source Code Documentation
Clone_Snapshot Class Reference

Dynamic database snapshot: Holds metadata and handle to data. More...

#include <clone0snapshot.h>

Classes

class  State_transit
 RAII style guard for begin & end of snapshot state transition. More...
 

Public Types

using File_Cbk_Func = std::function< int(Clone_file_ctx *)>
 

Public Member Functions

 Clone_Snapshot (Clone_Handle_Type hdl_type, Ha_clone_type clone_type, uint arr_idx, uint64_t snap_id)
 Construct snapshot. More...
 
 ~Clone_Snapshot ()
 Release contexts and free heap. More...
 
bool begin_ddl_state (Clone_notify::Type type, space_id_t space, bool no_wait, bool check_intr, int &error)
 DDL notification before the operation. More...
 
void end_ddl_state (Clone_notify::Type type, space_id_t space)
 DDL notification after the operation. More...
 
int pin_file (Clone_file_ctx *file_ctx, bool &handle_delete)
 Wait for concurrent DDL file operation and pin file. More...
 
void unpin_file (Clone_file_ctx *file_ctx)
 Unpin a file. More...
 
bool blocks_clone (const Clone_file_ctx *file_ctx)
 Check if DDL needs to block clone operation. More...
 
uint64_t get_disk_estimate () const
 
uint64_t get_id ()
 Get unique snapshot identifier. More...
 
uint get_index ()
 Get snapshot index in global array. More...
 
Clone_Monitorget_clone_monitor ()
 Get performance schema accounting object used to monitor stage progress. More...
 
mem_heap_tlock_heap ()
 Get snapshot heap used for allocation during clone. More...
 
void release_heap (mem_heap_t *&heap)
 
Snapshot_State get_state ()
 Get snapshot state. More...
 
uint64_t get_redo_file_size ()
 Get the redo file size for the snapshot. More...
 
uint get_num_chunks ()
 Get total number of chunks for current state. More...
 
size_t get_max_file_name_length ()
 Get maximum file length seen till now. More...
 
uint get_dyn_buffer_length ()
 Get maximum buffer size required for clone. More...
 
int iterate_files (File_Cbk_Func &&func)
 Iterate through all files in current state. More...
 
int iterate_data_files (File_Cbk_Func &&func)
 Iterate through all data files. More...
 
int iterate_redo_files (File_Cbk_Func &&func)
 Iterate through all redo files. More...
 
void get_state_info (bool do_estimate, Clone_Desc_State *state_desc)
 Fill state descriptor from snapshot. More...
 
void set_state_info (Clone_Desc_State *state_desc)
 Set state information during apply. More...
 
Snapshot_State get_next_state ()
 Get next state based on snapshot type. More...
 
bool attach (Clone_Handle_Type hdl_type, bool pfs_monitor)
 Try to attach to snapshot. More...
 
void detach ()
 Detach from snapshot. More...
 
void set_abort ()
 Set current snapshot aborted state. More...
 
bool is_aborted () const
 
int change_state (Clone_Desc_State *state_desc, Snapshot_State new_state, byte *temp_buffer, uint temp_buffer_len, Clone_Alert_Func cbk)
 Start transition to new state. More...
 
int get_file_from_desc (const Clone_File_Meta *file_meta, const char *data_dir, bool desc_create, bool &desc_exists, Clone_file_ctx *&file_ctx)
 Add file metadata entry at destination. More...
 
int rename_desc (const Clone_File_Meta *file_meta, const char *data_dir, Clone_file_ctx *&file_ctx)
 Rename an existing file descriptor. More...
 
int fix_ddl_extension (const char *data_dir, Clone_file_ctx *file_ctx)
 Fix files renamed with ddl extension. More...
 
bool add_file_from_desc (Clone_file_ctx *&file_ctx, bool ddl_create)
 Add file descriptor to file list. More...
 
dberr_t add_node (fil_node_t *node, bool by_ddl)
 Extract file information from node and add to snapshot. More...
 
int add_page (uint32_t space_id, uint32_t page_num)
 Add page ID to to the set of pages in snapshot. More...
 
int add_redo_file (char *file_name, uint64_t file_size, uint64_t file_offset)
 Add redo file to snapshot. More...
 
Clone_File_Metaget_file_by_index (uint index)
 Get file metadata by index for current state. More...
 
Clone_file_ctxget_file_ctx_by_index (uint index)
 Get clone file context by index for current state. More...
 
Clone_file_ctxget_file_ctx (uint32_t chunk_num, uint32_t block_num, uint32_t hint_index)
 Get clone file context by chunk and block number. More...
 
int get_next_block (uint chunk_num, uint &block_num, const Clone_file_ctx *&file_ctx, uint64_t &data_offset, byte *&data_buf, uint32_t &data_size, uint64_t &file_size)
 Get next block of data to transfer. More...
 
void update_block_size (uint buff_size)
 Update snapshot block size based on caller's buffer size. More...
 
uint32_t get_chunk_size () const
 
uint32_t get_blocks_per_chunk () const
 
bool is_copy () const
 Check if copy snapshot. More...
 
void update_file_size (uint32_t file_index, uint64_t file_size)
 Update file size when file is extended during page copy. More...
 
bool encrypt_key_in_header (const page_size_t &page_size, byte *page_data)
 Encrypt tablespace key in header page with master key. More...
 
bool encrypt_key_in_log_header (byte *log_header, uint32_t header_len)
 Encrypt tablespace key in header page with master key. More...
 
void decrypt_key_in_header (const Clone_File_Meta *file_meta, const page_size_t &page_size, byte *&page_data)
 Decrypt tablespace key in header page with master key. More...
 
uint32_t get_max_blocks_pin () const
 
void skip_deleted_blocks (uint32_t chunk_num, uint32_t &block_num)
 Skip all blocks belonging to currently deleted file context. More...
 

Private Types

enum class  Wait_type {
  STATE_TRANSIT_WAIT , STATE_TRANSIT , STATE_END_PAGE_COPY , STATE_BLOCKER ,
  DATA_FILE_WAIT , DATA_FILE_CLOSE , DDL_FILE_OPERATION
}
 Various wait types related to snapshot state. More...
 

Private Member Functions

void debug_wait_state_transit ()
 Debug sync Wait during state transition. More...
 
bool update_deleted_state (Clone_file_ctx *file_ctx)
 Update deleted state of a file if not yet done. More...
 
Clone_file_ctxget_data_file_ctx (uint32_t chunk_num, uint32_t hint_index)
 Get clone data file context by chunk number. More...
 
Clone_file_ctxget_page_file_ctx (uint32_t chunk_num, uint32_t block_num)
 Get clone page file context by chunk number and block number. More...
 
Clone_file_ctxget_redo_file_ctx (uint32_t chunk_num, uint32_t hint_index)
 Get clone redo file context by chunk number. More...
 
const char * wait_string (Wait_type wait_type) const
 Get wait information string based on wait type. More...
 
int wait (Wait_type type, const Clone_file_ctx *ctx, bool no_wait, bool check_intr)
 Wait for various operations based on type. More...
 
void get_wait_mesg (Wait_type wait_type, std::string &info, std::string &error)
 During wait get relevant message string for logging. More...
 
bool block_state_change (Clone_notify::Type type, space_id_t space, bool no_wait, bool check_intr, int &error)
 Block clone state transition. More...
 
void unblock_state_change ()
 Unblock clone state transition. More...
 
Clone_file_ctx::State get_target_file_state (Clone_notify::Type type, bool begin)
 Get next file state while being modified by ddl. More...
 
int begin_ddl_file (Clone_notify::Type type, space_id_t space, bool no_wait, bool check_intr)
 Handle files for DDL begin notification. More...
 
void end_ddl_file (Clone_notify::Type type, space_id_t space)
 Handle files for DDL end notification. More...
 
int synchronize_binlog_gtid (Clone_Alert_Func cbk)
 Synchronize snapshot with binary log and GTID. More...
 
int update_binlog_position ()
 Make sure that the trx sys page binary log position correctly reflects all transactions committed to innodb. More...
 
int wait_for_binlog_prepared_trx ()
 Wait for already prepared binlog transactions to end. More...
 
int wait_trx_end (THD *thd, trx_id_t trx_id)
 Wait for a transaction to end. More...
 
void begin_transit_ddl_wait ()
 Begin state transition before waiting for DDL. More...
 
void begin_transit (Snapshot_State new_state)
 Begin state transition. More...
 
void end_transit ()
 End state transition. More...
 
bool in_transit_state () const
 Check if state transition is in progress. More...
 
bool in_transit_wait () const
 
int init_redo_archiving ()
 Start redo archiving. More...
 
int init_file_copy (Snapshot_State new_state)
 Initialize snapshot state for file copy. More...
 
void init_disk_estimate ()
 Initialize disk byte estimate. More...
 
int init_page_copy (Snapshot_State new_state, byte *page_buffer, uint page_buffer_len)
 Initialize snapshot state for page copy. More...
 
int init_redo_copy (Snapshot_State new_state, Clone_Alert_Func cbk)
 Initialize snapshot state for redo copy. More...
 
int init_apply_state (Clone_Desc_State *state_desc)
 Initialize state while applying cloned data. More...
 
int extend_and_flush_files (bool flush_redo)
 Extend and flush files after copying data. More...
 
int create_desc (const char *data_dir, const Clone_File_Meta *file_meta, bool is_ddl, Clone_file_ctx *&file_ctx)
 Create file descriptor and add to current file list. More...
 
Clone_file_ctxget_file (Clone_File_Vec &file_vector, uint32_t chunk_num, uint32_t start_index)
 Get file context for current chunk. More...
 
int get_next_page (uint chunk_num, uint &block_num, const Clone_file_ctx *&file_ctx, uint64_t &data_offset, byte *&data_buf, uint32_t &data_size, uint64_t &file_size)
 Get next page from buffer pool. More...
 
int get_page_for_write (const page_id_t &page_id, const page_size_t &page_size, const Clone_file_ctx *file_ctx, byte *&page_data, uint &data_size)
 Get page from buffer pool and make ready for write. More...
 
void page_update_for_flush (const page_size_t &page_size, lsn_t page_lsn, byte *&page_data)
 
Clone_file_ctxbuild_file (const char *file_name, uint64_t file_size, uint64_t file_offset, uint &num_chunks)
 Build file metadata entry. More...
 
bool build_file_name (Clone_File_Meta *file_meta, const char *file_name)
 Allocate and set clone file name. More...
 
int add_buf_pool_file ()
 Add buffer pool dump file to the file list. More...
 
int add_file (const char *name, uint64_t size_bytes, uint64_t alloc_bytes, fil_node_t *node, bool by_ddl)
 Add file to snapshot. More...
 
bool file_ctx_changed (const fil_node_t *node, Clone_file_ctx *&file_ctx)
 Check if file context has been changed by ddl. More...
 
uint32_t chunk_size () const
 Get chunk size. More...
 
uint32_t block_size ()
 Get block size for file copy. More...
 
uint32_t blocks_per_chunk () const
 Get number of blocks per chunk for file copy. More...
 
int update_sys_file_name (bool replace, const Clone_File_Meta *file_meta, std::string &file_name)
 Update system file name from configuration. More...
 
int build_file_path (const char *data_dir, const Clone_File_Meta *file_desc, std::string &file_path)
 Build file name along with path for cloned data files. More...
 
int build_file_ctx (Clone_file_ctx::Extension extn, const Clone_File_Meta *file_meta, const std::string &file_path, Clone_file_ctx *&file_ctx)
 Build file context from file path. More...
 
int handle_existing_file (bool replace, bool undo_file, bool redo_file, uint32_t data_file_index, const std::string &data_file, Clone_file_ctx::Extension &extn)
 Check for existing file and if clone extension is needed. More...
 
size_t num_data_files () const
 
size_t num_redo_files () const
 

Private Attributes

Snapshot type and ID
Clone_Handle_Type m_snapshot_handle_type
 Snapshot handle type. More...
 
Ha_clone_type m_snapshot_type
 Clone type. More...
 
uint64_t m_snapshot_id
 Unique snapshot ID. More...
 
uint m_snapshot_arr_idx
 Index in global snapshot array. More...
 
Snapshot State <br>
ib_mutex_t m_snapshot_mutex
 Mutex to handle access by concurrent clones. More...
 
uint32_t m_num_blockers
 Number of blockers for state change. More...
 
bool m_aborted
 Set to true only if clone is aborted after error. More...
 
uint m_num_clones
 Number of clones attached to this snapshot. More...
 
uint m_num_clones_transit
 Number of clones in in state transition. More...
 
Snapshot_State m_snapshot_state
 Current state. More...
 
Snapshot_State m_snapshot_next_state
 Next state to move to. More...
 
Snapshot data block
mem_heap_tm_snapshot_heap
 Memory allocation heap. More...
 
uint m_chunk_size_pow2
 Chunk size in power of 2. More...
 
uint m_block_size_pow2
 Block size in power of 2. More...
 
uint m_num_current_chunks
 Number of chunks in current state. More...
 
size_t m_max_file_name_len
 Maximum file name length observed till now. More...
 
Snapshot file data
Clone_File_Vec m_data_file_vector
 All data files for transfer. More...
 
Clone_File_Map m_data_file_map
 Map space ID to file vector index. More...
 
uint m_num_data_chunks
 Total number of data chunks. More...
 
uint64_t m_data_bytes_disk
 Number of bytes on disk. More...
 
std::vector< int > m_undo_file_indexes
 Index into m_data_file_vector for all undo files. More...
 
Snapshot page data
Page_Arch_Client_Ctx m_page_ctx
 Page archiver client. More...
 
Clone_Page_Set m_page_set
 Set of unique page IDs. More...
 
Clone_Page_Vec m_page_vector
 Sorted page IDs to transfer. More...
 
uint m_num_pages
 Number of pages to transfer. More...
 
uint m_num_duplicate_pages
 Number of duplicate pages found. More...
 
Snapshot redo data
Log_Arch_Client_Ctx m_redo_ctx
 redo log archiver client More...
 
Clone_File_Vec m_redo_file_vector
 All archived redo files to transfer. More...
 
uint64_t m_redo_start_offset
 Start offset in first redo file. More...
 
bytem_redo_header
 Redo header block. More...
 
uint m_redo_header_size
 Redo header size. More...
 
bytem_redo_trailer
 Redo trailer block. More...
 
uint m_redo_trailer_size
 Redo trailer size. More...
 
uint64_t m_redo_trailer_offset
 Redo trailer block offset. More...
 
uint64_t m_redo_file_size
 Archived redo file size. More...
 
uint m_num_redo_chunks
 Total number of redo data chunks. More...
 
bool m_enable_pfs
 Enable PFS monitoring. More...
 
Clone_Monitor m_monitor
 Performance Schema accounting object to monitor stage progress. More...
 

Static Private Attributes

static const uint32_t S_MAX_PAGES_PIN = 64
 Allow DDL file operation after 64 pages. More...
 
static const uint32_t S_MAX_BLOCKS_PIN = 1
 Allow DDL file operation after every block (1M data by default) More...
 
static const size_t S_FILE_NAME_BASE_LEN = 256
 File name allocation size base. More...
 

Detailed Description

Dynamic database snapshot: Holds metadata and handle to data.

Member Typedef Documentation

◆ File_Cbk_Func

using Clone_Snapshot::File_Cbk_Func = std::function<int(Clone_file_ctx *)>

Member Enumeration Documentation

◆ Wait_type

enum class Clone_Snapshot::Wait_type
strongprivate

Various wait types related to snapshot state.

Enumerator
STATE_TRANSIT_WAIT 
STATE_TRANSIT 
STATE_END_PAGE_COPY 
STATE_BLOCKER 
DATA_FILE_WAIT 
DATA_FILE_CLOSE 
DDL_FILE_OPERATION 

Constructor & Destructor Documentation

◆ Clone_Snapshot()

Clone_Snapshot::Clone_Snapshot ( Clone_Handle_Type  hdl_type,
Ha_clone_type  clone_type,
uint  arr_idx,
uint64_t  snap_id 
)

Construct snapshot.

Parameters
[in]hdl_typecopy, apply
[in]clone_typeclone type
[in]arr_idxindex in global array
[in]snap_idunique snapshot ID

◆ ~Clone_Snapshot()

Clone_Snapshot::~Clone_Snapshot ( )

Release contexts and free heap.

Member Function Documentation

◆ add_buf_pool_file()

int Clone_Snapshot::add_buf_pool_file ( )
private

Add buffer pool dump file to the file list.

Returns
error code

◆ add_file()

int Clone_Snapshot::add_file ( const char *  name,
uint64_t  size_bytes,
uint64_t  alloc_bytes,
fil_node_t node,
bool  by_ddl 
)
private

Add file to snapshot.

Parameters
[in]namefile name
[in]size_bytesfile size in bytes
[in]alloc_bytesallocation size on disk for sparse file
[in]nodefile node
[in]by_ddlnode is added concurrently by DDL
Returns
error code.

◆ add_file_from_desc()

bool Clone_Snapshot::add_file_from_desc ( Clone_file_ctx *&  file_ctx,
bool  ddl_create 
)

Add file descriptor to file list.

Parameters
[in,out]file_ctxcurrent file context
[in]ddl_createadded by DDL concurrently
Returns
true, if it is the last file.

Check if it the last file

◆ add_node()

dberr_t Clone_Snapshot::add_node ( fil_node_t node,
bool  by_ddl 
)

Extract file information from node and add to snapshot.

Parameters
[in]nodefile node
[in]by_ddlnode is added concurrently by DDL
Returns
error code

◆ add_page()

int Clone_Snapshot::add_page ( uint32_t  space_id,
uint32_t  page_num 
)

Add page ID to to the set of pages in snapshot.

Parameters
[in]space_idpage tablespace
[in]page_numpage number within tablespace
Returns
error code

◆ add_redo_file()

int Clone_Snapshot::add_redo_file ( char *  file_name,
uint64_t  file_size,
uint64_t  file_offset 
)

Add redo file to snapshot.

Parameters
[in]file_namefile name
[in]file_sizefile size in bytes
[in]file_offsetstart offset
Returns
error code.

◆ attach()

bool Clone_Snapshot::attach ( Clone_Handle_Type  hdl_type,
bool  pfs_monitor 
)

Try to attach to snapshot.

Parameters
[in]hdl_typecopy, apply
[in]pfs_monitorenable PFS monitoring
Returns
true if successfully attached

◆ begin_ddl_file()

int Clone_Snapshot::begin_ddl_file ( Clone_notify::Type  type,
space_id_t  space,
bool  no_wait,
bool  check_intr 
)
private

Handle files for DDL begin notification.

Parameters
[in]typetype of DDL notification
[in]spacespace ID for the ddl operation
[in]no_waitreturn with error if needs to wait
[in]check_intrcheck for interrupt during wait
Returns
mysql error code

◆ begin_ddl_state()

bool Clone_Snapshot::begin_ddl_state ( Clone_notify::Type  type,
space_id_t  space,
bool  no_wait,
bool  check_intr,
int &  error 
)

DDL notification before the operation.

Parameters
[in]typetype of DDL notification
[in]spacespace ID for the ddl operation
[in]no_waitreturn with error if needs to wait
[in]check_intrcheck for interrupt during wait
[out]errormysql error code
Returns
true iff clone state change is blocked.

◆ begin_transit()

void Clone_Snapshot::begin_transit ( Snapshot_State  new_state)
inlineprivate

Begin state transition.

Parameters
[in]new_statestate to transit to

◆ begin_transit_ddl_wait()

void Clone_Snapshot::begin_transit_ddl_wait ( )
inlineprivate

Begin state transition before waiting for DDL.

◆ block_size()

uint32_t Clone_Snapshot::block_size ( )
inlineprivate

Get block size for file copy.

Returns
block size in pages

◆ block_state_change()

bool Clone_Snapshot::block_state_change ( Clone_notify::Type  type,
space_id_t  space,
bool  no_wait,
bool  check_intr,
int &  error 
)
private

Block clone state transition.

Clone must wait.

Parameters
[in]typetype of DDL notification
[in]spacespace ID for the ddl operation
[in]no_waitreturn with error if needs to wait
[in]check_intrcheck for interrupt during wait`
[out]errormysql error code
Returns
true iff clone state change is blocked.

◆ blocks_clone()

bool Clone_Snapshot::blocks_clone ( const Clone_file_ctx file_ctx)

Check if DDL needs to block clone operation.

Parameters
[in]file_ctxfile context
Returns
true iff clone operation needs to be blocked.

◆ blocks_per_chunk()

uint32_t Clone_Snapshot::blocks_per_chunk ( ) const
inlineprivate

Get number of blocks per chunk for file copy.

Returns
blocks per chunk

◆ build_file()

Clone_file_ctx * Clone_Snapshot::build_file ( const char *  file_name,
uint64_t  file_size,
uint64_t  file_offset,
uint &  num_chunks 
)
private

Build file metadata entry.

Parameters
[in]file_namename of the file
[in]file_sizefile size in bytes
[in]file_offsetstart offset
[in]num_chunkstotal number of chunks in the file
Returns
file context

◆ build_file_ctx()

int Clone_Snapshot::build_file_ctx ( Clone_file_ctx::Extension  extn,
const Clone_File_Meta file_meta,
const std::string &  file_path,
Clone_file_ctx *&  file_ctx 
)
private

Build file context from file path.

Parameters
[in]extnfile extension type
[in]file_metafile descriptor
[in]file_pathdata file along with path
[out]file_ctxcreated file context
Returns
error code

◆ build_file_name()

bool Clone_Snapshot::build_file_name ( Clone_File_Meta file_meta,
const char *  file_name 
)
private

Allocate and set clone file name.

Parameters
[in,out]file_metafile metadata
[in]file_namefile name
Returns
true iff successful.

◆ build_file_path()

int Clone_Snapshot::build_file_path ( const char *  data_dir,
const Clone_File_Meta file_desc,
std::string &  file_path 
)
private

Build file name along with path for cloned data files.

Parameters
[in]data_dirclone data directory
[in]file_descfile descriptor
[out]file_pathbuilt file path if returned 0
Returns
error code (0 on success)

◆ change_state()

int Clone_Snapshot::change_state ( Clone_Desc_State state_desc,
Snapshot_State  new_state,
byte temp_buffer,
uint  temp_buffer_len,
Clone_Alert_Func  cbk 
)

Start transition to new state.

Parameters
[in]state_descdescriptor for next state
[in]new_statestate to move for apply
[in]temp_bufferbuffer used for collecting page IDs
[in]temp_buffer_lenbuffer length
[in]cbkalter callback for long wait
Returns
error code

◆ chunk_size()

uint32_t Clone_Snapshot::chunk_size ( ) const
inlineprivate

Get chunk size.

Returns
chunk size in pages

◆ create_desc()

int Clone_Snapshot::create_desc ( const char *  data_dir,
const Clone_File_Meta file_meta,
bool  is_ddl,
Clone_file_ctx *&  file_ctx 
)
private

Create file descriptor and add to current file list.

Parameters
[in]data_dirdestination data directory
[in]file_metafile metadata from donor
[in]is_ddlif ddl temporary file
[out]file_ctxfile context
Returns
error code

◆ debug_wait_state_transit()

void Clone_Snapshot::debug_wait_state_transit ( )
private

Debug sync Wait during state transition.

◆ decrypt_key_in_header()

void Clone_Snapshot::decrypt_key_in_header ( const Clone_File_Meta file_meta,
const page_size_t page_size,
byte *&  page_data 
)

Decrypt tablespace key in header page with master key.

Parameters
[in]file_metaclone file metadata
[in]page_sizepage size descriptor
[in,out]page_datapage data to update

◆ detach()

void Clone_Snapshot::detach ( )

Detach from snapshot.

◆ encrypt_key_in_header()

bool Clone_Snapshot::encrypt_key_in_header ( const page_size_t page_size,
byte page_data 
)

Encrypt tablespace key in header page with master key.

Parameters
[in]page_sizepage size descriptor
[in,out]page_datapage data to update
Returns
true, if successful.

◆ encrypt_key_in_log_header()

bool Clone_Snapshot::encrypt_key_in_log_header ( byte log_header,
uint32_t  header_len 
)

Encrypt tablespace key in header page with master key.

Parameters
[in,out]log_headerpage data to update
[in]header_lenlength of log header
Returns
true, if successful.

◆ end_ddl_file()

void Clone_Snapshot::end_ddl_file ( Clone_notify::Type  type,
space_id_t  space 
)
private

Handle files for DDL end notification.

Parameters
[in]typetype of DDL notification
[in]spacespace ID for the ddl operation

◆ end_ddl_state()

void Clone_Snapshot::end_ddl_state ( Clone_notify::Type  type,
space_id_t  space 
)

DDL notification after the operation.

Parameters
[in]typetype of DDL notification
[in]spacespace ID for the ddl operation

◆ end_transit()

void Clone_Snapshot::end_transit ( )
inlineprivate

End state transition.

◆ extend_and_flush_files()

int Clone_Snapshot::extend_and_flush_files ( bool  flush_redo)
private

Extend and flush files after copying data.

Parameters
[in]flush_redoif true flush redo, otherwise data
Returns
error code

◆ file_ctx_changed()

bool Clone_Snapshot::file_ctx_changed ( const fil_node_t node,
Clone_file_ctx *&  file_ctx 
)
private

Check if file context has been changed by ddl.

Parameters
[in]nodetablespace file node
[out]file_ctxfile context if exists
Returns
true iff file is created or modified by DDL.

◆ fix_ddl_extension()

int Clone_Snapshot::fix_ddl_extension ( const char *  data_dir,
Clone_file_ctx file_ctx 
)

Fix files renamed with ddl extension.

The file name is checked against existing file and added to appropriate status file.

Parameters
[in]data_dirdestination data directory
[in,out]file_ctxSet to correct extension
Returns
error code

◆ get_blocks_per_chunk()

uint32_t Clone_Snapshot::get_blocks_per_chunk ( ) const
Returns
number of blocks per chunk for different states.

◆ get_chunk_size()

uint32_t Clone_Snapshot::get_chunk_size ( ) const
inline
Returns
chunk size in bytes.

◆ get_clone_monitor()

Clone_Monitor & Clone_Snapshot::get_clone_monitor ( )
inline

Get performance schema accounting object used to monitor stage progress.

Returns
PFS stage object

◆ get_data_file_ctx()

Clone_file_ctx * Clone_Snapshot::get_data_file_ctx ( uint32_t  chunk_num,
uint32_t  hint_index 
)
private

Get clone data file context by chunk number.

Parameters
[in]chunk_numchunk number
[in]hint_indexhint file index number to start search.
Returns
file context

◆ get_disk_estimate()

uint64_t Clone_Snapshot::get_disk_estimate ( ) const
inline
Returns
estimated bytes on disk

◆ get_dyn_buffer_length()

uint Clone_Snapshot::get_dyn_buffer_length ( )
inline

Get maximum buffer size required for clone.

Returns
maximum dynamic buffer

◆ get_file()

Clone_file_ctx * Clone_Snapshot::get_file ( Clone_File_Vec file_vector,
uint32_t  chunk_num,
uint32_t  start_index 
)
private

Get file context for current chunk.

Parameters
[in]file_vectorclone file vector
[in]chunk_numcurrent chunk number
[in]start_indexindex for starting the search
Returns
file context

◆ get_file_by_index()

Clone_File_Meta * Clone_Snapshot::get_file_by_index ( uint  index)

Get file metadata by index for current state.

Parameters
[in]indexfile index
Returns
file metadata entry

◆ get_file_ctx()

Clone_file_ctx * Clone_Snapshot::get_file_ctx ( uint32_t  chunk_num,
uint32_t  block_num,
uint32_t  hint_index 
)

Get clone file context by chunk and block number.

Parameters
[in]chunk_numchunk number
[in]block_numblock number
[in]hint_indexhint file index number to start search.
Returns
file context

◆ get_file_ctx_by_index()

Clone_file_ctx * Clone_Snapshot::get_file_ctx_by_index ( uint  index)

Get clone file context by index for current state.

Parameters
[in]indexfile index
Returns
file context

◆ get_file_from_desc()

int Clone_Snapshot::get_file_from_desc ( const Clone_File_Meta file_meta,
const char *  data_dir,
bool  desc_create,
bool &  desc_exists,
Clone_file_ctx *&  file_ctx 
)

Add file metadata entry at destination.

Parameters
[in]file_metafile metadata from donor
[in]data_dirdestination data directory
[in]desc_createcreate if doesn't exist
[out]desc_existsdescriptor already exists
[out]file_ctxif there, set to current file context
Returns
error code

◆ get_id()

uint64_t Clone_Snapshot::get_id ( )
inline

Get unique snapshot identifier.

Returns
snapshot ID

◆ get_index()

uint Clone_Snapshot::get_index ( void  )
inline

Get snapshot index in global array.

Returns
array index

◆ get_max_blocks_pin()

uint32_t Clone_Snapshot::get_max_blocks_pin ( ) const
Returns
maximum blocks to transfer with file pinned.

◆ get_max_file_name_length()

size_t Clone_Snapshot::get_max_file_name_length ( )
inline

Get maximum file length seen till now.

Returns
file name length

◆ get_next_block()

int Clone_Snapshot::get_next_block ( uint  chunk_num,
uint &  block_num,
const Clone_file_ctx *&  file_ctx,
uint64_t &  data_offset,
byte *&  data_buf,
uint32_t &  data_size,
uint64_t &  file_size 
)

Get next block of data to transfer.

Parameters
[in]chunk_numcurrent chunk
[in,out]block_numcurrent/next block
[in,out]file_ctxcurrent/next block file context
[out]data_offsetblock offset in file
[out]data_bufdata buffer or NULL if transfer from file
[out]data_sizesize of data in bytes
[out]file_sizeupdated file size if extended
Returns
error code

◆ get_next_page()

int Clone_Snapshot::get_next_page ( uint  chunk_num,
uint &  block_num,
const Clone_file_ctx *&  file_ctx,
uint64_t &  data_offset,
byte *&  data_buf,
uint32_t &  data_size,
uint64_t &  file_size 
)
private

Get next page from buffer pool.

Parameters
[in]chunk_numcurrent chunk
[in,out]block_numcurrent, next block
[in,out]file_ctxcurrent, next block file context
[out]data_offsetoffset in file
[out]data_bufpage data
[out]data_sizepage data size
[out]file_sizeupdated file size if extended
Returns
error code

◆ get_next_state()

Snapshot_State Clone_Snapshot::get_next_state ( )

Get next state based on snapshot type.

Returns
next state

◆ get_num_chunks()

uint Clone_Snapshot::get_num_chunks ( )
inline

Get total number of chunks for current state.

Returns
number of data chunks

◆ get_page_file_ctx()

Clone_file_ctx * Clone_Snapshot::get_page_file_ctx ( uint32_t  chunk_num,
uint32_t  block_num 
)
private

Get clone page file context by chunk number and block number.

Parameters
[in]chunk_numchunk number
[in]block_numblock number
Returns
file context

◆ get_page_for_write()

int Clone_Snapshot::get_page_for_write ( const page_id_t page_id,
const page_size_t page_size,
const Clone_file_ctx file_ctx,
byte *&  page_data,
uint &  data_size 
)
private

Get page from buffer pool and make ready for write.

Parameters
[in]page_idpage ID chunk
[in]page_sizepage size descriptor
[in]file_ctxclone file context
[out]page_datadata page
[out]data_sizepage size in bytes
Returns
error code

◆ get_redo_file_ctx()

Clone_file_ctx * Clone_Snapshot::get_redo_file_ctx ( uint32_t  chunk_num,
uint32_t  hint_index 
)
private

Get clone redo file context by chunk number.

Parameters
[in]chunk_numchunk number
[in]hint_indexhint file index number to start search.
Returns
file context

◆ get_redo_file_size()

uint64_t Clone_Snapshot::get_redo_file_size ( )
inline

Get the redo file size for the snapshot.

Returns
redo file size

◆ get_state()

Snapshot_State Clone_Snapshot::get_state ( )
inline

Get snapshot state.

Returns
state

◆ get_state_info()

void Clone_Snapshot::get_state_info ( bool  do_estimate,
Clone_Desc_State state_desc 
)

Fill state descriptor from snapshot.

Parameters
[in]do_estimateestimate data bytes to transfer
[out]state_descsnapshot state descriptor

◆ get_target_file_state()

Clone_file_ctx::State Clone_Snapshot::get_target_file_state ( Clone_notify::Type  type,
bool  begin 
)
private

Get next file state while being modified by ddl.

Parameters
[in]typeddl notification type
[in]begintrue, if DDL begin notification false, if DDL end notification
Returns
target file state.

◆ get_wait_mesg()

void Clone_Snapshot::get_wait_mesg ( Wait_type  wait_type,
std::string &  info,
std::string &  error 
)
private

During wait get relevant message string for logging.

Parameters
[in]wait_typewait type
[out]infonotification to log while waiting
[out]errorerror message to log on timeout

◆ handle_existing_file()

int Clone_Snapshot::handle_existing_file ( bool  replace,
bool  undo_file,
bool  redo_file,
uint32_t  data_file_index,
const std::string &  data_file,
Clone_file_ctx::Extension extn 
)
private

Check for existing file and if clone extension is needed.

This function has the side effect to add undo file indexes.

Parameters
[in]replaceif data directory is replaced
[in]undo_fileif undo tablespace file
[in]redo_fileif redo file
[in]data_file_indexindex of file
[in]data_filedata file name
[out]extnfile extension needs to be used
Returns
error code

◆ in_transit_state()

bool Clone_Snapshot::in_transit_state ( ) const
inlineprivate

Check if state transition is in progress.

Returns
true during state transition

◆ in_transit_wait()

bool Clone_Snapshot::in_transit_wait ( ) const
inlineprivate
Returns
true, if waiting before starting transition. Generally the case when some DDL blocks state transition.

◆ init_apply_state()

int Clone_Snapshot::init_apply_state ( Clone_Desc_State state_desc)
private

Initialize state while applying cloned data.

Parameters
[in]state_descsnapshot state descriptor
Returns
error code

◆ init_disk_estimate()

void Clone_Snapshot::init_disk_estimate ( )
inlineprivate

Initialize disk byte estimate.

◆ init_file_copy()

int Clone_Snapshot::init_file_copy ( Snapshot_State  new_state)
private

Initialize snapshot state for file copy.

Parameters
[in]new_statestate to move for apply
Returns
error code

◆ init_page_copy()

int Clone_Snapshot::init_page_copy ( Snapshot_State  new_state,
byte page_buffer,
uint  page_buffer_len 
)
private

Initialize snapshot state for page copy.

Parameters
[in]new_statestate to move for apply
[in]page_buffertemporary buffer to copy page IDs
[in]page_buffer_lenbuffer length
Returns
error code

◆ init_redo_archiving()

int Clone_Snapshot::init_redo_archiving ( )
private

Start redo archiving.

Returns
error code

◆ init_redo_copy()

int Clone_Snapshot::init_redo_copy ( Snapshot_State  new_state,
Clone_Alert_Func  cbk 
)
private

Initialize snapshot state for redo copy.

Parameters
[in]new_statestate to move for apply
[in]cbkalert callback for long wait
Returns
error code

◆ is_aborted()

bool Clone_Snapshot::is_aborted ( ) const
Returns
true, iff clone has aborted.

◆ is_copy()

bool Clone_Snapshot::is_copy ( ) const
inline

Check if copy snapshot.

Returns
true if snapshot is for copy

◆ iterate_data_files()

int Clone_Snapshot::iterate_data_files ( File_Cbk_Func &&  func)

Iterate through all data files.

Parameters
[in]funccallback function
Returns
error code

◆ iterate_files()

int Clone_Snapshot::iterate_files ( File_Cbk_Func &&  func)

Iterate through all files in current state.

Parameters
[in]funccallback function
Returns
error code

◆ iterate_redo_files()

int Clone_Snapshot::iterate_redo_files ( File_Cbk_Func &&  func)

Iterate through all redo files.

Parameters
[in]funccallback function
Returns
error code

◆ lock_heap()

mem_heap_t * Clone_Snapshot::lock_heap ( )
inline

Get snapshot heap used for allocation during clone.

Returns
heap

◆ num_data_files()

size_t Clone_Snapshot::num_data_files ( ) const
inlineprivate
Returns
number of data files to transfer.

◆ num_redo_files()

size_t Clone_Snapshot::num_redo_files ( ) const
inlineprivate
Returns
number of redo files to transfer.

◆ page_update_for_flush()

void Clone_Snapshot::page_update_for_flush ( const page_size_t page_size,
lsn_t  page_lsn,
byte *&  page_data 
)
private

◆ pin_file()

int Clone_Snapshot::pin_file ( Clone_file_ctx file_ctx,
bool &  handle_delete 
)

Wait for concurrent DDL file operation and pin file.

Parameters
[in,out]file_ctxfile context
[out]handle_deleteif caller needs to handle deleted state
Returns
mysql error code.

◆ release_heap()

void Clone_Snapshot::release_heap ( mem_heap_t *&  heap)
inline

◆ rename_desc()

int Clone_Snapshot::rename_desc ( const Clone_File_Meta file_meta,
const char *  data_dir,
Clone_file_ctx *&  file_ctx 
)

Rename an existing file descriptor.

Parameters
[in]file_metarenamed file metadata from donor
[in]data_dirdestination data directory
[out]file_ctxif there, set to current file context
Returns
error code

◆ set_abort()

void Clone_Snapshot::set_abort ( )

Set current snapshot aborted state.

Used in error cases before exiting clone to make sure any DDL notifier exits waiting.

◆ set_state_info()

void Clone_Snapshot::set_state_info ( Clone_Desc_State state_desc)

Set state information during apply.

Parameters
[in]state_descsnapshot state descriptor

◆ skip_deleted_blocks()

void Clone_Snapshot::skip_deleted_blocks ( uint32_t  chunk_num,
uint32_t &  block_num 
)

Skip all blocks belonging to currently deleted file context.

Parameters
[in]chunk_numcurrent chunk
[in,out]block_numcurrent, next block

◆ synchronize_binlog_gtid()

int Clone_Snapshot::synchronize_binlog_gtid ( Clone_Alert_Func  cbk)
private

Synchronize snapshot with binary log and GTID.

Parameters
[in]cbkalert callback for long wait
Returns
error code.

◆ unblock_state_change()

void Clone_Snapshot::unblock_state_change ( )
inlineprivate

Unblock clone state transition.

◆ unpin_file()

void Clone_Snapshot::unpin_file ( Clone_file_ctx file_ctx)
inline

Unpin a file.

Parameters
[in,out]file_ctxfile context

◆ update_binlog_position()

int Clone_Snapshot::update_binlog_position ( )
private

Make sure that the trx sys page binary log position correctly reflects all transactions committed to innodb.

It updates binary log position in transaction sys page, if required. The caller must ensure that any new transaction is committed in order of binary log.

Returns
error code.

◆ update_block_size()

void Clone_Snapshot::update_block_size ( uint  buff_size)

Update snapshot block size based on caller's buffer size.

Parameters
[in]buff_sizebuffer size for clone transfer

◆ update_deleted_state()

bool Clone_Snapshot::update_deleted_state ( Clone_file_ctx file_ctx)
private

Update deleted state of a file if not yet done.

Parameters
[in,out]file_ctxfile context
Returns
true, if updated state

◆ update_file_size()

void Clone_Snapshot::update_file_size ( uint32_t  file_index,
uint64_t  file_size 
)

Update file size when file is extended during page copy.

Parameters
[in]file_indexcurrent file index
[in]file_sizenew file size

◆ update_sys_file_name()

int Clone_Snapshot::update_sys_file_name ( bool  replace,
const Clone_File_Meta file_meta,
std::string &  file_name 
)
private

Update system file name from configuration.

Parameters
[in]replaceif replacing current data directory
[in]file_metafile descriptor
[in,out]file_namefile name to update
Returns
error code

◆ wait()

int Clone_Snapshot::wait ( Wait_type  type,
const Clone_file_ctx ctx,
bool  no_wait,
bool  check_intr 
)
private

Wait for various operations based on type.

Parameters
[in]typewait type
[in]ctxfile context when relevant
[in]no_waitreturn with error if needs to wait
[in]check_intrcheck for interrupt during wait
Returns
mysql error code.

◆ wait_for_binlog_prepared_trx()

int Clone_Snapshot::wait_for_binlog_prepared_trx ( )
private

Wait for already prepared binlog transactions to end.

Returns
error code.

◆ wait_string()

const char * Clone_Snapshot::wait_string ( Wait_type  wait_type) const
private

Get wait information string based on wait type.

Parameters
[in]wait_typewait type
Returns
wait information string.

◆ wait_trx_end()

int Clone_Snapshot::wait_trx_end ( THD thd,
trx_id_t  trx_id 
)
private

Wait for a transaction to end.

Parameters
[in]thdcurrent THD
[in]trx_idtransaction to wait for
Returns
error code.

Member Data Documentation

◆ m_aborted

bool Clone_Snapshot::m_aborted
private

Set to true only if clone is aborted after error.

◆ m_block_size_pow2

uint Clone_Snapshot::m_block_size_pow2
private

Block size in power of 2.

◆ m_chunk_size_pow2

uint Clone_Snapshot::m_chunk_size_pow2
private

Chunk size in power of 2.

◆ m_data_bytes_disk

uint64_t Clone_Snapshot::m_data_bytes_disk
private

Number of bytes on disk.

◆ m_data_file_map

Clone_File_Map Clone_Snapshot::m_data_file_map
private

Map space ID to file vector index.

◆ m_data_file_vector

Clone_File_Vec Clone_Snapshot::m_data_file_vector
private

All data files for transfer.

◆ m_enable_pfs

bool Clone_Snapshot::m_enable_pfs
private

Enable PFS monitoring.

◆ m_max_file_name_len

size_t Clone_Snapshot::m_max_file_name_len
private

Maximum file name length observed till now.

◆ m_monitor

Clone_Monitor Clone_Snapshot::m_monitor
private

Performance Schema accounting object to monitor stage progress.

◆ m_num_blockers

uint32_t Clone_Snapshot::m_num_blockers
private

Number of blockers for state change.

Usually DDLs for short duration.

◆ m_num_clones

uint Clone_Snapshot::m_num_clones
private

Number of clones attached to this snapshot.

◆ m_num_clones_transit

uint Clone_Snapshot::m_num_clones_transit
private

Number of clones in in state transition.

◆ m_num_current_chunks

uint Clone_Snapshot::m_num_current_chunks
private

Number of chunks in current state.

◆ m_num_data_chunks

uint Clone_Snapshot::m_num_data_chunks
private

Total number of data chunks.

◆ m_num_duplicate_pages

uint Clone_Snapshot::m_num_duplicate_pages
private

Number of duplicate pages found.

◆ m_num_pages

uint Clone_Snapshot::m_num_pages
private

Number of pages to transfer.

◆ m_num_redo_chunks

uint Clone_Snapshot::m_num_redo_chunks
private

Total number of redo data chunks.

◆ m_page_ctx

Page_Arch_Client_Ctx Clone_Snapshot::m_page_ctx
private

Page archiver client.

◆ m_page_set

Clone_Page_Set Clone_Snapshot::m_page_set
private

Set of unique page IDs.

◆ m_page_vector

Clone_Page_Vec Clone_Snapshot::m_page_vector
private

Sorted page IDs to transfer.

◆ m_redo_ctx

Log_Arch_Client_Ctx Clone_Snapshot::m_redo_ctx
private

redo log archiver client

◆ m_redo_file_size

uint64_t Clone_Snapshot::m_redo_file_size
private

Archived redo file size.

◆ m_redo_file_vector

Clone_File_Vec Clone_Snapshot::m_redo_file_vector
private

All archived redo files to transfer.

◆ m_redo_header

byte* Clone_Snapshot::m_redo_header
private

Redo header block.

◆ m_redo_header_size

uint Clone_Snapshot::m_redo_header_size
private

Redo header size.

◆ m_redo_start_offset

uint64_t Clone_Snapshot::m_redo_start_offset
private

Start offset in first redo file.

◆ m_redo_trailer

byte* Clone_Snapshot::m_redo_trailer
private

Redo trailer block.

◆ m_redo_trailer_offset

uint64_t Clone_Snapshot::m_redo_trailer_offset
private

Redo trailer block offset.

◆ m_redo_trailer_size

uint Clone_Snapshot::m_redo_trailer_size
private

Redo trailer size.

◆ m_snapshot_arr_idx

uint Clone_Snapshot::m_snapshot_arr_idx
private

Index in global snapshot array.

◆ m_snapshot_handle_type

Clone_Handle_Type Clone_Snapshot::m_snapshot_handle_type
private

Snapshot handle type.

◆ m_snapshot_heap

mem_heap_t* Clone_Snapshot::m_snapshot_heap
private

Memory allocation heap.

◆ m_snapshot_id

uint64_t Clone_Snapshot::m_snapshot_id
private

Unique snapshot ID.

◆ m_snapshot_mutex

ib_mutex_t Clone_Snapshot::m_snapshot_mutex
mutableprivate

Mutex to handle access by concurrent clones.

◆ m_snapshot_next_state

Snapshot_State Clone_Snapshot::m_snapshot_next_state
private

Next state to move to.

Set only during state transfer.

◆ m_snapshot_state

Snapshot_State Clone_Snapshot::m_snapshot_state
private

Current state.

◆ m_snapshot_type

Ha_clone_type Clone_Snapshot::m_snapshot_type
private

Clone type.

◆ m_undo_file_indexes

std::vector<int> Clone_Snapshot::m_undo_file_indexes
private

Index into m_data_file_vector for all undo files.

◆ S_FILE_NAME_BASE_LEN

const size_t Clone_Snapshot::S_FILE_NAME_BASE_LEN = 256
staticprivate

File name allocation size base.

◆ S_MAX_BLOCKS_PIN

const uint32_t Clone_Snapshot::S_MAX_BLOCKS_PIN = 1
staticprivate

Allow DDL file operation after every block (1M data by default)

◆ S_MAX_PAGES_PIN

const uint32_t Clone_Snapshot::S_MAX_PAGES_PIN = 64
staticprivate

Allow DDL file operation after 64 pages.


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