MySQL 8.4.2
Source Code Documentation
|
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>
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... | |
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.
|
inline |
Returns a reference to one of the underlying Key_value_store instances.
[in] THD (connection) identifier.
|
friend |
Do not break encapsulation when using CRTP.
|
private |
N_SHARDS instances of Key_value_store's.
|
staticconstexprprivate |
Check whether all compile-time pre-conditions are set.
Bitmask which enables us to implement modulo-arithmetic operation in single bitwise instruction.