MySQL 9.0.0
Source Code Documentation
temptable::Key_value_store< Lock, KeyValueImpl > Class Template Reference

Key-value store, a convenience wrapper class which models a thread-safe dictionary type. More...

#include <kv_store.h>

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

Public Member Functions

template<class... Args>
std::pair< typename Key_value_store_impl::iterator, bool > emplace (Args &&... args)
 Inserts a new table into the container constructed in-place with the given args if there is no table with the key in the container. More...
 
Tablefind (const std::string &key)
 Searches for a table with given name (key). More...
 
Key_value_store_impl::size_type erase (const std::string &key)
 Removes the table (if one exists) with the given name (key). More...
 

Private Types

using Exclusive_or_shared_lock = std::conditional_t< std::is_same< Lock, std::shared_timed_mutex >::value, std::shared_lock< Lock >, std::lock_guard< Lock > >
 Check whether we can use shared locks (which enable multiple concurrent readers) or must we rather fallback to exclusive locks. More...
 
using Key_value_store_impl = KeyValueImpl< std::string, Table >
 Alias for our key-value store implementation. More...
 

Private Attributes

Key_value_store_impl m_kv_store
 Container holding (table-name, Table) tuples. More...
 
Lock m_lock
 Lock type. More...
 

Friends

class Key_value_store_logger< Key_value_store< Lock, KeyValueImpl >, DEBUG_BUILD >
 Do not break encapsulation when using CRTP. More...
 

Additional Inherited Members

- Protected Member Functions inherited from temptable::Key_value_store_logger< Key_value_store< Lock, std::unordered_map >, DEBUG_BUILD >
void log (Key_value_store_stats::Event)
 
void dbug_print ()
 

Detailed Description

template<typename Lock, template< typename... > class KeyValueImpl = std::unordered_map>
class temptable::Key_value_store< Lock, KeyValueImpl >

Key-value store, a convenience wrapper class which models a thread-safe dictionary type.

Thread-safety is accomplished by using a Lock which can be any of the usual mutual exclusive algorithms from C++ thread-support library or any other which satisfy C++ concurrency named requirements. E.g. mutex, timed_mutex, recursive_mutex, recursive_timed_mutex, shared_mutex, shared_timed_mutex, ... User code can opt-in for any of those. Also, whether the actual implementation will use shared-locks or exclusive-locks (for read-only operations) is handled automagically by this class.

Furthermore, user code can similarly opt-in for different key-value implementation but whose interface is compatible with the one of std::unordered_map.

Member Typedef Documentation

◆ Exclusive_or_shared_lock

template<typename Lock , template< typename... > class KeyValueImpl = std::unordered_map>
using temptable::Key_value_store< Lock, KeyValueImpl >::Exclusive_or_shared_lock = std::conditional_t<std::is_same<Lock, std::shared_timed_mutex>::value, std::shared_lock<Lock>, std::lock_guard<Lock> >
private

Check whether we can use shared locks (which enable multiple concurrent readers) or must we rather fallback to exclusive locks.

Shared-locks will be used only during read-only operations.

◆ Key_value_store_impl

template<typename Lock , template< typename... > class KeyValueImpl = std::unordered_map>
using temptable::Key_value_store< Lock, KeyValueImpl >::Key_value_store_impl = KeyValueImpl<std::string, Table>
private

Alias for our key-value store implementation.

Member Function Documentation

◆ emplace()

template<typename Lock , template< typename... > class KeyValueImpl = std::unordered_map>
template<class... Args>
std::pair< typename Key_value_store_impl::iterator, bool > temptable::Key_value_store< Lock, KeyValueImpl >::emplace ( Args &&...  args)
inline

Inserts a new table into the container constructed in-place with the given args if there is no table with the key in the container.

[in] args Arguments to forward to the constructor of the table.

Returns
Returns a pair consisting of an iterator to the inserted table, or the already-existing table if no insertion happened, and a bool denoting whether the insertion took place (true if insertion happened, false if it did not).

◆ erase()

template<typename Lock , template< typename... > class KeyValueImpl = std::unordered_map>
Key_value_store_impl::size_type temptable::Key_value_store< Lock, KeyValueImpl >::erase ( const std::string &  key)
inline

Removes the table (if one exists) with the given name (key).

[in] key Name of a table to remove..

Returns
Number of elements removed.

◆ find()

template<typename Lock , template< typename... > class KeyValueImpl = std::unordered_map>
Table * temptable::Key_value_store< Lock, KeyValueImpl >::find ( const std::string &  key)
inline

Searches for a table with given name (key).

[in] key Name of a table to search for.

Returns
Pointer to table if found, nullptr otherwise.

Friends And Related Function Documentation

◆ Key_value_store_logger< Key_value_store< Lock, KeyValueImpl >, DEBUG_BUILD >

template<typename Lock , template< typename... > class KeyValueImpl = std::unordered_map>
friend class Key_value_store_logger< Key_value_store< Lock, KeyValueImpl >, DEBUG_BUILD >
friend

Do not break encapsulation when using CRTP.

Member Data Documentation

◆ m_kv_store

template<typename Lock , template< typename... > class KeyValueImpl = std::unordered_map>
Key_value_store_impl temptable::Key_value_store< Lock, KeyValueImpl >::m_kv_store
private

Container holding (table-name, Table) tuples.

◆ m_lock

template<typename Lock , template< typename... > class KeyValueImpl = std::unordered_map>
Lock temptable::Key_value_store< Lock, KeyValueImpl >::m_lock
private

Lock type.


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