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

TODO(ongaro): docs. More...

#include <SimpleFileLog.h>

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

List of all members.

Classes

class  Sync

Public Types

typedef Protocol::Raft::Entry Entry
 The type of a log entry (the same format that's used in AppendEntries).

Public Member Functions

 SimpleFileLog (const Storage::FilesystemUtil::File &parentDir)
 ~SimpleFileLog ()
std::pair< uint64_t, uint64_t > append (const std::vector< const Entry * > &entries)
 Start to append new entries to the log.
std::string getName () const
 Return the name of the log implementation as it would be specified in the config file.
std::unique_ptr< Log::SynctakeSync ()
 Get and remove the Log's Sync object in order to wait on it.
void truncatePrefix (uint64_t firstEntryId)
 Delete the log entries before the given index.
void truncateSuffix (uint64_t lastEntryId)
 Delete the log entries past the given index.
const EntrygetEntry (uint64_t) 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.
uint64_t getSizeBytes () const
 Get the size of the entire log in bytes.
void updateMetadata ()
 Call this after changing metadata.

Protected Member Functions

Storage::FilesystemUtil::File updateMetadataCallerSync ()
std::string readMetadata (const std::string &filename, SimpleFileLogMetadata::Metadata &metadata) const
std::vector< uint64_t > getEntryIds () const
Entry read (const std::string &entryPath) const

Protected Attributes

MemoryLog memoryLog
SimpleFileLogMetadata::Metadata metadata
 Opaque metadata that the log keeps track of.
Storage::FilesystemUtil::File dir
Storage::FilesystemUtil::File lostAndFound
std::unique_ptr< SynccurrentSync

Detailed Description

TODO(ongaro): docs.

Definition at line 37 of file SimpleFileLog.h.


Member Typedef Documentation

typedef Protocol::Raft::Entry LogCabin::Storage::SimpleFileLog::Entry

The type of a log entry (the same format that's used in AppendEntries).

Reimplemented from LogCabin::Storage::Log.

Definition at line 50 of file SimpleFileLog.h.


Constructor & Destructor Documentation

Definition at line 146 of file SimpleFileLog.cc.

Definition at line 219 of file SimpleFileLog.cc.


Member Function Documentation

std::pair< uint64_t, uint64_t > LogCabin::Storage::SimpleFileLog::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 226 of file SimpleFileLog.cc.

std::string LogCabin::Storage::SimpleFileLog::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 243 of file SimpleFileLog.cc.

std::unique_ptr< Log::Sync > LogCabin::Storage::SimpleFileLog::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 249 of file SimpleFileLog.cc.

void LogCabin::Storage::SimpleFileLog::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 257 of file SimpleFileLog.cc.

void LogCabin::Storage::SimpleFileLog::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 269 of file SimpleFileLog.cc.

const SimpleFileLog::Entry & LogCabin::Storage::SimpleFileLog::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 281 of file SimpleFileLog.cc.

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 287 of file SimpleFileLog.cc.

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 293 of file SimpleFileLog.cc.

uint64_t LogCabin::Storage::SimpleFileLog::getSizeBytes ( ) const [virtual]

Get the size of the entire log in bytes.

Implements LogCabin::Storage::Log.

Definition at line 299 of file SimpleFileLog.cc.

Call this after changing metadata.

Implements LogCabin::Storage::Log.

Definition at line 305 of file SimpleFileLog.cc.

Definition at line 314 of file SimpleFileLog.cc.

std::string LogCabin::Storage::SimpleFileLog::readMetadata ( const std::string &  filename,
SimpleFileLogMetadata::Metadata &  metadata 
) const [protected]

Definition at line 137 of file SimpleFileLog.cc.

std::vector< uint64_t > LogCabin::Storage::SimpleFileLog::getEntryIds ( ) const [protected]

Definition at line 328 of file SimpleFileLog.cc.

Log::Entry LogCabin::Storage::SimpleFileLog::read ( const std::string &  entryPath) const [protected]

Definition at line 355 of file SimpleFileLog.cc.


Member Data Documentation

Definition at line 71 of file SimpleFileLog.h.

SimpleFileLogMetadata::Metadata LogCabin::Storage::SimpleFileLog::metadata [protected]

Opaque metadata that the log keeps track of.

Reimplemented from LogCabin::Storage::Log.

Definition at line 72 of file SimpleFileLog.h.

Definition at line 73 of file SimpleFileLog.h.

Definition at line 74 of file SimpleFileLog.h.

Definition at line 75 of file SimpleFileLog.h.


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