LogCabin
|
This class helps with providing exactly-once semantics for read-write RPCs. More...
#include <ClientImpl.h>
Public Member Functions | |
ExactlyOnceRPCHelper (ClientImpl *client) | |
Constructor. | |
~ExactlyOnceRPCHelper () | |
Destructor. | |
void | exit () |
Prepare to shut down (join with thread). | |
Protocol::Client::ExactlyOnceRPCInfo | getRPCInfo (TimePoint timeout) |
Call this before sending an RPC. | |
void | doneWithRPC (const Protocol::Client::ExactlyOnceRPCInfo &) |
Call this after receiving an RPCs response. | |
Private Member Functions | |
Protocol::Client::ExactlyOnceRPCInfo | getRPCInfo (Core::HoldingMutex holdingMutex, TimePoint timeout) |
Internal version of getRPCInfo() to avoid deadlock with self. | |
void | doneWithRPC (const Protocol::Client::ExactlyOnceRPCInfo &, Core::HoldingMutex holdingMutex) |
Internal version of doneWithRPC() to avoid deadlock with self. | |
void | keepAliveThreadMain () |
Main function for keep-alive thread. | |
ExactlyOnceRPCHelper (const ExactlyOnceRPCHelper &) | |
ExactlyOnceRPCHelper & | operator= (const ExactlyOnceRPCHelper &) |
Private Attributes | |
ClientImpl * | client |
Used to open a session with the cluster. | |
Core::Mutex | mutex |
Protects all the members of this class. | |
std::set< uint64_t > | outstandingRPCNumbers |
The numbers of the RPCs for which this client is still awaiting a response. | |
uint64_t | clientId |
The client's session ID as returned by the open session RPC, or 0 if one has not yet been assigned. | |
uint64_t | nextRPCNumber |
The number to assign to the next RPC. | |
Core::ConditionVariable | keepAliveCV |
keepAliveThread blocks on this. | |
bool | exiting |
Flag to keepAliveThread that it should shut down. | |
TimePoint | lastKeepAliveStart |
Time just before the last keep-alive or read-write request to the cluster was made. | |
std::chrono::milliseconds | keepAliveInterval |
How often session keep-alive requests are sent during periods of inactivity. | |
std::chrono::milliseconds | sessionCloseTimeout |
How long to wait for the CloseSession RPC before giving up. | |
std::unique_ptr < LeaderRPCBase::Call > | keepAliveCall |
If set, this is an ongoing keep-alive RPC. | |
std::thread | keepAliveThread |
Runs keepAliveThreadMain(). |
This class helps with providing exactly-once semantics for read-write RPCs.
For example, it assigns sequence numbers to RPCs, which servers then use to prevent duplicate processing of duplicate requests.
This class is implemented in a monitor style.
Definition at line 211 of file ClientImpl.h.
LogCabin::Client::ClientImpl::ExactlyOnceRPCHelper::ExactlyOnceRPCHelper | ( | ClientImpl * | client | ) | [explicit] |
Constructor.
client | Used to open a session with the cluster. Should not be NULL. |
Definition at line 214 of file ClientImpl.cc.
Destructor.
Definition at line 236 of file ClientImpl.cc.
LogCabin::Client::ClientImpl::ExactlyOnceRPCHelper::ExactlyOnceRPCHelper | ( | const ExactlyOnceRPCHelper & | ) | [private] |
Prepare to shut down (join with thread).
Definition at line 241 of file ClientImpl.cc.
Protocol::Client::ExactlyOnceRPCInfo LogCabin::Client::ClientImpl::ExactlyOnceRPCHelper::getRPCInfo | ( | TimePoint | timeout | ) |
Call this before sending an RPC.
timeout | If this timeout elapses before a session can be opened with the cluster, this method will return early and the returned information will have a client_id set to 0, which is not a valid ID. |
Definition at line 286 of file ClientImpl.cc.
void LogCabin::Client::ClientImpl::ExactlyOnceRPCHelper::doneWithRPC | ( | const Protocol::Client::ExactlyOnceRPCInfo & | rpcInfo | ) |
Call this after receiving an RPCs response.
Definition at line 293 of file ClientImpl.cc.
Protocol::Client::ExactlyOnceRPCInfo LogCabin::Client::ClientImpl::ExactlyOnceRPCHelper::getRPCInfo | ( | Core::HoldingMutex | holdingMutex, |
TimePoint | timeout | ||
) | [private] |
Internal version of getRPCInfo() to avoid deadlock with self.
Definition at line 301 of file ClientImpl.cc.
void LogCabin::Client::ClientImpl::ExactlyOnceRPCHelper::doneWithRPC | ( | const Protocol::Client::ExactlyOnceRPCInfo & | rpcInfo, |
Core::HoldingMutex | holdingMutex | ||
) | [private] |
Internal version of doneWithRPC() to avoid deadlock with self.
Definition at line 351 of file ClientImpl.cc.
void LogCabin::Client::ClientImpl::ExactlyOnceRPCHelper::keepAliveThreadMain | ( | ) | [private] |
Main function for keep-alive thread.
Periodically makes requests to the cluster to keep the client's session active.
Definition at line 359 of file ClientImpl.cc.
ExactlyOnceRPCHelper& LogCabin::Client::ClientImpl::ExactlyOnceRPCHelper::operator= | ( | const ExactlyOnceRPCHelper & | ) | [private] |
Used to open a session with the cluster.
const and non-NULL except for unit tests.
Definition at line 267 of file ClientImpl.h.
Core::Mutex LogCabin::Client::ClientImpl::ExactlyOnceRPCHelper::mutex [mutable, private] |
Protects all the members of this class.
Definition at line 271 of file ClientImpl.h.
std::set<uint64_t> LogCabin::Client::ClientImpl::ExactlyOnceRPCHelper::outstandingRPCNumbers [private] |
The numbers of the RPCs for which this client is still awaiting a response.
Definition at line 276 of file ClientImpl.h.
uint64_t LogCabin::Client::ClientImpl::ExactlyOnceRPCHelper::clientId [private] |
The client's session ID as returned by the open session RPC, or 0 if one has not yet been assigned.
Definition at line 281 of file ClientImpl.h.
uint64_t LogCabin::Client::ClientImpl::ExactlyOnceRPCHelper::nextRPCNumber [private] |
The number to assign to the next RPC.
Definition at line 285 of file ClientImpl.h.
keepAliveThread blocks on this.
Notified when lastKeepAliveStart, keepAliveIntervalMs, or exiting changes.
Definition at line 290 of file ClientImpl.h.
bool LogCabin::Client::ClientImpl::ExactlyOnceRPCHelper::exiting [private] |
Flag to keepAliveThread that it should shut down.
Definition at line 294 of file ClientImpl.h.
Time just before the last keep-alive or read-write request to the cluster was made.
The next keep-alive request will be invoked keepAliveIntervalMs after this, if no intervening requests are made.
Definition at line 300 of file ClientImpl.h.
std::chrono::milliseconds LogCabin::Client::ClientImpl::ExactlyOnceRPCHelper::keepAliveInterval [private] |
How often session keep-alive requests are sent during periods of inactivity.
Definition at line 305 of file ClientImpl.h.
std::chrono::milliseconds LogCabin::Client::ClientImpl::ExactlyOnceRPCHelper::sessionCloseTimeout [private] |
How long to wait for the CloseSession RPC before giving up.
Definition at line 309 of file ClientImpl.h.
std::unique_ptr<LeaderRPCBase::Call> LogCabin::Client::ClientImpl::ExactlyOnceRPCHelper::keepAliveCall [private] |
If set, this is an ongoing keep-alive RPC.
This call is canceled to interrupt keepAliveThread when exiting.
Definition at line 315 of file ClientImpl.h.
std::thread LogCabin::Client::ClientImpl::ExactlyOnceRPCHelper::keepAliveThread [private] |
Runs keepAliveThreadMain().
Since this thread would be unexpected/wasteful for clients that only issue read-only requests (or no requests at all), it is spawned lazily, if/when the client opens its session with the cluster (upon its first read-write request).
Definition at line 324 of file ClientImpl.h.