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

This is the implementation of LeaderRPCBase that uses the RPC system. More...

#include <LeaderRPC.h>

Inheritance diagram for LogCabin::Client::LeaderRPC:
LogCabin::Client::LeaderRPCBase

List of all members.

Classes

class  Call
 See LeaderRPCBase::Call. More...

Public Member Functions

 LeaderRPC (const RPC::Address &hosts, SessionManager::ClusterUUID &clusterUUID, Backoff &sessionCreationBackoff, SessionManager &sessionManager)
 Constructor.
 ~LeaderRPC ()
 Destructor.
Status call (OpCode opCode, const google::protobuf::Message &request, google::protobuf::Message &response, TimePoint timeout)
 See LeaderRPCBase::call.
std::unique_ptr
< LeaderRPCBase::Call
makeCall ()
 See LeaderRPCBase::makeCall().

Private Member Functions

std::shared_ptr
< RPC::ClientSession
getSession (TimePoint timeout)
 Return a session connected to the most likely cluster leader, creating it if necessary.
void reportFailure (std::shared_ptr< RPC::ClientSession > cachedSession)
 Notify this class that an RPC on the given session failed.
void reportNotLeader (std::shared_ptr< RPC::ClientSession > cachedSession)
 Notify this class that a non-leader server rejected an RPC.
void reportRedirect (std::shared_ptr< RPC::ClientSession > cachedSession, const std::string &host)
 Notify this class that an RPC on the given session was redirected by a non-leader server.
void reportSuccess (std::shared_ptr< RPC::ClientSession > cachedSession)
 Notify this class that an RPC on the given session reached a leader.

Private Attributes

SessionManager::ClusterUUIDclusterUUID
 Keeps track of the unique ID for this cluster, if known.
BackoffsessionCreationBackoff
 Used to rate-limit the creation of ClientSession objects (TCP connections).
SessionManagersessionManager
 Used to create new sessions.
std::mutex mutex
 Protects all of the following member variables in this class.
bool isConnecting
 Set to true when some thread is already initiating a new session.
Core::ConditionVariable connected
 Notified when isConnecting becomes false (when leaderSession is set).
RPC::Address hosts
 An address referring to the hosts in the LogCabin cluster.
std::string leaderHint
 If nonempty, the address of the server that is likely to be the current leader.
std::shared_ptr
< RPC::ClientSession
leaderSession
 The goal is to get this session connected to the cluster leader.
uint64_t failuresSinceLastSuccess
 The number of attempted RPCs that have not successfully reached a leader since the last time an RPC did.

Detailed Description

This is the implementation of LeaderRPCBase that uses the RPC system.

(The other implementation, LeaderRPCMock, is only used for testing.)

Definition at line 224 of file LeaderRPC.h.


Constructor & Destructor Documentation

LogCabin::Client::LeaderRPC::LeaderRPC ( const RPC::Address hosts,
SessionManager::ClusterUUID clusterUUID,
Backoff sessionCreationBackoff,
SessionManager sessionManager 
)

Constructor.

Parameters:
hostsDescribe the servers to connect to. This class assumes that refreshing 'hosts' will result in a random host that might be the current cluster leader.
clusterUUIDKeeps track of the unique ID for this cluster, if known.
sessionCreationBackoffUsed to rate-limit new TCP connections.
sessionManagerUsed to create new sessions.

Definition at line 159 of file LeaderRPC.cc.

Destructor.

Definition at line 176 of file LeaderRPC.cc.


Member Function Documentation

LeaderRPC::Status LogCabin::Client::LeaderRPC::call ( OpCode  opCode,
const google::protobuf::Message &  request,
google::protobuf::Message &  response,
TimePoint  timeout 
) [virtual]

See LeaderRPCBase::call.

Implements LogCabin::Client::LeaderRPCBase.

Definition at line 182 of file LeaderRPC.cc.

See LeaderRPCBase::makeCall().

Implements LogCabin::Client::LeaderRPCBase.

Definition at line 205 of file LeaderRPC.cc.

std::shared_ptr< RPC::ClientSession > LogCabin::Client::LeaderRPC::getSession ( TimePoint  timeout) [private]

Return a session connected to the most likely cluster leader, creating it if necessary.

Parameters:
timeoutAfter this time has elapsed, stop trying to initiate the connection and return an invalid session.
Returns:
Session on which to execute RPCs.

Definition at line 211 of file LeaderRPC.cc.

void LogCabin::Client::LeaderRPC::reportFailure ( std::shared_ptr< RPC::ClientSession cachedSession) [private]

Notify this class that an RPC on the given session failed.

This will usually cause this class to connect to a random server next time getSession() is called.

Parameters:
cachedSessionSession previously returned by getSession(). This is used to detect races in which some other thread has already solved the problem.

Definition at line 284 of file LeaderRPC.cc.

void LogCabin::Client::LeaderRPC::reportNotLeader ( std::shared_ptr< RPC::ClientSession cachedSession) [private]

Notify this class that a non-leader server rejected an RPC.

This will usually cause this class to connect to a random server next time getSession() is called.

Parameters:
cachedSessionSession previously returned by getSession(). This is used to detect races in which some other thread has already solved the problem.

Definition at line 305 of file LeaderRPC.cc.

void LogCabin::Client::LeaderRPC::reportRedirect ( std::shared_ptr< RPC::ClientSession cachedSession,
const std::string &  host 
) [private]

Notify this class that an RPC on the given session was redirected by a non-leader server.

This will usually cause this class to connect to the given host the next time getSession() is called.

Parameters:
cachedSessionSession previously returned by getSession(). This is used to detect races in which some other thread has already solved the problem.
hostAddress of the server that is likely the leader.

Definition at line 326 of file LeaderRPC.cc.

void LogCabin::Client::LeaderRPC::reportSuccess ( std::shared_ptr< RPC::ClientSession cachedSession) [private]

Notify this class that an RPC on the given session reached a leader.

This is just here for debug log messages.

Parameters:
cachedSessionSession previously returned by getSession(). This is used to detect races in which some other thread has already solved any problems.

Definition at line 351 of file LeaderRPC.cc.


Member Data Documentation

Keeps track of the unique ID for this cluster, if known.

Definition at line 342 of file LeaderRPC.h.

Used to rate-limit the creation of ClientSession objects (TCP connections).

Definition at line 348 of file LeaderRPC.h.

Used to create new sessions.

Definition at line 353 of file LeaderRPC.h.

std::mutex LogCabin::Client::LeaderRPC::mutex [private]

Protects all of the following member variables in this class.

Definition at line 358 of file LeaderRPC.h.

Set to true when some thread is already initiating a new session.

When this is already true, other threads wait on connected rather than starting additional sessions.

Definition at line 365 of file LeaderRPC.h.

Notified when isConnecting becomes false (when leaderSession is set).

Definition at line 370 of file LeaderRPC.h.

An address referring to the hosts in the LogCabin cluster.

A random host is selected from here when this class doesn't know who the cluster leader is.

Definition at line 377 of file LeaderRPC.h.

If nonempty, the address of the server that is likely to be the current leader.

Definition at line 383 of file LeaderRPC.h.

The goal is to get this session connected to the cluster leader.

This is never null, but it might sometimes point to the wrong host.

Definition at line 389 of file LeaderRPC.h.

The number of attempted RPCs that have not successfully reached a leader since the last time an RPC did.

Used for rate-limiting and summarizing log messages: they're only printed when this number reaches a power of two.

Definition at line 397 of file LeaderRPC.h.


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