MySQL 9.1.0
Source Code Documentation
mtr_t Struct Reference

Mini-transaction handle and buffer. More...

#include <mtr0mtr.h>

Classes

class  Command
 
struct  Impl
 State variables of the mtr. More...
 
class  Logging
 mtr global logging More...
 

Public Member Functions

void check_nolog_and_mark ()
 Check if redo logging is disabled globally and mark the global counter till mtr ends. More...
 
void check_nolog_and_unmark ()
 Check if the mtr has marked the global no log counter and unmark it. More...
 
 mtr_t ()
 
 ~mtr_t ()
 
void remove_from_debug_list () const
 Removed the MTR from the s_my_thread_active_mtrs list. More...
 
void check_is_not_latching () const
 Assure that there are no slots that are latching any resources. More...
 
void start (bool sync=true)
 Start a mini-transaction. More...
 
bool is_async () const
 
void set_sync ()
 Request a future commit to be synchronous. More...
 
void commit ()
 Commit the mini-transaction. More...
 
ulint get_savepoint () const
 Return current size of the buffer. More...
 
void release_s_latch_at_savepoint (ulint savepoint, rw_lock_t *lock)
 Release the (index tree) s-latch stored in an mtr memo after a savepoint. More...
 
void release_block_at_savepoint (ulint savepoint, buf_block_t *block)
 Release the block in an mtr memo after a savepoint. More...
 
void sx_latch_at_savepoint (ulint savepoint, buf_block_t *block)
 SX-latch a not yet latched block after a savepoint. More...
 
void x_latch_at_savepoint (ulint savepoint, buf_block_t *block)
 X-latch a not yet latched block after a savepoint. More...
 
mtr_log_t get_log_mode () const
 Get the logging mode. More...
 
mtr_log_t set_log_mode (mtr_log_t mode)
 Change the logging mode. More...
 
uint32_t read_ulint (const byte *ptr, mlog_id_t type) const
 Read 1 - 4 bytes from a file page buffered in the buffer pool. More...
 
void s_lock (rw_lock_t *lock, ut::Location location)
 Locks a rw-latch in S mode. More...
 
void x_lock (rw_lock_t *lock, ut::Location location)
 Locks a rw-latch in X mode. More...
 
void sx_lock (rw_lock_t *lock, ut::Location location)
 Locks a rw-latch in X mode. More...
 
void x_lock_space (fil_space_t *space, ut::Location location)
 Acquire a tablespace X-latch. More...
 
void memo_release (const void *object, ulint type)
 Release an object in the memo stack. More...
 
void release_page (const void *ptr, mtr_memo_type_t type)
 Release a page latch. More...
 
void set_modified ()
 Note that the mini-transaction might have modified a buffer pool page. More...
 
bool has_modifications () const
 Checks if this mtr has modified any buffer pool page. More...
 
lsn_t commit_lsn () const
 Get the LSN of commit(). More...
 
void enter_ibuf ()
 Note that we are inside the change buffer code. More...
 
void exit_ibuf ()
 Note that we have exited from the change buffer code. More...
 
bool is_inside_ibuf () const
 
bool is_active () const
 
Flush_observerget_flush_observer () const
 Get flush observer. More...
 
void set_flush_observer (Flush_observer *observer)
 Set flush observer. More...
 
std::ostream & print_memos (std::ostream &out) const
 Print the memo objects (mtr_memo_slot_t) of mtr_t to the given output stream. More...
 
bool memo_contains_flagged (const void *ptr, ulint flags) const
 Check if memo contains the given item. More...
 
buf_block_tmemo_contains_page_flagged (const byte *ptr, ulint flags) const
 Check if memo contains the given page. More...
 
void memo_modify_page (const byte *ptr)
 Mark the given latched page as modified. More...
 
void print () const
 Print info of an mtr handle. More...
 
bool has_committed () const
 
bool is_committing () const
 
bool conflicts_with (const mtr_t *mtr2) const
 Check if the changes done in this mtr conflicts with changes done in the given mtr. More...
 
const mtr_buf_tget_memo () const
 
mtr_buf_tget_memo ()
 
size_t get_expected_log_size () const
 Computes the number of bytes that would be written to the redo log if mtr was committed right now (excluding headers of log blocks). More...
 
void wait_for_flush ()
 
void added_rec ()
 Note that a record has been added to the log. More...
 
bool has_any_log_record ()
 Checks if this mtr has generated any redo log records which should be written to the redo log during commit(). More...
 
const mtr_buf_tget_log () const
 Get the buffered redo log of this mini-transaction. More...
 
mtr_buf_tget_log ()
 Get the buffered redo log of this mini-transaction. More...
 
