MySQL 8.0.39
Source Code Documentation
TC_LOG_MMAP Class Reference

#include <tc_log.h>

Inheritance diagram for TC_LOG_MMAP:
[legend]

Classes

struct  PAGE
 

Public Types

enum  PAGE_STATE { PS_POOL , PS_ERROR , PS_DIRTY }
 
- Public Types inherited from TC_LOG
enum  enum_result { RESULT_SUCCESS , RESULT_ABORTED , RESULT_INCONSISTENT }
 

Public Member Functions

 TC_LOG_MMAP ()
 
int open (const char *opt_name) override
 Initialize and open the coordinator log. More...
 
void close () override
 Close the transaction coordinator log and free any resources. More...
 
enum_result commit (THD *thd, bool all) override
 Commit the transaction. More...
 
int rollback (THD *thd, bool all) override
 Log a rollback record of the transaction to the transaction coordinator log. More...
 
int prepare (THD *thd, bool all) override
 Log a prepare record of the transaction to the storage engines. More...
 
int recover ()
 
uint size () const
 Get the total amount of potentially usable slots for XIDs in TC log. More...
 
- Public Member Functions inherited from TC_LOG
bool using_heuristic_recover ()
 Perform heuristic recovery, if –tc-heuristic-recover was used. More...
 
 TC_LOG ()=default
 
virtual ~TC_LOG ()=default
 

Protected Member Functions

virtual int do_msync_and_fsync (int fd_arg, void *addr, size_t len, int flags)
 

Private Member Functions

ulong log_xid (my_xid xid)
 Record that transaction XID is committed on the persistent storage. More...
 
void unlog (ulong cookie, my_xid xid)
 erase xid from the page, update page free space counters/pointers. More...
 
PAGEget_active_from_pool ()
 there is no active page, let's got one from the pool. More...
 
bool sync ()
 Write the page data being synchronized to the disk. More...
 
void overflow ()
 
ulong store_xid_in_empty_slot (my_xid xid, PAGE *p, uchar *data_arg)
 Find empty slot in the page and write xid value there. More...
 
bool wait_sync_completion (PAGE *p)
 Wait for until page data will be written to the disk. More...
 

Private Attributes

char logname [FN_REFLEN]
 
File fd
 
my_off_t file_length
 
uint npages
 
uint inited
 
uchardata
 
PAGEpages
 
PAGEsyncing
 
PAGEactive
 
PAGEpool
 
PAGE ** pool_last_ptr
 
mysql_mutex_t LOCK_tc
 
mysql_cond_t COND_active
 Signalled when active PAGE is moved to syncing state, thus member "active" becomes 0. More...
 
mysql_cond_t COND_pool
 Signalled when one more page becomes available in the pool which we might select as active. More...
 

Friends

class TCLogMMapTest
 

Member Enumeration Documentation

◆ PAGE_STATE

Enumerator
PS_POOL 
PS_ERROR 
PS_DIRTY 

Constructor & Destructor Documentation

◆ TC_LOG_MMAP()

TC_LOG_MMAP::TC_LOG_MMAP ( )
inline

Member Function Documentation

◆ close()

void TC_LOG_MMAP::close ( )
overridevirtual

Close the transaction coordinator log and free any resources.

Called during server shutdown.

Implements TC_LOG.

◆ commit()

TC_LOG::enum_result TC_LOG_MMAP::commit ( THD thd,
bool  all 
)
overridevirtual

Commit the transaction.

Note
When the TC_LOG interface was changed, this function was added and uses the functions that were there with the old interface to implement the logic.

Implements TC_LOG.

◆ do_msync_and_fsync()

virtual int TC_LOG_MMAP::do_msync_and_fsync ( int  fd_arg,
void *  addr,
size_t  len,
int  flags 
)
inlineprotectedvirtual

◆ get_active_from_pool()

TC_LOG_MMAP::PAGE * TC_LOG_MMAP::get_active_from_pool ( )
private

there is no active page, let's got one from the pool.

Two strategies here:

  1. take the first from the pool
  2. if there're waiters - take the one with the most free space.
Returns
Pointer to qualifying page or NULL if no page in the pool can be made active.

◆ log_xid()

ulong TC_LOG_MMAP::log_xid ( my_xid  xid)
private

Record that transaction XID is committed on the persistent storage.

This function is called in the middle of two-phase commit: First all resources prepare the transaction, then tc_log->log() is called, then all resources commit the transaction, then tc_log->unlog() is called.

