Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
failure-detector.h
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 
16 #ifndef STATESTORE_FAILURE_DETECTOR_H
17 #define STATESTORE_FAILURE_DETECTOR_H
18 
19 #include <boost/thread/thread_time.hpp>
20 #include <string>
21 #include <boost/date_time/posix_time/posix_time_types.hpp>
22 #include <boost/thread/mutex.hpp>
23 
24 namespace impala {
25 
34  public:
35  enum PeerState {
36  FAILED = 0,
37  SUSPECTED = 1,
38  OK = 2,
39  UNKNOWN = 3
40  };
41 
42  virtual ~FailureDetector() {}
43 
48  //
53  virtual PeerState UpdateHeartbeat(const std::string& peer, bool seen) = 0;
54 
56  virtual PeerState GetPeerState(const std::string& peer) = 0;
57 
59  virtual void EvictPeer(const std::string& peer) = 0;
60 
62  static const std::string& PeerStateToString(PeerState peer_state);
63 };
64 
73  public:
74  TimeoutFailureDetector(boost::posix_time::time_duration failure_timeout,
75  boost::posix_time::time_duration suspect_timeout)
76  : failure_timeout_(failure_timeout),
77  suspect_timeout_(suspect_timeout) { };
78 
79  virtual PeerState UpdateHeartbeat(const std::string& peer, bool seen);
80 
81  virtual PeerState GetPeerState(const std::string& peer);
82 
83  virtual void EvictPeer(const std::string& peer);
84 
85  private:
87  boost::mutex lock_;
88 
90  std::map<std::string, boost::system_time> peer_heartbeat_record_;
91 
94  const boost::posix_time::time_duration failure_timeout_;
95 
98  const boost::posix_time::time_duration suspect_timeout_;
99 };
100 
109  public:
114  MissedHeartbeatFailureDetector(int32_t max_missed_heartbeats,
115  int32_t suspect_missed_heartbeats)
116  : max_missed_heartbeats_(max_missed_heartbeats),
117  suspect_missed_heartbeats_(suspect_missed_heartbeats) { }
118 
119  virtual PeerState UpdateHeartbeat(const std::string& peer, bool seen);
120 
121  virtual PeerState GetPeerState(const std::string& peer);
122 
123  virtual void EvictPeer(const std::string& peer);
124 
125  private:
127  boost::mutex lock_;
128 
132 
136 
138  std::map<std::string, int32_t> missed_heartbeat_counts_;
139 };
140 
141 }
142 
143 #endif // IMPALA_SPARROW_FAILURE_DETECTOR_H
const boost::posix_time::time_duration suspect_timeout_
MissedHeartbeatFailureDetector(int32_t max_missed_heartbeats, int32_t suspect_missed_heartbeats)
virtual PeerState GetPeerState(const std::string &peer)
Returns the current estimated state of a peer.
boost::mutex lock_
Protects all members.
virtual void EvictPeer(const std::string &peer)
Remove a peer from the failure detector completely.
virtual PeerState GetPeerState(const std::string &peer)=0
Returns the current estimated state of a peer.
const boost::posix_time::time_duration failure_timeout_
virtual PeerState UpdateHeartbeat(const std::string &peer, bool seen)=0
virtual PeerState GetPeerState(const std::string &peer)
Returns the current estimated state of a peer.
virtual void EvictPeer(const std::string &peer)
Remove a peer from the failure detector completely.
boost::mutex lock_
Protects all members.
static const std::string & PeerStateToString(PeerState peer_state)
Utility method to convert a PeerState enum to a string.
std::map< std::string, boost::system_time > peer_heartbeat_record_
Record of last time a successful heartbeat was received.
TimeoutFailureDetector(boost::posix_time::time_duration failure_timeout, boost::posix_time::time_duration suspect_timeout)
std::map< std::string, int32_t > missed_heartbeat_counts_
Number of consecutive heartbeats missed by peer.
virtual PeerState UpdateHeartbeat(const std::string &peer, bool seen)
virtual void EvictPeer(const std::string &peer)=0
Remove a peer from the failure detector completely.
virtual PeerState UpdateHeartbeat(const std::string &peer, bool seen)