0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Private Attributes | List of all members
Hypertable::ResponseManager Class Reference

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...
 

Detailed Description

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:

  1. Operation request is sent, operation is created at master and added to the OperationProcessor, and the operation ID is sent back to the client
  2. The client issues a FETCH_RESULT request, with the ID returned in step 1, to obtain the result of the operation

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:

  1. If the operation completes before the FETCH_RESULT request is received, the operation is added to m_context->expirable_ops. As soon as the FETCH_RESULT request is received, the operation results are sent back and the operation is removed.
  2. If the FETCH_RESULT request is received before the operation completes, the response delivery information is add to 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.

Constructor & Destructor Documentation

Hypertable::ResponseManager::ResponseManager ( )
inline

Constructor.

Definition at line 221 of file ResponseManager.h.

Member Function Documentation

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.

Parameters
operation_idID of operation whose delivery info is being added
eventEvent 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().

Parameters
operationCompleted 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.

void Hypertable::ResponseManager::set_mml_writer ( MetaLog::WriterPtr mml_writer)
inline

Sets MML writer.

Parameters
mml_writerMML 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.

Member Data Documentation

std::shared_ptr<ResponseManagerContext> Hypertable::ResponseManager::m_context
private

Pointer to shared context object.

Definition at line 292 of file ResponseManager.h.


The documentation for this class was generated from the following files: