MySQL 9.0.0
Source Code Documentation
Clone_Task_Manager Class Reference

Task manager for manging the tasks for a clone operation. More...

#include <clone0clone.h>

Public Member Functions

void init (Clone_Snapshot *snapshot)
 Initialize task manager for clone handle. More...
 
ib_mutex_t * get_mutex ()
 Get task state mutex. More...
 
int handle_error_other_task (bool raise_error)
 Handle any error raised by concurrent tasks. More...
 
void set_error (int err, const char *file_name)
 Set error number. More...
 
int add_task (THD *thd, const byte *ref_loc, uint loc_len, uint &task_id)
 Add a task to task manager. More...
 
bool drop_task (THD *thd, uint task_id, bool &is_master)
 Drop task from task manager. More...
 
bool is_chunk_reserved (uint32_t chunk_num)
 Check if chunk is already reserved. More...
 
void reset_chunk (Clone_Task *task)
 Reset chunk information for task. More...
 
Clone_Taskget_task_by_index (uint index)
 Get task by index. More...
 
int reserve_next_chunk (Clone_Task *task, uint32_t &ret_chunk, uint32_t &ret_block)
 Reserve next chunk from task manager. More...
 
int set_chunk (Clone_Task *task, Clone_Task_Meta *new_meta)
 Set current chunk and block information. More...
 
void add_incomplete_chunk (Clone_Task *task)
 Track any incomplete chunks handled by the task. More...
 
void init_state ()
 Initialize task manager for current state. More...
 
void reinit_copy_state (const byte *loc, uint loc_len)
 Reinitialize state using locator. More...
 
void reinit_apply_state (const byte *ref_loc, uint ref_len, byte *&new_loc, uint &new_len, uint &alloc_len)
 Reinitialize state using locator. More...
 
void reset_transition ()
 Reset state transition information. More...
 
void reset_error ()
 Reset error information. More...
 
Snapshot_State get_state ()
 Get current clone state. More...
 
bool in_transit_state ()
 Check if in state transition. More...
 
Clone_Snapshotget_snapshot ()
 Get attached snapshot. More...
 
int change_state (Clone_Task *task, Clone_Desc_State *state_desc, Snapshot_State new_state, Clone_Alert_Func cbk, uint &num_wait)
 Move to next snapshot state. More...
 
int check_state (Clone_Task *task, Snapshot_State new_state, bool exit_on_wait, int in_err, uint32_t &num_wait)
 Check if state transition is over and all tasks moved to next state. More...
 
bool is_restart_metadata (Clone_Task *task)
 Check if needs to send state metadata once. More...
 
bool is_file_metadata_transferred () const
 
void set_file_meta_transferred ()
 Set sub-state: all file metadata is transferred. More...
 
int finish_state (Clone_Task *task)
 Mark state finished for current task. More...
 
void ack_state (const Clone_Desc_State *state_desc)
 Set acknowledged state. More...
 
int wait_ack (Clone_Handle *clone, Clone_Task *task, Ha_clone_cbk *callback)
 Wait for acknowledgement. More...
 
bool check_ack (const Clone_Desc_State *state_desc)
 Check if state ACK is needed. More...
 
bool is_restarted ()
 Check if clone is restarted after failure. More...
 
int alloc_buffer (Clone_Task *task)
 Allocate buffers for current task. More...
 
bool debug_sync_check (uint32_t chunk_num, Clone_Task *task)
 Check if needs to wait for debug sync point. More...
 
void debug_wait (uint chunk_num, Clone_Task *task)
 Wait during clone operation. More...
 
void debug_wait_ddl_meta ()
 Wait before sending DDL metadata. More...
 
int debug_restart (Clone_Task *task, int in_err, int restart_count)
 Force restart clone operation by raising network error. More...
 
Clone_Taskfind_master_task ()
 

Private Member Functions

bool wait_before_add (const byte *ref_loc, uint loc_len)
 Check if we need to wait before adding current task. More...
 
bool is_network_error (int err)
 Check if network error. More...
 
void reserve_task (THD *thd, uint &task_id)
 Reserve free task from task manager and initialize. More...
 
bool process_inclomplete_chunk ()
 Check if we should process incomplete chunk next. More...
 
uint32_t get_next_incomplete_chunk (uint32_t &block_num)
 Get next in complete chunk if any. More...
 
