vkdb
A time series database engine in C++.
Loading...
Searching...
No Matches
vkdb::LSMTree< TValue > Class Template Reference

LSM tree on TimeSeriesKey. More...

#include <lsm_tree.h>

Public Types

using key_type = TimeSeriesKey
 
using mapped_type = std::optional<TValue>
 
using value_type = std::pair<const key_type, mapped_type>
 
using size_type = uint64_t
 
using table_type = typename MemTable<TValue>::table_type
 

Public Member Functions

 LSMTree (FilePath path) noexcept
 Construct a new LSMTree object.
 
 LSMTree (LSMTree &&) noexcept=default
 Move-construct a LSMTree object.
 
LSMTreeoperator= (LSMTree &&) noexcept=default
 Move-assign a LSMTree object.
 
 LSMTree (const LSMTree &)=delete
 Deleted copy constructor.
 
LSMTreeoperator= (const LSMTree &)=delete
 Deleted copy assignment operator.
 
 ~LSMTree () noexcept=default
 Destroy the LSMTree object.
 
void put (const key_type &key, const TValue &value, bool log=true)
 Put a key-value pair into the LSM tree.
 
void remove (const key_type &key, bool log=true)
 Remove a key pair from the LSM tree.
 
mapped_type get (const key_type &key) const noexcept
 Get a value from the LSM tree.
 
std::vector< value_type > getRange (const key_type &start, const key_type &end, TimeSeriesKeyFilter &&filter) const
 Get a filtered set of entries in a timestamp range.
 
void replayWAL ()
 Replay the write-ahead log.
 
void clear () noexcept
 Clear the LSM tree.
 
std::string str () const noexcept
 Convert the LSM tree to a string.
 
size_type sstableCount () const noexcept
 Get the number of SSTables in the LSM tree.
 
size_type sstableCount (size_type k) const
 Get the number of SSTables in a Ck layer.
 
bool empty () const noexcept
 Check if the LSM tree is empty.
 

Static Public Attributes

static constexpr size_type LAYER_COUNT {8}
 
