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

A configuration defines the servers that are part of the cluster. More...

#include <RaftConsensus.h>

List of all members.

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< ServerServerRef
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< LocalServerlocalServer
 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

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

Detailed Description

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.


Member Typedef Documentation

Definition at line 485 of file RaftConsensus.h.

Definition at line 486 of file RaftConsensus.h.

Definition at line 487 of file RaftConsensus.h.

Definition at line 488 of file RaftConsensus.h.


Member Enumeration Documentation

See state.

Enumerator:
BLANK 

The configuration specifies no servers.

Servers that are new to the cluster and have empty logs start in this state.

STABLE 

The configuration specifies a single list of servers: a quorum requires any majority of this list.

STAGING 

The configuration specifies two lists of servers: a quorum requires any majority of the first list, but the servers in the second list also receive log entries.

TRANSITIONAL 

The configuration specifies two lists of servers: a quorum requires any majority of the first list and any majority of the second.

Definition at line 510 of file RaftConsensus.h.


Constructor & Destructor Documentation

Constructor.

Definition at line 480 of file RaftConsensus.cc.

Destructor.

Definition at line 494 of file RaftConsensus.cc.


Member Function Documentation

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.

Return true if the given server may be part of a quorum, false otherwise.

Definition at line 506 of file RaftConsensus.cc.

Lookup the network addresses for a particular server (comma-delimited).

Returns empty string if not found.

Definition at line 517 of file RaftConsensus.cc.

Return true if there exists a quorum for which every server satisfies the predicate, false otherwise.

Definition at line 526 of file RaftConsensus.cc.

Return the smallest value of any server in the quorum of servers that have the largest values.

Returns:
Largest value for which every server in a quorum has a value greater than or equal to this one. 0 if the configuration is BLANK.

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.

Parameters:
newIdThe log entry ID of the configuration.
newDescriptionThe 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.

Return true if every server in the staging set satisfies the predicate, false otherwise.

Definition at line 647 of file RaftConsensus.cc.

Return the smallest value of any server in the staging set.

Returns:
Minimum value on any server in the staging set, or 0 if the staging set is empty.

Definition at line 656 of file RaftConsensus.cc.

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.

Returns:
Return the existing or new server. TODO(ongaro): this name and signature is misleading

Definition at line 727 of file RaftConsensus.cc.


Friends And Related Function Documentation

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.


Member Data Documentation

Used for constructing Server instances.

Definition at line 657 of file RaftConsensus.h.

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.

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.


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