Manages the sending of operation results back to clients. More...
#include <ResponseManager.h>
Public Member Functions | |
ResponseManager () | |
Constructor. More... | |
void | operator() () |
Worker thread run method. More... | |
void | add_operation (OperationPtr &operation) |
Queues a completed operation and/or delivers response. More... | |
void | add_delivery_info (int64_t operation_id, EventPtr &event) |
Adds response delivery information and/or delivers response. More... | |
void | set_mml_writer (MetaLog::WriterPtr &mml_writer) |
Sets MML writer. More... | |
void | shutdown () |
Initiates shutdown sequence. More... | |
Private Attributes | |
std::shared_ptr < ResponseManagerContext > | m_context |
Pointer to shared context object. More... | |
Manages the sending of operation results back to clients.
A single object of this class is created to handle sending operation results back to clients. It is designed to have a single worker thread to handle removal of expired and completed operations. The object created from this class should be passed into the Thread constructor of a single worker thread to handle the removal of expired and completed operations. This thread should live throughout the lifetime of the master and should only be joined during master shutdown. Clients create and carry out master operations in two steps:
The reason for this two-step process is so that master failover can be handled transparently by the client. For each operation, there are two scenarios handled by this class, depending on whether or not the operation completes before the FETCH_RESULT request is received:
m_context->expirable_ops
. As soon as the FETCH_RESULT request is received, the operation results are sent back and the operation is removed.m_context->m_context->delivery_list
. As soon as the operation completes and is added with a call to add_operation(), the operation results are sent back, the delivery record is removed from m_context->delivery_list
, and the operation is removed. Definition at line 216 of file ResponseManager.h.
|
inline |
Constructor.
Definition at line 221 of file ResponseManager.h.
void ResponseManager::add_delivery_info | ( | int64_t | operation_id, |
EventPtr & | event | ||
) |
Adds response delivery information and/or delivers response.
This method first checks to see if the operation specified by operation_id
has been added to m_context->expirable_ops
. If it has been added, then a response is immediately sent back to the client, the operation is removed from m_context->expirable_ops
and added to m_context->removal_queue
, and then m_context->cond
is signalled to notify the worker thread that the operation can be removed. If the corresponding operation has not yet been added to m_context->expirable_ops
, an entry containing event
is added to m_context->delivery_list
so that at a later time, when the corresponding operation is added via add_operation(), the operation result can be sent back to the client at the delivery address contained within event
.
operation_id | ID of operation whose delivery info is being added |
event | Event representing a COMMAND_FETCH_RESULT request |
Definition at line 120 of file ResponseManager.cc.
void ResponseManager::add_operation | ( | OperationPtr & | operation | ) |
Queues a completed operation and/or delivers response.
This method first checks m_context->delivery_list
to see if client delivery information has been added for operation
. If so, it sends a response message back to the client, removes the corresponding delivery information record from m_context->delivery_list
, adds operation
to m_context->removal_queue
, and then signals m_context->cond
to notify the worker thread that the operation can be removed. If client delivery information has not yet been added for operation
, it is added to m_context->expirable_ops
, deferring the delivery of the response message until the corresponding delivery information has been added with a call to add_delivery_info().
operation | Completed operation ready for response delivery |
Definition at line 150 of file ResponseManager.cc.
void ResponseManager::operator() | ( | ) |
Worker thread run method.
This method is called by the worker thread to handle the removal of expired and completed operations. It waits on m_context->cond
for the next operation or delivery information record to time out, or for completed operations to get added to m_context->removal_queue
by either the add_operation() or add_delivery_info() method. If an operation times out, it is removed from m_context->expirable_ops
and is added to m_context->removal_queue
. If a delivery information record times out, it is removed from m_context->delivery_list
. At the end of the wait loop, the operations in m_context->mml_writer->record_removal
are removed from the MML with a call to m_context->mml_writer->record_removal
and m_context->removal_queue
is cleared.
Definition at line 37 of file ResponseManager.cc.
|
inline |
Sets MML writer.
mml_writer | MML writer object |
Definition at line 279 of file ResponseManager.h.
void ResponseManager::shutdown | ( | ) |
Initiates shutdown sequence.
Sets m_context->shutdown
to true and singals m_context->cond
to force the worker thread to exit.
Definition at line 176 of file ResponseManager.cc.
|
private |
Pointer to shared context object.
Definition at line 292 of file ResponseManager.h.