Skip to content

Commit 09a1bd6

Browse files
veselink1jimwwalker
authored andcommitted
[BP] MB-58893: Extract collection size logic from tryAndScheduleOSOBackfill
And move it to the Collections::VB::Filter class, to make it easier to write a unit test against. Change-Id: I8b9cdb3e229713e7f76ab102d02e5f08617f0acc Reviewed-on: https://review.couchbase.org/c/kv_engine/+/200209 Reviewed-by: Vesko Karaganev <[email protected]> Tested-by: Jim Walker <[email protected]> Well-Formed: Restriction Checker
1 parent a2e3af5 commit 09a1bd6

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

engines/ep/src/collections/vbucket_filter.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,19 @@ cb::engine_errc Filter::checkPrivileges(
498498
return cb::engine_errc::success;
499499
}
500500

501+
Filter::CollectionSizeStats Filter::getSizeStats(
502+
const Manifest& manifest) const {
503+
size_t colItemCount = 0, colDiskSize = 0;
504+
// For each collection, obtain the item count and disk size
505+
for (auto [cid, sid] : filter) {
506+
(void)sid;
507+
const auto stats = manifest.lock(cid);
508+
colItemCount += stats.getItemCount();
509+
colDiskSize += stats.getDiskSize();
510+
}
511+
return {colItemCount, colDiskSize};
512+
}
513+
501514
void Filter::dump() const {
502515
std::cerr << *this << std::endl;
503516
}

engines/ep/src/collections/vbucket_filter.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,22 @@ class Filter {
218218
return !isPassThroughFilter() && !isLegacyFilter();
219219
}
220220

221+
struct CollectionSizeStats {
222+
/**
223+
* The number of items stored in the collections in the filter.
224+
*/
225+
size_t itemCount;
226+
/**
227+
* The tracked size (in bytes) of the collections in the filter on disk.
228+
*/
229+
size_t diskSize;
230+
};
231+
232+
/**
233+
* Get aggregated collection stats for all collections in the filter.
234+
*/
235+
CollectionSizeStats getSizeStats(const Manifest& manifest) const;
236+
221237
/**
222238
* Dump this to std::cerr
223239
*/

engines/ep/src/dcp/active_stream.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,12 +1922,9 @@ bool ActiveStream::tryAndScheduleOSOBackfill(DcpProducer& producer,
19221922
return false;
19231923
}
19241924
if (osoBackfill == "auto") {
1925-
// Retrieve collection stats from manifest; minimising the scope
1926-
// of manifest lock.
1927-
const auto [colItemCount, colDiskSize] = [&vb, cid] {
1928-
const auto stats = vb.getManifest().lock(cid);
1929-
return std::pair{stats.getItemCount(), stats.getDiskSize()};
1930-
}();
1925+
auto [colItemCount, colDiskSize] =
1926+
filter.getSizeStats(vb.getManifest());
1927+
19311928
const auto vbItemCount = vb.getNumItems();
19321929
if (!isOSOPreferredForCollectionBackfill(
19331930
config, colItemCount, colDiskSize, vbItemCount)) {

0 commit comments

Comments
 (0)