OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
cbdc::raft::log_store Class Reference

NuRaft log_store implementation using LevelDB. More...

#include <log_store.hpp>

Inheritance diagram for cbdc::raft::log_store:
Collaboration diagram for cbdc::raft::log_store:

Public Types

using log_entries_t = nuraft::ptr<std::vector<nuraft::ptr<nuraft::log_entry>>>
 List of log entries.
 

Public Member Functions

 log_store ()=default
 
 ~log_store () override=default
 
 log_store (const log_store &other)=delete
 
auto operator= (const log_store &other) -> log_store &=delete
 
 log_store (log_store &&other) noexcept
 
auto operator= (log_store &&other) noexcept -> log_store &
 
auto load (const std::string &db_dir) -> bool
 Load the log store from the given LevelDB database directory.
 
auto next_slot () const -> uint64_t override
 Return the log index of the next empty log entry.
 
auto start_index () const -> uint64_t override
 Return the first log index stored by the log store.
 
auto last_entry () const -> nuraft::ptr< nuraft::log_entry > override
 Return the last log entry in the log store.
 
auto append (nuraft::ptr< nuraft::log_entry > &entry) -> uint64_t override
 Append the given log entry to the end of the log.
 
void write_at (uint64_t index, nuraft::ptr< nuraft::log_entry > &entry) override
 Write a log entry at the given index.
 
auto log_entries (uint64_t start, uint64_t end) -> log_entries_t override
 Return the log entries in the given range of indices.
 
auto entry_at (uint64_t index) -> nuraft::ptr< nuraft::log_entry > override
 Return the log entry at the given index.
 
auto term_at (uint64_t index) -> uint64_t override
 Return the log term associated with the log entry at the given index.
 
auto pack (uint64_t index, int32_t cnt) -> nuraft::ptr< nuraft::buffer > override
 Serialize the given number of log entries from the given index.
 
void apply_pack (uint64_t index, nuraft::buffer &pack) override
 Deserialize the given log entries and write them starting at the given log index.
 
auto compact (uint64_t last_log_index) -> bool override
 Delete log entries from the start of the log up to the given log index.
 
auto flush () -> bool override
 Flush any buffered writes to disk.
 

Detailed Description

NuRaft log_store implementation using LevelDB.

Definition at line 17 of file log_store.hpp.

Member Typedef Documentation

◆ log_entries_t

using cbdc::raft::log_store::log_entries_t = nuraft::ptr<std::vector<nuraft::ptr<nuraft::log_entry>>>

List of log entries.

Definition at line 60 of file log_store.hpp.

Constructor & Destructor Documentation

◆ log_store() [1/3]

cbdc::raft::log_store::log_store ( )
default

◆ ~log_store()

cbdc::raft::log_store::~log_store ( )
overridedefault

◆ log_store() [2/3]

cbdc::raft::log_store::log_store ( const log_store & other)
delete

◆ log_store() [3/3]

cbdc::raft::log_store::log_store ( log_store && other)
noexcept

Member Function Documentation

◆ append()

auto cbdc::raft::log_store::append ( nuraft::ptr< nuraft::log_entry > & entry) -> uint64_t
override

Append the given log entry to the end of the log.

Parameters
entrylog entry to append.
Returns
index of the appended log entry.

Definition at line 124 of file log_store.cpp.

References cbdc::raft::get_key_slice(), and cbdc::raft::get_value_slice().

Here is the call graph for this function:

◆ apply_pack()

void cbdc::raft::log_store::apply_pack ( uint64_t index,
nuraft::buffer & pack )
override

Deserialize the given log entries and write them starting at the given log index.

Parameters
indexlog index at which to write the first log entry.
packserialized log entries.

Definition at line 249 of file log_store.cpp.

References cbdc::raft::get_first_or_last_index(), cbdc::raft::get_key_slice(), cbdc::raft::get_value_slice(), and pack().

Here is the call graph for this function:

◆ compact()

auto cbdc::raft::log_store::compact ( uint64_t last_log_index) -> bool
override

