0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Context.h
Go to the documentation of this file.
1 /* -*- c++ -*-
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 
28 #ifndef Hypertable_Master_Context_h
29 #define Hypertable_Master_Context_h
30 
31 #include "HyperspaceMasterFile.h"
32 #include "MetricsHandler.h"
33 #include "Monitoring.h"
34 #include "RangeServerConnection.h"
36 #include "RecoveredServers.h"
37 #include "RecoveryStepFuture.h"
38 #include "SystemState.h"
39 
43 #include <Hypertable/Lib/Table.h>
44 
45 #include <Hyperspace/Session.h>
46 
47 #include <AsyncComm/Comm.h>
50 
51 #include <Common/Filesystem.h>
52 #include <Common/Properties.h>
53 #include <Common/StringExt.h>
54 #include <Common/Thread.h>
55 
56 #include <boost/multi_index_container.hpp>
57 #include <boost/multi_index/hashed_index.hpp>
58 #include <boost/multi_index/mem_fun.hpp>
59 #include <boost/multi_index/sequenced_index.hpp>
60 #include <boost/multi_index/member.hpp>
61 #include <boost/thread/condition.hpp>
62 
63 #include <condition_variable>
64 #include <memory>
65 #include <mutex>
66 #include <set>
67 #include <unordered_map>
68 
69 using namespace Hypertable::Master;
70 
71 namespace Hypertable {
72 
75 
76  class LoadBalancer;
77  class Operation;
79  class OperationProcessor;
80  class ResponseManager;
81  class ReferenceManager;
83 
85  class Context : public std::enable_shared_from_this<Context> {
86 
87  class RecoveryState {
88  public:
89  void install_replay_future(int64_t id, RecoveryStepFuturePtr &future);
91  void erase_replay_future(int64_t id);
92 
93  void install_prepare_future(int64_t id, RecoveryStepFuturePtr &future);
95  void erase_prepare_future(int64_t id);
96 
97  void install_commit_future(int64_t id, RecoveryStepFuturePtr &future);
99  void erase_commit_future(int64_t id);
100 
101  private:
102  friend class Context;
103 
104  typedef std::map<int64_t, RecoveryStepFuturePtr> FutureMap;
105 
107  FutureMap m_replay_map;
108  FutureMap m_prepare_map;
109  FutureMap m_commit_map;
110  };
111 
112  public:
113 
119 
121 
123  ~Context();
124 
128  bool set_startup_status(bool status);
129 
132  bool startup_in_progress();
133 
135  void start_shutdown();
136 
139  bool shutdown_in_progress();
140 
142  std::condition_variable cond;
143  Comm *comm {};
156  std::unique_ptr<HyperspaceMasterFile> master_file;
160  std::unique_ptr<ReferenceManager> reference_manager;
161  std::unique_ptr<Thread> response_manager_thread;
162  std::unique_ptr<ResponseManager> response_manager;
168  time_t request_timeout {};
169  uint32_t timer_interval {};
170  uint32_t monitoring_interval {};
171  uint32_t gc_interval {};
173  time_t next_gc_time {};
174  std::unique_ptr<OperationProcessor> op;
175  std::shared_ptr<OperationTimedBarrier> recovery_barrier_op;
178  int32_t disk_threshold {};
179  int32_t max_allowable_skew {};
180  bool test_mode {};
181  bool quorum_reached {};
182 
196  bool add_move_operation(std::shared_ptr<Operation> operation);
197 
203  void remove_move_operation(std::shared_ptr<Operation> operation);
204 
213  std::shared_ptr<Operation> get_move_operation(int64_t hash_code);
214 
215  void add_available_server(const String &location);
216  void remove_available_server(const String &location);
217  size_t available_server_count();
218  void get_available_servers(StringSet &servers);
219 
220  bool can_accept_ranges(const RangeServerStatistics &stats);
221  void replay_status(EventPtr &event);
222  void replay_complete(EventPtr &event);
223  void prepare_complete(EventPtr &event);
224  void commit_complete(EventPtr &event);
225 
227  void notification_hook(const String &subject, const String &message);
228 
231 
232  // get the BalancePlanAuthority; this creates a new instance when
233  // called for the very first time
235 
236  // Gets smart pointer to BalancePlanAuthority.
238 
240 
241  // Instantiate a new table object
242  TablePtr new_table(const std::string &name);
243 
244  private:
245 
247 
250 
253 
255  std::unordered_map<int64_t, int64_t> m_outstanding_move_ops;
256 
258  bool m_startup {true};
259 
261  bool m_shutdown {};
262  };
263 
265  typedef std::shared_ptr<Context> ContextPtr;
266 
268 
269 }
270 
271 #endif // Hypertable_Master_Context_h
std::set< String > StringSet
STL Set managing Strings.
Definition: StringExt.h:42
String cluster_name
Name of cluster.
Definition: Context.h:176
StringSet available_servers
Definition: Context.h:146
ApplicationQueuePtr app_queue
Definition: Context.h:151
static std::mutex mutex
Definition: Logger.cc:43
Context(PropertiesPtr &p)
Definition: Context.h:120
std::shared_ptr< MetricsHandler > MetricsHandlerPtr
Smart pointer to MetricsHandler.
void install_prepare_future(int64_t id, RecoveryStepFuturePtr &future)
Definition: Context.cc:466
bool add_move_operation(std::shared_ptr< Operation > operation)
Adds operation to active move range operation map.
Definition: Context.cc:364
Abstract base class for a filesystem.
TablePtr rs_metrics_table
Definition: Context.h:167
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
std::shared_ptr< Entity > EntityPtr
Smart pointer to Entity.
RecoveryStepFuturePtr get_commit_future(int64_t id)
Definition: Context.cc:496
std::mutex m_outstanding_move_ops_mutex
Mutex for serializing access to m_outstanding_move_ops
Definition: Context.h:252
void status(ResponseCallbackStatus *cb)
Definition: Master.cc:1194
std::shared_ptr< RangeLocator > RangeLocatorPtr
Smart pointer to RangeLocator.
Definition: RangeLocator.h:198
time_t request_timeout
Definition: Context.h:168
Declarations for RecoveredServers.
ConnectionManagerPtr conn_manager
Definition: Context.h:148
LoadBalancer * balancer
Definition: Context.h:157
Program options handling.
int32_t max_allowable_skew
Definition: Context.h:179
void remove_move_operation(std::shared_ptr< Operation > operation)
Removes operation from active move range operation map.
Definition: Context.cc:373
MonitoringPtr monitoring
Definition: Context.h:158
bool set_startup_status(bool status)
Set startup flag to false.
Definition: Context.cc:116
TablePtr new_table(const std::string &name)
Definition: Context.cc:197
Declarations for MetaLog::Definition.
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
Definition: Event.h:228
SystemStatePtr system_state
System state entity.
Definition: Context.h:144
std::shared_ptr< SystemState > SystemStatePtr
Shared smart pointer to SystemState.
Definition: SystemState.h:191
std::unique_ptr< ResponseManager > response_manager
Definition: Context.h:162
RecoveryState m_recovery_state
Definition: Context.h:246
Holds references to operations that are to be manually removed.
std::unique_ptr< Thread > response_manager_thread
Definition: Context.h:161
void start_shutdown()
Start shutdown sequence.
Definition: Context.cc:130
void erase_prepare_future(int64_t id)
Definition: Context.cc:482
bool can_accept_ranges(const RangeServerStatistics &stats)
Definition: Context.cc:413
std::shared_ptr< Context > ContextPtr
Smart pointer to Context.
Definition: Context.h:265
Hyperspace definitions
int32_t disk_threshold
Disk use threshold percentage.
Definition: Context.h:178
RecoveryState & recovery_state()
Definition: Context.h:239
PropertiesPtr props
Configuration properties.
Definition: Context.h:147
Declarations for SystemState.
uint32_t monitoring_interval
Definition: Context.h:170
std::shared_ptr< RecoveryStepFuture > RecoveryStepFuturePtr
std::shared_ptr< Monitoring > MonitoringPtr
Definition: Monitoring.h:175
RangeLocatorPtr range_locator
Definition: Context.h:152
void erase_replay_future(int64_t id)
Definition: Context.cc:459
std::shared_ptr< Session > SessionPtr
Definition: Session.h:734
std::unique_ptr< OperationProcessor > op
Definition: Context.h:174
Hyperspace::SessionPtr hyperspace
Definition: Context.h:150
void prepare_complete(EventPtr &event)
Definition: Context.cc:282
MetaLog::DefinitionPtr mml_definition
Definition: Context.h:164
std::shared_ptr< Properties > PropertiesPtr
Definition: Properties.h:447
std::shared_ptr< RecoveredServers > RecoveredServersPtr
Smart pointer to RecoveredServers.
void remove_available_server(const String &location)
Definition: Context.cc:397
String location_hash
Definition: Context.h:177
RecoveredServersPtr recovered_servers
Definition: Context.h:159
void replay_status(EventPtr &event)
Definition: Context.cc:205
Declarations for HyperspaceMasterFile.
String toplevel_dir
Definition: Context.h:153
Importing boost::thread and boost::thread_group into the Hypertable namespace.
FilesystemPtr dfs
Definition: Context.h:165
void install_replay_future(int64_t id, RecoveryStepFuturePtr &future)
Definition: Context.cc:443
std::unique_ptr< HyperspaceMasterFile > master_file
Hyperspace master file handle
Definition: Context.h:156
Manages the sending of operation results back to clients.
bool shutdown_in_progress()
Gets flag indicating if server is shutting down.
Definition: Context.cc:149
Context(PropertiesPtr &p, Hyperspace::SessionPtr hs)
Context.
Definition: Context.cc:57
Hypertable definitions
RecoveryStepFuturePtr get_prepare_future(int64_t id)
Definition: Context.cc:473
std::shared_ptr< OperationTimedBarrier > recovery_barrier_op
Definition: Context.h:175
std::unordered_map< int64_t, int64_t > m_outstanding_move_ops
Map of outstanding move range operations.
Definition: Context.h:255
Declarations for MetaLog::Writer.
uint32_t timer_interval
Definition: Context.h:169
Central authority for balance plans.
MetaLog::WriterPtr mml_writer
Definition: Context.h:163
Entry point to AsyncComm service.
Definition: Comm.h:61
std::shared_ptr< Writer > WriterPtr
Smart pointer to Writer.
Declarations for ConnectionManager.
std::shared_ptr< Filesystem > FilesystemPtr
Smart pointer to Filesystem.
Definition: Filesystem.h:572
void set_balance_plan_authority(MetaLog::EntityPtr bpa)
Sets the BalancePlanAuthority.
Definition: Context.cc:177
Declarations for Comm.
TablePtr metadata_table
Definition: Context.h:166
void install_commit_future(int64_t id, RecoveryStepFuturePtr &future)
Definition: Context.cc:489
Abstract base class for master operations.
Definition: Operation.h:124
std::shared_ptr< RangeServerConnectionManager > RangeServerConnectionManagerPtr
Comm * comm
Comm layer.
Definition: Context.h:143
Execution context for the Master.
Definition: Context.h:85
Runs a set of operaions with dependency relationships.
MetaLog::EntityPtr m_balance_plan_authority
BalancePlanAuthority entity.
Definition: Context.h:249
uint32_t gc_interval
Definition: Context.h:171
bool m_startup
Flag indicating that server is starting up.
Definition: Context.h:258
bool startup_in_progress()
Gets flag indicating if server is starting up.
Definition: Context.cc:126
std::unique_ptr< ReferenceManager > reference_manager
Definition: Context.h:160
NameIdMapperPtr namemap
Definition: Context.h:154
std::map< int64_t, RecoveryStepFuturePtr > FutureMap
Definition: Context.h:104
void erase_commit_future(int64_t id)
Definition: Context.cc:505
RecoveryStepFuturePtr get_replay_future(int64_t id)
Definition: Context.cc:450
void commit_complete(EventPtr &event)
Definition: Context.cc:323
Declarations for ApplicationQueue.
std::mutex mutex
Definition: Context.h:141
std::shared_ptr< ConnectionManager > ConnectionManagerPtr
Smart pointer to ConnectionManager.
Declarations for MetricsHandler.
std::condition_variable cond
Definition: Context.h:142
time_t next_monitoring_time
Definition: Context.h:172
std::shared_ptr< ApplicationQueue > ApplicationQueuePtr
Shared smart pointer to ApplicationQueue object.
size_t available_server_count()
Definition: Context.cc:402
String extensions and helpers: sets, maps, append operators etc.
void replay_complete(EventPtr &event)
Definition: Context.cc:240
void get_available_servers(StringSet &servers)
Definition: Context.cc:407
std::shared_ptr< Operation > get_move_operation(int64_t hash_code)
Gets operation from active move range operation map.
Definition: Context.cc:381
std::shared_ptr< NameIdMapper > NameIdMapperPtr
Smart pointer to NameIdMapper.
Definition: NameIdMapper.h:121
BalancePlanAuthority * get_balance_plan_authority()
Definition: Context.cc:183
void notification_hook(const String &subject, const String &message)
Invoke notification hook.
Definition: Context.cc:156
MetricsHandlerPtr metrics_handler
Definition: Context.h:149
void add_available_server(const String &location)
Definition: Context.cc:392
std::shared_ptr< Table > TablePtr
Definition: Table.h:53
RangeServerConnectionManagerPtr rsc_manager
Definition: Context.h:145
std::shared_ptr< Definition > DefinitionPtr
Smart pointer to Definition.
time_t next_gc_time
Definition: Context.h:173
bool m_shutdown
Flag indicating that server is shutting down.
Definition: Context.h:261
~Context()
Destructor.
Definition: Context.cc:109