All access to active page is serialized but it's not a problem, as we're assuming that fsync() will be a main bottleneck. That is, parallelizing writes to log pages we'll decrease number of threads waiting for a page, but then all these threads will be waiting for a fsync() anyway

If tc_log == MYSQL_BIN_LOG then tc_log writes transaction to binlog and records XID in a special Xid_log_event. If tc_log = TC_LOG_MMAP then xid is written in a special memory-mapped log.

Returns
"cookie", a number that will be passed as an argument to unlog() call. tc_log can define it any way it wants, and use for whatever purposes. TC_LOG_MMAP sets it to the position in memory where xid was logged to.
Return values
0error

◆ open()

int TC_LOG_MMAP::open ( const char *  opt_name)
overridevirtual

Initialize and open the coordinator log.

Do recovery if necessary. Called during server startup.

Parameters
opt_nameName of logfile.
Return values
0success
1failed

Implements TC_LOG.

◆ overflow()

void TC_LOG_MMAP::overflow ( )
private

◆ prepare()

int TC_LOG_MMAP::prepare ( THD thd,
bool  all 
)
overridevirtual

Log a prepare record of the transaction to the storage engines.

Parameters
thdSession to log transaction record for.
alltrue if an explicit commit or an implicit commit for a statement, false if an internal commit of the statement.
Returns
Error code on failure, zero on success.

Implements TC_LOG.

◆ recover()

int TC_LOG_MMAP::recover ( )

◆ rollback()

int TC_LOG_MMAP::rollback ( THD thd,
bool  all 
)
overridevirtual

Log a rollback record of the transaction to the transaction coordinator log.

When the function returns, the transaction have been aborted in the transaction coordinator log.

Parameters
thdSession to log transaction record for.
alltrue if an explicit commit or an implicit commit for a statement, false if an internal commit of the statement.
Returns
Error code on failure, zero on success.

Implements TC_LOG.

◆ size()

uint TC_LOG_MMAP::size ( ) const

Get the total amount of potentially usable slots for XIDs in TC log.

◆ store_xid_in_empty_slot()

ulong TC_LOG_MMAP::store_xid_in_empty_slot ( my_xid  xid,
PAGE p,
uchar data_arg 
)
inlineprivate

Find empty slot in the page and write xid value there.

Parameters
xidvalue of xid to store in the page
ppointer to the page where to store xid
data_argpointer to the top of the mapped to memory file to calculate offset value (cookie)
Returns
offset value from the top of the page where the xid was stored.

◆ sync()

bool TC_LOG_MMAP::sync ( )
private

Write the page data being synchronized to the disk.

Return values
falseSuccess
trueFailure

◆ unlog()

void TC_LOG_MMAP::unlog ( ulong  cookie,
my_xid  xid 
)
private

erase xid from the page, update page free space counters/pointers.

cookie points directly to the memory where xid was logged.

◆ wait_sync_completion()

bool TC_LOG_MMAP::wait_sync_completion ( PAGE p)
inlineprivate

Wait for until page data will be written to the disk.

Parameters
ppointer to the PAGE to store to the disk
Return values
falseSuccess
trueFailure

Friends And Related Function Documentation

◆ TCLogMMapTest

friend class TCLogMMapTest
friend

Member Data Documentation

◆ active

PAGE * TC_LOG_MMAP::active
private

◆ COND_active

mysql_cond_t TC_LOG_MMAP::COND_active
private

Signalled when active PAGE is moved to syncing state, thus member "active" becomes 0.

◆ COND_pool

mysql_cond_t TC_LOG_MMAP::COND_pool
private

Signalled when one more page becomes available in the pool which we might select as active.

◆ data

uchar* TC_LOG_MMAP::data
private

◆ fd

File TC_LOG_MMAP::fd
private

◆ file_length

my_off_t TC_LOG_MMAP::file_length
private

◆ inited

uint TC_LOG_MMAP::inited
private

◆ LOCK_tc

mysql_mutex_t TC_LOG_MMAP::LOCK_tc
private

◆ logname

char TC_LOG_MMAP::logname[FN_REFLEN]
private

◆ npages

uint TC_LOG_MMAP::npages
private

◆ pages

PAGE* TC_LOG_MMAP::pages
private

◆ pool

PAGE * TC_LOG_MMAP::pool
private

◆ pool_last_ptr

PAGE ** TC_LOG_MMAP::pool_last_ptr
private

◆ syncing

PAGE * TC_LOG_MMAP::syncing
private

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