LogCabin
|
This interface is used by RaftConsensus to store log entries and metadata. More...
#include <Log.h>
Classes | |
class | Sync |
An interface for flushing newly appended log entries to stable storage. More... | |
Public Types | |
typedef Protocol::Raft::Entry | Entry |
The type of a log entry (the same format that's used in AppendEntries). | |
Public Member Functions | |
Log () | |
virtual | ~Log () |
virtual std::pair< uint64_t, uint64_t > | append (const std::vector< const Entry * > &entries)=0 |
Start to append new entries to the log. | |
virtual const Entry & | getEntry (uint64_t index) const =0 |
Look up an entry by its log index. | |
virtual uint64_t | getLogStartIndex () const =0 |
Get the index of the first entry in the log (whether or not this entry exists). | |
virtual uint64_t | getLastLogIndex () const =0 |
Get the index of the most recent entry in the log. | |
virtual std::string | getName () const =0 |
Return the name of the log implementation as it would be specified in the config file. | |
virtual uint64_t | getSizeBytes () const =0 |
Get the size of the entire log in bytes. | |
void | syncComplete (std::unique_ptr< Sync > sync) |
Release resources attached to the Sync object. | |
virtual std::unique_ptr< Sync > | takeSync ()=0 |
Get and remove the Log's Sync object in order to wait on it. | |
virtual void | truncatePrefix (uint64_t firstIndex)=0 |
Delete the log entries before the given index. | |
virtual void | truncateSuffix (uint64_t lastIndex)=0 |
Delete the log entries past the given index. | |
virtual void | updateMetadata ()=0 |
Call this after changing metadata. | |
virtual void | updateServerStats (Protocol::ServerStats &serverStats) const |
Add information about the log's state to the given structure. | |
Public Attributes | |
Protocol::RaftLogMetadata::Metadata | metadata |
Opaque metadata that the log keeps track of. | |
Protected Member Functions | |
virtual void | syncCompleteVirtual (std::unique_ptr< Sync > sync) |
See syncComplete(). | |
Log (const Log &) | |
Log & | operator= (const Log &) |
Friends | |
std::ostream & | operator<< (std::ostream &os, const Log &log) |
Print out a Log for debugging purposes. |
This interface is used by RaftConsensus to store log entries and metadata.
Typically, implementations will persist the log entries and metadata to stable storage (but MemoryLog keeps it all in volatile memory).
typedef Protocol::Raft::Entry LogCabin::Storage::Log::Entry |
The type of a log entry (the same format that's used in AppendEntries).
Reimplemented in LogCabin::Storage::SimpleFileLog.
LogCabin::Storage::Log::~Log | ( | ) | [virtual] |
LogCabin::Storage::Log::Log | ( | const Log & | ) | [protected] |
virtual std::pair<uint64_t, uint64_t> LogCabin::Storage::Log::append | ( | const std::vector< const Entry * > & | entries | ) | [pure virtual] |
Start to append new entries to the log.
The entries may not be on disk yet when this returns; see Sync.
entries | Entries to place at the end of the log. |
Implemented in LogCabin::Storage::SegmentedLog, LogCabin::Storage::SimpleFileLog, and LogCabin::Storage::MemoryLog.
virtual const Entry& LogCabin::Storage::Log::getEntry | ( | uint64_t | index | ) | const [pure virtual] |
Look up an entry by its log index.
index | Must be in the range [getLogStartIndex(), getLastLogIndex()]. Otherwise, this will crash the server. |
Implemented in LogCabin::Storage::SegmentedLog, LogCabin::Storage::SimpleFileLog, and LogCabin::Storage::MemoryLog.
virtual uint64_t LogCabin::Storage::Log::getLogStartIndex | ( | ) | const [pure virtual] |
Get the index of the first entry in the log (whether or not this entry exists).
Implemented in LogCabin::Storage::SegmentedLog, LogCabin::Storage::SimpleFileLog, and LogCabin::Storage::MemoryLog.
virtual uint64_t LogCabin::Storage::Log::getLastLogIndex | ( | ) | const [pure virtual] |
Get the index of the most recent entry in the log.
Implemented in LogCabin::Storage::SegmentedLog, LogCabin::Storage::SimpleFileLog, and LogCabin::Storage::MemoryLog.
virtual std::string LogCabin::Storage::Log::getName | ( | ) | const [pure virtual] |
Return the name of the log implementation as it would be specified in the config file.
Implemented in LogCabin::Storage::SegmentedLog, LogCabin::Storage::SimpleFileLog, and LogCabin::Storage::MemoryLog.
virtual uint64_t LogCabin::Storage::Log::getSizeBytes | ( | ) | const [pure virtual] |
Get the size of the entire log in bytes.
Implemented in LogCabin::Storage::SegmentedLog, LogCabin::Storage::SimpleFileLog, and LogCabin::Storage::MemoryLog.
void LogCabin::Storage::Log::syncComplete | ( | std::unique_ptr< Sync > | sync | ) | [inline] |
virtual void LogCabin::Storage::Log::syncCompleteVirtual | ( | std::unique_ptr< Sync > | sync | ) | [inline, protected, virtual] |
virtual std::unique_ptr<Sync> LogCabin::Storage::Log::takeSync | ( | ) | [pure virtual] |
Get and remove the Log's Sync object in order to wait on it.
This Sync object must later be returned to the Log with syncComplete().
While takeSync() and syncComplete() may not be done concurrently with other Log operations, Sync::wait() may be done concurrently with all operations except truncateSuffix().
Implemented in LogCabin::Storage::SegmentedLog, LogCabin::Storage::SimpleFileLog, and LogCabin::Storage::MemoryLog.
virtual void LogCabin::Storage::Log::truncatePrefix | ( | uint64_t | firstIndex | ) | [pure virtual] |
Delete the log entries before the given index.
Once you truncate a prefix from the log, there's no way to undo this. The entries may still be on disk when this returns and file descriptors and other resources may remain open; see Sync.
firstIndex | After this call, the log will contain no entries indexed less than firstIndex. This can be any log index, including 0 and those past the end of the log. |
Implemented in LogCabin::Storage::SegmentedLog, LogCabin::Storage::SimpleFileLog, and LogCabin::Storage::MemoryLog.
virtual void LogCabin::Storage::Log::truncateSuffix | ( | uint64_t | lastIndex | ) | [pure virtual] |
Delete the log entries past the given index.
This will not affect the log start index.
lastIndex | After this call, the log will contain no entries indexed greater than lastIndex. This can be any log index, including 0 and those past the end of the log. |
Implemented in LogCabin::Storage::SegmentedLog, LogCabin::Storage::SimpleFileLog, and LogCabin::Storage::MemoryLog.
virtual void LogCabin::Storage::Log::updateMetadata | ( | ) | [pure virtual] |
Call this after changing metadata.
Implemented in LogCabin::Storage::SegmentedLog, LogCabin::Storage::SimpleFileLog, and LogCabin::Storage::MemoryLog.
virtual void LogCabin::Storage::Log::updateServerStats | ( | Protocol::ServerStats & | serverStats | ) | const [inline, virtual] |
Add information about the log's state to the given structure.
Used for diagnostics.
Reimplemented in LogCabin::Storage::SegmentedLog.
std::ostream& operator<< | ( | std::ostream & | os, |
const Log & | log | ||
) | [friend] |
Protocol::RaftLogMetadata::Metadata LogCabin::Storage::Log::metadata |
Opaque metadata that the log keeps track of.
Reimplemented in LogCabin::Storage::SegmentedLog, and LogCabin::Storage::SimpleFileLog.