From 2bf4b7e4b0ad5bcab52eaabedb6439d4a86af37b Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 11 Aug 2021 11:49:52 +0800 Subject: [PATCH] mon: build without "using namespace std" * add "std::" prefix in headers * add "using" declarations in .cc files. so we don't rely on "using namespace std" in one or more included headers. Signed-off-by: Kefu Chai --- src/mon/ConnectionTracker.h | 4 ++-- src/mon/ElectionLogic.h | 3 ++- src/mon/Elector.h | 14 +++++++------- src/mon/KVMonitor.cc | 6 ++++++ src/mon/KVMonitor.h | 4 ++-- src/mon/LogMonitor.cc | 1 + src/mon/MDSMonitor.h | 2 +- src/mon/MonCap.h | 6 +++--- src/mon/MonClient.h | 14 +++++++------- src/mon/MonMap.cc | 2 ++ src/mon/MonMap.h | 4 ++-- src/mon/Monitor.h | 20 ++++++++++---------- src/mon/MonmapMonitor.h | 8 ++++---- src/mon/OSDMonitor.h | 23 ++++++++++++----------- src/mon/Session.h | 4 ++-- 15 files changed, 63 insertions(+), 52 deletions(-) diff --git a/src/mon/ConnectionTracker.h b/src/mon/ConnectionTracker.h index 58e9889eb2b..c62d3c200d7 100644 --- a/src/mon/ConnectionTracker.h +++ b/src/mon/ConnectionTracker.h @@ -136,7 +136,7 @@ class ConnectionTracker { private: epoch_t epoch; uint64_t version; - map peer_reports; + std::map peer_reports; ConnectionReport my_reports; double half_life; RankProvider *owner; @@ -190,7 +190,7 @@ class ConnectionTracker { void notify_rank_removed(int rank_removed); friend std::ostream& operator<<(std::ostream& o, const ConnectionTracker& c); friend ConnectionReport *get_connection_reports(ConnectionTracker& ct); - friend map *get_peer_reports(ConnectionTracker& ct); + friend std::map *get_peer_reports(ConnectionTracker& ct); void dump(ceph::Formatter *f) const; static void generate_test_instances(std::list& o); }; diff --git a/src/mon/ElectionLogic.h b/src/mon/ElectionLogic.h index 65c727ca134..e2f2db82ac8 100644 --- a/src/mon/ElectionLogic.h +++ b/src/mon/ElectionLogic.h @@ -17,6 +17,7 @@ #define CEPH_ELECTIONLOGIC_H #include +#include #include "include/types.h" #include "ConnectionTracker.h" @@ -95,7 +96,7 @@ public: * Like paxos_size(), This set can change between elections, but not * during them. */ - virtual const set& get_disallowed_leaders() const = 0; + virtual const std::set& get_disallowed_leaders() const = 0; /** * Tell the ElectionOwner we have started a new election. * diff --git a/src/mon/Elector.h b/src/mon/Elector.h index d14dbb5c4ce..a581daa7ff5 100644 --- a/src/mon/Elector.h +++ b/src/mon/Elector.h @@ -42,10 +42,10 @@ class Elector : public ElectionOwner, RankProvider { ElectionLogic logic; // connectivity validation and scoring ConnectionTracker peer_tracker; - map peer_acked_ping; // rank -> last ping stamp they acked - map peer_sent_ping; // rank -> last ping stamp we sent - set live_pinging; // ranks which we are currently pinging - set dead_pinging; // ranks which didn't answer (degrading scores) + std::map peer_acked_ping; // rank -> last ping stamp they acked + std::map peer_sent_ping; // rank -> last ping stamp we sent + std::set live_pinging; // ranks which we are currently pinging + std::set dead_pinging; // ranks which didn't answer (degrading scores) double ping_timeout; // the timeout after which we consider a ping to be dead int PING_DIVISOR = 2; // we time out pings @@ -242,8 +242,8 @@ class Elector : public ElectionOwner, RankProvider { /* Retrieve monmap->size() */ unsigned paxos_size() const; /* Right now we don't disallow anybody */ - set disallowed_leaders; - const set& get_disallowed_leaders() const { return disallowed_leaders; } + std::set disallowed_leaders; + const std::set& get_disallowed_leaders() const { return disallowed_leaders; } /** * Reset the expire_event timer so we can limit the amount of time we * will be electing. Clean up our peer_info. @@ -383,7 +383,7 @@ class Elector : public ElectionOwner, RankProvider { * @returns false if the set is unchanged, * true if the set changed */ - bool set_disallowed_leaders(const set& dl) { + bool set_disallowed_leaders(const std::set& dl) { if (dl == disallowed_leaders) return false; disallowed_leaders = dl; return true; diff --git a/src/mon/KVMonitor.cc b/src/mon/KVMonitor.cc index 9092bd15d4d..157e9ebfef7 100644 --- a/src/mon/KVMonitor.cc +++ b/src/mon/KVMonitor.cc @@ -10,6 +10,12 @@ #undef dout_prefix #define dout_prefix _prefix(_dout, mon, this) +using std::ostream; +using std::ostringstream; +using std::set; +using std::string; +using std::stringstream; + static ostream& _prefix(std::ostream *_dout, const Monitor &mon, const KVMonitor *hmon) { return *_dout << "mon." << mon.name << "@" << mon.rank diff --git a/src/mon/KVMonitor.h b/src/mon/KVMonitor.h index 3796e9b0b5a..8171ad34fda 100644 --- a/src/mon/KVMonitor.h +++ b/src/mon/KVMonitor.h @@ -16,14 +16,14 @@ class KVMonitor : public PaxosService version_t version = 0; std::map> pending; - bool _have_prefix(const string &prefix); + bool _have_prefix(const std::string &prefix); public: KVMonitor(Monitor &m, Paxos &p, const std::string& service_name); void init() override; - void get_store_prefixes(set& s) const override; + void get_store_prefixes(std::set& s) const override; bool preprocess_command(MonOpRequestRef op); bool prepare_command(MonOpRequestRef op); diff --git a/src/mon/LogMonitor.cc b/src/mon/LogMonitor.cc index e8b41e585e1..9103ddf7c5b 100644 --- a/src/mon/LogMonitor.cc +++ b/src/mon/LogMonitor.cc @@ -72,6 +72,7 @@ using std::hex; using std::list; using std::map; using std::make_pair; +using std::multimap; using std::ostream; using std::ostringstream; using std::pair; diff --git a/src/mon/MDSMonitor.h b/src/mon/MDSMonitor.h index c70814996fd..c41246992d5 100644 --- a/src/mon/MDSMonitor.h +++ b/src/mon/MDSMonitor.h @@ -130,7 +130,7 @@ class MDSMonitor : public PaxosService, public PaxosFSMap, protected CommandHand void count_metadata(const std::string& field, ceph::Formatter *f); public: - void print_fs_summary(ostream& out) { + void print_fs_summary(std::ostream& out) { get_fsmap().print_fs_summary(out); } void count_metadata(const std::string& field, std::map *out); diff --git a/src/mon/MonCap.h b/src/mon/MonCap.h index ab4e35bc90c..570f788ad59 100644 --- a/src/mon/MonCap.h +++ b/src/mon/MonCap.h @@ -183,8 +183,8 @@ struct MonCap { void dump(ceph::Formatter *f) const; static void generate_test_instances(std::list& ls); - std::vector allowed_fs_names() const { - std::vector ret; + std::vector allowed_fs_names() const { + std::vector ret; for (auto& g : grants) { if (not g.fs_name.empty()) { ret.push_back(g.fs_name); @@ -195,7 +195,7 @@ struct MonCap { return ret; } - bool fs_name_capable(const EntityName& ename, string_view fs_name, + bool fs_name_capable(const EntityName& ename, std::string_view fs_name, __u8 mask) { for (auto& g : grants) { if (g.is_allow_all()) { diff --git a/src/mon/MonClient.h b/src/mon/MonClient.h index c6ee6b8eb92..19aa047c218 100644 --- a/src/mon/MonClient.h +++ b/src/mon/MonClient.h @@ -698,20 +698,20 @@ public: } }; - void start_mon_command(const vector& cmd, const bufferlist& inbl, - bufferlist *outbl, string *outs, + void start_mon_command(const std::vector& cmd, const bufferlist& inbl, + bufferlist *outbl, std::string *outs, Context *onfinish) { start_mon_command(cmd, inbl, ContextVerter(outs, outbl, onfinish)); } void start_mon_command(int mon_rank, - const vector& cmd, const bufferlist& inbl, - bufferlist *outbl, string *outs, + const std::vector& cmd, const bufferlist& inbl, + bufferlist *outbl, std::string *outs, Context *onfinish) { start_mon_command(mon_rank, cmd, inbl, ContextVerter(outs, outbl, onfinish)); } - void start_mon_command(const string &mon_name, ///< mon name, with mon. prefix - const vector& cmd, const bufferlist& inbl, - bufferlist *outbl, string *outs, + void start_mon_command(const std::string &mon_name, ///< mon name, with mon. prefix + const std::vector& cmd, const bufferlist& inbl, + bufferlist *outbl, std::string *outs, Context *onfinish) { start_mon_command(mon_name, cmd, inbl, ContextVerter(outs, outbl, onfinish)); } diff --git a/src/mon/MonMap.cc b/src/mon/MonMap.cc index 22e4e4709ab..d45c039beeb 100644 --- a/src/mon/MonMap.cc +++ b/src/mon/MonMap.cc @@ -4,6 +4,7 @@ #include "MonMap.h" #include +#include #include #include #include @@ -29,6 +30,7 @@ using std::list; using std::map; using std::ostream; +using std::ostringstream; using std::set; using std::string; using std::vector; diff --git a/src/mon/MonMap.h b/src/mon/MonMap.h index 02304edfdd2..0516d188249 100644 --- a/src/mon/MonMap.h +++ b/src/mon/MonMap.h @@ -162,8 +162,8 @@ class MonMap { election_strategy strategy = CLASSIC; std::set disallowed_leaders; // can't be leader under CONNECTIVITY/DISALLOW bool stretch_mode_enabled = false; - string tiebreaker_mon; - set stretch_marked_down_mons; // can't be leader until fully recovered + std::string tiebreaker_mon; + std::set stretch_marked_down_mons; // can't be leader until fully recovered public: void calc_legacy_ranks(); diff --git a/src/mon/Monitor.h b/src/mon/Monitor.h index 8e4f39ae51e..22bf6e9669c 100644 --- a/src/mon/Monitor.h +++ b/src/mon/Monitor.h @@ -251,16 +251,16 @@ private: bool stretch_mode_engaged{false}; bool degraded_stretch_mode{false}; bool recovering_stretch_mode{false}; - string stretch_bucket_divider; - map> dead_mon_buckets; // bucket->mon ranks, locations with no live mons - set up_mon_buckets; // locations with a live mon + std::string stretch_bucket_divider; + std::map> dead_mon_buckets; // bucket->mon ranks, locations with no live mons + std::set up_mon_buckets; // locations with a live mon void do_stretch_mode_election_work(); bool session_stretch_allowed(MonSession *s, MonOpRequestRef& op); void disconnect_disallowed_stretch_sessions(); void set_elector_disallowed_leaders(bool allow_election); - map crush_loc; + std::map crush_loc; bool need_set_crush_loc{false}; public: bool is_stretch_mode() { return stretch_mode_engaged; } @@ -281,15 +281,15 @@ public: */ void try_engage_stretch_mode(); void maybe_go_degraded_stretch_mode(); - void trigger_degraded_stretch_mode(const set& dead_mons, - const set& dead_buckets); + void trigger_degraded_stretch_mode(const std::set& dead_mons, + const std::set& dead_buckets); void set_degraded_stretch_mode(); void go_recovery_stretch_mode(); void set_recovery_stretch_mode(); void trigger_healthy_stretch_mode(); void set_healthy_stretch_mode(); void enable_stretch_mode(); - void set_mon_crush_location(const string& loc); + void set_mon_crush_location(const std::string& loc); private: @@ -894,7 +894,7 @@ public: } cmdmap_t cmdmap; std::ostringstream ds; - string prefix; + std::string prefix; cmdmap_from_json(m->cmd, &cmdmap, ds); cmd_getval(cmdmap, "prefix", prefix); if (prefix != "config set" && prefix != "config-key set") @@ -995,8 +995,8 @@ private: void count_metadata(const std::string& field, ceph::Formatter *f); void count_metadata(const std::string& field, std::map *out); // get_all_versions() gathers version information from daemons for health check - void get_all_versions(std::map> &versions); - void get_versions(std::map> &versions); + void get_all_versions(std::map> &versions); + void get_versions(std::map> &versions); // features static CompatSet get_initial_supported_features(); diff --git a/src/mon/MonmapMonitor.h b/src/mon/MonmapMonitor.h index cf22ae9f8e3..dc75e9620b2 100644 --- a/src/mon/MonmapMonitor.h +++ b/src/mon/MonmapMonitor.h @@ -89,17 +89,17 @@ private: * @param tiebreaker_mon: the name of the monitor to declare tiebreaker * @param dividing_bucket: the bucket type (eg 'dc') that divides the cluster */ - void try_enable_stretch_mode(stringstream& ss, bool *okay, + void try_enable_stretch_mode(std::stringstream& ss, bool *okay, int *errcode, bool commit, - const string& tiebreaker_mon, - const string& dividing_bucket); + const std::string& tiebreaker_mon, + const std::string& dividing_bucket); public: /** * Set us to degraded stretch mode. Put the dead_mons in * the MonMap. */ - void trigger_degraded_stretch_mode(const set& dead_mons); + void trigger_degraded_stretch_mode(const std::set& dead_mons); /** * Set us to healthy stretch mode: clear out the * down list to allow any non-tiebreaker mon to be the leader again. diff --git a/src/mon/OSDMonitor.h b/src/mon/OSDMonitor.h index 0ecdcbb31f1..6ba44edd8c9 100644 --- a/src/mon/OSDMonitor.h +++ b/src/mon/OSDMonitor.h @@ -788,9 +788,10 @@ public: * This does not make any changes to the pools or state; it's just * a safety-check-and-collect function. */ - void try_enable_stretch_mode_pools(stringstream& ss, bool *okay, + void try_enable_stretch_mode_pools(std::stringstream& ss, bool *okay, int *errcode, - set* pools, const string& new_crush_rule); + std::set* pools, + const std::string& new_crush_rule); /** * Check validity of inputs and OSD/CRUSH state to * engage stretch mode. Designed to be used with @@ -807,26 +808,26 @@ public: * from try_enable_stretch_mode_pools()). * @param new_crush_rule: The crush rule to set the pools to. */ - void try_enable_stretch_mode(stringstream& ss, bool *okay, + void try_enable_stretch_mode(std::stringstream& ss, bool *okay, int *errcode, bool commit, - const string& dividing_bucket, + const std::string& dividing_bucket, uint32_t bucket_count, - const set& pools, - const string& new_crush_rule); + const std::set& pools, + const std::string& new_crush_rule); /** * Check the input dead_buckets mapping (buckets->dead monitors) to see * if the OSDs are also down. If so, fill in really_down_buckets and * really_down_mons and return true; else return false. */ - bool check_for_dead_crush_zones(const map>& dead_buckets, - set *really_down_buckets, - set *really_down_mons); + bool check_for_dead_crush_zones(const std::map>& dead_buckets, + std::set *really_down_buckets, + std::set *really_down_mons); /** * Set degraded mode in the OSDMap, adding the given dead buckets to the dead set * and using the live_zones (should presently be size 1) */ - void trigger_degraded_stretch_mode(const set& dead_buckets, - const set& live_zones); + void trigger_degraded_stretch_mode(const std::set& dead_buckets, + const std::set& live_zones); /** * This is just to maintain stretch_recovery_triggered; below */ diff --git a/src/mon/Session.h b/src/mon/Session.h index 3009d023944..e090e742404 100644 --- a/src/mon/Session.h +++ b/src/mon/Session.h @@ -109,11 +109,11 @@ struct MonSession : public RefCountedObject { get_peer_socket_addr()); } - std::vector get_allowed_fs_names() const { + std::vector get_allowed_fs_names() const { return caps.allowed_fs_names(); } - bool fs_name_capable(string_view fsname, __u8 mask) { + bool fs_name_capable(std::string_view fsname, __u8 mask) { return caps.fs_name_capable(entity_name, fsname, mask); } -- 2.39.5