MySQL 26.7.0
Source Code Documentation
MVCC Class Reference

The MVCC read view manager. More...

#include <read0read.h>

Inheritance diagram for MVCC:
[legend]

Public Member Functions

 MVCC (ulint size)
 Constructor. More...
 
 ~MVCC () override
 Destructor. More...
 
void initialize (trx_id_t max_committed_trx_id, trx_ids_t active_ids) override
 Initializes the MVCC once the max_committed_trx_id estimate is learned from reading system tablespace's header TRX_SYS_TRX_ID_STORE field. More...
 
void view_open (Read_view_interface *&view, trx_t *trx) override
 If view is nullptr then allocates a view, otherwise, reuses the one provided, in both cases opening it. More...
 
void view_close (Read_view_interface *&view, bool own_mutex) override
 Closes a view previously opened by view_open(..). More...
 
void clone_oldest_view (Read_view_interface *&view) override
 Clones the oldest open view or if there is no open view at the moment, clones one which would be created if view_open(..) was called. More...
 
void view_free (Read_view_interface *&view) override
 Makes sure the view is properly freed: if view is already nullptr does nothing, otherwise it must be already closed, and this function will take trx_sys->mutex, free the view, and set it to nullptr. More...
 
size_t get_open_views_count () const override
 Returns the number of open views. More...
 
void undo_purge_is_starting () override
 Instructs the MVCC that the Undo Purge is about to start working and MVCC will be asked to clone the oldest Read View. More...
 
void undo_purge_has_shutdown () override
 Instructs the MVCC that the Undo Purge was shutdown and will not be asking to clone the oldest Read View or any other MVCC anymore. More...
 
bool is_view_open (const Read_view_interface *view) const override
 Can be used only for nullptr or view assigned by view_open(view,..) or view_close(view,..) or clone_oldest_view(view,..). More...
 
void set_view_creator_trx_id (Read_view_interface *&view, trx_id_t id) override
 Sets the view creator transaction id, when a transaction which previously called view_open(view,..) when it was read-only (and thus had trx->id==0), has transitioned to a RW state and got a trx->id assigned. More...
 
- Public Member Functions inherited from MVCC_interface
virtual ~MVCC_interface ()=default
 Destructor. More...
 

Private Member Functions

void view_open (ReadView *&view, trx_t *trx)
 A helper for the interface method with the same name, which makes it cleaner to assign to the referenced pointer while using the actual implementation-specific type. More...
 
void view_close (ReadView *&view, bool own_mutex)
 A helper for the interface method with the same name, which makes it cleaner to assign to the referenced pointer while using the actual implementation-specific type. More...
 
void clone_oldest_view (ReadView *&view)
 A helper for the interface method with the same name, which makes it cleaner to assign to the referenced pointer while using the actual implementation-specific type. More...
 
void validate () const
 Asserts the read view list is sorted. More...
 
ReadViewget_view ()
 Get a view from the free list, or allocate a new one if it's empty. More...
 
 MVCC (const MVCC &)=delete
 
MVCCoperator= (const MVCC &)=delete
 
typedef UT_LIST_BASE_NODE_T (ReadView, m_view_list) view_list_t
 

Private Attributes

char _padding [ut::INNODB_CACHE_LINE_SIZE]
 
view_list_t m_free
 Free views ready for reuse. More...
 
view_list_t m_views
 Active and closed views. More...
 

Detailed Description

The MVCC read view manager.

Constructor & Destructor Documentation

◆ MVCC() [1/2]

MVCC::MVCC ( ulint  size)
explicit

Constructor.

Parameters
sizeNumber of views to pre-allocate

◆ ~MVCC()

MVCC::~MVCC ( )
override

Destructor.

Free all the views in the m_free list

◆ MVCC() [2/2]

MVCC::MVCC ( const MVCC )
privatedelete

Member Function Documentation

◆ clone_oldest_view() [1/2]

void MVCC::clone_oldest_view ( Read_view_interface *&  view)
overridevirtual