static constexpr size_type CACHE_CAPACITY {10'000}
 Max number of entries in the cache.
 

Detailed Description

template<ArithmeticNoCVRefQuals TValue>
class vkdb::LSMTree< TValue >

LSM tree on TimeSeriesKey.

Template Parameters
TValueValue type.

Definition at line 8 of file wal_lsm.h.

Member Typedef Documentation

◆ key_type

template<ArithmeticNoCVRefQuals TValue>
using vkdb::LSMTree< TValue >::key_type = TimeSeriesKey

Definition at line 39 of file lsm_tree.h.

◆ mapped_type

template<ArithmeticNoCVRefQuals TValue>
using vkdb::LSMTree< TValue >::mapped_type = std::optional<TValue>

Definition at line 40 of file lsm_tree.h.

◆ size_type

template<ArithmeticNoCVRefQuals TValue>
using vkdb::LSMTree< TValue >::size_type = uint64_t

Definition at line 42 of file lsm_tree.h.

◆ table_type

template<ArithmeticNoCVRefQuals TValue>
using vkdb::LSMTree< TValue >::table_type = typename MemTable<TValue>::table_type

Definition at line 43 of file lsm_tree.h.

◆ value_type

template<ArithmeticNoCVRefQuals TValue>
using vkdb::LSMTree< TValue >::value_type = std::pair<const key_type, mapped_type>

Definition at line 41 of file lsm_tree.h.

Constructor & Destructor Documentation

◆ LSMTree()

template<ArithmeticNoCVRefQuals TValue>
vkdb::LSMTree< TValue >::LSMTree ( FilePath path)
inlineexplicitnoexcept

Construct a new LSMTree object.

Loads SSTables from disk.

Parameters
pathPath of the LSM tree.

Definition at line 59 of file lsm_tree.h.

Member Function Documentation

◆ clear()

template<ArithmeticNoCVRefQuals TValue>
void vkdb::LSMTree< TValue >::clear ( )
inlinenoexcept

Clear the LSM tree.

Remove all SSTable files and the WAL file.

Definition at line 212 of file lsm_tree.h.

◆ empty()

template<ArithmeticNoCVRefQuals TValue>
bool vkdb::LSMTree< TValue >::empty ( ) const
inlinenodiscardnoexcept

Check if the LSM tree is empty.

Returns
true if the LSM tree is empty.
false if the LSM tree is not empty.

Definition at line 280 of file lsm_tree.h.

◆ get()

template<ArithmeticNoCVRefQuals TValue>
mapped_type vkdb::LSMTree< TValue >::get ( const key_type & key) const
inlinenodiscardnoexcept

Get a value from the LSM tree.

Parameters
keyKey.
Returns
mapped_type The value if it exists.

Definition at line 145 of file lsm_tree.h.

◆ getRange()

template<ArithmeticNoCVRefQuals TValue>
std::vector< value_type > vkdb::LSMTree< TValue >::getRange ( const key_type & start,
const key_type & end,
TimeSeriesKeyFilter && filter ) const
inlinenodiscard

Get a filtered set of entries in a timestamp range.

Parameters
startStart timestamp.
endEnd timestamp.
filterFilter.
Returns
std::vector<value_type> Entries.
Exceptions
std::exceptionIf getting the entries fails.

Definition at line 179 of file lsm_tree.h.

◆ put()

template<ArithmeticNoCVRefQuals TValue>
void vkdb::LSMTree< TValue >::put ( const key_type & key,
const TValue & value,
bool log = true )
inline

Put a key-value pair into the LSM tree.

Parameters
keyKey.
valueValue.
logWhether to log the operation in the WAL.
Exceptions
std::runtime_errorIf compaction fails in flushing.

Definition at line 108 of file lsm_tree.h.

◆ remove()

template<ArithmeticNoCVRefQuals TValue>
void vkdb::LSMTree< TValue >::remove ( const key_type & key,
bool log = true )
inline

Remove a key pair from the LSM tree.

Parameters
keyKey.
logWhether to log the operation in the WAL.
Exceptions
std::runtime_errorIf the memtable is flushed when the C1 layer is full.

Definition at line 128 of file lsm_tree.h.

◆ replayWAL()

template<ArithmeticNoCVRefQuals TValue>
void vkdb::LSMTree< TValue >::replayWAL ( )
inline

Replay the write-ahead log.

Definition at line 203 of file lsm_tree.h.

◆ sstableCount() [1/2]

template<ArithmeticNoCVRefQuals TValue>
size_type vkdb::LSMTree< TValue >::sstableCount ( ) const
inlinenodiscardnoexcept

Get the number of SSTables in the LSM tree.

Returns
size_type The number of SSTables.

Definition at line 249 of file lsm_tree.h.

◆ sstableCount() [2/2]

template<ArithmeticNoCVRefQuals TValue>
size_type vkdb::LSMTree< TValue >::sstableCount ( size_type k) const
inlinenodiscard

Get the number of SSTables in a Ck layer.

Parameters
kCk layer index.
Returns
size_type The number of SSTables.
Exceptions
std::out_of_rangeIf the layer index is out of range.

Definition at line 265 of file lsm_tree.h.

◆ str()

template<ArithmeticNoCVRefQuals TValue>
std::string vkdb::LSMTree< TValue >::str ( ) const
inlinenodiscardnoexcept

Convert the LSM tree to a string.

Returns
std::string The string representation of the LSM tree.

Definition at line 233 of file lsm_tree.h.

Member Data Documentation

◆ CACHE_CAPACITY

template<ArithmeticNoCVRefQuals TValue>
size_type vkdb::LSMTree< TValue >::CACHE_CAPACITY {10'000}
staticconstexpr

Max number of entries in the cache.

Definition at line 51 of file lsm_tree.h.

◆ LAYER_COUNT

template<ArithmeticNoCVRefQuals TValue>
size_type vkdb::LSMTree< TValue >::LAYER_COUNT {8}
staticconstexpr

Definition at line 45 of file lsm_tree.h.


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