MySQL 8.4.0
Source Code Documentation
binlog::BgcTicket Class Reference

Represents the Binlog Group Commit Ticket - BGC Ticket. More...

#include <bgc_ticket.h>

Public Types

using ValueType = std::uint64_t
 

Public Member Functions

 BgcTicket (const ValueType &ticket=first_ticket_value)
 Constructor. More...
 
ValueType get_value () const
 Obtain ticket value (1st bit cleared out) More...
 
const ValueTypeget () const
 Obtain ticket, may be in use or not (cannot be easily compared) More...
 
void set_in_use ()
 sets synchronization bit to 1, only 1 thread can operate on this ticket More...
 
void set_used ()
 sets synchronization bit to 0, other thread may "lock" this ticket for writing More...
 
bool is_in_use () const
 checks whether this ticket is "locked" for writing More...
 
BgcTicket next () const
 Returns incremented ticket, this remain unchanged. More...
 
void set_next ()
 Increments this ticket value. More...
 
bool is_set () const
 Checks whether the ticket value differs from kTicketUnset. More...
 

Static Public Attributes

static constexpr BgcTicket::ValueType kTicketUnset = 0
 Default value of ticket, which means it is not being used. More...
 
static constexpr ValueType set_bit = 1ULL << 63
 64-bit mask with all 0s except for the most significant bit, to extract synchronization bit More...
 
static constexpr ValueType clear_bit = set_bit - 1
 64-bit mask with all 0s except for the most significant bit, to clear out synchronization bit - get ticket value More...
 
static constexpr ValueType max_ticket_value
 Maximum allowed value for a ticket, after which will wrap around to first_ticket_value. More...
 
static constexpr ValueType first_ticket_value = 1
 Minimum allowed value for a ticket. More...
 

Protected Attributes

ValueType m_ticket
 1 bit for synchronization, 63 bits - ticket value More...
 

Friends

class AtomicBgcTicket
 
bool operator< (const BgcTicket &lhs, const BgcTicket &rhs)
 "Less than" operator More...
 
bool operator> (const BgcTicket &lhs, const BgcTicket &rhs)
 "Greater than" operator More...
 
bool operator>= (const BgcTicket &lhs, const BgcTicket &rhs)
 Comparison operator (>=) More...
 
bool operator== (const BgcTicket &lhs, const BgcTicket &rhs)
 Comparison operator. More...
 
bool operator!= (const BgcTicket &lhs, const BgcTicket &rhs)
 Comparison operator. More...
 
std::ostream & operator<< (std::ostream &os, const BgcTicket &arg)
 Stream operator impl for BgcTicket class. More...
 

Detailed Description

Represents the Binlog Group Commit Ticket - BGC Ticket.

Context: BGC ticket is granted to sessions with the same View, which may be changed with the View Change Event (server connecting to / disconnecting from group). When View Change Event is generated, it is granted a separate ticket value (value+1). All sessions that should be executed after View Change Event are assigned with a ticket value + 2. Implementation: Ticket is composed of 1 synchronization bit, used for critical section implementation and 63 bits that represent a ticket value. This class contains operation common for BGC tickets, such as: value extraction, changing synchronization bit between 0 and 1, ticket comparison, formatting, incrementation, internal constants. After reachning the maximum value for a ticket, ticket value is wrapped up to the first valid ticket value.

See also
Bgc_ticket_manager

Member Typedef Documentation

◆ ValueType

using binlog::BgcTicket::ValueType = std::uint64_t

Constructor & Destructor Documentation

◆ BgcTicket()

binlog::BgcTicket::BgcTicket ( const ValueType ticket = first_ticket_value)
explicit

Constructor.

Parameters
[in]ticketPattern to copy from

Member Function Documentation

◆ get()

const ValueType & binlog::BgcTicket::get ( ) const
inline

Obtain ticket, may be in use or not (cannot be easily compared)

Cannot be easily compared, use comparison operator from BgcTicket instead

Returns
Internal value of the ticket (value+sync bit)

◆ get_value()

BgcTicket::ValueType binlog::BgcTicket::get_value ( ) const

Obtain ticket value (1st bit cleared out)

Returns
Ticket value

◆ is_in_use()

bool binlog::BgcTicket::is_in_use ( ) const

