LogCabin
|
This is the implementation of LeaderRPCBase that uses the RPC system. More...
#include <LeaderRPC.h>
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::ClusterUUID & | clusterUUID |
Keeps track of the unique ID for this cluster, if known. | |
Backoff & | sessionCreationBackoff |
Used to rate-limit the creation of ClientSession objects (TCP connections). | |
SessionManager & | sessionManager |
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. |
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.
LogCabin::Client::LeaderRPC::LeaderRPC | ( | const RPC::Address & | hosts, |
SessionManager::ClusterUUID & | clusterUUID, | ||
Backoff & | sessionCreationBackoff, | ||
SessionManager & | sessionManager | ||
) |
Constructor.
hosts | Describe the servers to connect to. This class assumes that refreshing 'hosts' will result in a random host that might be the current cluster leader. |
clusterUUID | Keeps track of the unique ID for this cluster, if known. |
sessionCreationBackoff | Used to rate-limit new TCP connections. |
sessionManager | Used to create new sessions. |
Definition at line 159 of file LeaderRPC.cc.
Destructor.
Definition at line 176 of file LeaderRPC.cc.
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.
std::unique_ptr< LeaderRPCBase::Call > LogCabin::Client::LeaderRPC::makeCall | ( | ) | [virtual] |
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.
timeout | After this time has elapsed, stop trying to initiate the connection and return an invalid session. |
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.
cachedSession | Session 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.
cachedSession | Session 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.
cachedSession | Session previously returned by getSession(). This is used to detect races in which some other thread has already solved the problem. |
host | Address 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.
cachedSession | Session 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.
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.
bool LogCabin::Client::LeaderRPC::isConnecting [private] |
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.
std::string LogCabin::Client::LeaderRPC::leaderHint [private] |
If nonempty, the address of the server that is likely to be the current leader.
Definition at line 383 of file LeaderRPC.h.
std::shared_ptr<RPC::ClientSession> LogCabin::Client::LeaderRPC::leaderSession [private] |
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.
uint64_t LogCabin::Client::LeaderRPC::failuresSinceLastSuccess [private] |
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.