Timer interrupt handler. More...
#include <TimerHandler.h>
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... | |
Comm * | m_comm {} |
Comm object. More... | |
Apps::RangeServer * | m_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... | |
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.
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.
|
virtual |
Timer event handler callback method.
This method performs the following steps:
event
is not an Event::TIMER event, an error is logged and the method returns.event | Event object |
Implements Hypertable::DispatchHandler.
Definition at line 134 of file TimerHandler.cc.
|
private |
Checks for low memory.
Definition at line 232 of file TimerHandler.cc.
|
inline |
Test for low memory mode.
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:
Definition at line 102 of file TimerHandler.cc.
|
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.
|
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.
|
private |
Application queue.
Definition at line 166 of file TimerHandler.h.
|
private |
Application queue is paused.
Definition at line 199 of file TimerHandler.h.
|
private |
Comm object.
Definition at line 160 of file TimerHandler.h.
|
private |
Current timer interval (set to 500 when app queue is paused)
Definition at line 187 of file TimerHandler.h.
|
private |
An immediate maintenance timer has been scheduled.
Definition at line 196 of file TimerHandler.h.
|
private |
Last time maintenance was scheduled.
Definition at line 178 of file TimerHandler.h.
|
private |
Low memory mode.
Definition at line 202 of file TimerHandler.h.
|
private |
Maximum time to keep application queue paused each time it is paused.
Definition at line 190 of file TimerHandler.h.
|
private |
Mutex for serializing access
Definition at line 157 of file TimerHandler.h.
|
private |
Last time application queue was paused.
Definition at line 181 of file TimerHandler.h.
|
private |
Query cache max size (Hypertable.RangeServer.QueryCache.MaxMemory)
Definition at line 169 of file TimerHandler.h.
|
private |
Definition at line 163 of file TimerHandler.h.
|
private |
Generation of maintenance queue signalling application queue restart.
Definition at line 175 of file TimerHandler.h.
|
private |
A maintenance scheduling operation is outstanding.
Definition at line 205 of file TimerHandler.h.
|
private |
Indicates that a shutdown is in progress.
Definition at line 193 of file TimerHandler.h.
|
private |
Timer interval.
Definition at line 184 of file TimerHandler.h.
|
private |
Pause app queue if USER log exceeds this size.
Definition at line 172 of file TimerHandler.h.