checks whether this ticket is "locked" for writing

Return values
trueTicket is in use
falseTicket is not in use

◆ is_set()

bool binlog::BgcTicket::is_set ( ) const

Checks whether the ticket value differs from kTicketUnset.

Return values
trueTicket value is set
falseTicket value is unset

◆ next()

BgcTicket binlog::BgcTicket::next ( ) const

Returns incremented ticket, this remain unchanged.

Returns
Incremented ticket

◆ set_in_use()

void binlog::BgcTicket::set_in_use ( )

sets synchronization bit to 1, only 1 thread can operate on this ticket

◆ set_next()

void binlog::BgcTicket::set_next ( )

Increments this ticket value.

◆ set_used()

void binlog::BgcTicket::set_used ( )

sets synchronization bit to 0, other thread may "lock" this ticket for writing

Friends And Related Function Documentation

◆ AtomicBgcTicket

friend class AtomicBgcTicket
friend

◆ operator!=

bool operator!= ( const BgcTicket lhs,
const BgcTicket rhs 
)
friend

Comparison operator.

Comparison without (!) first bit

Parameters
[in]lhsLeft hand side BgcTicket argument (const ref)
[in]rhsRight hand side BgcTicket argument (const ref)
Return values
truelhs != rhs
falserhs == lhs

◆ operator<

bool operator< ( const BgcTicket lhs,
const BgcTicket rhs 
)
friend

"Less than" operator

Parameters
[in]lhsLeft hand side BgcTicket argument (const ref)
[in]rhsRight hand side BgcTicket argument (const ref)

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const BgcTicket arg 
)
friend

Stream operator impl for BgcTicket class.

Parameters
[in]osReference to stream obj
[in]argConstant reference to BgcTicket object
Returns
Reference to changed stream obj

◆ operator==

bool operator== ( const BgcTicket lhs,
const BgcTicket rhs 
)
friend

Comparison operator.

Comparison without (!) first bit, meaning that if some thread locked on lhs or rhs, tickets can still be equal

Parameters
[in]lhsLeft hand side BgcTicket argument (const ref)
[in]rhsRight hand side BgcTicket argument (const ref)
Return values
truelhs == rhs
falserhs != lhs

◆ operator>

bool operator> ( const BgcTicket lhs,
const BgcTicket rhs 
)
friend

"Greater than" operator

Parameters
[in]lhsLeft hand side BgcTicket argument (const ref)
[in]rhsRight hand side BgcTicket argument (const ref)
Return values
truelhs > rhs
falserhs <= lhs

◆ operator>=

bool operator>= ( const BgcTicket lhs,
const BgcTicket rhs 
)
friend

Comparison operator (>=)

Parameters
[in]lhsLeft hand side BgcTicket argument (const ref)
[in]rhsRight hand side BgcTicket argument (const ref)
Return values
truelhs >= rhs
false!(rhs >= lhs)

Member Data Documentation

◆ clear_bit

constexpr ValueType binlog::BgcTicket::clear_bit = set_bit - 1
staticconstexpr

64-bit mask with all 0s except for the most significant bit, to clear out synchronization bit - get ticket value

◆ first_ticket_value

constexpr ValueType binlog::BgcTicket::first_ticket_value = 1
staticconstexpr

Minimum allowed value for a ticket.

◆ kTicketUnset

constexpr BgcTicket::ValueType binlog::BgcTicket::kTicketUnset = 0
staticconstexpr

Default value of ticket, which means it is not being used.

◆ m_ticket

ValueType binlog::BgcTicket::m_ticket
protected

1 bit for synchronization, 63 bits - ticket value

◆ max_ticket_value

constexpr ValueType binlog::BgcTicket::max_ticket_value
staticconstexpr
Initial value:
=
std::numeric_limits<ValueType>::max() & clear_bit
static constexpr ValueType clear_bit
64-bit mask with all 0s except for the most significant bit, to clear out synchronization bit - get t...
Definition: bgc_ticket.h:147

Maximum allowed value for a ticket, after which will wrap around to first_ticket_value.

◆ set_bit

constexpr ValueType binlog::BgcTicket::set_bit = 1ULL << 63
staticconstexpr

64-bit mask with all 0s except for the most significant bit, to extract synchronization bit


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