MySQL 9.1.0
Source Code Documentation
Clone_persist_gtid Class Reference

Persist GTID along with transaction commit. More...

#include <clone0repl.h>

Public Member Functions

 Clone_persist_gtid ()
 Constructor: start gtid thread. More...
 
 ~Clone_persist_gtid ()
 Destructor: stop gtid thread. More...
 
bool start ()
 Start GTID persistence and background thread. More...
 
void stop ()
 
void wait_flush (bool compress_gtid, bool early_timeout, Clone_Alert_Func cbk)
 
bool is_active () const
 
bool is_thread_active () const
 
trx_id_t get_oldest_trx_no ()
 Get oldest transaction number for which GTID is not persisted to table. More...
 
void set_oldest_trx_no_recovery (trx_id_t max_trx_no)
 Set oldest transaction number for which GTID is not persisted to table. More...
 
void get_gtid_info (trx_t *trx, Gtid_desc &gtid_desc)
 Get transaction GTID information. More...
 
bool trx_check_set (trx_t *trx, bool prepare, bool rollback, bool &set_explicit)
 Set transaction flag to persist GTID and check if space need to be allocated for GTID. More...
 
bool has_gtid (trx_t *trx, THD *&thd, bool &passed_check)
 Check if current transaction has GTID. More...
 
trx_undo_t::Gtid_storage persists_gtid (const trx_t *trx)
 Check if GTID persistence is set. More...
 
void set_persist_gtid (trx_t *trx, bool set)
 Set or reset GTID persist flag in THD. More...
 
void add (const Gtid_desc &gtid_desc)
 Add GTID to in memory list. More...
 
void periodic_write ()
 Write GTIDs periodically to disk table. More...
 
int write_other_gtids ()
 Write GTIDs of non Innodb transactions to table. More...
 
 Clone_persist_gtid (Clone_persist_gtid const &)=delete
 Disable copy construction. More...
 
Clone_persist_gtidoperator= (Clone_persist_gtid const &)=delete
 Disable assignment. More...
 

Private Member Functions

bool check_gtid_prepare (THD *thd, trx_t *trx, bool found_gtid, bool &alloc)
 Check if GTID needs to persist at XA prepare. More...
 
bool check_gtid_commit (THD *thd, bool found_gtid, bool &set_explicit)
 Check if GTID needs to persist at commit. More...
 
bool check_gtid_rollback (THD *thd, trx_t *trx, bool found_gtid)
 Check if GTID needs to persist at rollback. More...
 
bool wait_thread (bool start, bool flush, uint64_t flush_number, bool compress, bool early_timeout, Clone_Alert_Func cbk)
 Wait for gtid thread to start, finish or flush. More...
 
Gtid_info_listget_active_list ()
 
Gtid_info_listget_list (uint64_t list_number)
 
bool debug_skip_write (bool compression)
 Check if we need to skip write or compression based on debug variables. More...
 
uint64_t request_immediate_flush (bool compress)
 Request immediate flush of all GTIDs accumulated. More...
 
bool check_flushed (uint64_t request_number) const
 Check if flush has finished up to a list number. More...
 
bool flush_immediate () const
 
bool check_compress ()
 Check if GTID compression is necessary based on threshold. More...
 
uint64_t switch_active_list ()
 Switch active GTID list. More...
 
int write_to_table (uint64_t flush_list_number, Gtid_set &table_gtid_set, Tsid_map &tsid_map)
 Persist GTID to gtid_executed table. More...
 
void update_gtid_trx_no (trx_id_t new_gtid_trx_no)
 Update transaction number up to which GTIDs are flushed to table. More...
 
void flush_gtids (THD *thd)
 Write all GTIDs to table and update GTID transaction number. More...
 
bool check_max_gtid_threshold ()
 

Private Attributes

Gtid_info_list m_gtids [2]
 Two lists of GTID. More...
 
std::atomic< uint64_t > m_active_number
 Number of the current GTID list. More...
 
std::atomic< uint64_t > m_flush_number
 Number up to which GTIDs are flushed. More...
 
std::atomic< bool > m_explicit_request
 If explicit request to flush is made. More...
 
uint64_t m_flush_request_number {0}
 Number for which last flush request was made. More...
 
