]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
osd/PG: extend pg state to 64 bits
authorYan Jun <yan.jun8@zte.com.cn>
Wed, 27 Sep 2017 08:35:14 +0000 (16:35 +0800)
committerYan Jun <yan.jun8@zte.com.cn>
Mon, 9 Oct 2017 04:45:16 +0000 (12:45 +0800)
Signed-off-by: Yan Jun <yan.jun8@zte.com.cn>
src/mon/PGMap.cc
src/mon/PGMap.h
src/osd/PG.h
src/osd/osd_types.cc
src/osd/osd_types.h

index c00f22a470839393c8426d9a1e1bfa7e8e6640f7..1cb1abd200294a3418b191dc460275c50681ef8b 100644 (file)
@@ -27,7 +27,11 @@ MEMPOOL_DEFINE_OBJECT_FACTORY(PGMap::Incremental, pgmap_inc, pgmap);
 void PGMapDigest::encode(bufferlist& bl, uint64_t features) const
 {
   // NOTE: see PGMap::encode_digest
-  ENCODE_START(1, 1, bl);
+  uint8_t v = 2;
+  if (!HAVE_FEATURE(features, SERVER_MIMIC)) {
+    v = 1;
+  }
+  ENCODE_START(v, 1, bl);
   ::encode(num_pg, bl);
   ::encode(num_pg_active, bl);
   ::encode(num_pg_unknown, bl);
@@ -35,7 +39,16 @@ void PGMapDigest::encode(bufferlist& bl, uint64_t features) const
   ::encode(pg_pool_sum, bl, features);
   ::encode(pg_sum, bl, features);
   ::encode(osd_sum, bl);
-  ::encode(num_pg_by_state, bl);
+  if (v >= 2) {
+    ::encode(num_pg_by_state, bl);
+  } else {
+    uint32_t n = num_pg_by_state.size();
+    ::encode(n, bl);
+    for (auto p : num_pg_by_state) {
+      ::encode((uint32_t)p.first, bl);
+      ::encode(p.second, bl);
+    }
+  }
   ::encode(num_pg_by_osd, bl);
   ::encode(num_pg_by_pool, bl);
   ::encode(osd_last_seq, bl);
@@ -49,7 +62,7 @@ void PGMapDigest::encode(bufferlist& bl, uint64_t features) const
 
 void PGMapDigest::decode(bufferlist::iterator& p)
 {
-  DECODE_START(1, p);
+  DECODE_START(2, p);
   ::decode(num_pg, p);
   ::decode(num_pg_active, p);
   ::decode(num_pg_unknown, p);
@@ -57,7 +70,15 @@ void PGMapDigest::decode(bufferlist::iterator& p)
   ::decode(pg_pool_sum, p);
   ::decode(pg_sum, p);
   ::decode(osd_sum, p);
-  ::decode(num_pg_by_state, p);
+  if (struct_v >= 2) {
+    ::decode(num_pg_by_state, p);
+  } else {
+    map<int32_t, int32_t> nps;
+    ::decode(nps, p);
+    for (auto i : nps) {
+      num_pg_by_state[i.first] = i.second;
+    }
+  }
   ::decode(num_pg_by_osd, p);
   ::decode(num_pg_by_pool, p);
   ::decode(osd_last_seq, p);
@@ -2938,7 +2959,7 @@ int process_pg_map_command(
         state = -1;
         break;
       } else {
-        int filter = pg_string_state(state_str);
+        int64_t filter = pg_string_state(state_str);
         if (filter < 0) {
           *ss << "'" << state_str << "' is not a valid pg state,"
               << " available choices: " << pg_state_string(0xFFFFFFFF);
index 781e3ae3af68a97ef52184748fe3d303ed85b94d..d196f76944320f2036014ea1eaa3775b13c3a48c 100644 (file)
@@ -52,7 +52,7 @@ public:
   mempool::pgmap::map<int64_t,int64_t> num_pg_by_pool;
   pool_stat_t pg_sum;
   osd_stat_t osd_sum;
-  mempool::pgmap::unordered_map<int32_t,int32_t> num_pg_by_state;
+  mempool::pgmap::unordered_map<uint64_t,int32_t> num_pg_by_state;
   struct pg_count {
     int32_t acting = 0;
     int32_t up = 0;
index 2e75fff4f8471eb29dbca4e5673855268e3d4f6e..3cb5c30d0575eb86d5610bf2a9e69803400fd222 100644 (file)
@@ -832,7 +832,7 @@ protected:
 
 protected:
   int         role;    // 0 = primary, 1 = replica, -1=none.
-  unsigned    state;   // PG_STATE_*
+  uint64_t    state;   // PG_STATE_*
 
   bool send_notify;    ///< true if we are non-primary and should notify the primary
 
@@ -2538,9 +2538,9 @@ protected:
     role = r;
   }
 
-  bool state_test(int m) const { return (state & m) != 0; }
-  void state_set(int m) { state |= m; }
-  void state_clear(int m) { state &= ~m; }
+  bool state_test(uint64_t m) const { return (state & m) != 0; }
+  void state_set(uint64_t m) { state |= m; }
+  void state_clear(uint64_t m) { state &= ~m; }
 
   bool is_complete() const { return info.last_complete == info.last_update; }
   bool should_send_notify() const { return send_notify; }
index 5db1e93ae9b7f84aa89d7804e6b78569d5460d06..5f32dc7ea4458b022fa79f7c98e69295e80be6d6 100644 (file)
@@ -788,7 +788,7 @@ std::string pg_vector_string(const vector<int32_t> &a)
   return oss.str();
 }
 
-std::string pg_state_string(int state)
+std::string pg_state_string(uint64_t state)
 {
   ostringstream oss;
   if (state & PG_STATE_STALE)
@@ -853,9 +853,9 @@ std::string pg_state_string(int state)
   return ret;
 }
 
-int pg_string_state(const std::string& state)
+int64_t pg_string_state(const std::string& state)
 {
-  int type;
+  int64_t type;
   if (state == "active")
     type = PG_STATE_ACTIVE;
   else if (state == "clean")
@@ -2328,11 +2328,11 @@ void pg_stat_t::dump_brief(Formatter *f) const
 
 void pg_stat_t::encode(bufferlist &bl) const
 {
-  ENCODE_START(22, 22, bl);
+  ENCODE_START(23, 22, bl);
   ::encode(version, bl);
   ::encode(reported_seq, bl);
   ::encode(reported_epoch, bl);
-  ::encode(state, bl);
+  ::encode((__u32)state, bl);   // for older peers
   ::encode(log_start, bl);
   ::encode(ondisk_log_start, bl);
   ::encode(created, bl);
@@ -2369,17 +2369,19 @@ void pg_stat_t::encode(bufferlist &bl) const
   ::encode(last_peered, bl);
   ::encode(last_became_peered, bl);
   ::encode(pin_stats_invalid, bl);
+  ::encode(state, bl);
   ENCODE_FINISH(bl);
 }
 
 void pg_stat_t::decode(bufferlist::iterator &bl)
 {
   bool tmp;
-  DECODE_START(22, bl);
+  uint32_t old_state;
+  DECODE_START(23, bl);
   ::decode(version, bl);
   ::decode(reported_seq, bl);
   ::decode(reported_epoch, bl);
-  ::decode(state, bl);
+  ::decode(old_state, bl);
   ::decode(log_start, bl);
   ::decode(ondisk_log_start, bl);
   ::decode(created, bl);
@@ -2422,6 +2424,11 @@ void pg_stat_t::decode(bufferlist::iterator &bl)
   ::decode(last_became_peered, bl);
   ::decode(tmp, bl);
   pin_stats_invalid = tmp;
+  if (struct_v >= 23) {
+    ::decode(state, bl);
+  } else {
+    state = old_state;
+  }
   DECODE_FINISH(bl);
 }
 
index 6da46e440507611ad156c401b532a334f46feadf..57acf95900ca5801a11c9783d1380073701e7123 100644 (file)
@@ -974,41 +974,41 @@ inline ostream& operator<<(ostream& out, const osd_stat_t& s) {
 /*
  * pg states
  */
-#define PG_STATE_CREATING     (1<<0)  // creating
-#define PG_STATE_ACTIVE       (1<<1)  // i am active.  (primary: replicas too)
-#define PG_STATE_CLEAN        (1<<2)  // peers are complete, clean of stray replicas.
-#define PG_STATE_DOWN         (1<<4)  // a needed replica is down, PG offline
-//#define PG_STATE_REPLAY       (1<<5)  // crashed, waiting for replay
-//#define PG_STATE_STRAY      (1<<6)  // i must notify the primary i exist.
-//#define PG_STATE_SPLITTING    (1<<7)  // i am splitting
-#define PG_STATE_SCRUBBING    (1<<8)  // scrubbing
-//#define PG_STATE_SCRUBQ       (1<<9)  // queued for scrub
-#define PG_STATE_DEGRADED     (1<<10) // pg contains objects with reduced redundancy
-#define PG_STATE_INCONSISTENT (1<<11) // pg replicas are inconsistent (but shouldn't be)
-#define PG_STATE_PEERING      (1<<12) // pg is (re)peering
-#define PG_STATE_REPAIR       (1<<13) // pg should repair on next scrub
-#define PG_STATE_RECOVERING   (1<<14) // pg is recovering/migrating objects
-#define PG_STATE_BACKFILL_WAIT     (1<<15) // [active] reserving backfill
-#define PG_STATE_INCOMPLETE   (1<<16) // incomplete content, peering failed.
-#define PG_STATE_STALE        (1<<17) // our state for this pg is stale, unknown.
-#define PG_STATE_REMAPPED     (1<<18) // pg is explicitly remapped to different OSDs than CRUSH
-#define PG_STATE_DEEP_SCRUB   (1<<19) // deep scrub: check CRC32 on files
-#define PG_STATE_BACKFILLING  (1<<20) // [active] backfilling pg content
-#define PG_STATE_BACKFILL_TOOFULL (1<<21) // backfill can't proceed: too full
-#define PG_STATE_RECOVERY_WAIT (1<<22) // waiting for recovery reservations
-#define PG_STATE_UNDERSIZED    (1<<23) // pg acting < pool size
-#define PG_STATE_ACTIVATING   (1<<24) // pg is peered but not yet active
-#define PG_STATE_PEERED        (1<<25) // peered, cannot go active, can recover
-#define PG_STATE_SNAPTRIM      (1<<26) // trimming snaps
-#define PG_STATE_SNAPTRIM_WAIT (1<<27) // queued to trim snaps
-#define PG_STATE_RECOVERY_TOOFULL (1<<28) // recovery can't proceed: too full
-#define PG_STATE_SNAPTRIM_ERROR (1<<29) // error stopped trimming snaps
-#define PG_STATE_FORCED_RECOVERY (1<<30) // force recovery of this pg before any other
-#define PG_STATE_FORCED_BACKFILL (1<<31) // force backfill of this pg before any other
-
-std::string pg_state_string(int state);
+#define PG_STATE_CREATING           (1ULL << 0)  // creating
+#define PG_STATE_ACTIVE             (1ULL << 1)  // i am active.  (primary: replicas too)
+#define PG_STATE_CLEAN              (1ULL << 2)  // peers are complete, clean of stray replicas.
+#define PG_STATE_DOWN               (1ULL << 4)  // a needed replica is down, PG offline
+//#define PG_STATE_REPLAY           (1ULL << 5)  // crashed, waiting for replay
+//#define PG_STATE_STRAY            (1ULL << 6)  // i must notify the primary i exist.
+//#define PG_STATE_SPLITTING        (1ULL << 7)  // i am splitting
+#define PG_STATE_SCRUBBING          (1ULL << 8)  // scrubbing
+//#define PG_STATE_SCRUBQ           (1ULL << 9)  // queued for scrub
+#define PG_STATE_DEGRADED           (1ULL << 10) // pg contains objects with reduced redundancy
+#define PG_STATE_INCONSISTENT       (1ULL << 11) // pg replicas are inconsistent (but shouldn't be)
+#define PG_STATE_PEERING            (1ULL << 12) // pg is (re)peering
+#define PG_STATE_REPAIR             (1ULL << 13) // pg should repair on next scrub
+#define PG_STATE_RECOVERING         (1ULL << 14) // pg is recovering/migrating objects
+#define PG_STATE_BACKFILL_WAIT      (1ULL << 15) // [active] reserving backfill
+#define PG_STATE_INCOMPLETE         (1ULL << 16) // incomplete content, peering failed.
+#define PG_STATE_STALE              (1ULL << 17) // our state for this pg is stale, unknown.
+#define PG_STATE_REMAPPED           (1ULL << 18) // pg is explicitly remapped to different OSDs than CRUSH
+#define PG_STATE_DEEP_SCRUB         (1ULL << 19) // deep scrub: check CRC32 on files
+#define PG_STATE_BACKFILLING        (1ULL << 20) // [active] backfilling pg content
+#define PG_STATE_BACKFILL_TOOFULL   (1ULL << 21) // backfill can't proceed: too full
+#define PG_STATE_RECOVERY_WAIT      (1ULL << 22) // waiting for recovery reservations
+#define PG_STATE_UNDERSIZED         (1ULL << 23) // pg acting < pool size
+#define PG_STATE_ACTIVATING         (1ULL << 24) // pg is peered but not yet active
+#define PG_STATE_PEERED             (1ULL << 25) // peered, cannot go active, can recover
+#define PG_STATE_SNAPTRIM           (1ULL << 26) // trimming snaps
+#define PG_STATE_SNAPTRIM_WAIT      (1ULL << 27) // queued to trim snaps
+#define PG_STATE_RECOVERY_TOOFULL   (1ULL << 28) // recovery can't proceed: too full
+#define PG_STATE_SNAPTRIM_ERROR     (1ULL << 29) // error stopped trimming snaps
+#define PG_STATE_FORCED_RECOVERY    (1ULL << 30) // force recovery of this pg before any other
+#define PG_STATE_FORCED_BACKFILL    (1ULL << 31) // force backfill of this pg before any other
+
+std::string pg_state_string(uint64_t state);
 std::string pg_vector_string(const vector<int32_t> &a);
-int pg_string_state(const std::string& state);
+int64_t pg_string_state(const std::string& state);
 
 
 /*
@@ -1911,7 +1911,7 @@ struct pg_stat_t {
   eversion_t version;
   version_t reported_seq;  // sequence number
   epoch_t reported_epoch;  // epoch of this report
-  __u32 state;
+  uint64_t state;
   utime_t last_fresh;   // last reported
   utime_t last_change;  // new state != previous state
   utime_t last_active;  // state & PG_STATE_ACTIVE