uint32_t get_next_chunk ()
 Get next unreserved chunk. More...
 

Private Attributes

ib_mutex_t m_state_mutex
 Mutex synchronizing access by concurrent tasks. More...
 
Chunk_Info m_chunk_info
 Finished and incomplete chunk information. More...
 
Clone_Task m_clone_tasks [CLONE_MAX_TASKS]
 Clone task array. More...
 
uint m_num_tasks
 Current number of tasks. More...
 
uint m_num_tasks_finished
 Number of tasks finished current state. More...
 
uint m_num_tasks_transit
 Number of tasks in transit state. More...
 
uint m_restart_count
 Number of times clone is restarted. More...
 
Snapshot_State m_ack_state
 Acknowledged state from client. More...
 
Snapshot_State m_current_state
 Current state for clone. More...
 
Snapshot_State m_next_state
 Next state: used during state transfer. More...
 
bool m_transferred_file_meta
 
bool m_send_state_meta
 Send state metadata before starting: Used for restart. More...
 
int m_saved_error
 Save any error raised by a task. More...
 
std::string m_err_file_name
 File name related to the saved error. More...
 
Clone_Snapshotm_clone_snapshot
 Attached snapshot handle. More...
 

Detailed Description

Task manager for manging the tasks for a clone operation.

Member Function Documentation

◆ ack_state()

void Clone_Task_Manager::ack_state ( const Clone_Desc_State state_desc)

Set acknowledged state.

Parameters
[in]state_descState descriptor

◆ add_incomplete_chunk()

void Clone_Task_Manager::add_incomplete_chunk ( Clone_Task task)

Track any incomplete chunks handled by the task.

Parameters
[in,out]taskcurrent task

◆ add_task()

int Clone_Task_Manager::add_task ( THD thd,
const byte ref_loc,
uint  loc_len,
uint &  task_id 
)

Add a task to task manager.

Parameters
[in]thdserver THD object
[in]ref_locreference locator from remote
[in]loc_lenlocator length in bytes
[out]task_idtask identifier
Returns
error code

◆ alloc_buffer()

int Clone_Task_Manager::alloc_buffer ( Clone_Task task)

Allocate buffers for current task.

Parameters
[in,out]taskcurrent task
Returns
error code

◆ change_state()

int Clone_Task_Manager::change_state ( Clone_Task task,
Clone_Desc_State state_desc,
Snapshot_State  new_state,
Clone_Alert_Func  cbk,
uint &  num_wait 
)

Move to next snapshot state.

Each task must call this after no more chunk is left in current state. The state can be changed only after all tasks have finished transferring the reserved chunks.

Parameters
[in]taskclone task
[in]state_descdescriptor for next state
[in]new_statenext state to move to
[in]cbkalert callback for long wait
[out]num_waitunfinished tasks in current state
Returns
error code

◆ check_ack()

bool Clone_Task_Manager::check_ack ( const Clone_Desc_State state_desc)
inline

Check if state ACK is needed.

Parameters
[in]state_descState descriptor
Returns
true if need to wait for ACK from remote

◆ check_state()

int Clone_Task_Manager::check_state ( Clone_Task task,
Snapshot_State  new_state,
bool  exit_on_wait,
int  in_err,
uint32_t &  num_wait 
)

Check if state transition is over and all tasks moved to next state.

Parameters
[in]taskrequesting task
[in]new_statenext state to move to
[in]exit_on_waitexit from transition if needs to wait
[in]in_errinput error if already occurred
[out]num_waitnumber of tasks to move to next state
Returns
error code

◆ debug_restart()

int Clone_Task_Manager::debug_restart ( Clone_Task task,
int  in_err,
int  restart_count 
)

Force restart clone operation by raising network error.

Parameters
[in]taskcurrent task
[in]in_errany err that has occurred
[in]restart_countrestart counter
Returns
error code

◆ debug_sync_check()

bool Clone_Task_Manager::debug_sync_check ( uint32_t  chunk_num,
Clone_Task task 
)

Check if needs to wait for debug sync point.

Parameters
[in]chunk_numchunk number to process
[in]taskcurrent task
Returns
true, if clone needs to check and wait

◆ debug_wait()

void Clone_Task_Manager::debug_wait ( uint  chunk_num,
Clone_Task task 
)

Wait during clone operation.

