summaryrefslogtreecommitdiff
path: root/src/mongo/idl
diff options
context:
space:
mode:
authorMatt Broadstone <mbroadst@mongodb.com>2022-01-13 19:30:48 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-01-13 20:27:45 +0000
commit364268284a6131c04e7abed051e5851479dceb6d (patch)
treed1424dec4e034dd6a2bf7d80f6bdef2b3a3ac580 /src/mongo/idl
parent4ec9cbe31da4397c101ad4500854eaf9a4a6d45d (diff)
downloadmongo-364268284a6131c04e7abed051e5851479dceb6d.tar.gz
SERVER-62016 support tagged write concerns
Diffstat (limited to 'src/mongo/idl')
-rw-r--r--src/mongo/idl/basic_types.h28
-rw-r--r--src/mongo/idl/basic_types.idl7
2 files changed, 22 insertions, 13 deletions
diff --git a/src/mongo/idl/basic_types.h b/src/mongo/idl/basic_types.h
index 42619522f3b..a725e9a8c87 100644
--- a/src/mongo/idl/basic_types.h
+++ b/src/mongo/idl/basic_types.h
@@ -29,6 +29,7 @@
#pragma once
+#include "mongo/util/assert_util.h"
#include <boost/optional.hpp>
#include "mongo/base/string_data.h"
@@ -191,21 +192,32 @@ public:
return WriteConcernW{wEl.safeNumberLong()};
} else if (wEl.type() == BSONType::String) {
return WriteConcernW{wEl.str()};
+ } else if (wEl.type() == BSONType::Object) {
+ auto tags = wEl.Obj().getOwned();
+ auto valid =
+ std::all_of(tags.begin(), tags.end(), [](BSONElement e) { return e.isNumber(); });
+ uassert(ErrorCodes::FailedToParse,
+ "tags must be a single level document with only number values",
+ valid);
+
+ return WriteConcernW{std::move(tags)};
} else if (wEl.eoo() || wEl.type() == BSONType::jstNULL ||
wEl.type() == BSONType::Undefined) {
return WriteConcernW{};
}
- uasserted(ErrorCodes::FailedToParse, "w has to be a number or string");
+ uasserted(ErrorCodes::FailedToParse, "w has to be a number, string, or object");
}
void serializeWriteConcernW(StringData fieldName, BSONObjBuilder* builder) const {
if (auto stringVal = stdx::get_if<std::string>(&_w)) {
builder->append(fieldName, *stringVal);
- return;
+ } else if (auto objVal = stdx::get_if<BSONObj>(&_w)) {
+ builder->append(fieldName, *objVal);
+ } else {
+ auto intVal = stdx::get_if<std::int64_t>(&_w);
+ invariant(intVal);
+ builder->appendNumber(fieldName, static_cast<long long>(*intVal));
}
- auto intVal = stdx::get_if<std::int64_t>(&_w);
- invariant(intVal);
- builder->appendNumber(fieldName, static_cast<long long>(*intVal));
}
WriteConcernW() : _w{1}, _usedDefaultConstructedW1{true} {};
@@ -214,14 +226,16 @@ public:
return _usedDefaultConstructedW1;
}
- stdx::variant<std::string, std::int64_t> getValue() const {
+ stdx::variant<std::string, std::int64_t, BSONObj> getValue() const {
return _w;
}
private:
WriteConcernW(std::int64_t w) : _w{w}, _usedDefaultConstructedW1{false} {};
WriteConcernW(std::string&& w) : _w(std::move(w)), _usedDefaultConstructedW1{false} {};
- stdx::variant<std::string, std::int64_t> _w;
+ WriteConcernW(BSONObj&& tags) : _w(std::move(tags)), _usedDefaultConstructedW1{false} {};
+
+ stdx::variant<std::string, std::int64_t, BSONObj> _w;
bool _usedDefaultConstructedW1;
};
diff --git a/src/mongo/idl/basic_types.idl b/src/mongo/idl/basic_types.idl
index ae3041063cd..03cf00ba413 100644
--- a/src/mongo/idl/basic_types.idl
+++ b/src/mongo/idl/basic_types.idl
@@ -242,12 +242,7 @@ types:
deserializer: mongo::IDLAnyTypeOwned::parseFromBSON
writeConcernW:
- bson_serialization_type:
- - string
- - int
- - decimal
- - double
- - long
+ bson_serialization_type: any
description: >-
A string or integer representing the 'w' option in a document specifying write concern.
See https://docs.mongodb.com/manual/reference/write-concern/"