void memo_push (void *object, mtr_memo_type_t type)
 Push an object to an mtr memo stack. More...
 

Static Public Member Functions

static bool memo_contains (const mtr_buf_t *memo, const void *object, ulint type)
 Check if memo contains the given item. More...
 
static void check_my_thread_mtrs_are_not_latching ()
 Iterate all MTRs created in this thread to assure they are not latching any resources. More...
 
static bool is_this_thread_inside_mtr ()
 This method is useful to detect if the thread is already inside an mtr. More...
 

Public Attributes

size_t m_restart_count {}
 Count the number of times the same mtr object has been committed and restarted. More...
 

Static Public Attributes

static bool s_mode_update [MTR_LOG_MODE_MAX][MTR_LOG_MODE_MAX]
 Matrix to check if a mode update request should be ignored. More...
 
static bool s_mode_update_valid [MTR_LOG_MODE_MAX][MTR_LOG_MODE_MAX]
 For checking invalid mode update requests. More...
 
static Logging s_logging
 Instance level logging information for all mtrs. More...
 

Private Attributes

Impl m_impl
 
lsn_t m_commit_lsn
 LSN at commit time. More...
 
bool m_sync
 true if it is synchronous mini-transaction More...
 

Static Private Attributes

static thread_local ut::unordered_set< const mtr_t * > s_my_thread_active_mtrs
 List of all non-committed MTR instances created in this thread. More...
 

Friends

class Command
 

Detailed Description

Mini-transaction handle and buffer.

Constructor & Destructor Documentation

◆ mtr_t()

mtr_t::mtr_t ( )
inline

◆ ~mtr_t()

mtr_t::~mtr_t ( )
inline

Member Function Documentation

◆ added_rec()

void mtr_t::added_rec ( )
inline

Note that a record has been added to the log.

◆ check_is_not_latching()

void mtr_t::check_is_not_latching ( ) const

Assure that there are no slots that are latching any resources.

Only buffer fixing a page is allowed.

◆ check_my_thread_mtrs_are_not_latching()

static void mtr_t::check_my_thread_mtrs_are_not_latching ( )
inlinestatic

Iterate all MTRs created in this thread to assure they are not latching any resources.

Violating this could lead to deadlocks under log_free_check().

◆ check_nolog_and_mark()

void mtr_t::check_nolog_and_mark ( )

Check if redo logging is disabled globally and mark the global counter till mtr ends.

◆ check_nolog_and_unmark()

void mtr_t::check_nolog_and_unmark ( )

Check if the mtr has marked the global no log counter and unmark it.

◆ commit()

void mtr_t::commit ( )

Commit the mini-transaction.

Commit a mini-transaction.

◆ commit_lsn()

lsn_t mtr_t::commit_lsn ( ) const
inline

Get the LSN of commit().

Returns
the commit LSN
Return values
0if the transaction only modified temporary tablespaces or logging is disabled globally.

◆ conflicts_with()

bool mtr_t::conflicts_with ( const mtr_t mtr2) const

Check if the changes done in this mtr conflicts with changes done in the given mtr.

Two mtrs are said to conflict with each other, if they modify the same buffer block.

Parameters
[in]mtr2the given mtr.
Returns
true if there is conflict, false otherwise.

◆ enter_ibuf()

void mtr_t::enter_ibuf ( )
inline

Note that we are inside the change buffer code.

◆ exit_ibuf()

void mtr_t::exit_ibuf ( )
inline

Note that we have exited from the change buffer code.

◆ get_expected_log_size()

size_t mtr_t::get_expected_log_size ( ) const
inline

Computes the number of bytes that would be written to the redo log if mtr was committed right now (excluding headers of log blocks).

Returns
number of bytes of the collected log records increased by 1 if MLOG_MULTI_REC_END would already be required

◆ get_flush_observer()

Flush_observer * mtr_t::get_flush_observer ( ) const
inline

Get flush observer.

Returns
flush observer

◆ get_log() [1/2]

mtr_buf_t * mtr_t::get_log ( )
inline

Get the buffered redo log of this mini-transaction.

Returns
redo log

◆ get_log() [2/2]

const mtr_buf_t * mtr_t::get_log ( ) const
inline

Get the buffered redo log of this mini-transaction.

Returns
redo log

◆ get_log_mode()

mtr_log_t mtr_t::get_log_mode ( ) const
inline

Get the logging mode.

Gets the logging mode of a mini-transaction.

Returns
logging mode
logging mode: MTR_LOG_NONE, ...

◆ get_memo() [1/2]

mtr_buf_t * mtr_t::get_memo ( )
inline
Returns
the memo stack

◆ get_memo() [2/2]

