MySQL 9.1.0
Source Code Documentation
temptable::Sharded_key_value_store< N_SHARDS, Lock, KeyValueImpl > Class Template Reference

Sharded key-value store, a convenience wrapper class around Key_value_store that creates N_SHARDS instances of Key_value_store and exposes a simple interface to further manipulate with them. More...

#include <sharded_kv_store.h>

Inheritance diagram for temptable::Sharded_key_value_store< N_SHARDS, Lock, KeyValueImpl >:
[legend]

Classes

struct  L1_dcache_aligned_kv_store
 In the event of inability to express ourselves with something like std::array<alignas<N> Key_value_store<...>> we have to fallback to this method. More...
 

Public Member Functions

Key_value_store< Lock, KeyValueImpl > & operator[] (size_t thd_id)
 Returns a reference to one of the underlying Key_value_store instances. More...
 
- Public Member Functions inherited from temptable::Sharded_key_value_store_logger< Sharded_key_value_store< N_SHARDS >, DEBUG_BUILD >
void dbug_print ()
 

Private Attributes

std::array< L1_dcache_aligned_kv_store, N_SHARDS > m_kv_store_shard
 N_SHARDS instances of Key_value_store's. More...
 

Static Private Attributes

static constexpr size_t MODULO_MASK = N_SHARDS - 1
 Check whether all compile-time pre-conditions are set. More...
 

Friends

struct Sharded_key_value_store_logger< Sharded_key_value_store, DEBUG_BUILD >
 Do not break encapsulation when using CRTP. More...
 

Detailed Description

template<size_t N_SHARDS, typename Lock = std::shared_timed_mutex, template< typename... > class KeyValueImpl = std::unordered_map>
class temptable::Sharded_key_value_store< N_SHARDS, Lock, KeyValueImpl >

Sharded key-value store, a convenience wrapper class around Key_value_store that creates N_SHARDS instances of Key_value_store and exposes a simple interface to further manipulate with them.

User code, if it wishes so, can opt-in for different key-value implementation or different locking mechanisms. Defaults are provided as convenience.

Mapping between a shard and an actual Key_value_store is done at the level of implementation detail of this class and it is done via modulo-arithmethic on THD (connection) identifier. It is guaranteed that the same shard (same Key_value_store instance) will always be returned given the same input: THD (connection) identifier. However, there is no guarantee that there will be only one such mapping (this function is not a bijection).

In other words, due to the wrap-around property of modulo-arithmetic and depending on the actual value of N_SHARDS, it is very much possible to get a reference to the same Key_value_store instance for two different THD (connection) identifiers. Thread-safety guarantees are exercised at the level of Key_value_store instance but are controlled through the Lock, this class template parameter.

Due to aforementioned modulo-arithmethic, and the questionable performance in its more general form, N_SHARDS must be a number which is a power of two. This enables us to implement a modulo operation in single bitwise instruction. Check whether N_SHARDS is a number which is power of two is run during the compile-time.

Member Function Documentation

◆ operator[]()

template<size_t N_SHARDS, typename Lock = std::shared_timed_mutex, template< typename... > class KeyValueImpl = std::unordered_map>
Key_value_store< Lock, KeyValueImpl > & temptable::Sharded_key_value_store< N_SHARDS, Lock, KeyValueImpl >::operator[] ( size_t  thd_id)
inline

Returns a reference to one of the underlying Key_value_store instances.

[in] THD (connection) identifier.

Returns
A reference to Key_value_store instance.

Friends And Related Function Documentation

◆ Sharded_key_value_store_logger< Sharded_key_value_store, DEBUG_BUILD >

template<size_t N_SHARDS, typename Lock = std::shared_timed_mutex, template< typename... > class KeyValueImpl = std::unordered_map>
friend struct Sharded_key_value_store_logger< Sharded_key_value_store, DEBUG_BUILD >
friend

Do not break encapsulation when using CRTP.

Member Data Documentation

◆ m_kv_store_shard

template<size_t N_SHARDS, typename Lock = std::shared_timed_mutex, template< typename... > class KeyValueImpl = std::unordered_map>
std::array<L1_dcache_aligned_kv_store, N_SHARDS> temptable::Sharded_key_value_store< N_SHARDS, Lock, KeyValueImpl >::m_kv_store_shard
private

N_SHARDS instances of Key_value_store's.

◆ MODULO_MASK

template<size_t N_SHARDS, typename Lock = std::shared_timed_mutex, template< typename... > class KeyValueImpl = std::unordered_map>
constexpr size_t temptable::Sharded_key_value_store< N_SHARDS, Lock, KeyValueImpl >::MODULO_MASK = N_SHARDS - 1
staticconstexprprivate

Check whether all compile-time pre-conditions are set.

Bitmask which enables us to implement modulo-arithmetic operation in single bitwise instruction.


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