From 6161d3162222f03eb8cf959b5ecc940c598a337e Mon Sep 17 00:00:00 2001 From: Dan Larkin-York Date: Thu, 1 Dec 2022 21:23:24 +0000 Subject: SERVER-71723 Store WriteBatch measurements using small_vector (cherry picked from commit 7ca2aafe4560839b35d7712eb2887baab6c7711a) --- src/mongo/db/timeseries/bucket_catalog.cpp | 8 ++++---- src/mongo/db/timeseries/bucket_catalog.h | 8 ++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/mongo/db/timeseries/bucket_catalog.cpp b/src/mongo/db/timeseries/bucket_catalog.cpp index 1d25e6036a6..396e58dddec 100644 --- a/src/mongo/db/timeseries/bucket_catalog.cpp +++ b/src/mongo/db/timeseries/bucket_catalog.cpp @@ -767,7 +767,7 @@ const BucketCatalog::BucketHandle& BucketCatalog::WriteBatch::bucket() const { return _bucket; } -const std::vector& BucketCatalog::WriteBatch::measurements() const { +const BucketCatalog::BatchMeasurements& BucketCatalog::WriteBatch::measurements() const { return _measurements; } @@ -797,9 +797,9 @@ bool BucketCatalog::WriteBatch::finished() const { BSONObj BucketCatalog::WriteBatch::toBSON() const { auto toFieldName = [](const auto& nameHashPair) { return nameHashPair.first; }; - return BSON("docs" << _measurements << "bucketMin" << _min << "bucketMax" << _max - << "numCommittedMeasurements" << int(_numPreviouslyCommittedMeasurements) - << "newFieldNamesToBeInserted" + return BSON("docs" << std::vector(_measurements.begin(), _measurements.end()) + << "bucketMin" << _min << "bucketMax" << _max << "numCommittedMeasurements" + << int(_numPreviouslyCommittedMeasurements) << "newFieldNamesToBeInserted" << std::set( boost::make_transform_iterator(_newFieldNamesToBeInserted.begin(), toFieldName), diff --git a/src/mongo/db/timeseries/bucket_catalog.h b/src/mongo/db/timeseries/bucket_catalog.h index bc907eadccf..5880ca39dff 100644 --- a/src/mongo/db/timeseries/bucket_catalog.h +++ b/src/mongo/db/timeseries/bucket_catalog.h @@ -53,6 +53,10 @@ protected: static constexpr std::size_t kNumStaticNewFields = 10; using NewFieldNames = boost::container::small_vector; + // Number of measurements we can hold in a batch without needing to allocate memory. + static constexpr std::size_t kNumStaticBatchMeasurements = 10; + using BatchMeasurements = boost::container::small_vector; + using StripeNumber = std::uint8_t; using EraCountMap = std::map; @@ -208,7 +212,7 @@ public: */ const BucketHandle& bucket() const; - const std::vector& measurements() const; + const BatchMeasurements& measurements() const; const BSONObj& min() const; const BSONObj& max() const; const StringMap& newFieldNamesToBeInserted() const; @@ -255,7 +259,7 @@ public: OperationId _opId; ExecutionStatsController _stats; - std::vector _measurements; + BatchMeasurements _measurements; BSONObj _min; // Batch-local min; full if first batch, updates otherwise. BSONObj _max; // Batch-local max; full if first batch, updates otherwise. uint32_t _numPreviouslyCommittedMeasurements = 0; -- cgit v1.2.1