const mtr_buf_t * mtr_t::get_memo ( ) const
inline
Returns
the memo stack

◆ get_savepoint()

ulint mtr_t::get_savepoint ( ) const
inline

Return current size of the buffer.

Returns
savepoint

◆ has_any_log_record()

bool mtr_t::has_any_log_record ( )
inline

Checks if this mtr has generated any redo log records which should be written to the redo log during commit().

Note: If redo logging is disabled by set_log_mode(MTR_LOG_NONE) or set_log_mode(MTR_LOG_NO_REDO) or globally by s_logging.disable(..), then it will return false, even if set_modified() was called. Note: Redo log records can be generated for things other than page modifications, for example for tablespace rename, or other metadata updates. Note: Redo log records can be generated for modifications of pages which were already marked as dirty in BP.

Returns
true iff there is at least one redo log record generated

◆ has_committed()

bool mtr_t::has_committed ( ) const
inline
Returns
true if the mini-transaction has committed

◆ has_modifications()

bool mtr_t::has_modifications ( ) const
inline

Checks if this mtr has modified any buffer pool page.

It errs on the safe side: may return true even if it didn't modify any page. This is used in MTR_LOG_NO_REDO mode to detect that pages should be added to flush lists during commit() even though no redo log will be produced.

Returns
true if the mini-transaction might have modified buffer pool pages.

◆ is_active()

bool mtr_t::is_active ( ) const
inline

◆ is_async()

bool mtr_t::is_async ( ) const
inline
Returns
whether this is an asynchronous mini-transaction.

◆ is_committing()

bool mtr_t::is_committing ( ) const
inline
Returns
true if the mini-transaction is committing

◆ is_inside_ibuf()

bool mtr_t::is_inside_ibuf ( ) const
inline
Returns
true if we are inside the change buffer code

◆ is_this_thread_inside_mtr()

static bool mtr_t::is_this_thread_inside_mtr ( )
inlinestatic

This method is useful to detect if the thread is already inside an mtr.

We should not do the log_free_check() in the child mtrs if a thread is already inside an mtr.

Returns
true if thread is not inside an mtr, false otherwise

◆ memo_contains()

bool mtr_t::memo_contains ( const mtr_buf_t memo,
const void *  object,
ulint  type 
)
static

Check if memo contains the given item.

Parameters
memomemo stack
objectobject to search
typetype of object
Returns
true if contains
true if contains

◆ memo_contains_flagged()

bool mtr_t::memo_contains_flagged ( const void *  ptr,
ulint  flags 
) const

Check if memo contains the given item.

Parameters
ptrobject to search
flagsspecify types of object (can be ORred) of MTR_MEMO_PAGE_S_FIX ... values
Returns
true if contains

◆ memo_contains_page_flagged()

buf_block_t * mtr_t::memo_contains_page_flagged ( const byte ptr,
ulint  flags 
) const

Check if memo contains the given page.

Parameters
[in]ptrpointer to within buffer frame
[in]flagsspecify types of object with OR of MTR_MEMO_PAGE_S_FIX... values
Returns
the block
Return values
NULLif not found

◆ memo_modify_page()

void mtr_t::memo_modify_page ( const byte ptr)

Mark the given latched page as modified.

Parameters
[in]ptrpointer to within buffer frame

◆ memo_push()

void mtr_t::memo_push ( void *  object,
mtr_memo_type_t  type 
)
inline

Push an object to an mtr memo stack.

Pushes an object to an mtr memo stack.

Parameters
objectobject
typeobject type: MTR_MEMO_S_LOCK, ...

◆ memo_release()

void mtr_t::memo_release ( const void *  object,
ulint  type 
)

Release an object in the memo stack.

Parameters
objectobject
typeobject type: MTR_MEMO_S_LOCK, ...

◆ print()

void mtr_t::print ( ) const

Print info of an mtr handle.

◆ print_memos()

std::ostream & mtr_t::print_memos ( std::ostream &  out) const

Print the memo objects (mtr_memo_slot_t) of mtr_t to the given output stream.

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

◆ read_ulint()

uint32_t mtr_t::read_ulint ( const byte ptr,
mlog_id_t  type 
) const
inline

Read 1 - 4 bytes from a file page buffered in the buffer pool.

Reads 1 - 4 bytes from a file page buffered in the buffer pool.

Parameters
ptrpointer from where to read
typeMLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES
Returns
value read
value read

◆ release_block_at_savepoint()

void mtr_t::release_block_at_savepoint ( ulint  savepoint,
buf_block_t block 
)
inline

Release the block in an mtr memo after a savepoint.

Releases the block in an mtr memo after a savepoint.

◆ release_page()

