00001 // rs_config.h 00002 // repl set configuration 00003 // 00004 00021 #pragma once 00022 00023 #include "../../util/hostandport.h" 00024 #include "health.h" 00025 00026 namespace mongo { 00027 00028 /* singleton config object is stored here */ 00029 const string rsConfigNs = "local.system.replset"; 00030 00031 class ReplSetConfig { 00032 enum { EMPTYCONFIG = -2 }; 00033 public: 00034 /* if something is misconfigured, throws an exception. 00035 if couldn't be queried or is just blank, ok() will be false. 00036 */ 00037 ReplSetConfig(const HostAndPort& h); 00038 00039 ReplSetConfig(BSONObj cfg); 00040 00041 bool ok() const { return _ok; } 00042 00043 struct MemberCfg { 00044 MemberCfg() : _id(-1), votes(1), priority(1.0), arbiterOnly(false), slaveDelay(0), hidden(false), buildIndexes(true) { } 00045 int _id; /* ordinal */ 00046 unsigned votes; /* how many votes this node gets. default 1. */ 00047 HostAndPort h; 00048 double priority; /* 0 means can never be primary */ 00049 bool arbiterOnly; 00050 int slaveDelay; /* seconds. int rather than unsigned for convenient to/front bson conversion. */ 00051 bool hidden; /* if set, don't advertise to drives in isMaster. for non-primaries (priority 0) */ 00052 bool buildIndexes; /* if false, do not create any non-_id indexes */ 00053 set<string> tags; /* tagging for data center, rack, etc. */ 00054 BSONObj initialSync; /* directions for initial sync source */ 00055 00056 void check() const; /* check validity, assert if not. */ 00057 BSONObj asBson() const; 00058 bool potentiallyHot() const { return !arbiterOnly && priority > 0; } 00059 bool operator==(const MemberCfg& r) const { 00060 return _id==r._id && votes == r.votes && h == r.h && priority == r.priority && 00061 arbiterOnly == r.arbiterOnly && slaveDelay == r.slaveDelay && hidden == r.hidden && 00062 buildIndexes == buildIndexes; 00063 } 00064 bool operator!=(const MemberCfg& r) const { return !(*this == r); } 00065 }; 00066 00067 vector<MemberCfg> members; 00068 string _id; 00069 int version; 00070 HealthOptions ho; 00071 string md5; 00072 BSONObj getLastErrorDefaults; 00073 00074 list<HostAndPort> otherMemberHostnames() const; // except self 00075 00077 bool empty() const { return version == EMPTYCONFIG; } 00078 00079 string toString() const { return asBson().toString(); } 00080 00082 void checkRsConfig() const; 00083 00085 static bool legalChange(const ReplSetConfig& old, const ReplSetConfig& n, string& errmsg); 00086 00087 //static void receivedNewConfig(BSONObj); 00088 void saveConfigLocally(BSONObj comment); // to local db 00089 string saveConfigEverywhere(); // returns textual info on what happened 00090 00091 BSONObj asBson() const; 00092 00093 private: 00094 bool _ok; 00095 void from(BSONObj); 00096 void clear(); 00097 }; 00098 00099 }