break;
case FN_COLLECTION:
- if (!fs->store->collection_empty(cid))
- return -ENOTEMPTY;
- t.remove_collection(cid);
+ {
+ bool empty;
+ int r = fs->store->collection_empty(cid, &empty);
+ if (r < 0)
+ return r;
+ if (!empty)
+ return -ENOTEMPTY;
+ t.remove_collection(cid);
+ }
break;
case FN_OBJECT_DATA:
* is a collection empty?
*
* @param c collection
- * @returns true if empty, false otherwise
+ * @param empty true if the specified collection is empty, false otherwise
+ * @returns 0 on success, negative error code on failure.
*/
- virtual bool collection_empty(const coll_t& c) = 0;
+ virtual int collection_empty(const coll_t& c, bool *empty) = 0;
/**
* return the number of significant bits of the coll_t::pgid.
return coll_map.count(c);
}
-bool BlueStore::collection_empty(const coll_t& cid)
+int BlueStore::collection_empty(const coll_t& cid, bool *empty)
{
dout(15) << __func__ << " " << cid << dendl;
vector<ghobject_t> ls;
ghobject_t next;
int r = collection_list(cid, ghobject_t(), ghobject_t::get_max(), true, 1,
&ls, &next);
- if (r < 0)
- return false; // fixme?
- bool empty = ls.empty();
- dout(10) << __func__ << " " << cid << " = " << (int)empty << dendl;
- return empty;
+ if (r < 0) {
+ derr << __func__ << " collection_list returned: " << cpp_strerror(r)
+ << dendl;
+ return r;
+ }
+ *empty = ls.empty();
+ dout(10) << __func__ << " " << cid << " = " << (int)(*empty) << dendl;
+ return 0;
}
int BlueStore::collection_bits(const coll_t& cid)
CollectionHandle open_collection(const coll_t &c) override;
bool collection_exists(const coll_t& c) override;
- bool collection_empty(const coll_t& c) override;
+ int collection_empty(const coll_t& c, bool *empty) override;
int collection_bits(const coll_t& c) override;
int collection_list(const coll_t& cid, ghobject_t start, ghobject_t end,
return ret;
}
-bool FileStore::collection_empty(const coll_t& c)
+int FileStore::collection_empty(const coll_t& c, bool *empty)
{
tracepoint(objectstore, collection_empty_enter, c.c_str());
dout(15) << "collection_empty " << c << dendl;
Index index;
int r = get_index(c, &index);
- if (r < 0)
- return false;
+ if (r < 0) {
+ derr << __func__ << " get_index returned: " << cpp_strerror(r)
+ << dendl;
+ return r;
+ }
assert(NULL != index.index);
RWLock::RLocker l((index.index)->access_lock);
r = index->collection_list_partial(ghobject_t(), ghobject_t::get_max(), true,
1, &ls, NULL);
if (r < 0) {
+ derr << __func__ << " collection_list_partial returned: "
+ << cpp_strerror(r) << dendl;
assert(!m_filestore_fail_eio || r != -EIO);
- return false;
+ return r;
}
- bool ret = ls.empty();
- tracepoint(objectstore, collection_empty_exit, ret);
- return ret;
+ *empty = ls.empty();
+ tracepoint(objectstore, collection_empty_exit, *empty);
+ return 0;
}
int FileStore::collection_list(const coll_t& c, ghobject_t start, ghobject_t end,
bool sort_bitwise, int max,
dout(15) << __func__ << " collection: " << c << " pg number: "
<< pg_num << " expected number of objects: " << expected_num_objs << dendl;
- if (!collection_empty(c) && !replaying) {
+ bool empty;
+ int ret = collection_empty(c, &empty);
+ if (ret < 0)
+ return ret;
+ if (!empty && !replaying) {
dout(0) << "Failed to give an expected number of objects hint to collection : "
<< c << ", only empty collection can take such type of hint. " << dendl;
return 0;
}
- int ret;
Index index;
ret = get_index(c, &index);
if (ret < 0)
int list_collections(vector<coll_t>& ls, bool include_temp);
int collection_stat(const coll_t& c, struct stat *st);
bool collection_exists(const coll_t& c);
- bool collection_empty(const coll_t& c);
+ int collection_empty(const coll_t& c, bool *empty);
// omap (see ObjectStore.h for documentation)
using ObjectStore::omap_get;
return coll_map.count(c);
}
-bool KStore::collection_empty(const coll_t& cid)
+int KStore::collection_empty(const coll_t& cid, bool *empty)
{
dout(15) << __func__ << " " << cid << dendl;
vector<ghobject_t> ls;
ghobject_t next;
int r = collection_list(cid, ghobject_t(), ghobject_t::get_max(), true, 1,
&ls, &next);
- if (r < 0)
- return false; // fixme?
- bool empty = ls.empty();
- dout(10) << __func__ << " " << cid << " = " << (int)empty << dendl;
- return empty;
+ if (r < 0) {
+ derr << __func__ << " collection_list returned: " << cpp_strerror(r)
+ << dendl;
+ return r;
+ }
+ *empty = ls.empty();
+ dout(10) << __func__ << " " << cid << " = " << (int)(*empty) << dendl;
+ return 0;
}
int KStore::collection_list(
int list_collections(vector<coll_t>& ls);
bool collection_exists(const coll_t& c);
- bool collection_empty(const coll_t& c);
+ int collection_empty(const coll_t& c, bool *empty);
using ObjectStore::collection_list;
int collection_list(const coll_t& cid, ghobject_t start, ghobject_t end,
return coll_map.count(cid);
}
-bool MemStore::collection_empty(const coll_t& cid)
+int MemStore::collection_empty(const coll_t& cid, bool *empty)
{
dout(10) << __func__ << " " << cid << dendl;
CollectionRef c = get_collection(cid);
if (!c)
- return false;
+ return -ENOENT;
RWLock::RLocker l(c->lock);
-
- return c->object_map.empty();
+ *empty = c->object_map.empty();
+ return 0;
}
int MemStore::collection_list(const coll_t& cid, ghobject_t start, ghobject_t end,
return get_collection(c);
}
bool collection_exists(const coll_t& c) override;
- bool collection_empty(const coll_t& c) override;
+ int collection_empty(const coll_t& c, bool *empty) override;
using ObjectStore::collection_list;
int collection_list(const coll_t& cid, ghobject_t start, ghobject_t end,
bool sort_bitwise, int max,
ASSERT_EQ(r, 0);
}
{
- bool r = store->collection_empty(cid);
- ASSERT_TRUE(r);
+ bool empty;
+ int r = store->collection_empty(cid, &empty);
+ ASSERT_EQ(0, r);
+ ASSERT_TRUE(empty);
}
{
bufferptr bp;
ASSERT_EQ(r, 0);
}
{
- bool r = store->collection_empty(cid);
- ASSERT_TRUE(!r);
+ bool empty;
+ int r = store->collection_empty(cid, &empty);
+ ASSERT_EQ(0, r);
+ ASSERT_TRUE(!empty);
}
{
bufferptr bp;