diff options
author | John Spray <john.spray@redhat.com> | 2014-07-21 21:22:46 +0200 |
---|---|---|
committer | John Spray <john.spray@redhat.com> | 2014-07-29 23:32:43 +0200 |
commit | 07665ec4b333bb41ec81c477b50e5fcba52890f2 (patch) | |
tree | 25d0dd050f10a1a0a0a41a8e39768f6160bb3245 | |
parent | mds: refactor MDS boot (diff) | |
download | ceph-07665ec4b333bb41ec81c477b50e5fcba52890f2.tar.xz ceph-07665ec4b333bb41ec81c477b50e5fcba52890f2.zip |
mds: introduce explicit DaemonState instead of int
Signed-off-by: John Spray <john.spray@redhat.com>
-rw-r--r-- | src/ceph_mds.cc | 4 | ||||
-rw-r--r-- | src/mds/MDS.cc | 22 | ||||
-rw-r--r-- | src/mds/MDS.h | 12 | ||||
-rw-r--r-- | src/mds/MDSMap.cc | 6 | ||||
-rw-r--r-- | src/mds/MDSMap.h | 79 | ||||
-rw-r--r-- | src/messages/MMDSBeacon.h | 10 | ||||
-rw-r--r-- | src/mon/MDSMonitor.cc | 8 |
7 files changed, 82 insertions, 59 deletions
diff --git a/src/ceph_mds.cc b/src/ceph_mds.cc index 3e9fb223bd5..b1ab386cc67 100644 --- a/src/ceph_mds.cc +++ b/src/ceph_mds.cc @@ -94,7 +94,7 @@ int main(int argc, const char **argv) global_init(NULL, args, CEPH_ENTITY_TYPE_MDS, CODE_ENVIRONMENT_DAEMON, 0); // mds specific args - int shadow = 0; + MDSMap::DaemonState shadow = MDSMap::STATE_NULL; std::string dump_file; std::string val, action; @@ -104,7 +104,7 @@ int main(int argc, const char **argv) } else if (ceph_argparse_witharg(args, i, &val, "--journal-check", (char*)NULL)) { int r = parse_rank("journal-check", val); - if (shadow) { + if (shadow != MDSMap::STATE_NULL) { dout(0) << "Error: can only select one standby state" << dendl; return -1; } diff --git a/src/mds/MDS.cc b/src/mds/MDS.cc index 3a9adb2ec00..65a5a252b19 100644 --- a/src/mds/MDS.cc +++ b/src/mds/MDS.cc @@ -98,7 +98,7 @@ MDS::MDS(const std::string &n, Messenger *m, MonClient *mc) : name(n), whoami(-1), incarnation(0), standby_for_rank(MDSMap::MDS_NO_STANDBY_PREF), - standby_type(0), + standby_type(MDSMap::STATE_NULL), standby_replaying(false), messenger(m), monc(mc), @@ -573,7 +573,7 @@ void MDS::send_message_client(Message *m, Session *session) } } -int MDS::init(int wanted_state) +int MDS::init(MDSMap::DaemonState wanted_state) { dout(10) << sizeof(MDSCacheObject) << "\tMDSCacheObject" << dendl; dout(10) << sizeof(CInode) << "\tCInode" << dendl; @@ -647,14 +647,16 @@ int MDS::init(int wanted_state) } mds_lock.Lock(); - if (want_state == CEPH_MDS_STATE_DNE) { + if (want_state == MDSMap::STATE_DNE) { suicide(); // we could do something more graceful here } timer.init(); - if (wanted_state==MDSMap::STATE_BOOT && g_conf->mds_standby_replay) + if (wanted_state==MDSMap::STATE_BOOT && g_conf->mds_standby_replay) { wanted_state = MDSMap::STATE_STANDBY_REPLAY; + } + // starting beacon. this will induce an MDSMap from the monitor want_state = wanted_state; if (wanted_state==MDSMap::STATE_STANDBY_REPLAY || @@ -681,7 +683,7 @@ int MDS::init(int wanted_state) standby_for_rank = MDSMap::MDS_STANDBY_ANY; else standby_for_rank = MDSMap::MDS_STANDBY_NAME; - } else if (!standby_type && !standby_for_name.empty()) + } else if (standby_type == MDSMap::STATE_NULL && !standby_for_name.empty()) standby_for_rank = MDSMap::MDS_MATCHED_ACTIVE; beacon_start(); @@ -1023,7 +1025,7 @@ void MDS::handle_mds_map(MMDSMap *m) // keep old map, for a moment MDSMap *oldmap = mdsmap; int oldwhoami = whoami; - int oldstate = state; + MDSMap::DaemonState oldstate = state; entity_addr_t addr; // decode and process @@ -1074,7 +1076,7 @@ void MDS::handle_mds_map(MMDSMap *m) goto out; } else if (state == MDSMap::STATE_STANDBY_REPLAY) { - if (standby_type && standby_type != MDSMap::STATE_STANDBY_REPLAY) { + if (standby_type != MDSMap::STATE_NULL && standby_type != MDSMap::STATE_STANDBY_REPLAY) { want_state = standby_type; beacon_send(); state = oldstate; @@ -1309,7 +1311,7 @@ void MDS::bcast_mds_map() } -void MDS::request_state(int s) +void MDS::request_state(MDSMap::DaemonState s) { dout(3) << "request_state " << ceph_mds_state_name(s) << dendl; want_state = s; @@ -1494,7 +1496,7 @@ void MDS::replay_start() if (is_standby_replay()) standby_replaying = true; - standby_type = 0; + standby_type = MDSMap::STATE_NULL; calc_recovery_set(); @@ -1801,7 +1803,7 @@ void MDS::handle_signal(int signum) void MDS::suicide() { assert(mds_lock.is_locked()); - want_state = CEPH_MDS_STATE_DNE; // whatever. + want_state = MDSMap::STATE_DNE; // whatever. dout(1) << "suicide. wanted " << ceph_mds_state_name(want_state) << ", now " << ceph_mds_state_name(state) << dendl; diff --git a/src/mds/MDS.h b/src/mds/MDS.h index 5beba79fd70..493857a8cb4 100644 --- a/src/mds/MDS.h +++ b/src/mds/MDS.h @@ -153,7 +153,7 @@ class MDS : public Dispatcher, public md_config_obs_t { int incarnation; int standby_for_rank; - int standby_type; + MDSMap::DaemonState standby_type; // one of STANDBY_REPLAY, ONESHOT_REPLAY string standby_for_name; bool standby_replaying; // true if current replay pass is in standby-replay mode @@ -188,9 +188,9 @@ class MDS : public Dispatcher, public md_config_obs_t { protected: // -- MDS state -- - int last_state; - int state; // my confirmed state - int want_state; // the state i want + MDSMap::DaemonState last_state; + MDSMap::DaemonState state; // my confirmed state + MDSMap::DaemonState want_state; // the state i want list<Context*> waiting_for_active, waiting_for_replay, waiting_for_reconnect, waiting_for_resolve; list<Context*> replay_queue; @@ -245,7 +245,7 @@ class MDS : public Dispatcher, public md_config_obs_t { bool is_stopped() { return mdsmap->is_stopped(whoami); } - void request_state(int s); + void request_state(MDSMap::DaemonState s); ceph_tid_t issue_tid() { return ++last_tid; } @@ -357,7 +357,7 @@ class MDS : public Dispatcher, public md_config_obs_t { } // start up, shutdown - int init(int wanted_state=MDSMap::STATE_BOOT); + int init(MDSMap::DaemonState wanted_state=MDSMap::STATE_BOOT); // admin socket handling friend class MDSSocketHook; diff --git a/src/mds/MDSMap.cc b/src/mds/MDSMap.cc index 97b148b94cc..c015370fa7f 100644 --- a/src/mds/MDSMap.cc +++ b/src/mds/MDSMap.cc @@ -365,7 +365,7 @@ void MDSMap::mds_info_t::encode_versioned(bufferlist& bl, uint64_t features) con ::encode(name, bl); ::encode(rank, bl); ::encode(inc, bl); - ::encode(state, bl); + ::encode((int32_t)state, bl); ::encode(state_seq, bl); ::encode(addr, bl); ::encode(laggy_since, bl); @@ -383,7 +383,7 @@ void MDSMap::mds_info_t::encode_unversioned(bufferlist& bl) const ::encode(name, bl); ::encode(rank, bl); ::encode(inc, bl); - ::encode(state, bl); + ::encode((int32_t)state, bl); ::encode(state_seq, bl); ::encode(addr, bl); ::encode(laggy_since, bl); @@ -399,7 +399,7 @@ void MDSMap::mds_info_t::decode(bufferlist::iterator& bl) ::decode(name, bl); ::decode(rank, bl); ::decode(inc, bl); - ::decode(state, bl); + ::decode((int32_t&)(state), bl); ::decode(state_seq, bl); ::decode(addr, bl); ::decode(laggy_since, bl); diff --git a/src/mds/MDSMap.h b/src/mds/MDSMap.h index 6923fa3c425..77ffa04de63 100644 --- a/src/mds/MDSMap.h +++ b/src/mds/MDSMap.h @@ -75,29 +75,43 @@ extern CompatSet get_mdsmap_compat_set_base(); // pre v0.20 class MDSMap { public: - // mds states - /* - static const int STATE_DNE = CEPH_MDS_STATE_DNE; // down, never existed. - static const int STATE_DESTROYING = CEPH_MDS_STATE_DESTROYING; // down, existing, semi-destroyed. - static const int STATE_FAILED = CEPH_MDS_STATE_FAILED; // down, active subtrees; needs to be recovered. - */ - static const int STATE_STOPPED = CEPH_MDS_STATE_STOPPED; // down, once existed, but no subtrees. empty log. - static const int STATE_BOOT = CEPH_MDS_STATE_BOOT; // up, boot announcement. destiny unknown. - - static const int STATE_STANDBY = CEPH_MDS_STATE_STANDBY; // up, idle. waiting for assignment by monitor. - static const int STATE_STANDBY_REPLAY = CEPH_MDS_STATE_STANDBY_REPLAY; // up, replaying active node; ready to take over. - static const int STATE_ONESHOT_REPLAY = CEPH_MDS_STATE_REPLAYONCE; //up, replaying active node journal to verify it, then shutting down - - static const int STATE_CREATING = CEPH_MDS_STATE_CREATING; // up, creating MDS instance (new journal, idalloc..). - static const int STATE_STARTING = CEPH_MDS_STATE_STARTING; // up, starting prior stopped MDS instance. - - static const int STATE_REPLAY = CEPH_MDS_STATE_REPLAY; // up, starting prior failed instance. scanning journal. - static const int STATE_RESOLVE = CEPH_MDS_STATE_RESOLVE; // up, disambiguating distributed operations (import, rename, etc.) - static const int STATE_RECONNECT = CEPH_MDS_STATE_RECONNECT; // up, reconnect to clients - static const int STATE_REJOIN = CEPH_MDS_STATE_REJOIN; // up, replayed journal, rejoining distributed cache - static const int STATE_CLIENTREPLAY = CEPH_MDS_STATE_CLIENTREPLAY; // up, active - static const int STATE_ACTIVE = CEPH_MDS_STATE_ACTIVE; // up, active - static const int STATE_STOPPING = CEPH_MDS_STATE_STOPPING; // up, exporting metadata (-> standby or out) + /* These states are the union of the set of possible states of an MDS daemon, + * and the set of possible states of an MDS rank */ + typedef enum { + // States of an MDS daemon not currently holding a rank + // ==================================================== + STATE_NULL = 0, // null value for fns returning this type. + STATE_BOOT = CEPH_MDS_STATE_BOOT, // up, boot announcement. destiny unknown. + STATE_STANDBY = CEPH_MDS_STATE_STANDBY, // up, idle. waiting for assignment by monitor. + STATE_STANDBY_REPLAY = CEPH_MDS_STATE_STANDBY_REPLAY, // up, replaying active node, ready to take over. + + // States of an MDS rank, and of any MDS daemon holding that rank + // ============================================================== + STATE_STOPPED = CEPH_MDS_STATE_STOPPED, // down, once existed, but no subtrees. empty log. may not be held by a daemon. + STATE_ONESHOT_REPLAY = CEPH_MDS_STATE_REPLAYONCE, // up, replaying active node journal to verify it, then shutting down + + STATE_CREATING = CEPH_MDS_STATE_CREATING, // up, creating MDS instance (new journal, idalloc..). + STATE_STARTING = CEPH_MDS_STATE_STARTING, // up, starting prior stopped MDS instance. + + STATE_REPLAY = CEPH_MDS_STATE_REPLAY, // up, starting prior failed instance. scanning journal. + STATE_RESOLVE = CEPH_MDS_STATE_RESOLVE, // up, disambiguating distributed operations (import, rename, etc.) + STATE_RECONNECT = CEPH_MDS_STATE_RECONNECT, // up, reconnect to clients + STATE_REJOIN = CEPH_MDS_STATE_REJOIN, // up, replayed journal, rejoining distributed cache + STATE_CLIENTREPLAY = CEPH_MDS_STATE_CLIENTREPLAY, // up, active + STATE_ACTIVE = CEPH_MDS_STATE_ACTIVE, // up, active + STATE_STOPPING = CEPH_MDS_STATE_STOPPING, // up, exporting metadata (-> standby or out) + STATE_DNE = CEPH_MDS_STATE_DNE // down, rank does not exist + + /* + * In addition to explicit states, an MDS rank implicitly in state: + * - STOPPED if it is not currently associated with an MDS daemon gid but it + * is in MDSMap::stopped + * - FAILED if it is not currently associated with an MDS daemon gid but it + * is in MDSMap::failed + * - DNE if it is not currently associated with an MDS daemon gid and it is + * missing from both MDSMap::failed and MDSMap::stopped + */ + } DaemonState; // indicate startup standby preferences for MDS // of course, if they have a specific rank to follow, they just set that! @@ -114,7 +128,7 @@ public: string name; int32_t rank; int32_t inc; - int32_t state; + MDSMap::DaemonState state; version_t state_seq; entity_addr_t addr; utime_t laggy_since; @@ -347,7 +361,7 @@ public: if (p->second.state >= STATE_CLIENTREPLAY && p->second.state <= STATE_STOPPING) s.insert(p->second.rank); } - void get_mds_set(set<int>& s, int state) { + void get_mds_set(set<int>& s, DaemonState state) { for (map<uint64_t,mds_info_t>::const_iterator p = mds_info.begin(); p != mds_info.end(); ++p) @@ -432,16 +446,23 @@ public: bool is_dne(int m) const { return in.count(m) == 0; } bool is_dne_gid(uint64_t gid) const { return mds_info.count(gid) == 0; } - int get_state(int m) const { + /** + * Get MDS rank state if the rank is up, else STATE_NULL + */ + DaemonState get_state(int m) const { map<int32_t,uint64_t>::const_iterator u = up.find(m); if (u == up.end()) - return 0; + return STATE_NULL; return get_state_gid(u->second); } - int get_state_gid(uint64_t gid) const { + + /** + * Get MDS daemon status by GID + */ + DaemonState get_state_gid(uint64_t gid) const { map<uint64_t,mds_info_t>::const_iterator i = mds_info.find(gid); if (i == mds_info.end()) - return 0; + return STATE_NULL; return i->second.state; } diff --git a/src/messages/MMDSBeacon.h b/src/messages/MMDSBeacon.h index 64d442bf958..40aa73e6d36 100644 --- a/src/messages/MMDSBeacon.h +++ b/src/messages/MMDSBeacon.h @@ -31,7 +31,7 @@ class MMDSBeacon : public PaxosServiceMessage { uint64_t global_id; string name; - __u32 state; + MDSMap::DaemonState state; version_t seq; __s32 standby_for_rank; string standby_for_name; @@ -40,7 +40,7 @@ class MMDSBeacon : public PaxosServiceMessage { public: MMDSBeacon() : PaxosServiceMessage(MSG_MDS_BEACON, 0, HEAD_VERSION) { } - MMDSBeacon(const uuid_d &f, uint64_t g, string& n, epoch_t les, int st, version_t se) : + MMDSBeacon(const uuid_d &f, uint64_t g, string& n, epoch_t les, MDSMap::DaemonState st, version_t se) : PaxosServiceMessage(MSG_MDS_BEACON, les, HEAD_VERSION), fsid(f), global_id(g), name(n), state(st), seq(se), standby_for_rank(-1) { @@ -53,7 +53,7 @@ public: uint64_t get_global_id() { return global_id; } string& get_name() { return name; } epoch_t get_last_epoch_seen() { return version; } - int get_state() { return state; } + MDSMap::DaemonState get_state() { return state; } version_t get_seq() { return seq; } const char *get_type_name() const { return "mdsbeacon"; } int get_standby_for_rank() { return standby_for_rank; } @@ -75,7 +75,7 @@ public: paxos_encode(); ::encode(fsid, payload); ::encode(global_id, payload); - ::encode(state, payload); + ::encode((__u32)state, payload); ::encode(seq, payload); ::encode(name, payload); ::encode(standby_for_rank, payload); @@ -87,7 +87,7 @@ public: paxos_decode(p); ::decode(fsid, p); ::decode(global_id, p); - ::decode(state, p); + ::decode((__u32&)state, p); ::decode(seq, p); ::decode(name, p); ::decode(standby_for_rank, p); diff --git a/src/mon/MDSMonitor.cc b/src/mon/MDSMonitor.cc index eed77913f41..70180bc1068 100644 --- a/src/mon/MDSMonitor.cc +++ b/src/mon/MDSMonitor.cc @@ -201,7 +201,7 @@ void MDSMonitor::_note_beacon(MMDSBeacon *m) bool MDSMonitor::preprocess_beacon(MMDSBeacon *m) { - int state = m->get_state(); + MDSMap::DaemonState state = m->get_state(); uint64_t gid = m->get_global_id(); version_t seq = m->get_seq(); MDSMap::mds_info_t info; @@ -377,7 +377,7 @@ bool MDSMonitor::prepare_beacon(MMDSBeacon *m) dout(12) << "prepare_beacon " << *m << " from " << m->get_orig_source_inst() << dendl; entity_addr_t addr = m->get_orig_source_inst().addr; uint64_t gid = m->get_global_id(); - int state = m->get_state(); + MDSMap::DaemonState state = m->get_state(); version_t seq = m->get_seq(); // Ignore beacons if filesystem is disabled @@ -1261,7 +1261,7 @@ bool MDSMonitor::filesystem_command( r = -EINVAL; return true; } - int64_t state; + int32_t state; if (!cmd_getval(g_ceph_context, cmdmap, "state", state)) { ss << "error parsing 'state' string value '" << cmd_vartype_stringify(cmdmap["state"]) << "'"; @@ -1270,7 +1270,7 @@ bool MDSMonitor::filesystem_command( } if (!pending_mdsmap.is_dne_gid(gid)) { MDSMap::mds_info_t& info = pending_mdsmap.get_info_gid(gid); - info.state = state; + info.state = MDSMap::DaemonState(state); stringstream ss; ss << "set mds gid " << gid << " to state " << state << " " << ceph_mds_state_name(state); r = 0; |