summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2022-06-16 09:34:27 +0200
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-06-17 14:20:28 +0000
commit9620b796444058fd69681973e9637880861d916d (patch)
treeada74a8ef29a0ad910dff14409e98f30eabe0abf /src/mongo
parent6dcf2594502b30a7199c3c0ff5e121132b2c0c8f (diff)
downloadmongo-9620b796444058fd69681973e9637880861d916d.tar.gz
SERVER-65530 Get rid of ChunkVersion::parse/serialiseMajorMinorVersionOnly
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/s/shard_metadata_util.cpp8
-rw-r--r--src/mongo/db/s/shard_server_catalog_cache_loader.cpp15
-rw-r--r--src/mongo/db/s/type_shard_collection.cpp20
-rw-r--r--src/mongo/db/s/type_shard_collection.h5
-rw-r--r--src/mongo/db/s/type_shard_collection.idl12
-rw-r--r--src/mongo/db/s/type_shard_collection_test.cpp21
-rw-r--r--src/mongo/s/chunk_version.cpp17
-rw-r--r--src/mongo/s/chunk_version.h6
8 files changed, 32 insertions, 72 deletions
diff --git a/src/mongo/db/s/shard_metadata_util.cpp b/src/mongo/db/s/shard_metadata_util.cpp
index 1651cfc167e..69d0a905642 100644
--- a/src/mongo/db/s/shard_metadata_util.cpp
+++ b/src/mongo/db/s/shard_metadata_util.cpp
@@ -105,8 +105,9 @@ Status unsetPersistedRefreshFlags(OperationContext* opCtx,
// Set 'refreshing' to false and update the last refreshed collection version.
BSONObjBuilder updateBuilder;
updateBuilder.append(ShardCollectionType::kRefreshingFieldName, false);
- updateBuilder.appendTimestamp(ShardCollectionType::kLastRefreshedCollectionVersionFieldName,
- refreshedVersion.toLong());
+ updateBuilder.appendTimestamp(
+ ShardCollectionType::kLastRefreshedCollectionMajorMinorVersionFieldName,
+ refreshedVersion.toLong());
return updateShardCollectionsEntry(opCtx,
BSON(ShardCollectionType::kNssFieldName << nss.ns()),
@@ -211,7 +212,8 @@ Status updateShardCollectionsEntry(OperationContext* opCtx,
if (upsert) {
// If upserting, this should be an update from the config server that does not have shard
// refresh / migration inc signal information.
- invariant(!update.hasField(ShardCollectionType::kLastRefreshedCollectionVersionFieldName));
+ invariant(!update.hasField(
+ ShardCollectionType::kLastRefreshedCollectionMajorMinorVersionFieldName));
}
try {
diff --git a/src/mongo/db/s/shard_server_catalog_cache_loader.cpp b/src/mongo/db/s/shard_server_catalog_cache_loader.cpp
index 1aa69f2140c..274ab8fd133 100644
--- a/src/mongo/db/s/shard_server_catalog_cache_loader.cpp
+++ b/src/mongo/db/s/shard_server_catalog_cache_loader.cpp
@@ -57,7 +57,6 @@
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding
-
namespace mongo {
using namespace shardmetadatautil;
@@ -211,13 +210,13 @@ ChunkVersion getPersistedMaxChunkVersion(OperationContext* opCtx, const Namespac
return ChunkVersion::UNSHARDED();
}
- auto statusWithChunk = shardmetadatautil::readShardChunks(opCtx,
- nss,
- BSONObj(),
- BSON(ChunkType::lastmod() << -1),
- 1LL,
- cachedCollection.getEpoch(),
- cachedCollection.getTimestamp());
+ auto statusWithChunk = readShardChunks(opCtx,
+ nss,
+ BSONObj(),
+ BSON(ChunkType::lastmod() << -1),
+ 1LL,
+ cachedCollection.getEpoch(),
+ cachedCollection.getTimestamp());
uassertStatusOKWithContext(
statusWithChunk,
str::stream() << "Failed to read highest version persisted chunk for collection '"
diff --git a/src/mongo/db/s/type_shard_collection.cpp b/src/mongo/db/s/type_shard_collection.cpp
index 4dbb0b1c2f8..30912e47a59 100644
--- a/src/mongo/db/s/type_shard_collection.cpp
+++ b/src/mongo/db/s/type_shard_collection.cpp
@@ -52,15 +52,6 @@ ShardCollectionType::ShardCollectionType(const BSONObj& obj) {
uassert(ErrorCodes::ShardKeyNotFound,
str::stream() << "Empty shard key. Failed to parse: " << obj.toString(),
!getKeyPattern().toBSON().isEmpty());
-
- // Last refreshed collection version is stored as a timestamp in the BSON representation of
- // shard collection type for legacy reasons. We therefore explicitly convert this timestamp, if
- // it exists, into a chunk version.
- if (getLastRefreshedCollectionVersion()) {
- ChunkVersion version = *getLastRefreshedCollectionVersion();
- setLastRefreshedCollectionVersion(ChunkVersion(
- version.majorVersion(), version.minorVersion(), getEpoch(), getTimestamp()));
- }
}
BSONObj ShardCollectionType::toBSON() const {
@@ -83,4 +74,15 @@ void ShardCollectionType::setAllowMigrations(bool allowMigrations) {
setPre50CompatibleAllowMigrations(false);
}
+boost::optional<ChunkVersion> ShardCollectionType::getLastRefreshedCollectionVersion() const {
+ // Last refreshed collection version is stored as a timestamp in the BSON representation of
+ // shard collection type for legacy reasons. We therefore explicitly convert this timestamp, if
+ // it exists, into a chunk version.
+ if (!getLastRefreshedCollectionMajorMinorVersion())
+ return boost::none;
+
+ Timestamp majorMinor = *getLastRefreshedCollectionMajorMinorVersion();
+ return ChunkVersion(majorMinor.getSecs(), majorMinor.getInc(), getEpoch(), getTimestamp());
+}
+
} // namespace mongo
diff --git a/src/mongo/db/s/type_shard_collection.h b/src/mongo/db/s/type_shard_collection.h
index 8180358174a..de6e56eb784 100644
--- a/src/mongo/db/s/type_shard_collection.h
+++ b/src/mongo/db/s/type_shard_collection.h
@@ -42,7 +42,7 @@ public:
using ShardCollectionTypeBase::kEnterCriticalSectionCounterFieldName;
using ShardCollectionTypeBase::kEpochFieldName;
using ShardCollectionTypeBase::kKeyPatternFieldName;
- using ShardCollectionTypeBase::kLastRefreshedCollectionVersionFieldName;
+ using ShardCollectionTypeBase::kLastRefreshedCollectionMajorMinorVersionFieldName;
using ShardCollectionTypeBase::kNssFieldName;
using ShardCollectionTypeBase::kRefreshingFieldName;
using ShardCollectionTypeBase::kReshardingFieldsFieldName;
@@ -57,7 +57,6 @@ public:
using ShardCollectionTypeBase::getEnterCriticalSectionCounter;
using ShardCollectionTypeBase::getEpoch;
using ShardCollectionTypeBase::getKeyPattern;
- using ShardCollectionTypeBase::getLastRefreshedCollectionVersion;
using ShardCollectionTypeBase::getMaxChunkSizeBytes;
using ShardCollectionTypeBase::getNss;
using ShardCollectionTypeBase::getRefreshing;
@@ -94,6 +93,8 @@ public:
return getPre50CompatibleAllowMigrations().value_or(true);
}
void setAllowMigrations(bool allowMigrations);
+
+ boost::optional<ChunkVersion> getLastRefreshedCollectionVersion() const;
};
} // namespace mongo
diff --git a/src/mongo/db/s/type_shard_collection.idl b/src/mongo/db/s/type_shard_collection.idl
index 051a6de35d3..11ef4a8daa7 100644
--- a/src/mongo/db/s/type_shard_collection.idl
+++ b/src/mongo/db/s/type_shard_collection.idl
@@ -80,15 +80,6 @@ imports:
- "mongo/s/resharding/type_collection_fields.idl"
- "mongo/s/type_collection_common_types.idl"
-types:
- ChunkVersionLegacy:
- bson_serialization_type: any
- description: "An object representing a chunk version for a collection. Ignores the
- component in the chunk version for legacy reasons."
- cpp_type: ChunkVersion
- serializer: ChunkVersion::serialiseMajorMinorVersionOnlyForShardCollectionType
- deserializer: ChunkVersion::parseMajorMinorVersionOnlyFromShardCollectionType
-
structs:
ShardCollectionTypeBase:
description: "Represents the layout and contents of documents contained in the shard
@@ -141,7 +132,8 @@ structs:
chunk metadata."
optional: true
lastRefreshedCollectionVersion:
- type: ChunkVersionLegacy
+ type: timestamp
+ cpp_name: lastRefreshedCollectionMajorMinorVersion
description: "Set by primaries and used by shard secondaries to safely refresh chunk
metadata. Indicates the collection version of the last complete chunk
metadata refresh, and is used to indicate if a refresh occurred if the
diff --git a/src/mongo/db/s/type_shard_collection_test.cpp b/src/mongo/db/s/type_shard_collection_test.cpp
index 59a85b1e13c..f21418cc206 100644
--- a/src/mongo/db/s/type_shard_collection_test.cpp
+++ b/src/mongo/db/s/type_shard_collection_test.cpp
@@ -67,25 +67,12 @@ TEST(ShardCollectionType, FromBSONEpochMatchesLastRefreshedCollectionVersionWhen
<< ShardCollectionType::kUuidFieldName << UUID::gen()
<< ShardCollectionType::kKeyPatternFieldName << kKeyPattern
<< ShardCollectionType::kUniqueFieldName << true
- << ShardCollectionType::kLastRefreshedCollectionVersionFieldName << Timestamp(1, 1)));
- ASSERT_EQ(epoch, shardCollType.getLastRefreshedCollectionVersion()->epoch());
- ASSERT_EQ(timestamp, shardCollType.getLastRefreshedCollectionVersion()->getTimestamp());
-}
-
-TEST(ShardCollectionType, FromBSONEpochMatchesLastRefreshedCollectionVersionWhenDate) {
- OID epoch = OID::gen();
- Timestamp timestamp(1, 1);
-
- ShardCollectionType shardCollType(
- BSON(ShardCollectionType::kNssFieldName
- << kNss.ns() << ShardCollectionType::kEpochFieldName << epoch
- << ShardCollectionType::kUuidFieldName << UUID::gen()
- << ShardCollectionType::kTimestampFieldName << timestamp
- << ShardCollectionType::kKeyPatternFieldName << kKeyPattern
- << ShardCollectionType::kUniqueFieldName << true
- << ShardCollectionType::kLastRefreshedCollectionVersionFieldName << Date_t()));
+ << ShardCollectionType::kLastRefreshedCollectionMajorMinorVersionFieldName
+ << Timestamp(123, 45)));
ASSERT_EQ(epoch, shardCollType.getLastRefreshedCollectionVersion()->epoch());
ASSERT_EQ(timestamp, shardCollType.getLastRefreshedCollectionVersion()->getTimestamp());
+ ASSERT_EQ(Timestamp(123, 45),
+ Timestamp(shardCollType.getLastRefreshedCollectionVersion()->toLong()));
}
TEST(ShardCollectionType, ToBSONEmptyDefaultCollationNotIncluded) {
diff --git a/src/mongo/s/chunk_version.cpp b/src/mongo/s/chunk_version.cpp
index c63214daf8e..12ed1ee72f7 100644
--- a/src/mongo/s/chunk_version.cpp
+++ b/src/mongo/s/chunk_version.cpp
@@ -78,21 +78,4 @@ std::string ChunkVersion::toString() const {
<< _timestamp.toString();
}
-ChunkVersion ChunkVersion::parseMajorMinorVersionOnlyFromShardCollectionType(
- const BSONElement& element) {
- uassert(ErrorCodes::TypeMismatch,
- str::stream() << "Invalid type " << element.type()
- << " for version major and minor part.",
- element.type() == bsonTimestamp || element.type() == Date);
-
- ChunkVersion version;
- version._combined = element._numberLong();
- return version;
-}
-
-void ChunkVersion::serialiseMajorMinorVersionOnlyForShardCollectionType(StringData field,
- BSONObjBuilder* out) const {
- out->appendTimestamp(field, toLong());
-}
-
} // namespace mongo
diff --git a/src/mongo/s/chunk_version.h b/src/mongo/s/chunk_version.h
index 79ff6c94c75..b25bae60691 100644
--- a/src/mongo/s/chunk_version.h
+++ b/src/mongo/s/chunk_version.h
@@ -199,12 +199,6 @@ public:
std::string toString() const;
- // Methods that are here for the purposes of parsing of ShardCollectionType only
- static ChunkVersion parseMajorMinorVersionOnlyFromShardCollectionType(
- const BSONElement& element);
- void serialiseMajorMinorVersionOnlyForShardCollectionType(StringData field,
- BSONObjBuilder* builder) const;
-
private:
// The combined major/minor version, which exists as subordinate to the collection generation
uint64_t _combined;