Skip to content

Commit b420380

Browse files
authored
Merge pull request ceph#52267 from xxhdx1985126/wip-crimson-pg-snapmapper-obj
crimson/osd: put snapmapper's key-value pairs into dedicated objs Reviewed-by: Samuel Just <[email protected]> Reviewed-by: Matan Breizman <[email protected]>
2 parents f2af813 + 8f7921e commit b420380

File tree

11 files changed

+122
-16
lines changed

11 files changed

+122
-16
lines changed

src/crimson/os/alienstore/alien_store.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,19 @@ seastar::future<> AlienStore::stop()
136136
});
137137
}
138138

139+
AlienStore::base_errorator::future<bool>
140+
AlienStore::exists(
141+
CollectionRef ch,
142+
const ghobject_t& oid)
143+
{
144+
return seastar::with_gate(op_gate, [=, this] {
145+
return tp->submit(ch->get_cid().hash_to_shard(tp->size()), [=, this] {
146+
auto c = static_cast<AlienCollection*>(ch.get());
147+
return store->exists(c->collection, oid);
148+
});
149+
});
150+
}
151+
139152
AlienStore::mount_ertr::future<> AlienStore::mount()
140153
{
141154
logger().debug("{}", __func__);

src/crimson/os/alienstore/alien_store.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class AlienStore final : public FuturizedStore,
3333
mount_ertr::future<> mount() final;
3434
seastar::future<> umount() final;
3535

36+
base_errorator::future<bool> exists(
37+
CollectionRef c,
38+
const ghobject_t& oid) final;
3639
mkfs_ertr::future<> mkfs(uuid_d new_osd_fsid) final;
3740
read_errorator::future<ceph::bufferlist> read(CollectionRef c,
3841
const ghobject_t& oid,

src/crimson/os/cyanstore/cyan_store.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,22 @@ CyanStore::Shard::list_collections()
242242
return seastar::make_ready_future<std::vector<coll_core_t>>(std::move(collections));
243243
}
244244

245+
CyanStore::Shard::base_errorator::future<bool>
246+
CyanStore::Shard::exists(
247+
CollectionRef ch,
248+
const ghobject_t &oid)
249+
{
250+
auto c = static_cast<Collection*>(ch.get());
251+
if (!c->exists) {
252+
return base_errorator::make_ready_future<bool>(false);
253+
}
254+
auto o = c->get_object(oid);
255+
if (!o) {
256+
return base_errorator::make_ready_future<bool>(false);
257+
}
258+
return base_errorator::make_ready_future<bool>(true);
259+
}
260+
245261
CyanStore::Shard::read_errorator::future<ceph::bufferlist>
246262
CyanStore::Shard::read(
247263
CollectionRef ch,

src/crimson/os/cyanstore/cyan_store.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Transaction;
2626

2727
namespace crimson::os {
2828
class CyanStore final : public FuturizedStore {
29+
public:
2930
class Shard : public FuturizedStore::Shard {
3031
public:
3132
Shard(std::string path)
@@ -35,6 +36,10 @@ class CyanStore final : public FuturizedStore {
3536
CollectionRef c,
3637
const ghobject_t& oid) final;
3738

39+
base_errorator::future<bool> exists(
40+
CollectionRef ch,
41+
const ghobject_t& oid) final;
42+
3843
read_errorator::future<ceph::bufferlist> read(
3944
CollectionRef c,
4045
const ghobject_t& oid,
@@ -158,7 +163,6 @@ class CyanStore final : public FuturizedStore {
158163
std::map<coll_t, boost::intrusive_ptr<Collection>> new_coll_map;
159164
};
160165

161-
public:
162166
CyanStore(const std::string& path);
163167
~CyanStore() final;
164168

src/crimson/os/futurized_store.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class FuturizedStore {
3636
const Shard& operator=(const Shard& o) = delete;
3737

3838
using CollectionRef = boost::intrusive_ptr<FuturizedCollection>;
39+
using base_errorator = crimson::errorator<crimson::ct_error::input_output_error>;
3940
using read_errorator = crimson::errorator<crimson::ct_error::enoent,
4041
crimson::ct_error::input_output_error>;
4142
virtual read_errorator::future<ceph::bufferlist> read(
@@ -51,6 +52,10 @@ class FuturizedStore {
5152
interval_set<uint64_t>& m,
5253
uint32_t op_flags = 0) = 0;
5354

55+
virtual base_errorator::future<bool> exists(
56+
CollectionRef c,
57+
const ghobject_t& oid) = 0;
58+
5459
using get_attr_errorator = crimson::errorator<
5560
crimson::ct_error::enoent,
5661
crimson::ct_error::enodata>;

src/crimson/os/seastore/seastore.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,29 @@ SeaStore::Shard::read(
852852
});
853853
}
854854

855+
SeaStore::Shard::base_errorator::future<bool>
856+
SeaStore::Shard::exists(
857+
CollectionRef c,
858+
const ghobject_t& oid)
859+
{
860+
LOG_PREFIX(SeaStore::exists);
861+
DEBUG("oid {}", oid);
862+
return repeat_with_onode<bool>(
863+
c,
864+
oid,
865+
Transaction::src_t::READ,
866+
"oid_exists",
867+
op_type_t::READ,
868+
[](auto&, auto&) {
869+
return seastar::make_ready_future<bool>(true);
870+
}).handle_error(
871+
crimson::ct_error::enoent::handle([] {
872+
return seastar::make_ready_future<bool>(false);
873+
}),
874+
crimson::ct_error::assert_all{"unexpected error"}
875+
);
876+
}
877+
855878
SeaStore::Shard::read_errorator::future<ceph::bufferlist>
856879
SeaStore::Shard::readv(
857880
CollectionRef ch,

src/crimson/os/seastore/seastore.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ class SeaStore final : public FuturizedStore {
116116
interval_set<uint64_t>& m,
117117
uint32_t op_flags = 0) final;
118118

119+
base_errorator::future<bool> exists(
120+
CollectionRef c,
121+
const ghobject_t& oid) final;
122+
119123
get_attr_errorator::future<ceph::bufferlist> get_attr(
120124
CollectionRef c,
121125
const ghobject_t& oid,

src/crimson/osd/ops_executer.cc

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,10 @@ static PG::interruptible_future<hobject_t> pgls_filter(
11661166
}
11671167
}
11681168

1169+
static inline bool is_snapmapper_oid(const hobject_t &obj) {
1170+
return obj.oid.name == SNAPMAPPER_OID;
1171+
}
1172+
11691173
static PG::interruptible_future<ceph::bufferlist> do_pgnls_common(
11701174
const hobject_t& pg_start,
11711175
const hobject_t& pg_end,
@@ -1186,6 +1190,13 @@ static PG::interruptible_future<ceph::bufferlist> do_pgnls_common(
11861190
[&backend, filter, nspace](auto&& ret)
11871191
-> PG::interruptible_future<std::tuple<std::vector<hobject_t>, hobject_t>> {
11881192
auto& [objects, next] = ret;
1193+
auto is_snapmapper = [](const hobject_t &obj) {
1194+
if (is_snapmapper_oid(obj)) {
1195+
return false;
1196+
} else {
1197+
return true;
1198+
}
1199+
};
11891200
auto in_my_namespace = [&nspace](const hobject_t& obj) {
11901201
using crimson::common::local_conf;
11911202
if (obj.get_namespace() == local_conf()->osd_hit_set_namespace) {
@@ -1213,7 +1224,8 @@ static PG::interruptible_future<ceph::bufferlist> do_pgnls_common(
12131224
}
12141225
};
12151226

1216-
auto range = objects | boost::adaptors::filtered(in_my_namespace)
1227+
auto range = objects | boost::adaptors::filtered(is_snapmapper)
1228+
| boost::adaptors::filtered(in_my_namespace)
12171229
| boost::adaptors::transformed(to_pglsed);
12181230
logger().debug("do_pgnls_common: finishing the 1st stage of pgls");
12191231
return seastar::when_all_succeed(std::begin(range),
@@ -1346,6 +1358,9 @@ static PG::interruptible_future<ceph::bufferlist> do_pgls_common(
13461358
PG::interruptor::map_reduce(std::move(objects),
13471359
[&backend, filter, nspace](const hobject_t& obj)
13481360
-> PG::interruptible_future<hobject_t>{
1361+
if (is_snapmapper_oid(obj)) {
1362+
return seastar::make_ready_future<hobject_t>();
1363+
}
13491364
if (obj.get_namespace() == nspace) {
13501365
if (filter) {
13511366
return pgls_filter(*filter, backend, obj);

src/crimson/osd/pg.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ PG::PG(
136136
osdriver(
137137
&shard_services.get_store(),
138138
coll_ref,
139-
pgid.make_pgmeta_oid()),
139+
make_snapmapper_oid()),
140140
snap_mapper(
141141
this->shard_services.get_cct(),
142142
&osdriver,
@@ -596,7 +596,7 @@ void PG::schedule_renew_lease(epoch_t last_peering_reset, ceph::timespan delay)
596596
}
597597

598598

599-
void PG::init(
599+
seastar::future<> PG::init(
600600
int role,
601601
const vector<int>& newup, int new_up_primary,
602602
const vector<int>& newacting, int new_acting_primary,
@@ -607,6 +607,16 @@ void PG::init(
607607
peering_state.init(
608608
role, newup, new_up_primary, newacting,
609609
new_acting_primary, history, pi, t);
610+
assert(coll_ref);
611+
return shard_services.get_store().exists(
612+
get_collection_ref(), make_snapmapper_oid()
613+
).safe_then([&t, this](bool existed) {
614+
if (!existed) {
615+
t.touch(coll_ref->get_cid(), make_snapmapper_oid());
616+
}
617+
},
618+
::crimson::ct_error::assert_all{"unexpected eio"}
619+
);
610620
}
611621

612622
seastar::future<> PG::read_state(crimson::os::FuturizedStore::Shard* store)

src/crimson/osd/pg.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#include "crimson/osd/object_context_loader.h"
4242
#include "crimson/osd/scrub/pg_scrubber.h"
4343

44+
#define SNAPMAPPER_OID "snapmapper"
45+
4446
class MQuery;
4547
class OSDMap;
4648
class PGBackend;
@@ -471,7 +473,7 @@ class PG : public boost::intrusive_ref_counter<
471473
}
472474

473475
/// initialize created PG
474-
void init(
476+
seastar::future<> init(
475477
int role,
476478
const std::vector<int>& up,
477479
int up_primary,
@@ -647,12 +649,22 @@ class PG : public boost::intrusive_ref_counter<
647649
private:
648650
OSDriver osdriver;
649651
SnapMapper snap_mapper;
650-
652+
ghobject_t make_snapmapper_oid() const {
653+
return ghobject_t(hobject_t(
654+
sobject_t(
655+
object_t(SNAPMAPPER_OID),
656+
0),
657+
std::string(),
658+
pgid.ps(),
659+
pgid.pool(),
660+
std::string()));
661+
}
651662
public:
652663
// PeeringListener
653664
void publish_stats_to_osd() final;
654665
void clear_publish_stats() final;
655666
pg_stat_t get_stats() const;
667+
656668
private:
657669
std::optional<pg_stat_t> pg_stats;
658670

0 commit comments

Comments
 (0)