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

Timer interrupt handler. More...

#include <TimerHandler.h>

Inheritance diagram for Hypertable::TimerHandler:
Inheritance graph
[legend]
Collaboration diagram for Hypertable::TimerHandler:
Collaboration graph
[legend]

Public Member Functions

 TimerHandler (Comm *comm, Apps::RangeServer *range_server)
 Constructor. More...
 
void start ()
 Start timer. More...
 
void handle (Hypertable::EventPtr &event)
 Timer event handler callback method. More...
 
void schedule_immediate_maintenance ()
 Force maintenance to be scheduled immediately. More...
 
void maintenance_scheduled_notify ()
 Signal maintenance scheduling complete. More...
 
bool low_memory_mode ()
 Test for low memory mode. More...
 
void shutdown ()
 Start shutdown sequence. More...
 
- Public Member Functions inherited from Hypertable::DispatchHandler
virtual ~DispatchHandler ()
 Destructor. More...
 

Private Member Functions

void pause_app_queue ()
 Pauses the application queue. More...
 
void restart_app_queue ()
 Restarts the application queue. More...
 
bool low_memory ()
 Checks for low memory. More...
 

Private Attributes

std::mutex m_mutex
 Mutex for serializing access More...
 
Commm_comm {}
 Comm object. More...
 
Apps::RangeServerm_range_server {}
 RangeServer. More...
 
ApplicationQueuePtr m_app_queue
 Application queue. More...
 
int64_t m_query_cache_memory {}
 Query cache max size (Hypertable.RangeServer.QueryCache.MaxMemory) More...
 
int64_t m_userlog_size_threshold {}
 Pause app queue if USER log exceeds this size. More...
 
int64_t m_restart_generation {}
 Generation of maintenance queue signalling application queue restart. More...
 
std::chrono::steady_clock::time_point m_last_schedule
 Last time maintenance was scheduled. More...
 
std::chrono::steady_clock::time_point m_pause_time
 Last time application queue was paused. More...
 
int32_t m_timer_interval {}
 Timer interval. More...
 
int32_t m_current_interval {}
 Current timer interval (set to 500 when app queue is paused) More...
 
int32_t m_max_app_queue_pause {}
 Maximum time to keep application queue paused each time it is paused. More...
 
bool m_shutdown {}
 Indicates that a shutdown is in progress. More...
 
bool m_immediate_maintenance_scheduled {}
 An immediate maintenance timer has been scheduled. More...
 
bool m_app_queue_paused {}
 Application queue is paused. More...
 
bool m_low_memory_mode {}
 Low memory mode. More...
 
bool m_schedule_outstanding {}
 A maintenance scheduling operation is outstanding. More...
 

Detailed Description

Timer interrupt handler.

Currently, the primary purpose of this class is to handle maintenance scheduling. Usually, it adds a RequestHandlerDoMaintenance object onto the application queue each time it is called. However, it also tests for low memory and if detected, will cause the maintenance prioritization algorithm to change to aggressively free memory. It also pauses the application queue to allow maintenance to catch up if it gets behind.

Definition at line 58 of file TimerHandler.h.

Constructor & Destructor Documentation

TimerHandler::TimerHandler ( Comm comm,
Apps::RangeServer range_server 
)

Constructor.

Initializes the timer handler by setting m_query_cache_memory to the property Hypertable.RangeServer.QueryCache.MaxMemory, m_userlog_size_threshold to 20% larger than the maximum log prune threshold, m_max_app_queue_pause to the property Hypertable.RangeServer.Maintenance.MaxAppQueuePause, and m_timer_interval to the lesser of Hypertable.RangeServer.Timer.Interval or Hypertable.RangeServer.Maintenance.Interval. It also initializes m_last_schedule to the current time, registers itself with the RangeServer with a call to RangeServer::register_timer, and then schedules a timer interrupt immediately.

Definition at line 51 of file TimerHandler.cc.

Member Function Documentation

void TimerHandler::handle ( Hypertable::EventPtr event)
virtual

Timer event handler callback method.

This method performs the following steps:

  1. If m_shutdown is true, return.
  2. If the application queue is paused, it will restart it in the following cirucmstances:
    • Low memory mode is in effect and the system is no longer low on memory.
    • The maintenance queue generation has reached m_restart_generation (meaning all of the maintenance that was last scheduled has been carried out).
    • m_max_app_queue_pause milliseconds have elapsed since the queue was paused.
  3. If the application queue was not paused upon entry to this method, and low maintenance mode is in effect, and the system is low on memory, then the application queue is paused.
  4. If the application queue was not paused upon entry to this method, and the system is not low on memory, m_low_memory_mode is set to false. If the size of the USER log has exceeded m_userlog_size_threshold, then the application queue is paused.
  5. If m_immediate_maintenance_scheduled is true, low memory mode is disabled.
  6. If event is not an Event::TIMER event, an error is logged and the method returns.
  7. If m_schedule_outstanding is false a RequestHandlerDoMaintenance object is added to the application queue and m_schedule_outstanding will be set to true under the following circumstances:
    • The application queue was not paused on entry to this method.
    • The application queue was paused on entry to this method and m_immediate_maintenance_scheduled is true.
  8. If a RequestHandlerDoMaintenance object was not added to the application queue, then the timer will get re-registered for m_current_interval milliseconds in the future.
    Parameters
    eventEvent object

Implements Hypertable::DispatchHandler.

Definition at line 134 of file TimerHandler.cc.

