]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/os/seastore: open_collection() returns nullptr if DNE 41708/head
authorKefu Chai <kchai@redhat.com>
Sat, 5 Jun 2021 09:39:25 +0000 (17:39 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 5 Jun 2021 10:02:45 +0000 (18:02 +0800)
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 <kchai@redhat.com>
src/crimson/os/seastore/seastore.cc

index 91cf5fdc9c13bddb1c0a557c9af00e9474c9d0e0..901e20128f51659ae3eed728716e4213b3329867 100644 (file)
@@ -155,7 +155,14 @@ seastar::future<CollectionRef> SeaStore::open_collection(const coll_t& cid)
 {
   LOG_PREFIX(SeaStore::open_collection);
   DEBUG("{}", cid);
-  return seastar::make_ready_future<CollectionRef>(_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<CollectionRef>(_get_collection(cid));
+    } else {
+      return seastar::make_ready_future<CollectionRef>();
+    }
+  });
 }
 
 seastar::future<std::vector<coll_t>> SeaStore::list_collections()