LogCabin
|
Ensures the current configuration reflects the latest state of the log and snapshot. More...
#include <RaftConsensus.h>
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 | |
Configuration & | configuration |
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 |
Ensures the current configuration reflects the latest state of the log and snapshot.
Definition at line 709 of file RaftConsensus.h.
LogCabin::Server::RaftConsensusInternal::ConfigurationManager::ConfigurationManager | ( | Configuration & | configuration | ) | [explicit] |
Constructor.
configuration | The configuration that this object is in charge of setting. |
Definition at line 743 of file RaftConsensus.cc.
Destructor.
void LogCabin::Server::RaftConsensusInternal::ConfigurationManager::add | ( | uint64_t | index, |
const Protocol::Raft::Configuration & | description | ||
) |
Called when a new configuration is added to the log.
index | The log index of this configuration (equivalently, its ID). |
description | The serializable representation of the configuration. |
void LogCabin::Server::RaftConsensusInternal::ConfigurationManager::truncatePrefix | ( | uint64_t | firstIndexKept | ) |
Called when a log prefix is truncated (after saving a snapshot that covers this prefix).
firstIndexKept | The log entries in range [1, firstIndexKept) are being discarded. |
void LogCabin::Server::RaftConsensusInternal::ConfigurationManager::truncateSuffix | ( | uint64_t | lastIndexKept | ) |
Called when a log suffix is truncated (when the leader doesn't agree with this server's log).
lastIndexKept | The 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.
index | The log index of this configuration (equivalently, its ID). |
description | The 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.
lastIncludedIndex | Configurations greater than this index will be ignored. |
Definition at line 790 of file RaftConsensus.cc.
Helper function called after changing this object's state.
Definition at line 806 of file RaftConsensus.cc.
friend class Invariants [friend] |
Definition at line 806 of file RaftConsensus.h.
Configuration& LogCabin::Server::RaftConsensusInternal::ConfigurationManager::configuration [private] |
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.