Skip to content

Commit 5b2ea3d

Browse files
veselink1jimwwalker
authored andcommitted
[BP] MB-58893: Handle dropped collections when computing data size for filter
When calculating the total size of all collections referenced by the filter, handle the case where the collection is not found in the manifest. Change-Id: I44a4aacba111d0e731dcf043a9d51c8e316668d3 Reviewed-on: https://review.couchbase.org/c/kv_engine/+/200210 Well-Formed: Restriction Checker Reviewed-by: Vesko Karaganev <[email protected]> Tested-by: Jim Walker <[email protected]>
1 parent 09a1bd6 commit 5b2ea3d

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

engines/ep/src/collections/vbucket_filter.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,10 @@ Filter::CollectionSizeStats Filter::getSizeStats(
505505
for (auto [cid, sid] : filter) {
506506
(void)sid;
507507
const auto stats = manifest.lock(cid);
508+
if (!stats.valid()) {
509+
// The collection has been dropped, so we don't increment the stats.
510+
continue;
511+
}
508512
colItemCount += stats.getItemCount();
509513
colDiskSize += stats.getDiskSize();
510514
}

engines/ep/src/collections/vbucket_filter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ class Filter {
230230
};
231231

232232
/**
233-
* Get aggregated collection stats for all collections in the filter.
233+
* Get aggregated collection stats for all collections in the filter. Any
234+
* collections which do not exist are ignored from the aggregate.
234235
*/
235236
CollectionSizeStats getSizeStats(const Manifest& manifest) const;
236237

engines/ep/tests/module_tests/collections/filter_test.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,25 @@ TEST_F(CollectionsVBFilterTest, snappy_event) {
12401240
0}));
12411241
}
12421242

1243+
TEST_F(CollectionsVBFilterTest, size_stats_for_dropped_collection) {
1244+
cm.add(CollectionEntry::fruit);
1245+
auto m = makeManifest(cm);
1246+
vbm.update(*vb, m);
1247+
1248+
// Filter by fruit collection.
1249+
std::string filterJson = R"({"collections":["9"]})";
1250+
std::optional<std::string_view> filterManifest{filterJson};
1251+
Collections::VB::Filter filter(filterManifest, vbm, *cookie, *engine);
1252+
1253+
cm.remove(CollectionEntry::fruit);
1254+
m = makeManifest(cm);
1255+
vbm.update(*vb, m);
1256+
1257+
// Make sure getSizeStats does not crash due to the collection in the
1258+
// filter having been dropped.
1259+
filter.getSizeStats(vbm);
1260+
}
1261+
12431262
class CollectionsVBFilterAccessControlTest : public CollectionsVBFilterTest {
12441263
void TearDown() override {
12451264
MockCookie::setCheckPrivilegeFunction({});

0 commit comments

Comments
 (0)