bool TimerHandler::low_memory ( )
private

Checks for low memory.

Returns
true if low on memory, false otherwise.

Definition at line 232 of file TimerHandler.cc.

bool Hypertable::TimerHandler::low_memory_mode ( )
inline

Test for low memory mode.

Returns
true if in low memory mode, false otherwise.

Definition at line 146 of file TimerHandler.h.

void TimerHandler::maintenance_scheduled_notify ( )

Signal maintenance scheduling complete.

This method is called by the RangeServer when it has finished scheduling maintenance and performs the following steps:

  1. It sets m_schedule_outstanding to false and sets m_last_schedule to the current time.
  2. If RangeServer replay has finished, it will do the following:
    • If the size of the user commit log is greater than m_userlog_size_threshold, it will pause the application queue if it is not already paused.
    • Otherwise, if the application queue is paused an the system is not low on memory, it will restart the application queue.
  3. If m_immediate_maintenance_scheduled is true, it is set to false. The timer is not re-registered because m_immediate_maintenance_scheduled implies that an additional "one shot" timer was registered to handle the immediate mantenance
  4. If m_immediate_maintenance_scheduled was set to false upon entry to this method, the timer is re-registered for m_current_interval milliseconds in the future.

Definition at line 102 of file TimerHandler.cc.

void TimerHandler::pause_app_queue ( )
private

Pauses the application queue.

Pauses the application queue, sets m_app_queue_paused to true, sets m_current_interval to 500, sets m_restart_generation to the current maintenance queue generation plus the size of the maintenance queue, and sets m_pause_time to the current time.

Definition at line 203 of file TimerHandler.cc.

void TimerHandler::restart_app_queue ( )
private

Restarts the application queue.

Restarts the application queue, sets m_app_queue_paused to false, sets m_low_memory_mode to false, and resets the timer interval m_current_interval back to normal (m_timer_interval).

Definition at line 215 of file TimerHandler.cc.

void TimerHandler::schedule_immediate_maintenance ( )

Force maintenance to be scheduled immediately.

If m_immediate_maintenance_scheduled and m_schedule_outstanding are set to false, the timer is registered immediately and m_immediate_maintenance_scheduled is set to true.

Definition at line 85 of file TimerHandler.cc.

void TimerHandler::shutdown ( )

Start shutdown sequence.

Sets m_shutdown to true, cancels current timer, and registers timer immediately. The handle method will complete the shutdown sequence.

Definition at line 127 of file TimerHandler.cc.

void TimerHandler::start ( )

Start timer.

This method sets a timer for 0 milliseconds in the future with itself as the handler.

Definition at line 78 of file TimerHandler.cc.

Member Data Documentation

ApplicationQueuePtr Hypertable::TimerHandler::m_app_queue
private

Application queue.

Definition at line 166 of file TimerHandler.h.

bool Hypertable::TimerHandler::m_app_queue_paused {}
private

Application queue is paused.

Definition at line 199 of file TimerHandler.h.

Comm* Hypertable::TimerHandler::m_comm {}
private

Comm object.

Definition at line 160 of file TimerHandler.h.

int32_t Hypertable::TimerHandler::m_current_interval {}
private

Current timer interval (set to 500 when app queue is paused)

Definition at line 187 of file TimerHandler.h.

bool Hypertable::TimerHandler::m_immediate_maintenance_scheduled {}
private

An immediate maintenance timer has been scheduled.

Definition at line 196 of file TimerHandler.h.

std::chrono::steady_clock::time_point Hypertable::TimerHandler::m_last_schedule
private

Last time maintenance was scheduled.

Definition at line 178 of file TimerHandler.h.

bool Hypertable::TimerHandler::m_low_memory_mode {}
private

Low memory mode.

Definition at line 202 of file TimerHandler.h.

int32_t Hypertable::TimerHandler::m_max_app_queue_pause {}
private

Maximum time to keep application queue paused each time it is paused.

Definition at line 190 of file TimerHandler.h.

std::mutex Hypertable::TimerHandler::m_mutex
private

Mutex for serializing access

Definition at line 157 of file TimerHandler.h.

std::chrono::steady_clock::time_point Hypertable::TimerHandler::m_pause_time
private

Last time application queue was paused.

Definition at line 181 of file TimerHandler.h.

int64_t Hypertable::TimerHandler::m_query_cache_memory {}
private

Query cache max size (Hypertable.RangeServer.QueryCache.MaxMemory)

Definition at line 169 of file TimerHandler.h.

Apps::RangeServer* Hypertable::TimerHandler::m_range_server {}
private

RangeServer.

Definition at line 163 of file TimerHandler.h.

int64_t Hypertable::TimerHandler::m_restart_generation {}
private

Generation of maintenance queue signalling application queue restart.

Definition at line 175 of file TimerHandler.h.

bool Hypertable::TimerHandler::m_schedule_outstanding {}
private

A maintenance scheduling operation is outstanding.

Definition at line 205 of file TimerHandler.h.

bool Hypertable::TimerHandler::m_shutdown {}
private

Indicates that a shutdown is in progress.

Definition at line 193 of file TimerHandler.h.

int32_t Hypertable::TimerHandler::m_timer_interval {}
private

Timer interval.

Definition at line 184 of file TimerHandler.h.

int64_t Hypertable::TimerHandler::m_userlog_size_threshold {}
private

Pause app queue if USER log exceeds this size.

Definition at line 172 of file TimerHandler.h.


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