os_event_t m_event
 Event for GTID background thread. More...
 
uint32_t m_compression_counter {0}
 Counter to keep track of the number of writes till it reaches compression threshold. More...
 
uint32_t m_compression_gtid_counter {0}
 Counter to keep number of GTIDs flushed before compression. More...
 
std::atomic< uint64_t > m_gtid_trx_no
 
std::atomic< int > m_num_gtid_mem
 Number of GTID accumulated in memory. More...
 
std::atomic< bool > m_flush_in_progress
 Flush of GTID is in progress. More...
 
std::atomic< bool > m_close_thread
 Set to true, when the background thread is asked to exit. More...
 
std::atomic< bool > m_thread_active
 true, if background thread is active. More...
 
std::atomic< bool > m_active
 true, if GTID persistence is active. More...
 

Static Private Attributes

static constexpr std::chrono::milliseconds s_time_threshold {100}
 Time threshold to trigger persisting GTID. More...
 
static const uint32_t s_compression_threshold = 50
 Threshold for the count for compressing GTID. More...
 
static const int s_gtid_threshold = 1024
 Number of transaction/GTID threshold for writing to disk table. More...
 
static const int s_max_gtid_threshold = 1024 * 1024
 Maximum Number of transaction/GTID to hold. More...
 

Detailed Description

Persist GTID along with transaction commit.

Constructor & Destructor Documentation

◆ Clone_persist_gtid() [1/2]

Clone_persist_gtid::Clone_persist_gtid ( )
inline

Constructor: start gtid thread.

◆ ~Clone_persist_gtid()

Clone_persist_gtid::~Clone_persist_gtid ( )
inline

Destructor: stop gtid thread.

◆ Clone_persist_gtid() [2/2]

Clone_persist_gtid::Clone_persist_gtid ( Clone_persist_gtid const &  )
delete

Disable copy construction.

Member Function Documentation

◆ add()

void Clone_persist_gtid::add ( const Gtid_desc gtid_desc)

Add GTID to in memory list.

Parameters
[in]gtid_descDescriptor with serialized GTID

◆ check_compress()

bool Clone_persist_gtid::check_compress ( )
private

Check if GTID compression is necessary based on threshold.

Returns
true, if GTID table needs to be compressed.

◆ check_flushed()

bool Clone_persist_gtid::check_flushed ( uint64_t  request_number) const
inlineprivate

Check if flush has finished up to a list number.

Parameters
[in]request_numberflush request number
Returns
true, if it is already flushed.

◆ check_gtid_commit()

bool Clone_persist_gtid::check_gtid_commit ( THD thd,
bool  found_gtid,
bool &  set_explicit 
)
private

Check if GTID needs to persist at commit.

Parameters
[in]thdsession THD
[in]found_gtidsession is owning GTID
[out]set_explicitif explicitly set to persist GTID
Returns
true, if GTID needs to be persisted

◆ check_gtid_prepare()

bool Clone_persist_gtid::check_gtid_prepare ( THD thd,
trx_t trx,
bool  found_gtid,
bool &  alloc 
)
private

Check if GTID needs to persist at XA prepare.

Parameters
[in]thdsession THD
[in,out]trxcurrent innnodb transaction
[in]found_gtidsession is owning GTID
[in,out]allocin:transaction checks are passed out:GTID space need to be allocated
Returns
true, if GTID needs to be persisted

◆ check_gtid_rollback()

bool Clone_persist_gtid::check_gtid_rollback ( THD thd,
trx_t trx,
bool  found_gtid 
)
private

Check if GTID needs to persist at rollback.

Parameters
[in]thdsession THD
[in,out]trxcurrent innnodb transaction
[in]found_gtidsession is owning GTID
Returns
true, if GTID needs to be persisted

◆ check_max_gtid_threshold()

bool Clone_persist_gtid::check_max_gtid_threshold ( )
private
Returns
true iff number of GTIDs in active list exceeded threshold.

◆ debug_skip_write()

bool Clone_persist_gtid::debug_skip_write ( bool  compression)
private

Check if we need to skip write or compression based on debug variables.

Parameters
[in]compressioncheck for compression
Returns
true, if we should skip.

◆ flush_gtids()

void Clone_persist_gtid::flush_gtids ( THD thd)
private

