LogCabin
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Private Member Functions | Private Attributes | Friends
LogCabin::Server::RaftConsensusInternal::ConfigurationManager Class Reference

Ensures the current configuration reflects the latest state of the log and snapshot. More...

#include <RaftConsensus.h>

List of all members.

Public Member Functions

 ConfigurationManager (Configuration &configuration)
 Constructor.
 ~ConfigurationManager ()
 Destructor.
void add (uint64_t index, const Protocol::Raft::Configuration &description)
 Called when a new configuration is added to the log.
void truncatePrefix (uint64_t firstIndexKept)
 Called when a log prefix is truncated (after saving a snapshot that covers this prefix).
void truncateSuffix (uint64_t lastIndexKept)
 Called when a log suffix is truncated (when the leader doesn't agree with this server's log).
void setSnapshot (uint64_t index, const Protocol::Raft::Configuration &description)
 Called when a new snapshot is saved.
std::pair< uint64_t,
Protocol::Raft::Configuration > 
getLatestConfigurationAsOf (uint64_t lastIncludedIndex) const
 Return the configuration as of a particular log index.

Private Member Functions

void restoreInvariants ()
 Helper function called after changing this object's state.

Private Attributes

Configurationconfiguration
 Defines the servers that are part of the cluster.
std::map< uint64_t,
Protocol::Raft::Configuration > 
descriptions
 This contains all the cluster configurations found in the log, plus one additional configuration from the latest snapshot.
std::pair< uint64_t,
Protocol::Raft::Configuration > 
snapshot
 This reflects the configuration found in this server's latest snapshot, or {0, {}} if this server has no snapshot.

Friends

class Invariants

Detailed Description

Ensures the current configuration reflects the latest state of the log and snapshot.

Definition at line 709 of file RaftConsensus.h.


Constructor & Destructor Documentation

Constructor.

Parameters:
configurationThe configuration that this object is in charge of setting.

Definition at line 743 of file RaftConsensus.cc.

Destructor.


Member Function Documentation

void LogCabin::Server::RaftConsensusInternal::ConfigurationManager::add ( uint64_t  index,
const Protocol::Raft::Configuration &  description 
)

Called when a new configuration is added to the log.

Parameters:
indexThe log index of this configuration (equivalently, its ID).
descriptionThe serializable representation of the configuration.

Called when a log prefix is truncated (after saving a snapshot that covers this prefix).

Parameters:
firstIndexKeptThe log entries in range [1, firstIndexKept) are being discarded.

Called when a log suffix is truncated (when the leader doesn't agree with this server's log).

Parameters:
lastIndexKeptThe log entries in range (lastIndexKept, infinity) are being discarded.
void LogCabin::Server::RaftConsensusInternal::ConfigurationManager::setSnapshot ( uint64_t  index,
const Protocol::Raft::Configuration &  description 
)

Called when a new snapshot is saved.

Only the latest such configuration is kept.

Parameters:
indexThe log index of this configuration (equivalently, its ID).
descriptionThe serializable representation of the configuration.
Protocol::Raft::Configuration LogCabin::Server::RaftConsensusInternal::ConfigurationManager::getLatestConfigurationAsOf ( uint64_t  lastIncludedIndex) const

Return the configuration as of a particular log index.

This is useful when taking snapshots.

Parameters:
lastIncludedIndexConfigurations greater than this index will be ignored.
Returns:
The index and description of the configuration with the largest index in the range [1, lastIncludedIndex].

Definition at line 790 of file RaftConsensus.cc.

Helper function called after changing this object's state.

  • Make sure the snapshot configuration is in the descriptions map.
  • Set configuration to the configuration with the largest index in the descriptions map, or reset it the map is empty.

Definition at line 806 of file RaftConsensus.cc.


Friends And Related Function Documentation

friend class Invariants [friend]

Definition at line 806 of file RaftConsensus.h.


Member Data Documentation

Defines the servers that are part of the cluster.

See Configuration.

Definition at line 783 of file RaftConsensus.h.

std::map<uint64_t, Protocol::Raft::Configuration> LogCabin::Server::RaftConsensusInternal::ConfigurationManager::descriptions [private]

This contains all the cluster configurations found in the log, plus one additional configuration from the latest snapshot.

It is used to find the right configuration when taking a snapshot and truncating the end of the log. It must be kept consistent with the log when it is loaded, as the log grows, as it gets truncated from the beginning for snapshots, and as it gets truncated from the end upon conflicts with the leader.

The key is the entry ID where the configuration belongs in the log; the value is the serializable form of the configuration.

Definition at line 798 of file RaftConsensus.h.

std::pair<uint64_t, Protocol::Raft::Configuration> LogCabin::Server::RaftConsensusInternal::ConfigurationManager::snapshot [private]

This reflects the configuration found in this server's latest snapshot, or {0, {}} if this server has no snapshot.

Definition at line 804 of file RaftConsensus.h.


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