From 48f4126507431da7c442411ab882c1c8e4e00c37 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 15 Sep 2017 23:31:54 -0400 Subject: [PATCH] osd/PG: simplify/streamline upgrade process There's no reason for this to be exposed to the OSD. Just do it directly in read_state(). Signed-off-by: Sage Weil --- src/osd/OSD.cc | 17 ----------------- src/osd/PG.cc | 18 +++++++++++++++--- src/osd/PG.h | 12 ++---------- 3 files changed, 17 insertions(+), 30 deletions(-) diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index e374bd1dcb4b0..75a020144b210 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -3879,8 +3879,6 @@ void OSD::load_pgs() derr << "failed to list pgs: " << cpp_strerror(-r) << dendl; } - bool has_upgraded = false; - for (vector::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 diff --git a/src/osd/PG.cc b/src/osd/PG.cc index 2cbd2379f6603..1dd26c0d78b12 100644 --- a/src/osd/PG.cc +++ b/src/osd/PG.cc @@ -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 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 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() diff --git a/src/osd/PG.h b/src/osd/PG.h index d52ebf8f3d140..4c2c9365b7116 100644 --- a/src/osd/PG.h +++ b/src/osd/PG.h @@ -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: -- 2.39.5