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

This is the rough equivalent of a SteadyClock that can be shared across the network with other Raft servers. More...

#include <RaftConsensus.h>

List of all members.

Public Member Functions

 ClusterClock ()
 Default constructor.
void newEpoch (uint64_t clusterTime)
 Reset to the given cluster time, assuming it's the current time right now.
uint64_t leaderStamp ()
 Called by leaders to generate a new cluster time for a new log entry.
uint64_t interpolate () const
 Return the best approximation of the current cluster time, assuming there's been a leader all along.

Public Attributes

uint64_t clusterTimeAtEpoch
 Invariant: this is equal to the cluster time in:
Core::Time::SteadyClock::time_point localTimeAtEpoch
 The local SteadyClock time when clusterTimeAtEpoch was set.

Detailed Description

This is the rough equivalent of a SteadyClock that can be shared across the network with other Raft servers.

The cluster time approximately tracks how long the cluster has been available with a working leader.

Cluster time is measured in nanoseconds and progresses at about the same rate as a normal clock when the cluster is operational. While there's a stable leader, the nanoseconds increase according to that leader's SteadyClock. When a new leader takes over, it starts ticking from cluster time value it finds in its last entry/snapshot, so some cluster time may be unaccounted for between the last leader replicating its final entry and then losing leadership.

The StateMachine uses cluster time to expire client sessions. Cluster times in committed log entries monotonically increase, so the state machine will see cluster times monotonically increase.

Before cluster time, client sessions were expired based on the SystemClock. That meant that if the SystemClock jumped forwards drastically, all clients would expire. That's undesirable, so cluster time was introduced in #90 ("make client session timeout use monotonic clock") to address this.

Definition at line 831 of file RaftConsensus.h.


Constructor & Destructor Documentation

Default constructor.

Definition at line 821 of file RaftConsensus.cc.


Member Function Documentation

Reset to the given cluster time, assuming it's the current time right now.

This is used, for example, when a follower gets a new log entry (which includes a cluster time) from the leader.

Definition at line 828 of file RaftConsensus.cc.

Called by leaders to generate a new cluster time for a new log entry.

This is equivalent to the following but slightly more efficient: uint64_t now = c.interpolate(); c.newEpoch(now); return now;

Definition at line 835 of file RaftConsensus.cc.

Return the best approximation of the current cluster time, assuming there's been a leader all along.

Definition at line 847 of file RaftConsensus.cc.


Member Data Documentation

Invariant: this is equal to the cluster time in:

  • the last log entry, if any, or
  • the last snapshot, if any, or
  • 0.

Definition at line 864 of file RaftConsensus.h.

The local SteadyClock time when clusterTimeAtEpoch was set.

Definition at line 869 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