LogCabin
|
#include <MemoryLog.h>
Public Member Functions | |
MemoryLog () | |
~MemoryLog () | |
std::pair< uint64_t, uint64_t > | append (const std::vector< const Entry * > &entries) |
Start to append new entries to the log. | |
const Entry & | getEntry (uint64_t logIndex) const |
Look up an entry by its log index. | |
uint64_t | getLogStartIndex () const |
Get the index of the first entry in the log (whether or not this entry exists). | |
uint64_t | getLastLogIndex () const |
Get the index of the most recent entry in the log. | |
std::string | getName () const |
Return the name of the log implementation as it would be specified in the config file. | |
uint64_t | getSizeBytes () const |
Get the size of the entire log in bytes. | |
std::unique_ptr< Sync > | takeSync () |
Get and remove the Log's Sync object in order to wait on it. | |
void | truncatePrefix (uint64_t firstIndex) |
Delete the log entries before the given index. | |
void | truncateSuffix (uint64_t lastIndex) |
Delete the log entries past the given index. | |
void | updateMetadata () |
Call this after changing metadata. | |
Protected Attributes | |
uint64_t | startIndex |
The index for the first entry in the log. | |
std::deque< Entry > | entries |
Stores the entries that make up the log. | |
std::unique_ptr< Sync > | currentSync |
This is returned by the next call to getSync. |
Definition at line 32 of file MemoryLog.h.
Definition at line 33 of file MemoryLog.cc.
Definition at line 40 of file MemoryLog.cc.
std::pair< uint64_t, uint64_t > LogCabin::Storage::MemoryLog::append | ( | const std::vector< const Entry * > & | entries | ) | [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. |
Implements LogCabin::Storage::Log.
Definition at line 46 of file MemoryLog.cc.
const Log::Entry & LogCabin::Storage::MemoryLog::getEntry | ( | uint64_t | index | ) | const [virtual] |
Look up an entry by its log index.
index | Must be in the range [getLogStartIndex(), getLastLogIndex()]. Otherwise, this will crash the server. |
Implements LogCabin::Storage::Log.
Definition at line 57 of file MemoryLog.cc.
uint64_t LogCabin::Storage::MemoryLog::getLogStartIndex | ( | ) | const [virtual] |
Get the index of the first entry in the log (whether or not this entry exists).
Implements LogCabin::Storage::Log.
Definition at line 64 of file MemoryLog.cc.
uint64_t LogCabin::Storage::MemoryLog::getLastLogIndex | ( | ) | const [virtual] |
Get the index of the most recent entry in the log.
Implements LogCabin::Storage::Log.
Definition at line 71 of file MemoryLog.cc.
std::string LogCabin::Storage::MemoryLog::getName | ( | ) | const [virtual] |
Return the name of the log implementation as it would be specified in the config file.
Implements LogCabin::Storage::Log.
Definition at line 77 of file MemoryLog.cc.
uint64_t LogCabin::Storage::MemoryLog::getSizeBytes | ( | ) | const [virtual] |
Get the size of the entire log in bytes.
Implements LogCabin::Storage::Log.
Definition at line 83 of file MemoryLog.cc.
std::unique_ptr< Log::Sync > LogCabin::Storage::MemoryLog::takeSync | ( | ) | [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().
Implements LogCabin::Storage::Log.
Definition at line 93 of file MemoryLog.cc.
void LogCabin::Storage::MemoryLog::truncatePrefix | ( | uint64_t | firstIndex | ) | [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. |
Implements LogCabin::Storage::Log.
Definition at line 101 of file MemoryLog.cc.
void LogCabin::Storage::MemoryLog::truncateSuffix | ( | uint64_t | lastIndex | ) | [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. |
Implements LogCabin::Storage::Log.
Definition at line 116 of file MemoryLog.cc.
void LogCabin::Storage::MemoryLog::updateMetadata | ( | ) | [virtual] |
Call this after changing metadata.
Implements LogCabin::Storage::Log.
Definition at line 125 of file MemoryLog.cc.
uint64_t LogCabin::Storage::MemoryLog::startIndex [protected] |
The index for the first entry in the log.
Begins as 1 for new logs but will be larger for logs that have been snapshotted.
Definition at line 55 of file MemoryLog.h.
std::deque<Entry> LogCabin::Storage::MemoryLog::entries [protected] |
Stores the entries that make up the log.
The offset into 'entries' is the index of the entry minus 'startIndex'. This is a deque rather than a vector to support fast prefix truncation (used after snapshotting a prefix of the log).
Definition at line 63 of file MemoryLog.h.
std::unique_ptr<Sync> LogCabin::Storage::MemoryLog::currentSync [protected] |
This is returned by the next call to getSync.
It's totally unnecessary to have this member for MemoryLog, as its syncs don't do anything. However, it's useful for injecting different times of Syncs into unit tests.
Definition at line 71 of file MemoryLog.h.