Parameters
[in]chunk_numchunk number to process
[in]taskcurrent task

◆ debug_wait_ddl_meta()

void Clone_Task_Manager::debug_wait_ddl_meta ( )

Wait before sending DDL metadata.

◆ drop_task()

bool Clone_Task_Manager::drop_task ( THD thd,
uint  task_id,
bool &  is_master 
)

Drop task from task manager.

Parameters
[in]thdserver THD object
[in]task_idcurrent task ID
[out]is_mastertrue, if master task
Returns
true if needs to wait for re-start

◆ find_master_task()

Clone_Task * Clone_Task_Manager::find_master_task ( )
Returns
clone master task.

◆ finish_state()

int Clone_Task_Manager::finish_state ( Clone_Task task)

Mark state finished for current task.

Parameters
[in]taskcurrent task
Returns
error code

◆ get_mutex()

ib_mutex_t * Clone_Task_Manager::get_mutex ( )
inline

Get task state mutex.

Returns
state mutex

◆ get_next_chunk()

uint32_t Clone_Task_Manager::get_next_chunk ( )
private

Get next unreserved chunk.

Returns
chunk number

◆ get_next_incomplete_chunk()

uint32_t Clone_Task_Manager::get_next_incomplete_chunk ( uint32_t &  block_num)
private

Get next in complete chunk if any.

Parameters
[out]block_numfirst block number in chunk
Returns
incomplete chunk number

◆ get_snapshot()

Clone_Snapshot * Clone_Task_Manager::get_snapshot ( )
inline

Get attached snapshot.

Returns
snapshot

◆ get_state()

Snapshot_State Clone_Task_Manager::get_state ( )
inline

Get current clone state.

Returns
clone state

◆ get_task_by_index()

Clone_Task * Clone_Task_Manager::get_task_by_index ( uint  index)
inline

Get task by index.

Parameters
[in]indextask index
Returns
task

◆ handle_error_other_task()

int Clone_Task_Manager::handle_error_other_task ( bool  raise_error)

Handle any error raised by concurrent tasks.

Parameters
[in]raise_errorraise error if true
Returns
error code

◆ in_transit_state()

bool Clone_Task_Manager::in_transit_state ( )
inline

Check if in state transition.

Returns
true if state transition is in progress

◆ init()

void Clone_Task_Manager::init ( Clone_Snapshot snapshot)

Initialize task manager for clone handle.

Parameters
[in]snapshotsnapshot

◆ init_state()

void Clone_Task_Manager::init_state ( )

Initialize task manager for current state.

◆ is_chunk_reserved()

bool Clone_Task_Manager::is_chunk_reserved ( uint32_t  chunk_num)
inline

Check if chunk is already reserved.

Parameters
[in]chunk_numchunk number
Returns
true, iff chunk is reserved.

◆ is_file_metadata_transferred()

bool Clone_Task_Manager::is_file_metadata_transferred ( ) const
inline
Returns
true if file metadata is transferred

◆ is_network_error()

bool Clone_Task_Manager::is_network_error ( int  err)
inlineprivate

Check if network error.

Parameters
[in]errerror code
Returns
true if network error

◆ is_restart_metadata()

bool Clone_Task_Manager::is_restart_metadata ( Clone_Task task)
inline

Check if needs to send state metadata once.

Parameters
[in]taskcurrent task
Returns
true if needs to send state metadata

◆ is_restarted()

bool Clone_Task_Manager::is_restarted ( )
inline

Check if clone is restarted after failure.

Returns
true if restarted

◆ process_inclomplete_chunk()

bool Clone_Task_Manager::process_inclomplete_chunk ( )
inlineprivate

Check if we should process incomplete chunk next.

Incomplete chunks could be there after a re-start from network failure. We always process the chunks in order and need to choose accordingly.

Returns
if need to process incomplete chunk next.

◆ reinit_apply_state()

void Clone_Task_Manager::reinit_apply_state ( const byte ref_loc,
uint  ref_len,
byte *&  new_loc,
uint &  new_len,
uint &  alloc_len 
)

Reinitialize state using locator.

Parameters
[in]ref_loccurrent locator
[in]ref_lencurrent locator length
[out]new_locnew locator to be sent to remote server
[out]new_lenlength of new locator
[in,out]alloc_lenallocated length for locator buffer

◆ reinit_copy_state()

