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

This interface is used by RaftConsensus to store log entries and metadata. More...

#include <Log.h>

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

List of all members.

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 EntrygetEntry (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< SynctakeSync ()=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 &)
Logoperator= (const Log &)

Friends

std::ostream & operator<< (std::ostream &os, const Log &log)
 Print out a Log for debugging purposes.

Detailed Description

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

Definition at line 40 of file Log.h.


Member Typedef Documentation

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.

Definition at line 77 of file Log.h.


Constructor & Destructor Documentation

Definition at line 45 of file Log.cc.

Definition at line 50 of file Log.cc.

LogCabin::Storage::Log::Log ( const Log ) [protected]

Member Function Documentation

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.

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

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.

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.

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

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

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.

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

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]

Release resources attached to the Sync object.

Call this after waiting on the Sync object.

Definition at line 136 of file Log.h.

virtual void LogCabin::Storage::Log::syncCompleteVirtual ( std::unique_ptr< Sync sync) [inline, protected, virtual]

See syncComplete().

Intended for subclasses to override.

Definition at line 144 of file Log.h.

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.

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.

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.

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.

Implemented in LogCabin::Storage::SegmentedLog, LogCabin::Storage::SimpleFileLog, and LogCabin::Storage::MemoryLog.

virtual void LogCabin::Storage::Log::updateMetadata ( ) [pure virtual]
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.

Definition at line 192 of file Log.h.

Log& LogCabin::Storage::Log::operator= ( const Log ) [protected]

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const Log log 
) [friend]

Print out a Log for debugging purposes.

Definition at line 55 of file Log.cc.


Member Data Documentation

Protocol::RaftLogMetadata::Metadata LogCabin::Storage::Log::metadata

Opaque metadata that the log keeps track of.

Reimplemented in LogCabin::Storage::SegmentedLog, and LogCabin::Storage::SimpleFileLog.

Definition at line 197 of file Log.h.


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