LogCabin
|
A configuration defines the servers that are part of the cluster. More...
#include <RaftConsensus.h>
Classes | |
struct | SimpleConfiguration |
A list of servers in which a simple majority constitutes a quorum. More... | |
Public Types | |
enum | State { BLANK, STABLE, STAGING, TRANSITIONAL } |
See state. More... | |
typedef std::shared_ptr< Server > | ServerRef |
typedef std::function< bool(Server &)> | Predicate |
typedef std::function < uint64_t(Server &)> | GetValue |
typedef std::function< void(Server &)> | SideEffect |
Public Member Functions | |
Configuration (uint64_t serverId, RaftConsensus &consensus) | |
Constructor. | |
~Configuration () | |
Destructor. | |
void | forEach (const SideEffect &sideEffect) |
Apply a function to every known server, including the local, old, new, and staging servers. | |
bool | hasVote (ServerRef server) const |
Return true if the given server may be part of a quorum, false otherwise. | |
std::string | lookupAddress (uint64_t serverId) const |
Lookup the network addresses for a particular server (comma-delimited). | |
bool | quorumAll (const Predicate &predicate) const |
Return true if there exists a quorum for which every server satisfies the predicate, false otherwise. | |
uint64_t | quorumMin (const GetValue &getValue) const |
Return the smallest value of any server in the quorum of servers that have the largest values. | |
void | resetStagingServers () |
Remove the staging servers, if any. | |
void | reset () |
Set the state of this object as if it had just been constructed. | |
void | setConfiguration (uint64_t newId, const Protocol::Raft::Configuration &newDescription) |
Set the configuration. | |
void | setStagingServers (const Protocol::Raft::SimpleConfiguration &stagingServers) |
Add servers that are to mirror the log but that may not have a vote (listeners). | |
bool | stagingAll (const Predicate &predicate) const |
Return true if every server in the staging set satisfies the predicate, false otherwise. | |
uint64_t | stagingMin (const GetValue &getValue) const |
Return the smallest value of any server in the staging set. | |
void | updateServerStats (Protocol::ServerStats &serverStats, Core::Time::SteadyTimeConverter &time) const |
Write the configuration servers' state into the given structure. | |
Public Attributes | |
std::shared_ptr< LocalServer > | localServer |
This server. | |
State | state |
Specifies the meaning of oldServers and newServers. | |
uint64_t | id |
The ID of the current configuration. | |
Protocol::Raft::Configuration | description |
A description of the current configuration. | |
Private Member Functions | |
ServerRef | getServer (uint64_t newServerId) |
If no server by the given ID is known, construct a new one. | |
Private Attributes | |
RaftConsensus & | consensus |
Used for constructing Server instances. | |
std::unordered_map< uint64_t, ServerRef > | knownServers |
A map from server ID to Server of every server, including the local, previous, new, and staging servers. | |
SimpleConfiguration | oldServers |
A majority of these servers are necessary for a quorum under STABLE, STAGING, and TRANSITIONAL configurations. | |
SimpleConfiguration | newServers |
A majority of these servers are necessary for a quorum under TRANSITIONAL configurations. | |
Friends | |
class | Invariants |
std::ostream & | operator<< (std::ostream &os, State state) |
Print out a State for debugging purposes. | |
std::ostream & | operator<< (std::ostream &os, const Configuration &configuration) |
Print out a Configuration for debugging purposes. |
A configuration defines the servers that are part of the cluster.
This class does not do any internal locking; it should be accessed only while holding the RaftConsensus lock.
Definition at line 483 of file RaftConsensus.h.
typedef std::shared_ptr<Server> LogCabin::Server::RaftConsensusInternal::Configuration::ServerRef |
Definition at line 485 of file RaftConsensus.h.
typedef std::function<bool(Server&)> LogCabin::Server::RaftConsensusInternal::Configuration::Predicate |
Definition at line 486 of file RaftConsensus.h.
typedef std::function<uint64_t(Server&)> LogCabin::Server::RaftConsensusInternal::Configuration::GetValue |
Definition at line 487 of file RaftConsensus.h.
typedef std::function<void(Server&)> LogCabin::Server::RaftConsensusInternal::Configuration::SideEffect |
Definition at line 488 of file RaftConsensus.h.
See state.
Definition at line 510 of file RaftConsensus.h.
LogCabin::Server::RaftConsensusInternal::Configuration::Configuration | ( | uint64_t | serverId, |
RaftConsensus & | consensus | ||
) |
Constructor.
Definition at line 480 of file RaftConsensus.cc.
Destructor.
Definition at line 494 of file RaftConsensus.cc.
void LogCabin::Server::RaftConsensusInternal::Configuration::forEach | ( | const SideEffect & | sideEffect | ) |
Apply a function to every known server, including the local, old, new, and staging servers.
The function will only be called once for each server, even if a server exists in more than one of these categories.
Definition at line 499 of file RaftConsensus.cc.
bool LogCabin::Server::RaftConsensusInternal::Configuration::hasVote | ( | ServerRef | server | ) | const |
Return true if the given server may be part of a quorum, false otherwise.
Definition at line 506 of file RaftConsensus.cc.
std::string LogCabin::Server::RaftConsensusInternal::Configuration::lookupAddress | ( | uint64_t | serverId | ) | const |
Lookup the network addresses for a particular server (comma-delimited).
Returns empty string if not found.
Definition at line 517 of file RaftConsensus.cc.
bool LogCabin::Server::RaftConsensusInternal::Configuration::quorumAll | ( | const Predicate & | predicate | ) | const |
Return true if there exists a quorum for which every server satisfies the predicate, false otherwise.
Definition at line 526 of file RaftConsensus.cc.
uint64_t LogCabin::Server::RaftConsensusInternal::Configuration::quorumMin | ( | const GetValue & | getValue | ) | const |
Return the smallest value of any server in the quorum of servers that have the largest values.
Definition at line 537 of file RaftConsensus.cc.
Remove the staging servers, if any.
Return to the configuration state prior to a preceding call to setStagingServers.
Definition at line 548 of file RaftConsensus.cc.
Set the state of this object as if it had just been constructed.
Definition at line 565 of file RaftConsensus.cc.
void LogCabin::Server::RaftConsensusInternal::Configuration::setConfiguration | ( | uint64_t | newId, |
const Protocol::Raft::Configuration & | newDescription | ||
) |
Set the configuration.
Any existing staging servers are dropped.
newId | The log entry ID of the configuration. |
newDescription | The IDs and addresses of the servers in the configuration. If any newServers are listed in the description, it is considered TRANSITIONAL; otherwise, it is STABLE. |
Definition at line 580 of file RaftConsensus.cc.
void LogCabin::Server::RaftConsensusInternal::Configuration::setStagingServers | ( | const Protocol::Raft::SimpleConfiguration & | stagingServers | ) |
Add servers that are to mirror the log but that may not have a vote (listeners).
This can only be called on a STABLE configuration and makes it STAGING. TODO(ongaro): that might be a sign of a poor interface. descriptions should probably have three sets, as john said.
Definition at line 632 of file RaftConsensus.cc.
bool LogCabin::Server::RaftConsensusInternal::Configuration::stagingAll | ( | const Predicate & | predicate | ) | const |
Return true if every server in the staging set satisfies the predicate, false otherwise.
Definition at line 647 of file RaftConsensus.cc.
uint64_t LogCabin::Server::RaftConsensusInternal::Configuration::stagingMin | ( | const GetValue & | getValue | ) | const |
Return the smallest value of any server in the staging set.
Definition at line 656 of file RaftConsensus.cc.
void LogCabin::Server::RaftConsensusInternal::Configuration::updateServerStats | ( | Protocol::ServerStats & | serverStats, |
Core::Time::SteadyTimeConverter & | time | ||
) | const |
Write the configuration servers' state into the given structure.
Used for diagnostics.
Definition at line 665 of file RaftConsensus.cc.
std::shared_ptr< Server > LogCabin::Server::RaftConsensusInternal::Configuration::getServer | ( | uint64_t | newServerId | ) | [private] |
If no server by the given ID is known, construct a new one.
Definition at line 727 of file RaftConsensus.cc.
friend class Invariants [friend] |
Definition at line 702 of file RaftConsensus.h.
std::ostream& operator<< | ( | std::ostream & | os, |
Configuration::State | state | ||
) | [friend] |
Print out a State for debugging purposes.
Definition at line 686 of file RaftConsensus.cc.
std::ostream& operator<< | ( | std::ostream & | os, |
const Configuration & | configuration | ||
) | [friend] |
Print out a Configuration for debugging purposes.
Definition at line 707 of file RaftConsensus.cc.
Used for constructing Server instances.
Definition at line 657 of file RaftConsensus.h.
std::unordered_map<uint64_t, ServerRef> LogCabin::Server::RaftConsensusInternal::Configuration::knownServers [private] |
A map from server ID to Server of every server, including the local, previous, new, and staging servers.
Definition at line 663 of file RaftConsensus.h.
This server.
Definition at line 669 of file RaftConsensus.h.
Specifies the meaning of oldServers and newServers.
Definition at line 674 of file RaftConsensus.h.
The ID of the current configuration.
This is the same as the entry ID in which this configuration's description is written to the log.
Definition at line 680 of file RaftConsensus.h.
Protocol::Raft::Configuration LogCabin::Server::RaftConsensusInternal::Configuration::description |
A description of the current configuration.
Definition at line 685 of file RaftConsensus.h.
A majority of these servers are necessary for a quorum under STABLE, STAGING, and TRANSITIONAL configurations.
(Under TRANSITIONAL, a majority of newServers is also needed.)
Definition at line 693 of file RaftConsensus.h.
A majority of these servers are necessary for a quorum under TRANSITIONAL configurations.
Under STAGING configurations, these servers receive log entries but do not participate in elections.
Definition at line 700 of file RaftConsensus.h.