From 3a93c1d2f8a80e4819e1702e91cd18243d678db1 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 24 Nov 2008 11:49:10 -0800 Subject: [PATCH] osd: include a blacklist in the OSDMap --- src/include/encoding.h | 23 +++++++++++++++++++++++ src/osd/OSDMap.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/include/encoding.h b/src/include/encoding.h index 9403619270588..4f33696726533 100644 --- a/src/include/encoding.h +++ b/src/include/encoding.h @@ -93,6 +93,7 @@ WRITE_INTTYPE_ENCODER(s16, le16) #include #include #include +#include #include "triple.h" // pair @@ -387,6 +388,28 @@ inline void decode(__gnu_cxx::hash_map& m, bufferlist::iterator& p) } } +// hash_set +template +inline void encode(const __gnu_cxx::hash_set& m, bufferlist& bl) +{ + __u32 n = m.size(); + encode(n, bl); + for (typename __gnu_cxx::hash_set::const_iterator p = m.begin(); p != m.end(); ++p) + encode(*p, bl); +} +template +inline void decode(__gnu_cxx::hash_set& m, bufferlist::iterator& p) +{ + __u32 n; + decode(n, p); + m.clear(); + while (n--) { + T k; + decode(k, p); + m.insert(k); + } +} + // string inline void encode(const std::string& s, bufferlist& bl) { diff --git a/src/osd/OSDMap.h b/src/osd/OSDMap.h index df78234871452..aef6ef285cb66 100644 --- a/src/osd/OSDMap.h +++ b/src/osd/OSDMap.h @@ -38,6 +38,10 @@ #include using namespace std; +#include +using __gnu_cxx::hash_set; + + /* * some system constants @@ -143,6 +147,9 @@ public: map new_pg_swap_primary; list old_pg_swap_primary; + vector new_blacklist; + vector old_blacklist; + snapid_t new_max_snap; interval_set removed_snaps; @@ -171,6 +178,8 @@ public: ::encode(old_pg_swap_primary, bl); ::encode(new_max_snap, bl); ::encode(removed_snaps.m, bl); + ::encode(new_blacklist, bl); + ::encode(old_blacklist, bl); } void decode(bufferlist::iterator &p) { // base @@ -197,6 +206,8 @@ public: ::decode(old_pg_swap_primary, p); ::decode(new_max_snap, p); ::decode(removed_snaps.m, p); + ::decode(new_blacklist, p); + ::decode(old_blacklist, p); } Incremental(epoch_t e=0) : epoch(e), new_flags(-1), new_max_osd(-1), @@ -254,6 +265,8 @@ private: snapid_t max_snap; interval_set removed_snaps; + hash_set blacklist; + public: CrushWrapper crush; // hierarchical map @@ -312,6 +325,10 @@ private: } interval_set& get_removed_snaps() { return removed_snaps; } + bool is_blacklisted(const entity_addr_t& a) { + return !blacklist.empty() && blacklist.count(a); + } + /***** cluster state *****/ /* osds */ int get_max_osd() const { return max_osd; } @@ -529,10 +546,21 @@ private: i++) pg_swap_primary.erase(*i); + // snaps if (inc.new_max_snap > 0) max_snap = inc.new_max_snap; removed_snaps.union_of(inc.removed_snaps); + // blacklist + for (vector::iterator p = inc.new_blacklist.begin(); + p != inc.new_blacklist.end(); + p++) + blacklist.insert(*p); + for (vector::iterator p = inc.old_blacklist.begin(); + p != inc.old_blacklist.end(); + p++) + blacklist.erase(*p); + // do new crush map last (after up/down stuff) if (inc.crush.length()) { bufferlist::iterator blp = inc.crush.begin(); @@ -570,6 +598,7 @@ private: ::encode(max_snap, blist); ::encode(removed_snaps.m, blist); + ::encode(blacklist, blist); } void decode(bufferlist& blist) { @@ -604,6 +633,7 @@ private: ::decode(max_snap, p); ::decode(removed_snaps.m, p); + ::decode(blacklist, p); } -- 2.39.5