void Clone_Task_Manager::reinit_copy_state ( const byte loc,
uint  loc_len 
)

Reinitialize state using locator.

Parameters
[in]loclocator from remote client
[in]loc_lenlocator length in bytes

◆ reserve_next_chunk()

int Clone_Task_Manager::reserve_next_chunk ( Clone_Task task,
uint32_t &  ret_chunk,
uint32_t &  ret_block 
)

Reserve next chunk from task manager.

Called by individual tasks.

Parameters
[in]taskrequesting task
[out]ret_chunkreserved chunk number
[out]ret_blockstart block number '0' if no more chunk.
Returns
error code

◆ reserve_task()

void Clone_Task_Manager::reserve_task ( THD thd,
uint &  task_id 
)
private

Reserve free task from task manager and initialize.

Parameters
[in]thdserver THD object
[out]task_idinitialized task ID

◆ reset_chunk()

void Clone_Task_Manager::reset_chunk ( Clone_Task task)
inline

Reset chunk information for task.

Parameters
[in]taskcurrent task

◆ reset_error()

void Clone_Task_Manager::reset_error ( )
inline

Reset error information.

◆ reset_transition()

void Clone_Task_Manager::reset_transition ( )
inline

Reset state transition information.

◆ set_chunk()

int Clone_Task_Manager::set_chunk ( Clone_Task task,
Clone_Task_Meta new_meta 
)

Set current chunk and block information.

Parameters
[in,out]taskrequesting task
[in]new_metaupdated task metadata
Returns
error code

◆ set_error()

void Clone_Task_Manager::set_error ( int  err,
const char *  file_name 
)
inline

Set error number.

Parameters
[in]errerror number
[in]file_nameassociated file name if any

◆ set_file_meta_transferred()

void Clone_Task_Manager::set_file_meta_transferred ( )
inline

Set sub-state: all file metadata is transferred.

◆ wait_ack()

int Clone_Task_Manager::wait_ack ( Clone_Handle clone,
Clone_Task task,
Ha_clone_cbk callback 
)

Wait for acknowledgement.

Parameters
[in]cloneparent clone handle
[in]taskcurrent task
[in]callbackuser callback interface
Returns
error code

◆ wait_before_add()

bool Clone_Task_Manager::wait_before_add ( const byte ref_loc,
uint  loc_len 
)
private

Check if we need to wait before adding current task.

Parameters
[in]ref_locreference locator from remote
[in]loc_lenreference locator length
Returns
true, if needs to wait

Member Data Documentation

◆ m_ack_state

Snapshot_State Clone_Task_Manager::m_ack_state
private

Acknowledged state from client.

◆ m_chunk_info

Chunk_Info Clone_Task_Manager::m_chunk_info
private

Finished and incomplete chunk information.

◆ m_clone_snapshot

Clone_Snapshot* Clone_Task_Manager::m_clone_snapshot
private

Attached snapshot handle.

◆ m_clone_tasks

Clone_Task Clone_Task_Manager::m_clone_tasks[CLONE_MAX_TASKS]
private

Clone task array.

◆ m_current_state

Snapshot_State Clone_Task_Manager::m_current_state
private

Current state for clone.

◆ m_err_file_name

std::string Clone_Task_Manager::m_err_file_name
private

File name related to the saved error.

◆ m_next_state

Snapshot_State Clone_Task_Manager::m_next_state
private

Next state: used during state transfer.

◆ m_num_tasks

uint Clone_Task_Manager::m_num_tasks
private

Current number of tasks.

◆ m_num_tasks_finished

uint Clone_Task_Manager::m_num_tasks_finished
private

Number of tasks finished current state.

◆ m_num_tasks_transit

uint Clone_Task_Manager::m_num_tasks_transit
private

Number of tasks in transit state.

◆ m_restart_count

uint Clone_Task_Manager::m_restart_count
private

Number of times clone is restarted.

◆ m_saved_error

int Clone_Task_Manager::m_saved_error
private

Save any error raised by a task.

◆ m_send_state_meta

bool Clone_Task_Manager::m_send_state_meta
private

Send state metadata before starting: Used for restart.

◆ m_state_mutex

ib_mutex_t Clone_Task_Manager::m_state_mutex
private

Mutex synchronizing access by concurrent tasks.

◆ m_transferred_file_meta

bool Clone_Task_Manager::m_transferred_file_meta
private

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