Clones the oldest open view or if there is no open view at the moment, clones one which would be created if view_open(..) was called.

The view provided by a caller must be either nullptr or a closed view obtained from an earlier call to clone_oldest_view(..). This function will either allocate a new view or clone into view provided. After the call view will be considered closed. It must be freed by the caller using view_free(view) when no longer needed.

Parameters
[in,out]viewA pointer to a closed view obtained from an earlier call to this method or a nullptr. It must not be a result of view_close(..) or view_open(..). Upon return it will point to a closed view which is a clone of the oldest open read view found during the call. It should be freed with view_free(..). Do not call view_open(..) on it.

Implements MVCC_interface.

◆ clone_oldest_view() [2/2]

void MVCC::clone_oldest_view ( ReadView *&  view)
private

A helper for the interface method with the same name, which makes it cleaner to assign to the referenced pointer while using the actual implementation-specific type.

Clones the oldest view into the provided view, unless the function determines that the provided view is already a good enough lower bound. The caller owns the view that is passed in, which is interpreted to be a previous lower bound known to the caller. No need to call view_close(view,..).

Note: This function is called by Purge to determine the purge_sys->view used to distinguish which transactions are considered committed by everybody, and thus their undo logs can be purged. Purge mainly uses purge_sys->view->low_limit_no(), which is a safe lower-bound on what can be purged based on NO, and further limits it to the lowest needed NO reported by GTID Persistor. But other places like ROLLBACK use purge_sys->view->changes_visible(ID,..).

Parameters
[in,out]viewPreallocated view, owned by the caller. Can be either default constructed (m_low_limit_no is 0) or a fully initialized ReadView object.
See also
clone_oldest_view(Read_view_interface*&)

◆ get_open_views_count()

size_t MVCC::get_open_views_count ( ) const
overridevirtual

Returns the number of open views.

Implements MVCC_interface.

◆ get_view()

ReadView * MVCC::get_view ( )
inlineprivate

Get a view from the free list, or allocate a new one if it's empty.

Returns
a view to use

◆ initialize()

void MVCC::initialize ( trx_id_t  max_assigned_trx_id,
trx_ids_t  active_ids 
)
overridevirtual

Initializes the MVCC once the max_committed_trx_id estimate is learned from reading system tablespace's header TRX_SYS_TRX_ID_STORE field.

Parameters
[in]max_assigned_trx_idThe upper-bound on highest assigned trx id. No record in any B-tree can currently have DB_TRX_ID larger than this. No Undo Log can have TRX_UNDO_TRX_NO or TRX_UNDO_TRX_ID larger than this.
[in]active_idsThe set of ids of currently active transactions. They should all be at <= max_committed_trx_id.

Implements MVCC_interface.

◆ is_view_open()

bool MVCC::is_view_open ( const Read_view_interface view) const
inlineoverridevirtual

Can be used only for nullptr or view assigned by view_open(view,..) or view_close(view,..) or clone_oldest_view(view,..).

(note, though that clone_oldest_view always gives you a closed view, so no need to check).

Parameters
[in]viewThe view to check. Can be nullptr.
Returns
true if the view is not nullptr and is open

Implements MVCC_interface.

◆ operator=()

MVCC & MVCC::operator= ( const MVCC )
privatedelete

◆ set_view_creator_trx_id()

void MVCC::set_view_creator_trx_id ( Read_view_interface *&  view,
trx_id_t  id 
)
inlineoverridevirtual

Sets the view creator transaction id, when a transaction which previously called view_open(view,..) when it was read-only (and thus had trx->id==0), has transitioned to a RW state and got a trx->id assigned.

One can imagine an implementation which could change the view instance to another (say: from one shared with other read-only transactions to one tailored to this particular RW transaction, which should see its own writes).

Parameters
[in,out]viewSet the creator trx id for this view. The view should be already open first by view_open(view, trx) when trx->id was 0.
[in]idTransaction id to set, should be the trx->id assigned to the same trx for which view_open(view, trx) was called earlier.

Implements MVCC_interface.

