MySQL 8.3.0
Source Code Documentation
MDL_ticket_store Class Reference

Keep track of MDL_ticket for different durations. More...

#include <mdl.h>

Classes

struct  Duration
 
struct  Hash
 
struct  Key_equal
 
struct  MDL_ticket_handle
 Utility struct for representing a ticket pointer and its duration. More...
 

Public Types

using List_iterator = Ticket_p_list::Iterator
 Public alias. More...
 

Public Member Functions

 MDL_ticket_store ()
 Constructs store. More...
 
template<typename CLOS >
void for_each_ticket_in_duration_list (enum_mdl_duration dur, CLOS &&clos)
 Calls the closure provided as argument for each of the MDL_tickets in the given duration. More...
 
template<typename CLOS >
void for_each_ticket_in_ticket_lists (CLOS &&clos)
 Calls the closure provided as argument for each of the MDL_tickets in the store. More...
 
bool is_empty () const
 Predicate for the emptiness of the store. More...
 
bool is_empty (int di) const
 Predicate for the emptiness of a given duration list. More...
 
MDL_ticketfront (int di)
 Return the first MDL_ticket for the given duration. More...
 
void push_front (enum_mdl_duration dur, MDL_ticket *ticket)
 Push a ticket onto the list for a given duration. More...
 
void remove (enum_mdl_duration dur, MDL_ticket *ticket)
 Remove a ticket from a duration list. More...
 
List_iterator list_iterator (int di) const
 Return a P-list iterator to the given duration. More...
 
void move_all_to_explicit_duration ()
 Move all tickets to the explicit duration list. More...
 
void move_explicit_to_transaction_duration ()
 Move all tickets to the transaction duration list. More...
 
MDL_ticket_handle find (const MDL_request &req) const
 Look up a ticket based on its MDL_key. More...
 
void set_materialized ()
 Mark boundary for tickets with fast_path=false, so that later calls to materialize_fast_path_locks() do not have to traverse the whole set of tickets. More...
 
MDL_ticketmaterialized_front (int di)
 Return the first ticket for which materialize_fast_path_locks already has been called for the given duration. More...
 

Private Types

using Ticket_p_list = I_P_List< MDL_ticket, I_P_List_adapter< MDL_ticket, &MDL_ticket::next_in_context, &MDL_ticket::prev_in_context > >
 
using Ticket_map = std::unordered_multimap< const MDL_key *, MDL_ticket_handle, Hash, Key_equal >
 

Private Member Functions

MDL_ticket_handle find_in_lists (const MDL_request &req) const
 
MDL_ticket_handle find_in_hash (const MDL_request &req) const
 

Private Attributes

Duration m_durations [MDL_DURATION_END]
 
const size_t THRESHOLD = 256
 If the number of tickets in the ticket store (in all durations) is equal to, or exceeds this constant the hash index (in the form of an unordered_multi_map) will be maintained and used for lookups. More...
 
const size_t INITIAL_BUCKET_COUNT = THRESHOLD * 2
 Initial number of buckets in the hash index. More...
 
size_t m_count = 0
 
std::unique_ptr< Ticket_mapm_map
 

Detailed Description

Keep track of MDL_ticket for different durations.

Maintains a hash-based secondary index into the linked lists, to speed up access by MDL_key.

Member Typedef Documentation

◆ List_iterator

◆ Ticket_map

using MDL_ticket_store::Ticket_map = std::unordered_multimap<const MDL_key *, MDL_ticket_handle, Hash, Key_equal>
private

◆ Ticket_p_list

Constructor & Destructor Documentation

◆ MDL_ticket_store()

MDL_ticket_store::MDL_ticket_store ( )
inline

Constructs store.

The hash index is initially empty. Filled on demand.

Member Function Documentation

◆ find()

MDL_ticket_store::MDL_ticket_handle MDL_ticket_store::find ( const MDL_request req) const

Look up a ticket based on its MDL_key.

