From: Varsha Rao Date: Thu, 24 Oct 2019 11:07:11 +0000 (+0530) Subject: mds: Reorganize class members in MDSMap header X-Git-Tag: v15.1.0~473^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=67aa4afbed9d5497c9bc53bef2add1eada43085a;p=ceph.git mds: Reorganize class members in MDSMap header Fixes: https://tracker.ceph.com/issues/42464 Signed-off-by: Varsha Rao --- diff --git a/src/mds/MDSMap.cc b/src/mds/MDSMap.cc index 1cc476f81c21..33c9fc56de90 100644 --- a/src/mds/MDSMap.cc +++ b/src/mds/MDSMap.cc @@ -944,3 +944,92 @@ bool MDSMap::check_health(mds_rank_t standby_daemon_count) } return false; } + +mds_gid_t MDSMap::find_mds_gid_by_name(std::string_view s) const { + for (const auto& [gid, info] : mds_info) { + if (info.name == s) { + return gid; + } + } + return MDS_GID_NONE; +} + +unsigned MDSMap::get_num_mds(int state) const { + unsigned n = 0; + for (std::map::const_iterator p = mds_info.begin(); + p != mds_info.end(); + ++p) + if (p->second.state == state) ++n; + return n; +} + +void MDSMap::get_up_mds_set(std::set& s) const { + for (std::map::const_iterator p = up.begin(); + p != up.end(); + ++p) + s.insert(p->first); +} + +uint64_t MDSMap::get_up_features() { + if (!cached_up_features) { + bool first = true; + for (std::map::const_iterator p = up.begin(); + p != up.end(); + ++p) { + std::map::const_iterator q = + mds_info.find(p->second); + ceph_assert(q != mds_info.end()); + if (first) { + cached_up_features = q->second.mds_features; + first = false; + } else { + cached_up_features &= q->second.mds_features; + } + } + } + return cached_up_features; +} + +void MDSMap::get_recovery_mds_set(std::set& s) const { + s = failed; + for (const auto& p : damaged) + s.insert(p); + for (const auto& p : mds_info) + if (p.second.state >= STATE_REPLAY && p.second.state <= STATE_STOPPING) + s.insert(p.second.rank); +} + +void MDSMap::get_mds_set_lower_bound(std::set& s, DaemonState first) const { + for (std::map::const_iterator p = mds_info.begin(); + p != mds_info.end(); + ++p) + if (p->second.state >= first && p->second.state <= STATE_STOPPING) + s.insert(p->second.rank); +} + +void MDSMap::get_mds_set(std::set& s, DaemonState state) const { + for (std::map::const_iterator p = mds_info.begin(); + p != mds_info.end(); + ++p) + if (p->second.state == state) + s.insert(p->second.rank); +} + +mds_gid_t MDSMap::get_standby_replay(mds_rank_t r) const { + for (auto& [gid,info] : mds_info) { + if (info.rank == r && info.state == STATE_STANDBY_REPLAY) { + return gid; + } + } + return MDS_GID_NONE; +} + +bool MDSMap::is_degraded() const { + if (!failed.empty() || !damaged.empty()) + return true; + for (const auto& p : mds_info) { + if (p.second.is_degraded()) + return true; + } + return false; +} diff --git a/src/mds/MDSMap.h b/src/mds/MDSMap.h index 4f361e3ea3c4..91f299807c47 100644 --- a/src/mds/MDSMap.h +++ b/src/mds/MDSMap.h @@ -12,7 +12,6 @@ * */ - #ifndef CEPH_MDSMAP_H #define CEPH_MDSMAP_H @@ -36,9 +35,6 @@ #include "mds/mdstypes.h" -class CephContext; -class health_check_map_t; - #define MDS_FEATURE_INCOMPAT_BASE CompatSet::Feature(1, "base v0.20") #define MDS_FEATURE_INCOMPAT_CLIENTRANGES CompatSet::Feature(2, "client writeable ranges") #define MDS_FEATURE_INCOMPAT_FILELAYOUT CompatSet::Feature(3, "default file layouts on dirs") @@ -52,6 +48,9 @@ class health_check_map_t; #define MDS_FS_NAME_DEFAULT "cephfs" +class CephContext; +class health_check_map_t; + class MDSMap { public: /* These states are the union of the set of possible states of an MDS daemon, @@ -100,22 +99,15 @@ public: */ } DaemonState; - struct mds_info_t { - mds_gid_t global_id = MDS_GID_NONE; - std::string name; - mds_rank_t rank = MDS_RANK_NONE; - int32_t inc = 0; - MDSMap::DaemonState state = STATE_STANDBY; - version_t state_seq = 0; - entity_addrvec_t addrs; - utime_t laggy_since; - std::set export_targets; - uint64_t mds_features = 0; - uint64_t flags = 0; - enum mds_flags : uint64_t { - FROZEN = 1 << 0, - }; + typedef enum + { + AVAILABLE = 0, + TRANSIENT_UNAVAILABLE = 1, + STUCK_UNAVAILABLE = 2 + + } availability_t; + struct mds_info_t { mds_info_t() = default; bool laggy() const { return !(laggy_since == utime_t()); } @@ -145,77 +137,34 @@ public: std::string human_name() const; static void generate_test_instances(std::list& ls); + + mds_gid_t global_id = MDS_GID_NONE; + std::string name; + mds_rank_t rank = MDS_RANK_NONE; + int32_t inc = 0; + MDSMap::DaemonState state = STATE_STANDBY; + version_t state_seq = 0; + entity_addrvec_t addrs; + utime_t laggy_since; + std::set export_targets; + uint64_t mds_features = 0; + uint64_t flags = 0; + enum mds_flags : uint64_t { + FROZEN = 1 << 0, + }; private: void encode_versioned(bufferlist& bl, uint64_t features) const; void encode_unversioned(bufferlist& bl) const; }; - static CompatSet get_compat_set_all(); - static CompatSet get_compat_set_default(); - static CompatSet get_compat_set_base(); // pre v0.20 - -protected: - // base map - epoch_t epoch = 0; - bool enabled = false; - std::string fs_name = MDS_FS_NAME_DEFAULT; - uint32_t flags = CEPH_MDSMAP_DEFAULTS; // flags - epoch_t last_failure = 0; // mds epoch of last failure - epoch_t last_failure_osd_epoch = 0; // osd epoch of last failure; any mds entering replay needs - // at least this osdmap to ensure the blacklist propagates. - utime_t created; - utime_t modified; - - mds_rank_t tableserver = 0; // which MDS has snaptable - mds_rank_t root = 0; // which MDS has root directory - - __u32 session_timeout = 60; - __u32 session_autoclose = 300; - uint64_t max_file_size = 1ULL<<40; /* 1TB */ - - ceph_release_t min_compat_client{ceph_release_t::unknown}; - - std::vector data_pools; // file data pools available to clients (via an ioctl). first is the default. - int64_t cas_pool = -1; // where CAS objects go - int64_t metadata_pool = -1; // where fs metadata objects go - - /* - * in: the set of logical mds #'s that define the cluster. this is the set - * of mds's the metadata may be distributed over. - * up: map from logical mds #'s to the addrs filling those roles. - * failed: subset of @in that are failed. - * stopped: set of nodes that have been initialized, but are not active. - * - * @up + @failed = @in. @in * @stopped = {}. - */ - - mds_rank_t max_mds = 1; /* The maximum number of active MDSes. Also, the maximum rank. */ - mds_rank_t old_max_mds = 0; /* Value to restore when MDS cluster is marked up */ - mds_rank_t standby_count_wanted = -1; - string balancer; /* The name/version of the mantle balancer (i.e. the rados obj name) */ - - std::set in; // currently defined cluster - - // which ranks are failed, stopped, damaged (i.e. not held by a daemon) - std::set failed, stopped, damaged; - std::map up; // who is in those roles - std::map mds_info; - - uint8_t ever_allowed_features = 0; //< bitmap of features the cluster has allowed - uint8_t explicitly_allowed_features = 0; //< bitmap of features explicitly enabled - - bool inline_data_enabled = false; - - uint64_t cached_up_features = 0; - -public: - CompatSet compat; - friend class MDSMonitor; friend class Filesystem; friend class FSMap; -public: + static CompatSet get_compat_set_all(); + static CompatSet get_compat_set_default(); + static CompatSet get_compat_set_base(); // pre v0.20 + bool get_inline_data_enabled() const { return inline_data_enabled; } void set_inline_data_enabled(bool enabled) { inline_data_enabled = enabled; } @@ -329,14 +278,7 @@ public: ceph_assert(up.count(m) && mds_info.count(up.at(m))); return mds_info.at(up.at(m)); } - mds_gid_t find_mds_gid_by_name(std::string_view s) const { - for (const auto& [gid, info] : mds_info) { - if (info.name == s) { - return gid; - } - } - return MDS_GID_NONE; - } + mds_gid_t find_mds_gid_by_name(std::string_view s) const; // counts unsigned get_num_in_mds() const { @@ -352,15 +294,7 @@ public: int get_num_failed_mds() const { return failed.size(); } - unsigned get_num_mds(int state) const { - unsigned n = 0; - for (std::map::const_iterator p = mds_info.begin(); - p != mds_info.end(); - ++p) - if (p->second.state == state) ++n; - return n; - } - + unsigned get_num_mds(int state) const; // data pools void add_data_pool(int64_t poolid) { data_pools.push_back(poolid); @@ -377,12 +311,7 @@ public: void get_mds_set(std::set& s) const { s = in; } - void get_up_mds_set(std::set& s) const { - for (std::map::const_iterator p = up.begin(); - p != up.end(); - ++p) - s.insert(p->first); - } + void get_up_mds_set(std::set& s) const; void get_active_mds_set(std::set& s) const { get_mds_set(s, MDSMap::STATE_ACTIVE); } @@ -394,25 +323,7 @@ public: } // features - uint64_t get_up_features() { - if (!cached_up_features) { - bool first = true; - for (std::map::const_iterator p = up.begin(); - p != up.end(); - ++p) { - std::map::const_iterator q = - mds_info.find(p->second); - ceph_assert(q != mds_info.end()); - if (first) { - cached_up_features = q->second.mds_features; - first = false; - } else { - cached_up_features &= q->second.mds_features; - } - } - } - return cached_up_features; - } + uint64_t get_up_features(); /** * Get MDS ranks which are in but not up. @@ -431,43 +342,16 @@ public: void get_stopped_mds_set(std::set& s) const { s = stopped; } - void get_recovery_mds_set(std::set& s) const { - s = failed; - for (const auto& p : damaged) - s.insert(p); - for (const auto& p : mds_info) - if (p.second.state >= STATE_REPLAY && p.second.state <= STATE_STOPPING) - s.insert(p.second.rank); - } - - void get_mds_set_lower_bound(std::set& s, DaemonState first) const { - for (std::map::const_iterator p = mds_info.begin(); - p != mds_info.end(); - ++p) - if (p->second.state >= first && p->second.state <= STATE_STOPPING) - s.insert(p->second.rank); - } - void get_mds_set(std::set& s, DaemonState state) const { - for (std::map::const_iterator p = mds_info.begin(); - p != mds_info.end(); - ++p) - if (p->second.state == state) - s.insert(p->second.rank); - } + void get_recovery_mds_set(std::set& s) const; + + void get_mds_set_lower_bound(std::set& s, DaemonState first) const; + void get_mds_set(std::set& s, DaemonState state) const; void get_health(list >& summary, list > *detail) const; void get_health_checks(health_check_map_t *checks) const; - typedef enum - { - AVAILABLE = 0, - TRANSIENT_UNAVAILABLE = 1, - STUCK_UNAVAILABLE = 2 - - } availability_t; - /** * Return indication of whether cluster is available. This is a * heuristic for clients to see if they should bother waiting to talk to @@ -552,14 +436,7 @@ public: return is_clientreplay(m) || is_active(m) || is_stopping(m); } - mds_gid_t get_standby_replay(mds_rank_t r) const { - for (auto& [gid,info] : mds_info) { - if (info.rank == r && info.state == STATE_STANDBY_REPLAY) { - return gid; - } - } - return MDS_GID_NONE; - } + mds_gid_t get_standby_replay(mds_rank_t r) const; bool has_standby_replay(mds_rank_t r) const { return get_standby_replay(r) != MDS_GID_NONE; } @@ -583,15 +460,7 @@ public: // degraded = some recovery in process. fixes active membership and // recovery_set. - bool is_degraded() const { - if (!failed.empty() || !damaged.empty()) - return true; - for (const auto& p : mds_info) { - if (p.second.is_degraded()) - return true; - } - return false; - } + bool is_degraded() const; bool is_any_failed() const { return failed.size(); } @@ -670,6 +539,62 @@ public: static void generate_test_instances(std::list& ls); static bool state_transition_valid(DaemonState prev, DaemonState next); + + CompatSet compat; +protected: + // base map + epoch_t epoch = 0; + bool enabled = false; + std::string fs_name = MDS_FS_NAME_DEFAULT; + uint32_t flags = CEPH_MDSMAP_DEFAULTS; // flags + epoch_t last_failure = 0; // mds epoch of last failure + epoch_t last_failure_osd_epoch = 0; // osd epoch of last failure; any mds entering replay needs + // at least this osdmap to ensure the blacklist propagates. + utime_t created; + utime_t modified; + + mds_rank_t tableserver = 0; // which MDS has snaptable + mds_rank_t root = 0; // which MDS has root directory + + __u32 session_timeout = 60; + __u32 session_autoclose = 300; + uint64_t max_file_size = 1ULL<<40; /* 1TB */ + + ceph_release_t min_compat_client{ceph_release_t::unknown}; + + std::vector data_pools; // file data pools available to clients (via an ioctl). first is the default. + int64_t cas_pool = -1; // where CAS objects go + int64_t metadata_pool = -1; // where fs metadata objects go + + /* + * in: the set of logical mds #'s that define the cluster. this is the set + * of mds's the metadata may be distributed over. + * up: map from logical mds #'s to the addrs filling those roles. + * failed: subset of @in that are failed. + * stopped: set of nodes that have been initialized, but are not active. + * + * @up + @failed = @in. @in * @stopped = {}. + */ + + mds_rank_t max_mds = 1; /* The maximum number of active MDSes. Also, the maximum rank. */ + mds_rank_t old_max_mds = 0; /* Value to restore when MDS cluster is marked up */ + mds_rank_t standby_count_wanted = -1; + string balancer; /* The name/version of the mantle balancer (i.e. the rados obj name) */ + + std::set in; // currently defined cluster + + // which ranks are failed, stopped, damaged (i.e. not held by a daemon) + std::set failed, stopped, damaged; + std::map up; // who is in those roles + std::map mds_info; + + uint8_t ever_allowed_features = 0; //< bitmap of features the cluster has allowed + uint8_t explicitly_allowed_features = 0; //< bitmap of features explicitly enabled + + bool inline_data_enabled = false; + + uint64_t cached_up_features = 0; + }; WRITE_CLASS_ENCODER_FEATURES(MDSMap::mds_info_t) WRITE_CLASS_ENCODER_FEATURES(MDSMap) @@ -683,5 +608,4 @@ inline std::ostream& operator<<(std::ostream& o, const MDSMap::mds_info_t& info) info.dump(o); return o; } - #endif