Skip to content

Commit 6f0803a

Browse files
committed
crimson/os: add FuturizedStore::Shard::exists() interface
Signed-off-by: Xuehan Xu <[email protected]>
1 parent 41e6d78 commit 6f0803a

File tree

7 files changed

+69
-1
lines changed

7 files changed

+69
-1
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,

0 commit comments

Comments
 (0)