summaryrefslogtreecommitdiff
path: root/src/mongo/s/chunk_version.cpp
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2022-05-17 14:58:04 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-05-17 16:12:50 +0000
commitb070532288487c1e70af51756587943aa092160b (patch)
tree27a8b442115d911d9a30ddcfbd9aaae17dd14015 /src/mongo/s/chunk_version.cpp
parent286d2a9de1fe9492899f90c015de814699e3dc20 (diff)
downloadmongo-b070532288487c1e70af51756587943aa092160b.tar.gz
SERVER-65530 Get rid of ChunkVersionArrayWronglyEncodedAsBSONObjFormat
Diffstat (limited to 'src/mongo/s/chunk_version.cpp')
-rw-r--r--src/mongo/s/chunk_version.cpp32
1 files changed, 20 insertions, 12 deletions
diff --git a/src/mongo/s/chunk_version.cpp b/src/mongo/s/chunk_version.cpp
index 434b7303d9e..1073e819413 100644
--- a/src/mongo/s/chunk_version.cpp
+++ b/src/mongo/s/chunk_version.cpp
@@ -57,16 +57,6 @@ std::string CollectionGeneration::toString() const {
return str::stream() << _epoch << "|" << _timestamp;
}
-ChunkVersion ChunkVersion::_parse60Format(const BSONObj& obj) {
- IDLParserErrorContext ctx("_parse60Format");
- auto parsedVersion = ChunkVersion60Format::parse(ctx, obj);
- auto version = parsedVersion.getVersion();
- return ChunkVersion(version.getSecs(),
- version.getInc(),
- parsedVersion.getEpoch(),
- parsedVersion.getTimestamp());
-}
-
ChunkVersion ChunkVersion::_parseArrayOrObjectPositionalFormat(const BSONObj& obj) {
BSONObjIterator it(obj);
uassert(ErrorCodes::BadValue, "Unexpected empty version array", it.more());
@@ -199,7 +189,7 @@ StatusWith<ChunkVersion> ChunkVersion::_parseLegacyWithField(const BSONObj& obj,
ChunkVersion ChunkVersion::fromBSONLegacyOrNewerFormat(const BSONObj& obj, StringData field) {
// New format.
if (obj[field].isABSONObj()) {
- return _parse60Format(obj[field].Obj());
+ return parse(obj[field]);
}
// Legacy format.
@@ -208,13 +198,31 @@ ChunkVersion ChunkVersion::fromBSONLegacyOrNewerFormat(const BSONObj& obj, Strin
ChunkVersion ChunkVersion::fromBSONPositionalOrNewerFormat(const BSONElement& element) {
auto obj = element.Obj();
+
// Positional or wrongly encoded format.
if (obj.couldBeArray()) {
return ChunkVersion::_parseArrayOrObjectPositionalFormat(obj);
}
// New format.
- return _parse60Format(obj);
+ return parse(element);
+}
+
+ChunkVersion ChunkVersion::parse(const BSONElement& element) {
+ auto parsedVersion =
+ ChunkVersion60Format::parse(IDLParserErrorContext("ChunkVersion"), element.Obj());
+ auto version = parsedVersion.getVersion();
+ return ChunkVersion(version.getSecs(),
+ version.getInc(),
+ parsedVersion.getEpoch(),
+ parsedVersion.getTimestamp());
+}
+
+void ChunkVersion::serialize(StringData field, BSONObjBuilder* builder) {
+ ChunkVersion60Format version;
+ version.setGeneration({_epoch, _timestamp});
+ version.setPlacement(Timestamp(majorVersion(), minorVersion()));
+ builder->append(field, version.toBSON());
}
void ChunkVersion::serializeToPositionalWronlyEcondedOr60AsBSON(StringData field,