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>
{
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()