Parameters
reqrequest to locate ticket for
Returns
MDL_ticket_handle with ticket pointer and found duration (or nullptr and MDL_DURATION_END if not found

NDEBUG

◆ find_in_hash()

MDL_ticket_store::MDL_ticket_handle MDL_ticket_store::find_in_hash ( const MDL_request req) const
private

◆ find_in_lists()

MDL_ticket_store::MDL_ticket_handle MDL_ticket_store::find_in_lists ( const MDL_request req) const
private

◆ for_each_ticket_in_duration_list()

template<typename CLOS >
void MDL_ticket_store::for_each_ticket_in_duration_list ( enum_mdl_duration  dur,
CLOS &&  clos 
)
inline

Calls the closure provided as argument for each of the MDL_tickets in the given duration.

Parameters
durduration list to iterate over
closclosure to invoke for each ticket in the list

◆ for_each_ticket_in_ticket_lists()

template<typename CLOS >
void MDL_ticket_store::for_each_ticket_in_ticket_lists ( CLOS &&  clos)
inline

Calls the closure provided as argument for each of the MDL_tickets in the store.

Parameters
closclosure to invoke for each ticket in the store

◆ front()

MDL_ticket * MDL_ticket_store::front ( int  di)

Return the first MDL_ticket for the given duration.

Parameters
diduration to get first ticket for
Returns
first ticket in the given duration or nullptr if no such tickets exist

◆ is_empty() [1/2]

bool MDL_ticket_store::is_empty ( ) const

Predicate for the emptiness of the store.

Returns
true if there are no tickets in the store

◆ is_empty() [2/2]

bool MDL_ticket_store::is_empty ( int  di) const

Predicate for the emptiness of a given duration list.

Parameters
dithe duration to check
Returns
true if there are no tickets with the given duration

◆ list_iterator()

List_iterator MDL_ticket_store::list_iterator ( int  di) const
inline

Return a P-list iterator to the given duration.

Parameters
diduration list index
Returns
P-list iterator to tickets with given duration

◆ materialized_front()

MDL_ticket * MDL_ticket_store::materialized_front ( int  di)

Return the first ticket for which materialize_fast_path_locks already has been called for the given duration.

Parameters
diduration list index
Returns
first materialized ticket for the given duration

◆ move_all_to_explicit_duration()

void MDL_ticket_store::move_all_to_explicit_duration ( )

Move all tickets to the explicit duration list.

◆ move_explicit_to_transaction_duration()

void MDL_ticket_store::move_explicit_to_transaction_duration ( )

Move all tickets to the transaction duration list.

◆ push_front()

void MDL_ticket_store::push_front ( enum_mdl_duration  dur,
MDL_ticket ticket 
)

Push a ticket onto the list for a given duration.

Parameters
durduration list to push into
ticketto push

◆ remove()

void MDL_ticket_store::remove ( enum_mdl_duration  dur,
MDL_ticket ticket 
)

Remove a ticket from a duration list.

Note that since the underlying list is an intrusive linked list there is no guarantee that the ticket is actually in the duration list. It will be removed from which ever list it is in.

◆ set_materialized()

void MDL_ticket_store::set_materialized ( )

Mark boundary for tickets with fast_path=false, so that later calls to materialize_fast_path_locks() do not have to traverse the whole set of tickets.

Member Data Documentation

◆ INITIAL_BUCKET_COUNT

const size_t MDL_ticket_store::INITIAL_BUCKET_COUNT = THRESHOLD * 2
private

Initial number of buckets in the hash index.

THRESHOLD is chosen to get a fill-factor of 50% when reaching the threshold value.

◆ m_count

size_t MDL_ticket_store::m_count = 0
private

◆ m_durations

Duration MDL_ticket_store::m_durations[MDL_DURATION_END]
private

◆ m_map

std::unique_ptr<Ticket_map> MDL_ticket_store::m_map
private

◆ THRESHOLD

const size_t MDL_ticket_store::THRESHOLD = 256
private

If the number of tickets in the ticket store (in all durations) is equal to, or exceeds this constant the hash index (in the form of an unordered_multi_map) will be maintained and used for lookups.

The value 256 is chosen as it has worked well in benchmarks.


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