Delete log entries from the start of the log up to the given log index.

Parameters
last_log_indexlast log index to delete (inclusive).
Returns
true.

Definition at line 290 of file log_store.cpp.

References cbdc::raft::get_key_slice().

Here is the call graph for this function:

◆ entry_at()

auto cbdc::raft::log_store::entry_at ( uint64_t index) -> nuraft::ptr<nuraft::log_entry>
nodiscardoverride

Return the log entry at the given index.

Returns a null log entry if there is no log entry at the given index.

Parameters
indexlog index.
Returns
log entry.

Definition at line 190 of file log_store.cpp.

References cbdc::raft::get_key_slice(), and cbdc::raft::log_entry_from_slice().

Here is the call graph for this function:

◆ flush()

auto cbdc::raft::log_store::flush ( ) -> bool
override

Flush any buffered writes to disk.

Returns
true if the flush was successful.

Definition at line 314 of file log_store.cpp.

◆ last_entry()

auto cbdc::raft::log_store::last_entry ( ) const -> nuraft::ptr<nuraft::log_entry>
nodiscardoverride

Return the last log entry in the log store.

Returns an empty log entry at index zero if the log store is empty.

Returns
log entry.

Definition at line 85 of file log_store.cpp.

References last_entry(), and cbdc::raft::log_entry_from_slice().

Referenced by last_entry().

Here is the call graph for this function:

◆ load()

auto cbdc::raft::log_store::load ( const std::string & db_dir) -> bool
nodiscard

Load the log store from the given LevelDB database directory.

Parameters
db_dirdatabase directory.
Returns
true if loading the database succeeded.

Definition at line 40 of file log_store.cpp.

References cbdc::raft::get_first_or_last_index().

Here is the call graph for this function:

◆ log_entries()

auto cbdc::raft::log_store::log_entries ( uint64_t start,
uint64_t end ) -> log_entries_t
nodiscardoverride

Return the log entries in the given range of indices.

Parameters
startfirst log entry to retrieve.
endlast log entry to retrieve (exclusive).
Returns
list of log entries.

Definition at line 163 of file log_store.cpp.

References cbdc::raft::get_key_slice(), and cbdc::raft::log_entry_from_slice().

Here is the call graph for this function:

◆ next_slot()

auto cbdc::raft::log_store::next_slot ( ) const -> uint64_t
nodiscardoverride

Return the log index of the next empty log entry.

Returns
log index.

Definition at line 66 of file log_store.cpp.

◆ operator=() [1/2]

auto cbdc::raft::log_store::operator= ( const log_store & other) -> log_store &=delete
delete

◆ operator=() [2/2]

auto cbdc::raft::log_store::operator= ( log_store && other) -> log_store &
noexcept

◆ pack()

auto cbdc::raft::log_store::pack ( uint64_t index,
int32_t cnt ) -> nuraft::ptr<nuraft::buffer>
nodiscardoverride

Serialize the given number of log entries from the given index.

Parameters
indexstarting log index.
cntnumber of log entries to serialize. Must be positive.
Returns
buffer containing serialized log entries.

Definition at line 216 of file log_store.cpp.

Referenced by apply_pack().

◆ start_index()

auto cbdc::raft::log_store::start_index ( ) const -> uint64_t
nodiscardoverride

Return the first log index stored by the log store.

Returns
log index.

Definition at line 71 of file log_store.cpp.

◆ term_at()

auto cbdc::raft::log_store::term_at ( uint64_t index) -> uint64_t
nodiscardoverride

Return the log term associated with the log entry at the given index.

Parameters
indexlog index.
Returns
log term.

Definition at line 211 of file log_store.cpp.

◆ write_at()

void cbdc::raft::log_store::write_at ( uint64_t index,
nuraft::ptr< nuraft::log_entry > & entry )
override

Write a log entry at the given index.

Parameters
indexlog index at which to write the entry.
entrylog entry to write.

Definition at line 138 of file log_store.cpp.

References cbdc::raft::get_key_slice(), and cbdc::raft::get_value_slice().

Here is the call graph for this function:

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