summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Larkin-York <dan.larkin-york@mongodb.com>2022-12-01 21:23:24 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-12-06 17:22:19 +0000
commit6161d3162222f03eb8cf959b5ecc940c598a337e (patch)
treec4740436b377b27563e9ace73c8b1f805675aa56
parentf2a5b9e9bf80da0cc90b1c8c1cf8513593b28192 (diff)
downloadmongo-6161d3162222f03eb8cf959b5ecc940c598a337e.tar.gz
SERVER-71723 Store WriteBatch measurements using small_vector
(cherry picked from commit 7ca2aafe4560839b35d7712eb2887baab6c7711a)
-rw-r--r--src/mongo/db/timeseries/bucket_catalog.cpp8
-rw-r--r--src/mongo/db/timeseries/bucket_catalog.h8
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<BSONObj>& 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<BSONObj>(_measurements.begin(), _measurements.end())
+ << "bucketMin" << _min << "bucketMax" << _max << "numCommittedMeasurements"
+ << int(_numPreviouslyCommittedMeasurements) << "newFieldNamesToBeInserted"
<< std::set<std::string>(
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<StringMapHashedKey, kNumStaticNewFields>;
+ // 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<BSONObj, kNumStaticBatchMeasurements>;
+
using StripeNumber = std::uint8_t;
using EraCountMap = std::map<uint64_t, uint64_t>;
@@ -208,7 +212,7 @@ public:
*/
const BucketHandle& bucket() const;
- const std::vector<BSONObj>& measurements() const;
+ const BatchMeasurements& measurements() const;
const BSONObj& min() const;
const BSONObj& max() const;
const StringMap<std::size_t>& newFieldNamesToBeInserted() const;
@@ -255,7 +259,7 @@ public:
OperationId _opId;
ExecutionStatsController _stats;
- std::vector<BSONObj> _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;