◆ undo_purge_has_shutdown()

void MVCC::undo_purge_has_shutdown ( )
overridevirtual

Instructs the MVCC that the Undo Purge was shutdown and will not be asking to clone the oldest Read View or any other MVCC anymore.

To be called before trx_sys is being destroyed.

Implements MVCC_interface.

◆ undo_purge_is_starting()

void MVCC::undo_purge_is_starting ( )
overridevirtual

Instructs the MVCC that the Undo Purge is about to start working and MVCC will be asked to clone the oldest Read View.

Implements MVCC_interface.

◆ UT_LIST_BASE_NODE_T()

typedef MVCC::UT_LIST_BASE_NODE_T ( ReadView  ,
m_view_list   
)
private

◆ validate()

void MVCC::validate ( ) const
private

Asserts the read view list is sorted.

◆ view_close() [1/2]

void MVCC::view_close ( Read_view_interface *&  view,
bool  own_mutex 
)
overridevirtual

Closes a view previously opened by view_open(..).

It's safe to call it on a view which was already closed. After the call, it is unsafe to access view's members, because it might be freed by this function (in which case view is nullptr). Even if the view is still not null after the call, it is at least in the closed state - so can be reopen again with view_open(..) or freed with view_free(..).

Parameters
[in,out]viewMust not be nullptr. Must be a pointer obtained from view_open(..) or view_close(..). Upon return it will be either nullptr or pointing to a closed view.
[in]own_mutextrue if the caller owns the trx_sys->mutex

Implements MVCC_interface.

◆ view_close() [2/2]

void MVCC::view_close ( ReadView *&  view,
bool  own_mutex 
)
private

A helper for the interface method with the same name, which makes it cleaner to assign to the referenced pointer while using the actual implementation-specific type.

In case own_mutex is true, it will move the view to the free list and assign nullptr to the argument. Otherwise it only closes the view, without freeing it.

See also
view_close(Read_view_interface*&,bool)

◆ view_free()

void MVCC::view_free ( Read_view_interface *&  view)
overridevirtual

Makes sure the view is properly freed: if view is already nullptr does nothing, otherwise it must be already closed, and this function will take trx_sys->mutex, free the view, and set it to nullptr.

Parameters
[in,out]viewnullptr or a closed view. Upon return it will be nullptr.

Implements MVCC_interface.

◆ view_open() [1/2]

void MVCC::view_open ( Read_view_interface *&  view,
trx_t trx 
)
overridevirtual

If view is nullptr then allocates a view, otherwise, reuses the one provided, in both cases opening it.

That is, after the call view is not null, view members can be accessed, and view->is_closed() == false. It is guaranteed that clone_oldest_view(v2) calls which happen-before the call to view_close(view,...) for this view, will clone a v2 which is not fresher than this view.

Parameters
[in,out]viewMust be either nullptr or a result of view_close(..), which in turn should be a result of an earlier view_open(..). It must not be a result of clone_oldest_view(..). Upon return it will be not null and open. Must be closed by calling view_close(..). If it is still not nullptr after view_close(..) it must be passed to view_free(..) to free it.
[in]trxTransaction instance of caller

Implements MVCC_interface.

◆ view_open() [2/2]

void MVCC::view_open ( ReadView *&  view,
trx_t trx 
)
private

A helper for the interface method with the same name, which makes it cleaner to assign to the referenced pointer while using the actual implementation-specific type.

If trx is auto-commit non-locking transaction and view is not-null, it attempts to reopen it. This fast path succeeds if the view is still the freshest possible, in which case taking trx_sys mutex is avoided. Otherwise it falls back to the slow path, which requires a trx_sys mutex to (re)initialize the view.

See also
view_open(Read_view_interface*&,trx_t*)

Member Data Documentation

◆ _padding

char MVCC::_padding[ut::INNODB_CACHE_LINE_SIZE]
private

◆ m_free

view_list_t MVCC::m_free
private

Free views ready for reuse.

◆ m_views

view_list_t MVCC::m_views
private

Active and closed views.


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