LogCabin
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Protected Attributes
LogCabin::Storage::MemoryLog Class Reference

#include <MemoryLog.h>

Inheritance diagram for LogCabin::Storage::MemoryLog:
LogCabin::Storage::Log

List of all members.

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 EntrygetEntry (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< SynctakeSync ()
 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< Entryentries
 Stores the entries that make up the log.
std::unique_ptr< SynccurrentSync
 This is returned by the next call to getSync.

Detailed Description

Definition at line 32 of file MemoryLog.h.


Constructor & Destructor Documentation

Definition at line 33 of file MemoryLog.cc.

Definition at line 40 of file MemoryLog.cc.


Member Function Documentation

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.

Parameters:
entriesEntries to place at the end of the log.
Returns:
Range of indexes of the new entries in the log, inclusive.

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.

Parameters:
indexMust be in the range [getLogStartIndex(), getLastLogIndex()]. Otherwise, this will crash the server.
Returns:
The entry corresponding to that index. This reference is only guaranteed to be valid until the next time the log is modified.

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).

Returns:
1 for logs that have never had truncatePrefix called, otherwise the largest index passed to truncatePrefix.

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.

Returns:
The index of the most recent entry in the log, or getLogStartIndex() - 1 if the log is empty.

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.

Parameters:
firstIndexAfter 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.

Parameters:
lastIndexAfter 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.
Warning:
Callers should wait() on all Sync object prior to calling truncateSuffix(). This never happens on leaders, so it's not a real limitation, but things may go wonky otherwise.

Implements LogCabin::Storage::Log.

Definition at line 116 of file MemoryLog.cc.

Call this after changing metadata.

Implements LogCabin::Storage::Log.

Definition at line 125 of file MemoryLog.cc.


Member Data Documentation

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.

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.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines