summaryrefslogtreecommitdiff
path: root/db/repl/rs_member.h
diff options
context:
space:
mode:
authordwight <dwight@10gen.com>2010-07-22 17:50:54 -0400
committerdwight <dwight@10gen.com>2010-07-22 17:50:54 -0400
commit6212e5c2df3d1ddfb342cef43ffabe396bc0d227 (patch)
tree29aab7c80d0cc0a48b2028429b6ff2d40939e867 /db/repl/rs_member.h
parent48e9ea71fb45963ef1affa03aa689b3c97bbf42d (diff)
downloadmongo-6212e5c2df3d1ddfb342cef43ffabe396bc0d227.tar.gz
rs de-spaghetti
Diffstat (limited to 'db/repl/rs_member.h')
-rw-r--r--db/repl/rs_member.h35
1 files changed, 24 insertions, 11 deletions
diff --git a/db/repl/rs_member.h b/db/repl/rs_member.h
index 3997143ce54..0275684642d 100644
--- a/db/repl/rs_member.h
+++ b/db/repl/rs_member.h
@@ -30,16 +30,30 @@ namespace mongo {
RS_FATAL something bad has occurred and server is not completely offline with regard to the replica set. fatal error.
RS_STARTUP2 loaded config, still determining who is primary
*/
- enum MemberState {
- RS_STARTUP,
- RS_PRIMARY,
- RS_SECONDARY,
- RS_RECOVERING,
- RS_FATAL,
- RS_STARTUP2,
- RS_UNKNOWN, /* remote node not yet reached */
- RS_ARBITER,
- RS_DOWN /* node not reachable for a report */
+ struct MemberState {
+ enum MS {
+ RS_STARTUP,
+ RS_PRIMARY,
+ RS_SECONDARY,
+ RS_RECOVERING,
+ RS_FATAL,
+ RS_STARTUP2,
+ RS_UNKNOWN, /* remote node not yet reached */
+ RS_ARBITER,
+ RS_DOWN /* node not reachable for a report */
+ } s;
+
+ MemberState(MS ms = RS_UNKNOWN) : s(ms) { }
+ explicit MemberState(int ms) : s((MS) ms) { }
+
+ bool primary() const { return s == RS_PRIMARY; }
+ bool secondary() const { return s == RS_SECONDARY; }
+ bool recovering() const { return s == RS_RECOVERING; }
+ bool startup2() const { return s == RS_STARTUP2; }
+ bool fatal() const { return s == RS_FATAL; }
+
+ bool operator==(const MemberState& r) const { return s == r.s; }
+ bool operator!=(const MemberState& r) const { return s != r.s; }
};
/* this is supposed to be just basic information on a member,
@@ -61,7 +75,6 @@ namespace mongo {
};
inline HeartbeatInfo::HeartbeatInfo(unsigned id) : _id(id) {
- hbstate = RS_UNKNOWN;
health = -1.0;
lastHeartbeat = upSince = 0;
}