0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TimerHandler.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; version 3 of the
9  * License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
26 
27 #ifndef Hypertable_RangeServer_TimerHandler_h
28 #define Hypertable_RangeServer_TimerHandler_h
29 
32 
33 #include <Common/Time.h>
34 
35 #include <boost/shared_ptr.hpp>
36 #include <boost/thread/condition.hpp>
37 
38 #include <chrono>
39 #include <memory>
40 #include <mutex>
41 
42 namespace Hypertable {
43 
44  namespace Apps {
45  class RangeServer;
46  }
47 
50 
58  class TimerHandler : public DispatchHandler {
59 
60  public:
74  TimerHandler(Comm *comm, Apps::RangeServer *range_server);
75 
79  void start();
80 
116  void handle(Hypertable::EventPtr &event);
117 
123 
143 
147 
152  void shutdown();
153 
154  private:
155 
158 
161 
164 
167 
170 
173 
176 
178  std::chrono::steady_clock::time_point m_last_schedule;
179 
181  std::chrono::steady_clock::time_point m_pause_time;
182 
184  int32_t m_timer_interval {};
185 
187  int32_t m_current_interval {};
188 
191 
193  bool m_shutdown {};
194 
197 
200 
203 
206 
212  void pause_app_queue();
213 
218  void restart_app_queue();
219 
222  bool low_memory();
223  };
224 
226  typedef std::shared_ptr<TimerHandler> TimerHandlerPtr;
227 
229 }
230 
231 #endif // Hypertable_RangeServer_TimerHandler_h
232 
static std::mutex mutex
Definition: Logger.cc:43
void handle(Hypertable::EventPtr &event)
Timer event handler callback method.
Abstract base class for application dispatch handlers registered with AsyncComm.
bool low_memory_mode()
Test for low memory mode.
Definition: TimerHandler.h:146
int64_t m_userlog_size_threshold
Pause app queue if USER log exceeds this size.
Definition: TimerHandler.h:172
void shutdown()
Start shutdown sequence.
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
Definition: Event.h:228
bool m_shutdown
Indicates that a shutdown is in progress.
Definition: TimerHandler.h:193
void schedule_immediate_maintenance()
Force maintenance to be scheduled immediately.
Definition: TimerHandler.cc:85
int32_t m_current_interval
Current timer interval (set to 500 when app queue is paused)
Definition: TimerHandler.h:187
Declarations for DispatchHandler.
bool m_low_memory_mode
Low memory mode.
Definition: TimerHandler.h:202
bool m_schedule_outstanding
A maintenance scheduling operation is outstanding.
Definition: TimerHandler.h:205
void restart_app_queue()
Restarts the application queue.
Apps::RangeServer * m_range_server
RangeServer.
Definition: TimerHandler.h:163
void start()
Start timer.
Definition: TimerHandler.cc:78
std::mutex m_mutex
Mutex for serializing access
Definition: TimerHandler.h:157
std::shared_ptr< TimerHandler > TimerHandlerPtr
Smart pointer to TimerHandler.
Definition: TimerHandler.h:226
TimerHandler(Comm *comm, Apps::RangeServer *range_server)
Constructor.
Definition: TimerHandler.cc:51
Time related declarations.
bool low_memory()
Checks for low memory.
Hypertable definitions
int32_t m_timer_interval
Timer interval.
Definition: TimerHandler.h:184
bool m_immediate_maintenance_scheduled
An immediate maintenance timer has been scheduled.
Definition: TimerHandler.h:196
bool m_app_queue_paused
Application queue is paused.
Definition: TimerHandler.h:199
Entry point to AsyncComm service.
Definition: Comm.h:61
void pause_app_queue()
Pauses the application queue.
int64_t m_restart_generation
Generation of maintenance queue signalling application queue restart.
Definition: TimerHandler.h:175
int32_t m_max_app_queue_pause
Maximum time to keep application queue paused each time it is paused.
Definition: TimerHandler.h:190
int64_t m_query_cache_memory
Query cache max size (Hypertable.RangeServer.QueryCache.MaxMemory)
Definition: TimerHandler.h:169
Timer interrupt handler.
Definition: TimerHandler.h:58
std::chrono::steady_clock::time_point m_pause_time
Last time application queue was paused.
Definition: TimerHandler.h:181
std::chrono::steady_clock::time_point m_last_schedule
Last time maintenance was scheduled.
Definition: TimerHandler.h:178
ApplicationQueuePtr m_app_queue
Application queue.
Definition: TimerHandler.h:166
void maintenance_scheduled_notify()
Signal maintenance scheduling complete.
Declarations for ApplicationQueue.
Comm * m_comm
Comm object.
Definition: TimerHandler.h:160
std::shared_ptr< ApplicationQueue > ApplicationQueuePtr
Shared smart pointer to ApplicationQueue object.