From f2914af52ebb3005d23ddd4fbf1dd882c53a03c5 Mon Sep 17 00:00:00 2001 From: Samuel Just Date: Thu, 6 Dec 2012 13:57:01 -0800 Subject: [PATCH] HashIndex: fix list_by_hash handling of next->is_max() get_path_str() should not handle hobject_t::get_max(). get_path_str() now asserts that the passed object is not max and the callers now check for is_max(). This caused HashIndex.cc to incorrectly scan an entire collection before returning no objects rather than scanning the top level and returning no objects. It did not actually list_by_hash to return an incorrect answer, however. Signed-off-by: Samuel Just Reviewed-by: Josh Durgin --- src/os/HashIndex.cc | 4 +++- src/test/filestore/store_test.cc | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/os/HashIndex.cc b/src/os/HashIndex.cc index 34a7074bce0b1..8948c5064119b 100644 --- a/src/os/HashIndex.cc +++ b/src/os/HashIndex.cc @@ -371,6 +371,7 @@ string HashIndex::get_hash_str(uint32_t hash) { } string HashIndex::get_path_str(const hobject_t &hoid) { + assert(!hoid.is_max()); return get_hash_str(hoid.hash); } @@ -428,7 +429,8 @@ int HashIndex::get_path_contents_by_hash(const vector &path, if (lower_bound && candidate < lower_bound->substr(0, candidate.size())) continue; if (next_object && - candidate < get_path_str(*next_object).substr(0, candidate.size())) + (next_object->is_max() || + candidate < get_path_str(*next_object).substr(0, candidate.size()))) continue; hash_prefixes->insert(cur_prefix + *i); } diff --git a/src/test/filestore/store_test.cc b/src/test/filestore/store_test.cc index 3a41fa10e4c6b..af13c4493e65c 100644 --- a/src/test/filestore/store_test.cc +++ b/src/test/filestore/store_test.cc @@ -198,9 +198,22 @@ TEST_F(StoreTest, ManyObjectTest) { } ASSERT_TRUE(listed.size() == created.size()); + hobject_t start, next; + objects.clear(); + r = store->collection_list_partial( + cid, + hobject_t::get_max(), + 50, + 60, + 0, + &objects, + &next + ); + ASSERT_EQ(r, 0); + ASSERT_TRUE(objects.empty()); + objects.clear(); listed.clear(); - hobject_t start, next; while (1) { r = store->collection_list_partial(cid, start, 50, -- 2.39.5