Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

HA.h

Go to the documentation of this file.
00001 #ifndef MEDUSA_HA_H 00002 #define MEDUSA_HA_H 00003 00004 #include "BasicComponent.h" 00005 #include "Recovery.h" 00006 00007 MEDUSA_NAMESPACE_BEGIN 00008 00009 00019 class HA : public BasicComponent { 00020 00021 public: 00022 00023 // RPC: #include "Schema.h" 00024 // RPC: #include "StreamDef.h" 00025 // RPC: #include "Query.h" 00026 // RPC: #include "Name.h" 00027 00032 class NodeType { 00033 public: 00034 static const NodeType PRIMARY; 00035 static const NodeType REPLICA; 00036 static const NodeType PROVIDER; 00037 static const NodeType NONE; 00038 bool operator==(const NodeType& t) const { 00039 return (t.m_type == m_type); 00040 } 00041 string as_string() const { return m_type; } 00042 // Ideally the constructor should be private to 00043 // ensure that no one creates new instances of PrimaryType 00044 NodeType(string type) : m_type(type) {} 00045 private: 00046 string m_type; 00047 }; 00048 00052 class MonitoredNode { 00053 public: 00054 MonitoredNode(MedusaID id, NodeType t) 00055 : m_node_id(id), m_type(t), m_started(false), m_recovered(false), m_failed_pings(0), 00056 m_pending_ping(false) {} 00057 00059 MedusaID m_node_id; 00060 00062 NodeType m_type; 00063 00065 bool m_started; 00066 00068 bool m_recovered; 00069 00071 int m_failed_pings; 00072 // After a few failed pings we consider monitored node to have failed 00073 static const int MAX_FAILED_PINGS = 3; 00074 00076 bool m_pending_ping; 00077 00078 // The stuff below is only used for PROVIDER type of monitored node so 00079 // we should probably decouple this 00080 // List of streams monitored because of that node and alternates if available 00081 typedef vector< ptr<StreamDef> > AltStreams; // Includes the StreamDef of main stream 00082 typedef map< StreamID, AltStreams > MonitoredStreams; 00083 MonitoredStreams m_streams; 00084 00085 // The stuff below is only used for PRIMARY type of monitored node so 00086 // we should probably decouple this 00088 vector<Query> m_queries; 00090 vector<Subscription> m_subs; 00091 00092 string as_string() const { 00093 return "Monitored {id=" + to_string(m_node_id) + ",type=" + m_type + "}"; 00094 } 00095 }; 00096 00100 class Secondary { 00101 public: 00102 Secondary(MedusaID secondary) 00103 : m_secondary_id(secondary) {} 00104 00106 MedusaID m_secondary_id; 00107 string as_string() const { 00108 return "Secondary {id=" + to_string(m_secondary_id) + "}"; 00109 } 00110 }; 00111 00112 typedef map<MedusaID, ptr<MonitoredNode> > MonitoredNodes; 00113 00114 typedef map<MedusaID, ptr<Secondary> > Secondaries; 00115 00124 HA(string id, string configFileName=DEFAULT_CONFIG_FILE, 00125 RecoveryMethod recovery_method = UPSTREAM_BACKUP); 00126 00127 ~HA() {} 00128 00133 AsyncRPC<void> replicate_query(MedusaID primary, Query query); 00134 00138 AsyncRPC<void> replicate_subs(MedusaID primary, vector<Subscription> subs); 00139 00144 RPC<void> keep_alive(); 00145 00150 RPC<void> failure_notification(MedusaID failed_node, Time time_failure_detected); 00151 00155 RPC<void> start(); 00156 00160 RPC<void> stop(); 00161 00162 00163 NMSTL_RPC_OBJECT(HA); 00164 00169 inline RecoveryMethod get_recovery_method() {return m_recovery_method;}; 00170 00175 inline bool is_primary() {return m_is_primary;}; 00176 00182 RPC< vector<MedusaID> > get_secondary_ids() { return m_secondary_ids; } 00183 00184 protected: 00185 // Starts periodic primary monitoring 00186 void in_thread_init(); 00187 00188 private: 00189 00194 void init_qp(); 00195 00202 void init_config(); 00203 void init_global(const DOMElement* ha_config); 00204 void init_process_pairs(const DOMElement* ha_config); 00205 void init_replicas(const DOMElement* ha_config); 00206 00211 void register_primaries(); 00212 void register_primaries_2(MedusaID primary, RPC<void> result); 00213 00217 void replicate_response(MedusaID secondary, RPC<void> result); 00218 00222 void monitor_nodes(); 00223 00228 void monitor_nodes_2(MedusaID primary,RPC<void> result); 00229 00235 void failure_notification_2(MedusaID failed_node, Time time_failure_detected, RPC<MedusaID> result); 00236 void failure_notification_3(MedusaID failed_node, MedusaID secondary_node, RPC<void> result); 00237 00242 void primary_failure(MedusaID failed_node); 00243 00247 void primary_failure_2(RPC<void> result); 00248 00249 00253 void monitor_admin(); 00254 00258 void admin_stream_notification(RPC<InputStreamInfo> changed_input); 00259 void local_admin_notification(StreamDef changed_input, MonitoredNode::AltStreams& alt_streams); 00260 00264 void admin_query_notification(RPC<Query> new_query); 00265 00269 void admin_sub_notification(RPC< vector<Subscription> > new_subs); 00270 00274 void provider_failure(MedusaID failed_node, Time failure_time); 00275 00280 void update_stream_resp(RPC<void> result); 00281 00286 void generic_qp_resp(RPC<void> result); 00287 00292 ptr<MonitoredNode> get_monitored_node(MedusaID node); 00293 00297 MonitoredNodes m_monitored_nodes; 00298 00300 vector<MedusaID> m_replica_ids; 00301 00305 Secondaries m_secondaries; 00306 vector<MedusaID> m_secondary_ids; 00307 00308 // File with load management and HA config information 00309 string m_configFileName; 00310 int m_ping_interval; 00311 int m_ping_start; 00312 00316 bool m_enabled; 00317 00321 RecoveryMethod m_recovery_method; 00322 00327 bool m_is_primary; 00328 00329 }; 00330 00331 NMSTL_TO_STRING(HA::NodeType); 00332 NMSTL_TO_STRING(HA::MonitoredNode); 00333 NMSTL_TO_STRING(HA::Secondary); 00334 MEDUSA_NAMESPACE_END 00335 00336 #endif

Generated on Fri Nov 12 15:15:21 2004 for Borealis by doxygen 1.3.8