]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd/: move pg/osd state machinery into osd_types for use in crimson
authorSamuel Just <sjust@redhat.com>
Thu, 30 May 2019 00:31:46 +0000 (17:31 -0700)
committerSamuel Just <sjust@redhat.com>
Fri, 31 May 2019 21:04:32 +0000 (14:04 -0700)
Signed-off-by: Samuel Just <sjust@redhat.com>
src/osd/OSD.cc
src/osd/PG.cc
src/osd/PG.h
src/osd/PrimaryLogPG.h
src/osd/osd_types.cc
src/osd/osd_types.h
src/tools/ceph_objectstore_tool.cc

index 6e20299efcb78418a797ee714a6a01ffc6483ca4..744dda22caa23cdcac2ef8b3476e9e7f79ce985c 100644 (file)
@@ -4084,8 +4084,9 @@ PGRef OSD::handle_pg_create_info(const OSDMapRef& osdmap,
                 << "the pool allows ec overwrites but is not stored in "
                 << "bluestore, so deep scrubbing will not detect bitrot";
   }
-  PG::_create(rctx.transaction, pgid, pgid.get_split_bits(pp->get_pg_num()));
-  PG::_init(rctx.transaction, pgid, pp);
+  create_pg_collection(
+    rctx.transaction, pgid, pgid.get_split_bits(pp->get_pg_num()));
+  init_pg_ondisk(rctx.transaction, pgid, pp);
 
   int role = startmap->calc_pg_role(whoami, acting, acting.size());
   if (!pp->is_replicated() && role != pgid.shard) {
index 430362792f982b4564c3c3b0abcc30eb3ac02d3b..0809de971313b27c502e8bd6bac001a6661153be 100644 (file)
@@ -871,7 +871,7 @@ void PG::shutdown()
 
 void PG::upgrade(ObjectStore *store)
 {
-  dout(0) << __func__ << " " << info_struct_v << " -> " << latest_struct_v
+  dout(0) << __func__ << " " << info_struct_v << " -> " << pg_latest_struct_v
          << dendl;
   ceph_assert(info_struct_v <= 10);
   ObjectStore::Transaction t;
@@ -882,9 +882,9 @@ void PG::upgrade(ObjectStore *store)
   ceph_assert(info_struct_v == 10);
 
   // update infover_key
-  if (info_struct_v < latest_struct_v) {
+  if (info_struct_v < pg_latest_struct_v) {
     map<string,bufferlist> v;
-    __u8 ver = latest_struct_v;
+    __u8 ver = pg_latest_struct_v;
     encode(ver, v[string(infover_key)]);
     t.omap_setkeys(coll, pgmeta_oid, v);
   }
@@ -909,35 +909,6 @@ void PG::upgrade(ObjectStore *store)
 #pragma GCC diagnostic pop
 #pragma GCC diagnostic warning "-Wpragmas"
 
-void PG::_create(ObjectStore::Transaction& t, spg_t pgid, int bits)
-{
-  coll_t coll(pgid);
-  t.create_collection(coll, bits);
-}
-
-void PG::_init(ObjectStore::Transaction& t, spg_t pgid, const pg_pool_t *pool)
-{
-  coll_t coll(pgid);
-
-  if (pool) {
-    // Give a hint to the PG collection
-    bufferlist hint;
-    uint32_t pg_num = pool->get_pg_num();
-    uint64_t expected_num_objects_pg = pool->expected_num_objects / pg_num;
-    encode(pg_num, hint);
-    encode(expected_num_objects_pg, hint);
-    uint32_t hint_type = ObjectStore::Transaction::COLL_HINT_EXPECTED_NUM_OBJECTS;
-    t.collection_hint(coll, hint_type, hint);
-  }
-
-  ghobject_t pgmeta_oid(pgid.make_pgmeta_oid());
-  t.touch(coll, pgmeta_oid);
-  map<string,bufferlist> values;
-  __u8 struct_v = latest_struct_v;
-  encode(struct_v, values[string(infover_key)]);
-  t.omap_setkeys(coll, pgmeta_oid, values);
-}
-
 void PG::prepare_write(
   pg_info_t &info,
   pg_info_t &last_written_info,
@@ -1115,7 +1086,7 @@ void PG::read_state(ObjectStore *store)
     info_struct_v);
   ceph_assert(r >= 0);
 
-  if (info_struct_v < compat_struct_v) {
+  if (info_struct_v < pg_compat_struct_v) {
     derr << "PG needs upgrade, but on-disk data is too old; upgrade to"
         << " an older version first." << dendl;
     ceph_abort_msg("PG too old to upgrade");
@@ -1140,7 +1111,7 @@ void PG::read_state(ObjectStore *store)
       return 0;
     });
 
-  if (info_struct_v < latest_struct_v) {
+  if (info_struct_v < pg_latest_struct_v) {
     upgrade(store);
   }
 
@@ -3780,10 +3751,10 @@ void PG::do_delete_work(ObjectStore::Transaction &t)
     if (!osd->try_finish_pg_delete(this, pool.info.get_pg_num())) {
       dout(1) << __func__ << " raced with merge, reinstantiating" << dendl;
       ch = osd->store->create_new_collection(coll);
-      _create(t,
+      create_pg_collection(t,
              info.pgid,
              info.pgid.get_split_bits(pool.info.get_pg_num()));
-      _init(t, info.pgid, &pool.info);
+      init_pg_ondisk(t, info.pgid, &pool.info);
       recovery_state.reset_last_persisted();
     } else {
       recovery_state.set_delete_complete();
index 16a94d4048a976c59cb3e1cd80154fdfdb911b8f..1b425525b86c05ec8b6b7ec324184e210dc03ec1 100644 (file)
@@ -351,10 +351,10 @@ public:
   static int peek_map_epoch(ObjectStore *store, spg_t pgid, epoch_t *pepoch);
 
   static int get_latest_struct_v() {
-    return latest_struct_v;
+    return pg_latest_struct_v;
   }
   static int get_compat_struct_v() {
-    return compat_struct_v;
+    return pg_compat_struct_v;
   }
   static int read_info(
     ObjectStore *store, spg_t pgid, const coll_t &coll,
@@ -646,13 +646,6 @@ protected:
 
 protected:
   __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;
   void upgrade(ObjectStore *store);
 
 protected:
@@ -1405,10 +1398,6 @@ protected:
   void do_pending_flush();
 
 public:
-  static void _create(ObjectStore::Transaction& t, spg_t pgid, int bits);
-  static void _init(ObjectStore::Transaction& t,
-                   spg_t pgid, const pg_pool_t *pool);
-
   virtual void prepare_write(
     pg_info_t &info,
     pg_info_t &last_written_info,
index 31ba38ab9a0e4d687b4bfa3476e83eb0f71fe5ef..7ed859780f1277cf465b6060b69dde13e7ebd794 100644 (file)
@@ -1552,13 +1552,13 @@ public:
     const pg_pool_t *pool,
     ObjectStore::Transaction &t) override {
     coll_t target = coll_t(child);
-    PG::_create(t, child, split_bits);
+    create_pg_collection(t, child, split_bits);
     t.split_collection(
       coll,
       split_bits,
       seed,
       target);
-    PG::_init(t, child, pool);
+    init_pg_ondisk(t, child, pool);
   }
 private:
 
index 79802e4dd647dfeabc864d82eba8e95ef7a20e4b..771326a09f7dc69d12b48a8bc4790b8966a5c205 100644 (file)
@@ -37,6 +37,7 @@ extern "C" {
 #include "common/Formatter.h"
 #include "OSDMap.h"
 #include "osd_types.h"
+#include "os/Transaction.h"
 
 using std::list;
 using std::make_pair;
@@ -6648,3 +6649,34 @@ int prepare_info_keymap(
   return 0;
 }
 
+void create_pg_collection(
+  ceph::os::Transaction& t, spg_t pgid, int bits)
+{
+  coll_t coll(pgid);
+  t.create_collection(coll, bits);
+}
+
+void init_pg_ondisk(
+  ceph::os::Transaction& t,
+  spg_t pgid,
+  const pg_pool_t *pool)
+{
+  coll_t coll(pgid);
+  if (pool) {
+    // Give a hint to the PG collection
+    bufferlist hint;
+    uint32_t pg_num = pool->get_pg_num();
+    uint64_t expected_num_objects_pg = pool->expected_num_objects / pg_num;
+    encode(pg_num, hint);
+    encode(expected_num_objects_pg, hint);
+    uint32_t hint_type = ceph::os::Transaction::COLL_HINT_EXPECTED_NUM_OBJECTS;
+    t.collection_hint(coll, hint_type, hint);
+  }
+
+  ghobject_t pgmeta_oid(pgid.make_pgmeta_oid());
+  t.touch(coll, pgmeta_oid);
+  map<string,bufferlist> values;
+  __u8 struct_v = pg_latest_struct_v;
+  encode(struct_v, values[string(infover_key)]);
+  t.omap_setkeys(coll, pgmeta_oid, values);
+}
index a86c840b815d2da71a16c6974026a4ea1a6a705a..6713456d06ddeec4984da08e9659421160ae5164 100644 (file)
@@ -6013,6 +6013,14 @@ static const string_view biginfo_key = "_biginfo"sv;
 static const string_view epoch_key = "_epoch"sv;
 static const string_view fastinfo_key = "_fastinfo"sv;
 
+static const __u8 pg_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 pg_compat_struct_v = 10;
+
 int prepare_info_keymap(
   CephContext* cct,
   map<string,bufferlist> *km,
@@ -6026,6 +6034,16 @@ int prepare_info_keymap(
   PerfCounters *logger = nullptr,
   DoutPrefixProvider *dpp = nullptr);
 
+namespace ceph::os {
+  class Transaction;
+};
+
+void create_pg_collection(
+  ceph::os::Transaction& t, spg_t pgid, int bits);
+
+void init_pg_ondisk(
+  ceph::os::Transaction& t, spg_t pgid, const pg_pool_t *pool);
+
 // omap specific stats
 struct omap_stat_t {
  int large_omap_objects;
index fe6c91ec6198b44cf3bf62381861310f449acba7..27242aea2d2a0ddddf9fb589746abf1ce7b3dd6e 100644 (file)
@@ -1759,10 +1759,10 @@ int ObjectStoreTool::do_import(ObjectStore *store, OSDSuperblock& sb,
       if (!dry_run) {
        ObjectStore::Transaction t;
        ch = store->create_new_collection(coll);
-       PG::_create(
+       create_pg_collection(
          t, pgid,
          pgid.get_split_bits(ms.osdmap.get_pg_pool(pgid.pool())->get_pg_num()));
-       PG::_init(t, pgid, NULL);
+       init_pg_ondisk(t, pgid, NULL);
 
        // mark this coll for removal until we're done
        map<string,bufferlist> values;