MySQL 9.1.0
Source Code Documentation

A 'lock' protecting performance schema internal buffers. More...

#include <pfs_lock.h>

Public Member Functions

uint32 copy_version_state ()
 
bool is_free ()
 Returns true if the record is free. More...
 
bool is_populated ()
 Returns true if the record contains values that can be read. More...
 
bool free_to_dirty (pfs_dirty_state *copy_ptr)
 Execute a free to dirty transition. More...
 
void allocated_to_dirty (pfs_dirty_state *copy_ptr)
 Execute an allocated to dirty transition. More...
 
void dirty_to_allocated (const pfs_dirty_state *copy)
 Execute a dirty to allocated transition. More...
 
void set_allocated ()
 Initialize a lock to allocated. More...
 
void set_dirty (pfs_dirty_state *copy_ptr)
 Initialize a lock to dirty. More...
 
void dirty_to_free (const pfs_dirty_state *copy)
 Execute a dirty to free transition. More...
 
void allocated_to_free ()
 Execute an allocated to free transition. More...
 
void begin_optimistic_lock (pfs_optimistic_state *copy)
 Start an optimistic read operation. More...
 
bool end_optimistic_lock (const pfs_optimistic_state *copy)
 End an optimistic read operation. More...
 
uint32 get_version ()
 

Public Attributes

std::atomic< uint32m_version_state
 The record internal version and state. More...
 

Detailed Description

A 'lock' protecting performance schema internal buffers.

This lock is used to mark the state of a record. Access to the record is not enforced here, it's up to the readers and writers to look at the record state before making an actual read or write operation.

The following state diagram shows the general states maintained by the lock.

An internal version counter is also incremented, to detect each modification done to a record.

The following diagram represent a fragment of all the states reached, for an object creation, modification and destruction.

Member Function Documentation

◆ allocated_to_dirty()

void pfs_lock::allocated_to_dirty ( pfs_dirty_state copy_ptr)
inline

Execute an allocated to dirty transition.

This transition should be executed by the writer that owns the record, before the record is modified.

◆ allocated_to_free()

void pfs_lock::allocated_to_free ( )
inline

Execute an allocated to free transition.

This transition should be executed by the writer that owns the record.

◆ begin_optimistic_lock()

void pfs_lock::begin_optimistic_lock ( pfs_optimistic_state copy)
inline

Start an optimistic read operation.

Parameters
[out]copySaved lock state
See also
end_optimist_lock.

◆ copy_version_state()

uint32 pfs_lock::copy_version_state ( )
inline

◆ dirty_to_allocated()

void pfs_lock::dirty_to_allocated ( const pfs_dirty_state copy)
inline

Execute a dirty to allocated transition.

This transition should be executed by the writer that owns the record, after the record is in a state ready to be read.

◆ dirty_to_free()

void pfs_lock::dirty_to_free ( const pfs_dirty_state copy)
inline

Execute a dirty to free transition.

This transition should be executed by the writer that owns the record.

◆ end_optimistic_lock()

bool pfs_lock::end_optimistic_lock ( const pfs_optimistic_state copy)
inline

End an optimistic read operation.

See also
begin_optimist_lock.
Parameters
copySaved lock state
Returns
true if the data read is safe to use.

◆ free_to_dirty()

bool pfs_lock::free_to_dirty ( pfs_dirty_state copy_ptr)
inline

Execute a free to dirty transition.

This transition is safe to execute concurrently by multiple writers. Only one writer will succeed to acquire the record.

Returns
true if the operation succeed

◆ get_version()

uint32 pfs_lock::get_version ( )
inline

◆ is_free()

bool pfs_lock::is_free ( )
inline

Returns true if the record is free.

◆ is_populated()

bool pfs_lock::is_populated ( )
inline

Returns true if the record contains values that can be read.

◆ set_allocated()

void pfs_lock::set_allocated ( )
inline

Initialize a lock to allocated.

This transition should be executed by the writer that owns the record and the lock, after the record is in a state ready to be read.

◆ set_dirty()

void pfs_lock::set_dirty ( pfs_dirty_state copy_ptr)
inline

Initialize a lock to dirty.

Member Data Documentation

◆ m_version_state

std::atomic<uint32> pfs_lock::m_version_state

The record internal version and state.

See also
PFS_LOCK_FREE
PFS_LOCK_DIRTY
PFS_LOCK_ALLOCATED The version number is to transform the 'ABA' problem (see http://en.wikipedia.org/wiki/ABA_problem) into an 'A(n)BA(n + 1)' problem, where 'n' is the m_version number. When the performance schema instrumentation deletes a record, then create a different record reusing the same memory allocation, the version number is incremented, so that a reader can detect that the record was changed. Note that the version number is never reset to zero when a new record is created. The version number is stored in the high 30 bits. The state is stored in the low 2 bits.

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