void mtr_t::release_page ( const void *  ptr,
mtr_memo_type_t  type 
)

Release a page latch.

Parameters
[in]ptrpointer to within a page frame
[in]typeobject type: MTR_MEMO_PAGE_X_FIX, ...

◆ release_s_latch_at_savepoint()

void mtr_t::release_s_latch_at_savepoint ( ulint  savepoint,
rw_lock_t lock 
)
inline

Release the (index tree) s-latch stored in an mtr memo after a savepoint.

Releases the (index tree) s-latch stored in an mtr memo after a savepoint.

Parameters
savepointvalue returned by
See also
set_savepoint.
Parameters
locklatch to release

◆ remove_from_debug_list()

void mtr_t::remove_from_debug_list ( ) const

Removed the MTR from the s_my_thread_active_mtrs list.

◆ s_lock()

void mtr_t::s_lock ( rw_lock_t lock,
ut::Location  location 
)
inline

Locks a rw-latch in S mode.

Locks a lock in s-mode.

NOTE: use mtr_s_lock().

Parameters
lockrw-lock
locationlocation from where called

◆ set_flush_observer()

void mtr_t::set_flush_observer ( Flush_observer observer)
inline

Set flush observer.

Parameters
[in]observerflush observer

◆ set_log_mode()

mtr_log_t mtr_t::set_log_mode ( mtr_log_t  mode)

Change the logging mode.

Parameters
modelogging mode
Returns
old mode

◆ set_modified()

void mtr_t::set_modified ( )
inline

Note that the mini-transaction might have modified a buffer pool page.

As it's called from mlog_open(), which is called from fil_op_write_log() and perhaps other places which do not modify any page, this can be a false positive.

◆ set_sync()

void mtr_t::set_sync ( )
inline

Request a future commit to be synchronous.

◆ start()

void mtr_t::start ( bool  sync = true)

Start a mini-transaction.

Parameters
synctrue if it is a synchronous mini-transaction

◆ sx_latch_at_savepoint()

void mtr_t::sx_latch_at_savepoint ( ulint  savepoint,
buf_block_t block 
)
inline

SX-latch a not yet latched block after a savepoint.

SX-latches the not yet latched block after a savepoint.

◆ sx_lock()

void mtr_t::sx_lock ( rw_lock_t lock,
ut::Location  location 
)
inline

Locks a rw-latch in X mode.

Locks a lock in sx-mode.

NOTE: use mtr_sx_lock().

Parameters
lockrw-lock
locationlocation from where called

◆ wait_for_flush()

void mtr_t::wait_for_flush ( )

◆ x_latch_at_savepoint()

void mtr_t::x_latch_at_savepoint ( ulint  savepoint,
buf_block_t block 
)
inline

X-latch a not yet latched block after a savepoint.

X-latches the not yet latched block after a savepoint.

◆ x_lock()

void mtr_t::x_lock ( rw_lock_t lock,
ut::Location  location 
)
inline

Locks a rw-latch in X mode.

Locks a lock in x-mode.

NOTE: use mtr_x_lock().

Parameters
lockrw-lock
locationlocation where name from where called

◆ x_lock_space()

void mtr_t::x_lock_space ( fil_space_t space,
ut::Location  location 
)

Acquire a tablespace X-latch.

NOTE: use mtr_x_lock_space().

Parameters
[in]spacetablespace instance
[in]locationlocation from where called

Friends And Related Function Documentation

◆ Command

friend class Command
friend

Member Data Documentation

◆ m_commit_lsn

lsn_t mtr_t::m_commit_lsn
private

LSN at commit time.

◆ m_impl

Impl mtr_t::m_impl
private

◆ m_restart_count

size_t mtr_t::m_restart_count {}

Count the number of times the same mtr object has been committed and restarted.

◆ m_sync

bool mtr_t::m_sync
private

true if it is synchronous mini-transaction

◆ s_logging

mtr_t::Logging mtr_t::s_logging
static

Instance level logging information for all mtrs.

◆ s_mode_update

bool mtr_t::s_mode_update
static
Initial value:
= {
{false, true, true, true},
{true, false, true, false},
{false, true, false, false},
{true, false, false, false}
}

Matrix to check if a mode update request should be ignored.

◆ s_mode_update_valid

bool mtr_t::s_mode_update_valid
static
Initial value:
= {
{true, true, true, true},
{true, true, true, true},
{true, true, true, true},
{true, false, false, true}
}

For checking invalid mode update requests.

◆ s_my_thread_active_mtrs

thread_local ut::unordered_set< const mtr_t * > mtr_t::s_my_thread_active_mtrs
staticprivate

List of all non-committed MTR instances created in this thread.

Used for debug purposes in the log_free_check().


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