From 9fbd60131b5396beb81ce745c9ccf01388f7e303 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sat, 5 Jun 2021 17:39:25 +0800 Subject: [PATCH] crimson/os/seastore: open_collection() returns nullptr if DNE we check for the existence of meta collection by trying to open it, if it exists, we continue check for the superblock stored in it, if the superblock does not exist or corrupted, we consider it as a failure. before this change, open_collection() always return a valud Collection even if the store does not have the collection with specified cid. this behavior could be misleading in the use case above. after this change, open_collection() looks up the collections stored in root collection node for the specfied cid, and return nullptr if it does not exist. Signed-off-by: Kefu Chai --- src/crimson/os/seastore/seastore.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/crimson/os/seastore/seastore.cc b/src/crimson/os/seastore/seastore.cc index 91cf5fdc9c1..901e20128f5 100644 --- a/src/crimson/os/seastore/seastore.cc +++ b/src/crimson/os/seastore/seastore.cc @@ -155,7 +155,14 @@ seastar::future SeaStore::open_collection(const coll_t& cid) { LOG_PREFIX(SeaStore::open_collection); DEBUG("{}", cid); - return seastar::make_ready_future(_get_collection(cid)); + return list_collections().then([cid, this] (auto colls) { + if (auto found = std::find(colls.begin(), colls.end(), cid); + found != colls.end()) { + return seastar::make_ready_future(_get_collection(cid)); + } else { + return seastar::make_ready_future(); + } + }); } seastar::future> SeaStore::list_collections() -- 2.47.3