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

This class helps with providing exactly-once semantics for read-write RPCs. More...

#include <ClientImpl.h>

List of all members.

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 &)
ExactlyOnceRPCHelperoperator= (const ExactlyOnceRPCHelper &)

Private Attributes

ClientImplclient
 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().

Detailed Description

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.


Constructor & Destructor Documentation

Constructor.

Parameters:
clientUsed 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.


Member Function Documentation

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.

Parameters:
timeoutIf 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.
Returns:
Info to be used with read-write RPCs, or if the timeout elapsed, a client_id set to 0.

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.

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]

Member Data Documentation

Used to open a session with the cluster.

const and non-NULL except for unit tests.

Definition at line 267 of file ClientImpl.h.

Protects all the members of this class.

Definition at line 271 of file ClientImpl.h.

The numbers of the RPCs for which this client is still awaiting a response.

Definition at line 276 of file ClientImpl.h.

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.

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.

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.

How often session keep-alive requests are sent during periods of inactivity.

Definition at line 305 of file ClientImpl.h.

How long to wait for the CloseSession RPC before giving up.

Definition at line 309 of file ClientImpl.h.

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.

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.


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