diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 6e20299efcb..744dda22caa 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -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) { diff --git a/src/osd/PG.cc b/src/osd/PG.cc index 430362792f9..0809de97131 100644 --- a/src/osd/PG.cc +++ b/src/osd/PG.cc @@ -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 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 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(); diff --git a/src/osd/PG.h b/src/osd/PG.h index 16a94d4048a..1b425525b86 100644 --- a/src/osd/PG.h +++ b/src/osd/PG.h @@ -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, diff --git a/src/osd/PrimaryLogPG.h b/src/osd/PrimaryLogPG.h index 31ba38ab9a0..7ed859780f1 100644 --- a/src/osd/PrimaryLogPG.h +++ b/src/osd/PrimaryLogPG.h @@ -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: diff --git a/src/osd/osd_types.cc b/src/osd/osd_types.cc index 79802e4dd64..771326a09f7 100644 --- a/src/osd/osd_types.cc +++ b/src/osd/osd_types.cc @@ -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 values; + __u8 struct_v = pg_latest_struct_v; + encode(struct_v, values[string(infover_key)]); + t.omap_setkeys(coll, pgmeta_oid, values); +} diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index a86c840b815..6713456d06d 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -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 *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; diff --git a/src/tools/ceph_objectstore_tool.cc b/src/tools/ceph_objectstore_tool.cc index fe6c91ec619..27242aea2d2 100644 --- a/src/tools/ceph_objectstore_tool.cc +++ b/src/tools/ceph_objectstore_tool.cc @@ -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 values;