Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os/bluestore: fix collection_list end bound off-by-one #11771

Merged
merged 3 commits into from
Nov 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/os/bluestore/BlueStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5672,7 +5672,7 @@ int BlueStore::_collection_list(
}
dout(20) << __func__ << " pend " << pretty_binary_string(pend) << dendl;
while (true) {
if (!it->valid() || it->key() > pend) {
if (!it->valid() || it->key() >= pend) {
if (!it->valid())
dout(20) << __func__ << " iterator not valid (end of db?)" << dendl;
else
Expand All @@ -5691,14 +5691,15 @@ int BlueStore::_collection_list(
}
break;
}
dout(20) << __func__ << " key " << pretty_binary_string(it->key()) << dendl;
dout(30) << __func__ << " key " << pretty_binary_string(it->key()) << dendl;
if (is_extent_shard_key(it->key())) {
it->next();
continue;
}
ghobject_t oid;
int r = get_key_object(it->key(), &oid);
assert(r == 0);
dout(20) << __func__ << " oid " << oid << " end " << end << dendl;
if (ls->size() >= (unsigned)max) {
dout(20) << __func__ << " reached max " << max << dendl;
*pnext = oid;
Expand Down
2 changes: 1 addition & 1 deletion src/os/kstore/KStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1498,7 +1498,7 @@ int KStore::_collection_list(
}
dout(20) << __func__ << " pend " << pretty_binary_string(pend) << dendl;
while (true) {
if (!it->valid() || it->key() > pend) {
if (!it->valid() || it->key() >= pend) {
if (!it->valid())
dout(20) << __func__ << " iterator not valid (end of db?)" << dendl;
else
Expand Down
52 changes: 52 additions & 0 deletions src/test/objectstore/store_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2364,6 +2364,58 @@ TEST_P(StoreTest, SimpleListTest) {
}
}

TEST_P(StoreTest, ListEndTest) {
ObjectStore::Sequencer osr("test");
int r;
coll_t cid(spg_t(pg_t(0, 1), shard_id_t(1)));
{
ObjectStore::Transaction t;
t.create_collection(cid, 0);
cerr << "Creating collection " << cid << std::endl;
r = apply_transaction(store, &osr, std::move(t));
ASSERT_EQ(r, 0);
}
set<ghobject_t, ghobject_t::BitwiseComparator> all;
{
ObjectStore::Transaction t;
for (int i=0; i<200; ++i) {
string name("object_");
name += stringify(i);
ghobject_t hoid(hobject_t(sobject_t(name, CEPH_NOSNAP)),
ghobject_t::NO_GEN, shard_id_t(1));
hoid.hobj.pool = 1;
all.insert(hoid);
t.touch(cid, hoid);
cerr << "Creating object " << hoid << std::endl;
}
r = apply_transaction(store, &osr, std::move(t));
ASSERT_EQ(r, 0);
}
{
ghobject_t end(hobject_t(sobject_t("object_100", CEPH_NOSNAP)),
ghobject_t::NO_GEN, shard_id_t(1));
end.hobj.pool = 1;
vector<ghobject_t> objects;
ghobject_t next;
int r = store->collection_list(cid, ghobject_t(), end,
true, 500,
&objects, &next);
ASSERT_EQ(r, 0);
for (auto &p : objects) {
ASSERT_NE(p, end);
}
}
{
ObjectStore::Transaction t;
for (set<ghobject_t, ghobject_t::BitwiseComparator>::iterator p = all.begin(); p != all.end(); ++p)
t.remove(cid, *p);
t.remove_collection(cid);
cerr << "Cleaning" << std::endl;
r = apply_transaction(store, &osr, std::move(t));
ASSERT_EQ(r, 0);
}
}

TEST_P(StoreTest, Sort) {
{
hobject_t a(sobject_t("a", CEPH_NOSNAP));
Expand Down