Write all GTIDs to table and update GTID transaction number.

Parameters
[in,out]thdcurrent session thread

◆ flush_immediate()

bool Clone_persist_gtid::flush_immediate ( ) const
inlineprivate
Returns
true, iff background needs to flush immediately.

◆ get_active_list()

Gtid_info_list & Clone_persist_gtid::get_active_list ( )
inlineprivate
Returns
current active GTID list

◆ get_gtid_info()

void Clone_persist_gtid::get_gtid_info ( trx_t trx,
Gtid_desc gtid_desc 
)

Get transaction GTID information.

Parameters
[in,out]trxinnodb transaction
[out]gtid_descdescriptor with serialized GTID

◆ get_list()

Gtid_info_list & Clone_persist_gtid::get_list ( uint64_t  list_number)
inlineprivate
Returns
GTID list by number.
Parameters
[in]list_numberlist number
Returns
GTID list reference.

◆ get_oldest_trx_no()

trx_id_t Clone_persist_gtid::get_oldest_trx_no ( )
inline

Get oldest transaction number for which GTID is not persisted to table.

Transactions committed after this point should not be purged.

Returns
oldest transaction number.

◆ has_gtid()

bool Clone_persist_gtid::has_gtid ( trx_t trx,
THD *&  thd,
bool &  passed_check 
)

Check if current transaction has GTID.

Parameters
[in]trxinnodb transaction
[in,out]thdsession THD
[out]passed_checktrue if transaction is good for GTID
Returns
true, if transaction has valid GTID.

◆ is_active()

bool Clone_persist_gtid::is_active ( ) const
inline
Returns
true, if GTID persistence is active.

◆ is_thread_active()

bool Clone_persist_gtid::is_thread_active ( ) const
inline
Returns
true, if GTID thread is active.

◆ operator=()

Clone_persist_gtid & Clone_persist_gtid::operator= ( Clone_persist_gtid const &  )
delete

Disable assignment.

◆ periodic_write()

void Clone_persist_gtid::periodic_write ( )

Write GTIDs periodically to disk table.

◆ persists_gtid()

trx_undo_t::Gtid_storage Clone_persist_gtid::persists_gtid ( const trx_t trx)

Check if GTID persistence is set.

Parameters
[in]trxcurrent innnodb transaction
Returns
GTID storage type.

◆ request_immediate_flush()

uint64_t Clone_persist_gtid::request_immediate_flush ( bool  compress)
inlineprivate

Request immediate flush of all GTIDs accumulated.

Parameters
[in]compressrequest compression of GTID table
Returns
flush list number to track and wait for flush to complete.

◆ set_oldest_trx_no_recovery()

void Clone_persist_gtid::set_oldest_trx_no_recovery ( trx_id_t  max_trx_no)
inline

Set oldest transaction number for which GTID is not persisted to table.

This is set during recovery from persisted value.

Parameters
[in]max_trx_notransaction number

◆ set_persist_gtid()

void Clone_persist_gtid::set_persist_gtid ( trx_t trx,
bool  set 
)

Set or reset GTID persist flag in THD.

Parameters
[in,out]trxcurrent innnodb transaction
[in]settrue, if need to set

◆ start()

bool Clone_persist_gtid::start ( )

Start GTID persistence and background thread.

Returns
true, if successful.

◆ stop()

void Clone_persist_gtid::stop ( )

◆ switch_active_list()

uint64_t Clone_persist_gtid::switch_active_list ( )
inlineprivate

Switch active GTID list.

◆ trx_check_set()

bool Clone_persist_gtid::trx_check_set ( trx_t trx,
bool  prepare,
bool  rollback,
bool &  set_explicit 
)

Set transaction flag to persist GTID and check if space need to be allocated for GTID.

Parameters
[in,out]trxcurrent innodb transaction
[in]prepareif operation is Prepare
[in]rollbackif operation is Rollback
[out]set_explicitif explicitly set to persist GTID
Returns
true, if undo space needs to be allocated.

◆ update_gtid_trx_no()

void Clone_persist_gtid::update_gtid_trx_no ( trx_id_t  new_gtid_trx_no)
private

Update transaction number up to which GTIDs are flushed to table.

Parameters
[in]new_gtid_trx_noGTID transaction number

