summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Noma <gregory.noma@gmail.com>2021-10-08 19:40:48 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-10-14 02:09:24 +0000
commit61b33a95185511390ba5fb1147b34ba7cd7c4ec6 (patch)
treec3b0565df92e0522c6cf612f9e3e126af31682d4
parent4dd1657c288948a150b66ea603f13aeb4ec9b835 (diff)
downloadmongo-61b33a95185511390ba5fb1147b34ba7cd7c4ec6.tar.gz
SERVER-60548 Check for `kUnset` in `MinMax::_appendUpdates`
(cherry picked from commit 2caf04aea31915ca82238559b57a4a2c170072c3)
-rw-r--r--src/mongo/db/timeseries/minmax.cpp3
-rw-r--r--src/mongo/db/timeseries/minmax_test.cpp22
2 files changed, 24 insertions, 1 deletions
diff --git a/src/mongo/db/timeseries/minmax.cpp b/src/mongo/db/timeseries/minmax.cpp
index f59c7f0d7e6..a2197045dad 100644
--- a/src/mongo/db/timeseries/minmax.cpp
+++ b/src/mongo/db/timeseries/minmax.cpp
@@ -591,7 +591,8 @@ bool MinMax::_appendUpdates(MinMaxStore::Obj obj, BSONObjBuilder* builder, GetDa
_clearUpdated(it, getData);
appended = true;
hasUpdateSection = true;
- } else if (subdata.type() != MinMaxStore::Type::kValue) {
+ } else if (subdata.type() != MinMaxStore::Type::kValue &&
+ subdata.type() != MinMaxStore::Type::kUnset) {
BSONObjBuilder subDiff;
if (_appendUpdates(obj.object(it), &subDiff, getData)) {
// An update occurred at a lower level, so append the sub diff.
diff --git a/src/mongo/db/timeseries/minmax_test.cpp b/src/mongo/db/timeseries/minmax_test.cpp
index dde3e0c8e63..eb2dea2be04 100644
--- a/src/mongo/db/timeseries/minmax_test.cpp
+++ b/src/mongo/db/timeseries/minmax_test.cpp
@@ -123,6 +123,28 @@ TEST(MinMax, MinMaxNoUpdatesAfterFullMinMax) {
ASSERT_BSONOBJ_EQ(minMaxObj.minUpdates(), BSON("u" << BSON("a" << 1)));
}
+TEST(MinMax, MinMaxNoUpdatesAfterFullMinMaxNested) {
+ MinMax minMaxObj;
+ const auto* strCmp = &SimpleStringDataComparator::kInstance;
+
+ auto obj = BSON("a" << BSON("z" << 1) << "b" << BSON_ARRAY(BSON("z" << 1) << BSON("z" << 2)));
+ minMaxObj.update(obj, "_meta"_sd, strCmp);
+ ASSERT_BSONOBJ_EQ(minMaxObj.min(), obj);
+ ASSERT_BSONOBJ_EQ(minMaxObj.max(), obj);
+ ASSERT_BSONOBJ_EQ(minMaxObj.minUpdates(), BSONObj{});
+ ASSERT_BSONOBJ_EQ(minMaxObj.maxUpdates(), BSONObj{});
+
+ minMaxObj.update(
+ BSON("a" << BSON_ARRAY(BSON("z" << 1) << BSON("z" << 2)) << "b" << BSON("z" << 1)),
+ "_meta"_sd,
+ strCmp);
+ ASSERT_BSONOBJ_EQ(minMaxObj.minUpdates(), BSON("u" << BSON("b" << BSON("z" << 1))));
+ ASSERT_BSONOBJ_EQ(minMaxObj.maxUpdates(),
+ BSON("u" << BSON("a" << BSON_ARRAY(BSON("z" << 1) << BSON("z" << 2)))));
+ ASSERT_BSONOBJ_EQ(minMaxObj.minUpdates(), BSONObj{});
+ ASSERT_BSONOBJ_EQ(minMaxObj.maxUpdates(), BSONObj{});
+}
+
TEST(MinMax, MinMaxInitialUpdates) {
MinMax minMaxObj;
const auto* strCmp = &SimpleStringDataComparator::kInstance;