diff options
author | Tor Brede Vekterli <vekterli@yahooinc.com> | 2023-03-13 10:20:57 +0000 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@yahooinc.com> | 2023-03-13 10:20:57 +0000 |
commit | 9a23880768d1045917d635d2783b68268dca1047 (patch) | |
tree | e61c8c37afc3919d299061049ddd2576b5d96a3e /storage/src/tests/distributor | |
parent | 86748ce4fadf24108eb5a459fd7f6caa01623cc4 (diff) |
Be explicit about lbound/ubound for bucket DB iteration and add lbound variant
The DB API was rather coy about whether `forEach` had lower or
upper bound semantics with regards to the bucket ID passed in as
a starting point. Be explicit and add a lower-bound variant.
Diffstat (limited to 'storage/src/tests/distributor')
-rw-r--r-- | storage/src/tests/distributor/bucketdatabasetest.cpp | 85 | ||||
-rw-r--r-- | storage/src/tests/distributor/top_level_bucket_db_updater_test.cpp | 4 |
2 files changed, 59 insertions, 30 deletions
diff --git a/storage/src/tests/distributor/bucketdatabasetest.cpp b/storage/src/tests/distributor/bucketdatabasetest.cpp index 661fd7fee72..fcc64e0cccf 100644 --- a/storage/src/tests/distributor/bucketdatabasetest.cpp +++ b/storage/src/tests/distributor/bucketdatabasetest.cpp @@ -87,7 +87,7 @@ struct ListAllProcessor : public BucketDatabase::EntryProcessor { std::string dump_db(const BucketDatabase& db) { ListAllProcessor proc; - db.forEach(proc, document::BucketId()); + db.for_each_upper_bound(proc, document::BucketId()); return proc.ost.str(); } @@ -122,41 +122,70 @@ TEST_P(BucketDatabaseTest, iterating) { { ListAllProcessor proc; - db().forEach(proc, document::BucketId()); - - EXPECT_EQ( - std::string( - "BucketId(0x4000000000000010) : " - "node(idx=1,crc=0x0,docs=0/0,bytes=1/1,trusted=false,active=false,ready=false)\n" - "BucketId(0x400000000000002a) : " - "node(idx=3,crc=0x0,docs=0/0,bytes=1/1,trusted=false,active=false,ready=false)\n" - "BucketId(0x400000000000000b) : " - "node(idx=2,crc=0x0,docs=0/0,bytes=1/1,trusted=false,active=false,ready=false)\n"), - proc.ost.str()); + db().for_each_upper_bound(proc, document::BucketId()); + + EXPECT_EQ("BucketId(0x4000000000000010) : " + "node(idx=1,crc=0x0,docs=0/0,bytes=1/1,trusted=false,active=false,ready=false)\n" + "BucketId(0x400000000000002a) : " + "node(idx=3,crc=0x0,docs=0/0,bytes=1/1,trusted=false,active=false,ready=false)\n" + "BucketId(0x400000000000000b) : " + "node(idx=2,crc=0x0,docs=0/0,bytes=1/1,trusted=false,active=false,ready=false)\n", + proc.ost.str()); } { ListAllProcessor proc; - db().forEach(proc, document::BucketId(16, 0x2a)); + db().for_each_lower_bound(proc, document::BucketId()); // lbound (in practice) equal to ubound when starting at zero + + EXPECT_EQ("BucketId(0x4000000000000010) : " + "node(idx=1,crc=0x0,docs=0/0,bytes=1/1,trusted=false,active=false,ready=false)\n" + "BucketId(0x400000000000002a) : " + "node(idx=3,crc=0x0,docs=0/0,bytes=1/1,trusted=false,active=false,ready=false)\n" + "BucketId(0x400000000000000b) : " + "node(idx=2,crc=0x0,docs=0/0,bytes=1/1,trusted=false,active=false,ready=false)\n", + proc.ost.str()); + } + + { + ListAllProcessor proc; + db().for_each_upper_bound(proc, document::BucketId(16, 0x2a)); + + EXPECT_EQ("BucketId(0x400000000000000b) : " + "node(idx=2,crc=0x0,docs=0/0,bytes=1/1,trusted=false,active=false,ready=false)\n", + proc.ost.str()); + } + + { + ListAllProcessor proc; + db().for_each_lower_bound(proc, document::BucketId(16, 0x2a)); + // Includes 0x2a + EXPECT_EQ("BucketId(0x400000000000002a) : " + "node(idx=3,crc=0x0,docs=0/0,bytes=1/1,trusted=false,active=false,ready=false)\n" + "BucketId(0x400000000000000b) : " + "node(idx=2,crc=0x0,docs=0/0,bytes=1/1,trusted=false,active=false,ready=false)\n", + proc.ost.str()); + } - EXPECT_EQ( - std::string( - "BucketId(0x400000000000000b) : " - "node(idx=2,crc=0x0,docs=0/0,bytes=1/1,trusted=false,active=false,ready=false)\n"), - proc.ost.str()); + { + StoppingProcessor proc; + db().for_each_upper_bound(proc, document::BucketId()); + + EXPECT_EQ("BucketId(0x4000000000000010) : " + "node(idx=1,crc=0x0,docs=0/0,bytes=1/1,trusted=false,active=false,ready=false)\n" + "BucketId(0x400000000000002a) : " + "node(idx=3,crc=0x0,docs=0/0,bytes=1/1,trusted=false,active=false,ready=false)\n", + proc.ost.str()); } { StoppingProcessor proc; - db().forEach(proc, document::BucketId()); - - EXPECT_EQ( - std::string( - "BucketId(0x4000000000000010) : " - "node(idx=1,crc=0x0,docs=0/0,bytes=1/1,trusted=false,active=false,ready=false)\n" - "BucketId(0x400000000000002a) : " - "node(idx=3,crc=0x0,docs=0/0,bytes=1/1,trusted=false,active=false,ready=false)\n"), - proc.ost.str()); + db().for_each_lower_bound(proc, document::BucketId()); + + EXPECT_EQ("BucketId(0x4000000000000010) : " + "node(idx=1,crc=0x0,docs=0/0,bytes=1/1,trusted=false,active=false,ready=false)\n" + "BucketId(0x400000000000002a) : " + "node(idx=3,crc=0x0,docs=0/0,bytes=1/1,trusted=false,active=false,ready=false)\n", + proc.ost.str()); } } @@ -761,7 +790,7 @@ TEST_P(BucketDatabaseTest, DISABLED_benchmark_const_iteration) { auto elapsed = vespalib::BenchmarkTimer::benchmark([&] { DummyProcessor proc; - db().forEach(proc, document::BucketId()); + db().for_each_upper_bound(proc, document::BucketId()); }, 5); fprintf(stderr, "Full DB iteration of %s takes %g seconds\n", db().toString(false).c_str(), elapsed); diff --git a/storage/src/tests/distributor/top_level_bucket_db_updater_test.cpp b/storage/src/tests/distributor/top_level_bucket_db_updater_test.cpp index 7b4f688b253..d5d33a178fe 100644 --- a/storage/src/tests/distributor/top_level_bucket_db_updater_test.cpp +++ b/storage/src/tests/distributor/top_level_bucket_db_updater_test.cpp @@ -1697,7 +1697,7 @@ TopLevelBucketDBUpdaterTest::merge_bucket_lists( BucketDumper dumper_tmp(true); for (auto* s : distributor_stripes()) { auto& db = s->getBucketSpaceRepo().get(document::FixedBucketSpaces::default_space()).getBucketDatabase(); - db.forEach(dumper_tmp); + db.for_each_upper_bound(dumper_tmp); } { @@ -1717,7 +1717,7 @@ TopLevelBucketDBUpdaterTest::merge_bucket_lists( BucketDumper dumper(include_bucket_info); for (auto* s : distributor_stripes()) { auto& db = s->getBucketSpaceRepo().get(document::FixedBucketSpaces::default_space()).getBucketDatabase(); - db.forEach(dumper); + db.for_each_upper_bound(dumper); db.clear(); } return dumper.ost.str(); |