◆ wait_flush()

void Clone_persist_gtid::wait_flush ( bool  compress_gtid,
bool  early_timeout,
Clone_Alert_Func  cbk 
)

◆ wait_thread()

bool Clone_persist_gtid::wait_thread ( bool  start,
bool  flush,
uint64_t  flush_number,
bool  compress,
bool  early_timeout,
Clone_Alert_Func  cbk 
)
private

Wait for gtid thread to start, finish or flush.

Parameters
[in]startif waiting for start
[in]flushwait for immediate flush
[in]flush_numberwait flush to reach this number
[in]compresswait also for compression
[in]early_timeoutdon't wait long if flush is blocked
[in]cbkalert callback for long wait
Returns
true if successful.

◆ write_other_gtids()

int Clone_persist_gtid::write_other_gtids ( )

Write GTIDs of non Innodb transactions to table.

◆ write_to_table()

int Clone_persist_gtid::write_to_table ( uint64_t  flush_list_number,
Gtid_set table_gtid_set,
Tsid_map tsid_map 
)
private

Persist GTID to gtid_executed table.

Parameters
[in]flush_list_numberlist number to flush
[in,out]table_gtid_setGTIDs in table during recovery
[in,out]tsid_mapTSID map for GTIDs
Returns
mysql error code.

Member Data Documentation

◆ m_active

std::atomic<bool> Clone_persist_gtid::m_active
private

true, if GTID persistence is active.

◆ m_active_number

std::atomic<uint64_t> Clone_persist_gtid::m_active_number
private

Number of the current GTID list.

Increased when list is switched

◆ m_close_thread

std::atomic<bool> Clone_persist_gtid::m_close_thread
private

Set to true, when the background thread is asked to exit.

◆ m_compression_counter

uint32_t Clone_persist_gtid::m_compression_counter {0}
private

Counter to keep track of the number of writes till it reaches compression threshold.

◆ m_compression_gtid_counter

uint32_t Clone_persist_gtid::m_compression_gtid_counter {0}
private

Counter to keep number of GTIDs flushed before compression.

◆ m_event

os_event_t Clone_persist_gtid::m_event
private

Event for GTID background thread.

◆ m_explicit_request

std::atomic<bool> Clone_persist_gtid::m_explicit_request
private

If explicit request to flush is made.

◆ m_flush_in_progress

std::atomic<bool> Clone_persist_gtid::m_flush_in_progress
private

Flush of GTID is in progress.

◆ m_flush_number

std::atomic<uint64_t> Clone_persist_gtid::m_flush_number
private

Number up to which GTIDs are flushed.

Increased when list is flushed.

◆ m_flush_request_number

uint64_t Clone_persist_gtid::m_flush_request_number {0}
private

Number for which last flush request was made.

◆ m_gtid_trx_no

std::atomic<uint64_t> Clone_persist_gtid::m_gtid_trx_no
private

◆ m_gtids

Gtid_info_list Clone_persist_gtid::m_gtids[2]
private

Two lists of GTID.

One of them is active where running transactions add their GTIDs. Other list is used to persist them to table from time to time.

◆ m_num_gtid_mem

std::atomic<int> Clone_persist_gtid::m_num_gtid_mem
private

Number of GTID accumulated in memory.

◆ m_thread_active

std::atomic<bool> Clone_persist_gtid::m_thread_active
private

true, if background thread is active.

◆ s_compression_threshold

const uint32_t Clone_persist_gtid::s_compression_threshold = 50
staticprivate

Threshold for the count for compressing GTID.

◆ s_gtid_threshold

const int Clone_persist_gtid::s_gtid_threshold = 1024
staticprivate

Number of transaction/GTID threshold for writing to disk table.

◆ s_max_gtid_threshold

const int Clone_persist_gtid::s_max_gtid_threshold = 1024 * 1024
staticprivate

Maximum Number of transaction/GTID to hold.

Transaction commits must wait beyond this point. Not expected to happen as GTIDs are compressed and written together.

◆ s_time_threshold

constexpr std::chrono::milliseconds Clone_persist_gtid::s_time_threshold {100}
staticconstexprprivate

Time threshold to trigger persisting GTID.

Insert GTID once per 1k transactions or every 100 millisecond.


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