]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd/PG: simplify/streamline upgrade process
authorSage Weil <sage@redhat.com>
Sat, 16 Sep 2017 03:31:54 +0000 (23:31 -0400)
committerSage Weil <sage@redhat.com>
Fri, 6 Oct 2017 18:08:17 +0000 (13:08 -0500)
There's no reason for this to be exposed to the OSD.  Just do it directly
in read_state().

Signed-off-by: Sage Weil <sage@redhat.com>
src/osd/OSD.cc
src/osd/PG.cc
src/osd/PG.h

index e374bd1dcb4b014b64d3cf630865c832bd767d53..75a020144b210efd9044f39f01e911a0c3e27ca8 100644 (file)
@@ -3879,8 +3879,6 @@ void OSD::load_pgs()
     derr << "failed to list pgs: " << cpp_strerror(-r) << dendl;
   }
 
-  bool has_upgraded = false;
-
   for (vector<coll_t>::iterator it = ls.begin();
        it != ls.end();
        ++it) {
@@ -3941,21 +3939,6 @@ void OSD::load_pgs()
     // read pg state, log
     pg->read_state(store);
 
-    if (pg->must_upgrade()) {
-      if (!pg->can_upgrade()) {
-       derr << "PG needs upgrade, but on-disk data is too old; upgrade to"
-            << " an older version first." << dendl;
-       assert(0 == "PG too old to upgrade");
-      }
-      if (!has_upgraded) {
-       derr << "PGs are upgrading" << dendl;
-       has_upgraded = true;
-      }
-      dout(10) << "PG " << pg->pg_id
-              << " must upgrade..." << dendl;
-      pg->upgrade(store);
-    }
-
     service.init_splits_between(pg->pg_id, pg->get_osdmap(), osdmap);
 
     // generate state for PG's current mapping
index 2cbd2379f6603bf3f2f33dc868561d69c9cad562..1dd26c0d78b12ab22316aa2d9559dfb5ad22262e 100644 (file)
@@ -2819,6 +2819,8 @@ void PG::init(
 
 void PG::upgrade(ObjectStore *store)
 {
+  dout(0) << __func__ << " " << info_struct_v << " -> " << latest_struct_v
+         << dendl;
   assert(info_struct_v <= 10);
   ObjectStore::Transaction t;
 
@@ -2828,9 +2830,9 @@ void PG::upgrade(ObjectStore *store)
   assert(info_struct_v == 10);
 
   // update infover_key
-  if (info_struct_v < cur_struct_v) {
+  if (info_struct_v < latest_struct_v) {
     map<string,bufferlist> v;
-    __u8 ver = cur_struct_v;
+    __u8 ver = latest_struct_v;
     ::encode(ver, v[infover_key]);
     t.omap_setkeys(coll, pgmeta_oid, v);
   }
@@ -2947,7 +2949,7 @@ void PG::_init(ObjectStore::Transaction& t, spg_t pgid, const pg_pool_t *pool)
   ghobject_t pgmeta_oid(pgid.make_pgmeta_oid());
   t.touch(coll, pgmeta_oid);
   map<string,bufferlist> values;
-  __u8 struct_v = cur_struct_v;
+  __u8 struct_v = latest_struct_v;
   ::encode(struct_v, values[infover_key]);
   t.omap_setkeys(coll, pgmeta_oid, values);
 }
@@ -3231,6 +3233,12 @@ void PG::read_state(ObjectStore *store)
                    info_struct_v);
   assert(r >= 0);
 
+  if (info_struct_v < compat_struct_v) {
+    derr << "PG needs upgrade, but on-disk data is too old; upgrade to"
+        << " an older version first." << dendl;
+    assert(0 == "PG too old to upgrade");
+  }
+
   last_written_info = info;
 
   ostringstream oss;
@@ -3248,6 +3256,10 @@ void PG::read_state(ObjectStore *store)
 
   // log any weirdness
   log_weirdness();
+
+  if (info_struct_v < latest_struct_v) {
+    upgrade(store);
+  }
 }
 
 void PG::log_weirdness()
index d52ebf8f3d1408a01b870a3770faae41e2f8a071..4c2c9365b71166a42a1854bd4590e51e88961221 100644 (file)
@@ -529,22 +529,14 @@ protected:
   // pg state
   pg_info_t info;               ///< current pg info
   pg_info_t last_written_info;  ///< last written info
-  __u8 info_struct_v;
-public:
-  static const __u8 cur_struct_v = 10;
+  __u8 info_struct_v = 0;
+  static const __u8 latest_struct_v = 10;
   // v10 is the new past_intervals encoding
   // v9 was fastinfo_key addition
   // v8 was the move to a per-pg pgmeta object
   // v7 was SnapMapper addition in 86658392516d5175b2756659ef7ffaaf95b0f8ad
   // (first appeared in cuttlefish).
   static const __u8 compat_struct_v = 10;
-protected:
-  bool must_upgrade() {
-    return info_struct_v < cur_struct_v;
-  }
-  bool can_upgrade() {
-    return info_struct_v >= compat_struct_v;
-  }
   void upgrade(ObjectStore *store);
 
 protected: