summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jstests/core/time_series/time_series_metadata.js18
-rw-r--r--src/mongo/db/commands/write_commands/write_commands.cpp9
2 files changed, 20 insertions, 7 deletions
diff --git a/jstests/core/time_series/time_series_metadata.js b/jstests/core/time_series/time_series_metadata.js
index e5f0e00434e..7d1bb6b6003 100644
--- a/jstests/core/time_series/time_series_metadata.js
+++ b/jstests/core/time_series/time_series_metadata.js
@@ -64,13 +64,16 @@ const runTest = function(docsBucketA, docsBucketB) {
'invalid number of measurements in first bucket: ' + tojson(bucketDocs[0]));
if (docsBucketA[0].hasOwnProperty(metaFieldName)) {
assert.eq(docsBucketA[0][metaFieldName],
- bucketDocs[0].control.min[metaFieldName],
+ bucketDocs[0].control.meta,
'invalid control.meta in first bucket: ' + tojson(bucketDocs[0].control));
assert(bucketDocs[0].data.hasOwnProperty(metaFieldName),
'metadata missing first bucket data: ' + tojson(bucketDocs[0]));
} else {
- assert(!bucketDocs[0].control.hasOwnProperty(metaFieldName),
- 'invalid control.meta in first bucket: ' + tojson(bucketDocs[0].control));
+ assert(bucketDocs[0].control.hasOwnProperty('meta'),
+ 'missing control.meta in first bucket: ' + tojson(bucketDocs[0].control));
+ assert.eq(null,
+ bucketDocs[0].control.meta,
+ 'invalid control.meta for x in first bucket: ' + tojson(bucketDocs[0].control));
}
// Second bucket should contain documents specified in 'bucketB'.
@@ -79,13 +82,16 @@ const runTest = function(docsBucketA, docsBucketB) {
'invalid number of measurements in second bucket: ' + tojson(bucketDocs[1]));
if (docsBucketB[0].hasOwnProperty(metaFieldName)) {
assert.eq(docsBucketB[0][metaFieldName],
- bucketDocs[1].control.min[metaFieldName],
+ bucketDocs[1].control.meta,
'invalid control.meta in second bucket: ' + tojson(bucketDocs[1].control));
assert(bucketDocs[1].data.hasOwnProperty(metaFieldName),
'metadata missing second bucket data: ' + tojson(bucketDocs[1]));
} else {
- assert(!bucketDocs[1].control.hasOwnProperty(metaFieldName),
- 'invalid control.meta in second bucket: ' + tojson(bucketDocs[1].control));
+ assert(bucketDocs[1].control.hasOwnProperty('meta'),
+ 'missing control.meta in second bucket: ' + tojson(bucketDocs[1].control));
+ assert.eq(null,
+ bucketDocs[1].control.meta,
+ 'invalid control.meta for x in second bucket: ' + tojson(bucketDocs[1].control));
}
};
diff --git a/src/mongo/db/commands/write_commands/write_commands.cpp b/src/mongo/db/commands/write_commands/write_commands.cpp
index 6351b7211a4..14a482ea4da 100644
--- a/src/mongo/db/commands/write_commands/write_commands.cpp
+++ b/src/mongo/db/commands/write_commands/write_commands.cpp
@@ -178,6 +178,7 @@ BSONObj makeTimeseriesDataStages(const std::vector<BSONObj>& docs, uint16_t coun
*/
BSONObj makeTimeseriesUpsertRequest(const OID& oid,
const std::vector<BSONObj>& docs,
+ const BSONObj& metadata,
uint16_t count) {
BSONObjBuilder builder;
builder.append(write_ops::UpdateOpEntry::kQFieldName, BSON("_id" << oid));
@@ -190,6 +191,11 @@ BSONObj makeTimeseriesUpsertRequest(const OID& oid,
BSON("$set" << BSON("control.version"
<< BSON("$ifNull" << BSON_ARRAY("$control.version"
<< kTimeseriesControlVersion)))));
+ if (auto metadataElem = metadata.firstElement()) {
+ stagesBuilder.append(BSON(
+ "$set" << BSON("control.meta"
+ << BSON("$ifNull" << BSON_ARRAY("$control.meta" << metadataElem)))));
+ }
stagesBuilder.append(BSON("$set" << makeTimeseriesControlMinMaxStages(docs)));
stagesBuilder.append(BSON("$set" << makeTimeseriesDataStages(docs, count)));
}
@@ -491,6 +497,7 @@ private:
boost::optional<OID> electionId;
for (const auto& [bucketId, index] : bucketsToCommit) {
+ auto metadata = bucketCatalog.getMetadata(bucketId);
auto data = bucketCatalog.commit(bucketId);
while (!data.docs.empty()) {
BSONObjBuilder builder;
@@ -509,7 +516,7 @@ private:
BSONArrayBuilder updatesBuilder(
builder.subarrayStart(write_ops::Update::kUpdatesFieldName));
updatesBuilder.append(makeTimeseriesUpsertRequest(
- bucketId, data.docs, data.numCommittedMeasurements));
+ bucketId, data.docs, metadata, data.numCommittedMeasurements));
}
auto request = OpMsgRequest::fromDBAndBody(bucketsNs.db(), builder.obj());