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

Sorted string table for storing key-value pairs. More...

#include <sstable.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
 

Public Member Functions

 SSTable ()=delete
 Deleted default constructor.
 
 SSTable (FilePath file_path)
 Construct a new SSTable object given a file path.
 
 SSTable (FilePath file_path, MemTable< TValue > &&mem_table, size_type expected_entries=MemTable< TValue >::C0_LAYER_SSTABLE_MAX_ENTRIES)
 Construct a new SSTable object given a file path and a memtable.
 
 SSTable (SSTable &&) noexcept=default
 Move-construct a SSTable object.
 
SSTableoperator= (SSTable &&) noexcept=default
 Move-assign a SSTable object.
 
 SSTable (const SSTable &)=delete
 Deleted copy constructor.
 
SSTableoperator= (const SSTable &)=delete
 Deleted copy assignment operator.
 
 ~SSTable () noexcept=default
 Destroy the SSTable object.
 
bool operator== (const SSTable &other) const noexcept
 
void writeDataToDisk (MemTable< TValue > &&mem_table)
 Write data to disk.
 
bool contains (const key_type &key) const noexcept
 Check if the SSTable may contain the given key.
 
mapped_type get (const key_type &key) const
 Get the value associated with a key.
 
std::vector< value_type > getRange (const key_type &start, const key_type &end) const noexcept
 Get a filtered set of entries in a timestamp range.
 
std::vector< value_type > entries () const noexcept
 Get the entries of the SSTable.
 
FilePath path () const noexcept
 Get the path of the SSTable.
 
FilePath metadataPath () const noexcept
 Get the path of the metadata file.
 
KeyRange keyRange () const noexcept
 Get the key range of the SSTable.
 
TimeRange timeRange () const noexcept
 Get the time range of the SSTable.
 

Static Public Attributes

static constexpr double BLOOM_FILTER_FALSE_POSITIVE_RATE {0.01}
 False positive rate for the Bloom filters.
 

Detailed Description

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

Sorted string table for storing key-value pairs.

Template Parameters
TValueValue type.

Definition at line 29 of file sstable.h.

Member Typedef Documentation

◆ key_type

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

Definition at line 31 of file sstable.h.

◆ mapped_type

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

Definition at line 32 of file sstable.h.

◆ size_type

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

Definition at line 34 of file sstable.h.

◆ value_type

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

Definition at line 33 of file sstable.h.

Constructor & Destructor Documentation

◆ SSTable() [1/2]

template<ArithmeticNoCVRefQuals TValue>
vkdb::SSTable< TValue >::SSTable ( FilePath file_path)
inlineexplicit

Construct a new SSTable object given a file path.

Parameters
file_pathPath.
Exceptions
std::runtime_errorIf metadata loading fails.

Definition at line 55 of file sstable.h.

◆ SSTable() [2/2]

template<ArithmeticNoCVRefQuals TValue>
vkdb::SSTable< TValue >::SSTable ( FilePath file_path,
MemTable< TValue > && mem_table,
size_type expected_entries = MemTable<TValue>::C0_LAYER_SSTABLE_MAX_ENTRIES )
inlineexplicit

Construct a new SSTable object given a file path and a memtable.

Parameters
file_pathPath.
mem_tableMemtable.
Exceptions
std::runtime_errorIf writing data to disk fails.

Definition at line 76 of file sstable.h.

Member Function Documentation

◆ contains()

template<ArithmeticNoCVRefQuals TValue>
bool vkdb::SSTable< TValue >::contains ( const key_type & key) const
inlinenodiscardnoexcept

Check if the SSTable may contain the given key.

Parameters
keyKey.
Returns
true if the SSTable may contain the key.
false if the SSTable does not contain the key.

Definition at line 144 of file sstable.h.

◆ entries()

template<ArithmeticNoCVRefQuals TValue>
std::vector< value_type > vkdb::SSTable< TValue >::entries ( ) const
inlinenodiscardnoexcept

Get the entries of the SSTable.

Returns
std::vector<value_type> Entries.

Definition at line 233 of file sstable.h.

◆ get()

template<ArithmeticNoCVRefQuals TValue>
mapped_type vkdb::SSTable< TValue >::get ( const key_type & key) const
inlinenodiscard

Get the value associated with a key.

Parameters
keyKey.
Returns
mapped_type The value if it exists, std::nullopt otherwise.
Exceptions
std::runtime_errorIf the position is invalid or the key does not match the entry read.

Definition at line 157 of file sstable.h.

◆ getRange()

template<ArithmeticNoCVRefQuals TValue>
std::vector< value_type > vkdb::SSTable< TValue >::getRange ( const key_type & start,
const key_type & end ) const
inlinenodiscardnoexcept

Get a filtered set of entries in a timestamp range.

Parameters
startStart timestamp.
endEnd timestamp.
Returns
std::vector<value_type> Entries.

Definition at line 196 of file sstable.h.

◆ keyRange()

template<ArithmeticNoCVRefQuals TValue>
KeyRange vkdb::SSTable< TValue >::keyRange ( ) const
inlinenodiscardnoexcept

Get the key range of the SSTable.

Returns
KeyRange Key range.

Definition at line 262 of file sstable.h.

◆ metadataPath()

template<ArithmeticNoCVRefQuals TValue>
FilePath vkdb::SSTable< TValue >::metadataPath ( ) const
inlinenodiscardnoexcept

Get the path of the metadata file.

Returns
FilePath Path.

Definition at line 251 of file sstable.h.

◆ operator==()

template<ArithmeticNoCVRefQuals TValue>
bool vkdb::SSTable< TValue >::operator== ( const SSTable< TValue > & other) const
inlinenodiscardnoexcept

Definition at line 120 of file sstable.h.

◆ path()

template<ArithmeticNoCVRefQuals TValue>
FilePath vkdb::SSTable< TValue >::path ( ) const
inlinenodiscardnoexcept

Get the path of the SSTable.

Returns
FilePath Path.

Definition at line 242 of file sstable.h.

◆ timeRange()

template<ArithmeticNoCVRefQuals TValue>
TimeRange vkdb::SSTable< TValue >::timeRange ( ) const
inlinenodiscardnoexcept

Get the time range of the SSTable.

Returns
TimeRange Time range.

Definition at line 271 of file sstable.h.

◆ writeDataToDisk()

template<ArithmeticNoCVRefQuals TValue>
void vkdb::SSTable< TValue >::writeDataToDisk ( MemTable< TValue > && mem_table)
inline

Write data to disk.

Saves the memtable to disk and saves the metadata.

Parameters
mem_tableMemtable.
Exceptions
std::runtime_errorIf saving the memtable or metadata fails.

Definition at line 132 of file sstable.h.

Member Data Documentation

◆ BLOOM_FILTER_FALSE_POSITIVE_RATE

template<ArithmeticNoCVRefQuals TValue>
double vkdb::SSTable< TValue >::BLOOM_FILTER_FALSE_POSITIVE_RATE {0.01}
staticconstexpr

False positive rate for the Bloom filters.

Definition at line 40 of file sstable.h.


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