diff options
author | Sergi Mateo Bellido <sergi.mateo-bellido@mongodb.com> | 2020-12-02 12:59:01 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-12-10 10:14:41 +0000 |
commit | 4e5de13940486910b57c1feb57e58687f778b855 (patch) | |
tree | 6597549ba1d16a10b6e4f849d1ddcfdcfe006e23 /src | |
parent | f2f7e1d867dca21c66bd2ff699812f63b5f82b87 (diff) | |
download | mongo-4e5de13940486910b57c1feb57e58687f778b855.tar.gz |
SERVER-53093 Add timestamp to ChunkVersion
PART 1: Adding the timestamp to the ChunkVersion class and to the places
where we construct a ChunkVersion
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/s/config/configsvr_reshard_collection_cmd.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/s/config/initial_split_policy.cpp | 29 | ||||
-rw-r--r-- | src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp | 31 | ||||
-rw-r--r-- | src/mongo/db/s/set_shard_version_command.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/s/shard_metadata_util.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/s/shard_metadata_util.h | 3 | ||||
-rw-r--r-- | src/mongo/db/s/shard_server_catalog_cache_loader.cpp | 20 | ||||
-rw-r--r-- | src/mongo/db/s/type_shard_collection.cpp | 4 | ||||
-rw-r--r-- | src/mongo/s/catalog/type_chunk.cpp | 7 | ||||
-rw-r--r-- | src/mongo/s/catalog/type_chunk.h | 4 | ||||
-rw-r--r-- | src/mongo/s/catalog_cache.cpp | 1 | ||||
-rw-r--r-- | src/mongo/s/chunk_manager.cpp | 24 | ||||
-rw-r--r-- | src/mongo/s/chunk_manager.h | 8 | ||||
-rw-r--r-- | src/mongo/s/chunk_version.h | 15 | ||||
-rw-r--r-- | src/mongo/s/config_server_catalog_cache_loader.cpp | 2 |
15 files changed, 123 insertions, 46 deletions
diff --git a/src/mongo/db/s/config/configsvr_reshard_collection_cmd.cpp b/src/mongo/db/s/config/configsvr_reshard_collection_cmd.cpp index 3373da60a87..d22f559b15b 100644 --- a/src/mongo/db/s/config/configsvr_reshard_collection_cmd.cpp +++ b/src/mongo/db/s/config/configsvr_reshard_collection_cmd.cpp @@ -39,10 +39,12 @@ #include "mongo/db/s/resharding/resharding_coordinator_service.h" #include "mongo/db/s/resharding/resharding_server_parameters_gen.h" #include "mongo/db/s/resharding_util.h" +#include "mongo/db/vector_clock.h" #include "mongo/logv2/log.h" #include "mongo/s/catalog/type_tags.h" #include "mongo/s/grid.h" #include "mongo/s/request_types/reshard_collection_gen.h" +#include "mongo/s/sharded_collections_ddl_parameters_gen.h" namespace mongo { namespace { @@ -127,7 +129,15 @@ public: int numInitialChunks; std::set<ShardId> recipientShardIds; std::vector<ChunkType> initialChunks; - ChunkVersion version(1, 0, OID::gen()); + + boost::optional<Timestamp> timestamp; + if (feature_flags::gShardingFullDDLSupport.isEnabled( + serverGlobalParams.featureCompatibility)) { + const auto now = VectorClock::get(opCtx)->getTime(); + timestamp = now.clusterTime().asTimestamp(); + } + + ChunkVersion version(1, 0, OID::gen(), timestamp); auto tempReshardingNss = constructTemporaryReshardingNss( nss.db(), getCollectionUUIDFromChunkManger(nss, cm)); diff --git a/src/mongo/db/s/config/initial_split_policy.cpp b/src/mongo/db/s/config/initial_split_policy.cpp index c7efc2019f7..56cf3f008ba 100644 --- a/src/mongo/db/s/config/initial_split_policy.cpp +++ b/src/mongo/db/s/config/initial_split_policy.cpp @@ -40,6 +40,7 @@ #include "mongo/s/catalog/type_shard.h" #include "mongo/s/grid.h" #include "mongo/s/shard_util.h" +#include "mongo/s/sharded_collections_ddl_parameters_gen.h" namespace mongo { namespace { @@ -110,7 +111,12 @@ InitialSplitPolicy::ShardCollectionConfig createChunks(const ShardKeyPattern& sh const std::vector<ShardId>& allShardIds, std::vector<BSONObj>& finalSplitPoints, const Timestamp& validAfter) { - ChunkVersion version(1, 0, OID::gen()); + boost::optional<Timestamp> timestamp; + if (feature_flags::gShardingFullDDLSupport.isEnabled(serverGlobalParams.featureCompatibility)) { + timestamp = validAfter; + } + + ChunkVersion version(1, 0, OID::gen(), timestamp); const auto& keyPattern(shardKeyPattern.getKeyPattern()); std::vector<ChunkType> chunks; @@ -277,9 +283,17 @@ std::unique_ptr<InitialSplitPolicy> InitialSplitPolicy::calculateOptimizationStr InitialSplitPolicy::ShardCollectionConfig SingleChunkOnPrimarySplitPolicy::createFirstChunks( OperationContext* opCtx, const ShardKeyPattern& shardKeyPattern, SplitPolicyParams params) { ShardCollectionConfig initialChunks; - ChunkVersion version(1, 0, OID::gen()); - const auto& keyPattern = shardKeyPattern.getKeyPattern(); + const auto currentTime = VectorClock::get(opCtx)->getTime(); + const auto clusterTime = currentTime.clusterTime().asTimestamp(); + + boost::optional<Timestamp> timestamp; + if (feature_flags::gShardingFullDDLSupport.isEnabled(serverGlobalParams.featureCompatibility)) { + timestamp = clusterTime; + } + + ChunkVersion version(1, 0, OID::gen(), timestamp); + const auto& keyPattern = shardKeyPattern.getKeyPattern(); appendChunk(params.nss, params.collectionUUID, keyPattern.globalMin(), @@ -288,7 +302,7 @@ InitialSplitPolicy::ShardCollectionConfig SingleChunkOnPrimarySplitPolicy::creat currentTime.clusterTime().asTimestamp(), params.primaryShardId, &initialChunks.chunks); - initialChunks.creationTime = currentTime.clusterTime().asTimestamp(); + initialChunks.creationTime = clusterTime; return initialChunks; } @@ -373,7 +387,12 @@ InitialSplitPolicy::ShardCollectionConfig AbstractTagsBasedSplitPolicy::createFi return shardIds[indx++ % shardIds.size()]; }; - ChunkVersion version(1, 0, OID::gen()); + boost::optional<Timestamp> timestamp; + if (feature_flags::gShardingFullDDLSupport.isEnabled(serverGlobalParams.featureCompatibility)) { + timestamp = validAfter; + } + + ChunkVersion version(1, 0, OID::gen(), timestamp); auto lastChunkMax = keyPattern.globalMin(); std::vector<ChunkType> chunks; for (const auto& tag : _tags) { diff --git a/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp index caaf535a1e6..0011b1478e3 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp @@ -378,7 +378,8 @@ BSONObj getShardAndCollectionVersion(OperationContext* opCtx, if (swDonorShardVersion.getStatus().code() == 50577) { // The query to find 'nss' chunks belonging to the donor shard didn't return any chunks, // meaning the last chunk for fromShard was donated. Gracefully handle the error. - shardVersion = ChunkVersion(0, 0, collectionVersion.epoch()); + shardVersion = + ChunkVersion(0, 0, collectionVersion.epoch(), collectionVersion.getTimestamp()); } else { // Bubble up any other error uassertStatusOK(swDonorShardVersion); @@ -404,8 +405,10 @@ void bumpMajorVersionOneChunkPerShard(OperationContext* opCtx, TxnNumber txnNumber, const std::vector<ShardId>& shardIds) { auto curCollectionVersion = uassertStatusOK(getCollectionVersion(opCtx, nss)); - ChunkVersion targetChunkVersion( - curCollectionVersion.majorVersion() + 1, 0, curCollectionVersion.epoch()); + ChunkVersion targetChunkVersion(curCollectionVersion.majorVersion() + 1, + 0, + curCollectionVersion.epoch(), + curCollectionVersion.getTimestamp()); for (const auto& shardId : shardIds) { BSONObjBuilder updateBuilder; @@ -930,8 +933,10 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunkMigration( newMigratedChunk.setCollectionUUID(collectionUUID); } newMigratedChunk.setShard(toShard); - newMigratedChunk.setVersion(ChunkVersion( - currentCollectionVersion.majorVersion() + 1, 0, currentCollectionVersion.epoch())); + newMigratedChunk.setVersion(ChunkVersion(currentCollectionVersion.majorVersion() + 1, + 0, + currentCollectionVersion.epoch(), + currentCollectionVersion.getTimestamp())); // Copy the complete history. auto newHistory = origChunk.getValue().getHistory(); @@ -983,8 +988,10 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunkMigration( newControlChunk = origControlChunk.getValue(); newControlChunk->setName(origControlChunk.getValue().getName()); - newControlChunk->setVersion(ChunkVersion( - currentCollectionVersion.majorVersion() + 1, 1, currentCollectionVersion.epoch())); + newControlChunk->setVersion(ChunkVersion(currentCollectionVersion.majorVersion() + 1, + 1, + currentCollectionVersion.epoch(), + currentCollectionVersion.getTimestamp())); } auto command = makeCommitChunkTransactionCommand( @@ -1111,8 +1118,10 @@ void ShardingCatalogManager::clearJumboFlag(OperationContext* opCtx, << chunk.toString() << ").", currentCollectionVersion.epoch() == collectionEpoch); - ChunkVersion newVersion( - currentCollectionVersion.majorVersion() + 1, 0, currentCollectionVersion.epoch()); + ChunkVersion newVersion(currentCollectionVersion.majorVersion() + 1, + 0, + currentCollectionVersion.epoch(), + currentCollectionVersion.getTimestamp()); BSONObj chunkQuery(BSON(ChunkType::ns(nss.ns()) << ChunkType::epoch(collectionEpoch) << ChunkType::min(chunk.getMin()) @@ -1228,8 +1237,8 @@ void ShardingCatalogManager::ensureChunkVersionIsGreaterThan(OperationContext* o // Generate a new version for the chunk by incrementing the collectionVersion's major version. auto newChunk = currentChunk; - newChunk.setVersion( - ChunkVersion(highestChunk.getVersion().majorVersion() + 1, 0, version.epoch())); + newChunk.setVersion(ChunkVersion( + highestChunk.getVersion().majorVersion() + 1, 0, version.epoch(), version.getTimestamp())); // Update the chunk, if it still exists, to have the bumped version. earlyReturnBeforeDoingWriteGuard.dismiss(); diff --git a/src/mongo/db/s/set_shard_version_command.cpp b/src/mongo/db/s/set_shard_version_command.cpp index c1ab9fbc146..997df91264b 100644 --- a/src/mongo/db/s/set_shard_version_command.cpp +++ b/src/mongo/db/s/set_shard_version_command.cpp @@ -323,7 +323,7 @@ public: result.appendBool("reloadConfig", true); // Zero-version also needed to trigger full mongos reload, sadly // TODO: Make this saner, and less impactful (full reload on last chunk is bad) - ChunkVersion(0, 0, OID()).appendLegacyWithField(&result, "version"); + ChunkVersion::UNSHARDED().appendLegacyWithField(&result, "version"); // For debugging requestedVersion.appendLegacyWithField(&result, "origVersion"); } else { diff --git a/src/mongo/db/s/shard_metadata_util.cpp b/src/mongo/db/s/shard_metadata_util.cpp index baf9582d42f..5aca5172c98 100644 --- a/src/mongo/db/s/shard_metadata_util.cpp +++ b/src/mongo/db/s/shard_metadata_util.cpp @@ -134,7 +134,7 @@ StatusWith<RefreshState> getPersistedRefreshFlags(OperationContext* opCtx, entry.getRefreshing() ? *entry.getRefreshing() : true, entry.getLastRefreshedCollectionVersion() ? *entry.getLastRefreshedCollectionVersion() - : ChunkVersion(0, 0, entry.getEpoch())}; + : ChunkVersion(0, 0, entry.getEpoch(), entry.getTimestamp())}; } StatusWith<ShardCollectionType> readShardCollectionsEntry(OperationContext* opCtx, @@ -292,7 +292,8 @@ StatusWith<std::vector<ChunkType>> readShardChunks(OperationContext* opCtx, const BSONObj& query, const BSONObj& sort, boost::optional<long long> limit, - const OID& epoch) { + const OID& epoch, + const boost::optional<Timestamp>& timestamp) { try { Query fullQuery(query); fullQuery.sort(sort); @@ -311,7 +312,7 @@ StatusWith<std::vector<ChunkType>> readShardChunks(OperationContext* opCtx, std::vector<ChunkType> chunks; while (cursor->more()) { BSONObj document = cursor->nextSafe().getOwned(); - auto statusWithChunk = ChunkType::fromShardBSON(document, epoch); + auto statusWithChunk = ChunkType::fromShardBSON(document, epoch, timestamp); if (!statusWithChunk.isOK()) { return statusWithChunk.getStatus().withContext( str::stream() << "Failed to parse chunk '" << document.toString() << "'"); diff --git a/src/mongo/db/s/shard_metadata_util.h b/src/mongo/db/s/shard_metadata_util.h index 376b29eca56..45bee780dd0 100644 --- a/src/mongo/db/s/shard_metadata_util.h +++ b/src/mongo/db/s/shard_metadata_util.h @@ -175,7 +175,8 @@ StatusWith<std::vector<ChunkType>> readShardChunks(OperationContext* opCtx, const BSONObj& query, const BSONObj& sort, boost::optional<long long> limit, - const OID& epoch); + const OID& epoch, + const boost::optional<Timestamp>& timestamp); /** * Takes a vector of 'chunks' and updates the shard's chunks collection for 'nss'. Any chunk 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 d5a81a24128..05945aecc74 100644 --- a/src/mongo/db/s/shard_server_catalog_cache_loader.cpp +++ b/src/mongo/db/s/shard_server_catalog_cache_loader.cpp @@ -194,8 +194,13 @@ ChunkVersion getPersistedMaxChunkVersion(OperationContext* opCtx, const Namespac return ChunkVersion::UNSHARDED(); } - auto statusWithChunk = shardmetadatautil::readShardChunks( - opCtx, nss, BSONObj(), BSON(ChunkType::lastmod() << -1), 1LL, cachedCollection.getEpoch()); + auto statusWithChunk = shardmetadatautil::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 '" @@ -224,12 +229,17 @@ CollectionAndChangedChunks getPersistedMetadataSinceVersion(OperationContext* op // If the persisted epoch doesn't match what the CatalogCache requested, read everything. ChunkVersion startingVersion = (shardCollectionEntry.getEpoch() == version.epoch()) ? version - : ChunkVersion(0, 0, shardCollectionEntry.getEpoch()); + : ChunkVersion(0, 0, shardCollectionEntry.getEpoch(), shardCollectionEntry.getTimestamp()); QueryAndSort diff = createShardChunkDiffQuery(startingVersion); - auto changedChunks = uassertStatusOK( - readShardChunks(opCtx, nss, diff.query, diff.sort, boost::none, startingVersion.epoch())); + auto changedChunks = uassertStatusOK(readShardChunks(opCtx, + nss, + diff.query, + diff.sort, + boost::none, + startingVersion.epoch(), + startingVersion.getTimestamp())); return CollectionAndChangedChunks{shardCollectionEntry.getEpoch(), shardCollectionEntry.getTimestamp(), diff --git a/src/mongo/db/s/type_shard_collection.cpp b/src/mongo/db/s/type_shard_collection.cpp index 74d40fcc940..fa6e8d68ea0 100644 --- a/src/mongo/db/s/type_shard_collection.cpp +++ b/src/mongo/db/s/type_shard_collection.cpp @@ -61,8 +61,8 @@ ShardCollectionType::ShardCollectionType(const BSONObj& obj) { // it exists, into a chunk version. if (getLastRefreshedCollectionVersion()) { ChunkVersion version = *getLastRefreshedCollectionVersion(); - setLastRefreshedCollectionVersion( - ChunkVersion(version.majorVersion(), version.minorVersion(), getEpoch())); + setLastRefreshedCollectionVersion(ChunkVersion( + version.majorVersion(), version.minorVersion(), getEpoch(), getTimestamp())); } } diff --git a/src/mongo/s/catalog/type_chunk.cpp b/src/mongo/s/catalog/type_chunk.cpp index 1e9076980cd..e948938cf8e 100644 --- a/src/mongo/s/catalog/type_chunk.cpp +++ b/src/mongo/s/catalog/type_chunk.cpp @@ -365,7 +365,9 @@ BSONObj ChunkType::toConfigBSON() const { return builder.obj(); } -StatusWith<ChunkType> ChunkType::fromShardBSON(const BSONObj& source, const OID& epoch) { +StatusWith<ChunkType> ChunkType::fromShardBSON(const BSONObj& source, + const OID& epoch, + const boost::optional<Timestamp>& timestamp) { ChunkType chunk; { @@ -406,7 +408,8 @@ StatusWith<ChunkType> ChunkType::fromShardBSON(const BSONObj& source, const OID& return statusWithChunkVersion.getStatus(); } auto version = std::move(statusWithChunkVersion.getValue()); - chunk._version = ChunkVersion(version.majorVersion(), version.minorVersion(), epoch); + chunk._version = + ChunkVersion(version.majorVersion(), version.minorVersion(), epoch, timestamp); } { diff --git a/src/mongo/s/catalog/type_chunk.h b/src/mongo/s/catalog/type_chunk.h index 355e0a8deaf..bf6876d5254 100644 --- a/src/mongo/s/catalog/type_chunk.h +++ b/src/mongo/s/catalog/type_chunk.h @@ -241,7 +241,9 @@ public: * * Also does validation of the contents. */ - static StatusWith<ChunkType> fromShardBSON(const BSONObj& source, const OID& epoch); + static StatusWith<ChunkType> fromShardBSON(const BSONObj& source, + const OID& epoch, + const boost::optional<Timestamp>& timestamp); /** * Returns the BSON representation of the entry for a shard server's config.chunks.<epoch> diff --git a/src/mongo/s/catalog_cache.cpp b/src/mongo/s/catalog_cache.cpp index f2f9e3784f8..1cc6be6204d 100644 --- a/src/mongo/s/catalog_cache.cpp +++ b/src/mongo/s/catalog_cache.cpp @@ -587,6 +587,7 @@ CatalogCache::CollectionCache::LookupResult CatalogCache::CollectionCache::_look std::move(defaultCollator), collectionAndChunks.shardKeyIsUnique, collectionAndChunks.epoch, + collectionAndChunks.creationTime, std::move(collectionAndChunks.reshardingFields), collectionAndChunks.allowMigrations, collectionAndChunks.changedChunks); diff --git a/src/mongo/s/chunk_manager.cpp b/src/mongo/s/chunk_manager.cpp index 1c6858175af..cc9692e692a 100644 --- a/src/mongo/s/chunk_manager.cpp +++ b/src/mongo/s/chunk_manager.cpp @@ -127,8 +127,12 @@ ShardVersionMap ChunkMap::constructShardVersionMap() const { // Tracks the max shard version for the shard on which the current range will reside auto shardVersionIt = shardVersions.find(currentRangeShardId); if (shardVersionIt == shardVersions.end()) { - shardVersionIt = - shardVersions.emplace(currentRangeShardId, _collectionVersion.epoch()).first; + shardVersionIt = shardVersions + .emplace(std::piecewise_construct, + std::forward_as_tuple(currentRangeShardId), + std::forward_as_tuple(_collectionVersion.epoch(), + _collectionVersion.getTimestamp())) + .first; } auto& maxShardVersion = shardVersionIt->second.shardVersion; @@ -216,7 +220,8 @@ ChunkMap ChunkMap::createMerged( size_t chunkMapIndex = 0; size_t changedChunkIndex = 0; - ChunkMap updatedChunkMap(getVersion().epoch(), _chunkMap.size() + changedChunks.size()); + ChunkMap updatedChunkMap( + getVersion().epoch(), getVersion().getTimestamp(), _chunkMap.size() + changedChunks.size()); while (chunkMapIndex < _chunkMap.size() || changedChunkIndex < changedChunks.size()) { if (chunkMapIndex >= _chunkMap.size()) { @@ -298,8 +303,9 @@ ChunkMap::_overlappingBounds(const BSONObj& min, const BSONObj& max, bool isMaxI return {itMin, itMax}; } -ShardVersionTargetingInfo::ShardVersionTargetingInfo(const OID& epoch) - : shardVersion(0, 0, epoch) {} +ShardVersionTargetingInfo::ShardVersionTargetingInfo(const OID& epoch, + const boost::optional<Timestamp>& timestamp) + : shardVersion(0, 0, epoch, timestamp) {} RoutingTableHistory::RoutingTableHistory( NamespaceString nss, @@ -680,8 +686,9 @@ ChunkVersion RoutingTableHistory::_getVersion(const ShardId& shardName, auto it = _shardVersions.find(shardName); if (it == _shardVersions.end()) { // Shards without explicitly tracked shard versions (meaning they have no chunks) always - // have a version of (0, 0, epoch) - return ChunkVersion(0, 0, _chunkMap.getVersion().epoch()); + // have a version of (0, 0, epoch, timestamp) + const auto collVersion = _chunkMap.getVersion(); + return ChunkVersion(0, 0, collVersion.epoch(), collVersion.getTimestamp()); } if (throwOnStaleShard && gEnableFinerGrainedCatalogCacheRefresh) { @@ -726,6 +733,7 @@ RoutingTableHistory RoutingTableHistory::makeNew( std::unique_ptr<CollatorInterface> defaultCollator, bool unique, OID epoch, + const boost::optional<Timestamp>& timestamp, boost::optional<TypeCollectionReshardingFields> reshardingFields, bool allowMigrations, const std::vector<ChunkType>& chunks) { @@ -736,7 +744,7 @@ RoutingTableHistory RoutingTableHistory::makeNew( std::move(unique), boost::none, allowMigrations, - ChunkMap{epoch}) + ChunkMap{epoch, timestamp}) .makeUpdated(std::move(reshardingFields), allowMigrations, chunks); } diff --git a/src/mongo/s/chunk_manager.h b/src/mongo/s/chunk_manager.h index 59b70fa138b..35f57639e70 100644 --- a/src/mongo/s/chunk_manager.h +++ b/src/mongo/s/chunk_manager.h @@ -59,7 +59,7 @@ struct ShardVersionTargetingInfo { // Max chunk version for the shard ChunkVersion shardVersion; - ShardVersionTargetingInfo(const OID& epoch); + ShardVersionTargetingInfo(const OID& epoch, const boost::optional<Timestamp>& timestamp); }; // Map from a shard to a struct indicating both the max chunk version on that shard and whether the @@ -76,7 +76,10 @@ class ChunkMap { using ChunkVector = std::vector<std::shared_ptr<ChunkInfo>>; public: - explicit ChunkMap(OID epoch, size_t initialCapacity = 0) : _collectionVersion(0, 0, epoch) { + explicit ChunkMap(OID epoch, + const boost::optional<Timestamp>& timestamp, + size_t initialCapacity = 0) + : _collectionVersion(0, 0, epoch, timestamp) { _chunkMap.reserve(initialCapacity); } @@ -165,6 +168,7 @@ public: std::unique_ptr<CollatorInterface> defaultCollator, bool unique, OID epoch, + const boost::optional<Timestamp>& timestamp, boost::optional<TypeCollectionReshardingFields> reshardingFields, bool allowMigrations, const std::vector<ChunkType>& chunks); diff --git a/src/mongo/s/chunk_version.h b/src/mongo/s/chunk_version.h index 71a8a2f589e..2c776256898 100644 --- a/src/mongo/s/chunk_version.h +++ b/src/mongo/s/chunk_version.h @@ -54,11 +54,15 @@ public: */ static constexpr StringData kShardVersionField = "shardVersion"_sd; - ChunkVersion(uint32_t major, uint32_t minor, const OID& epoch) + ChunkVersion(uint32_t major, + uint32_t minor, + const OID& epoch, + boost::optional<Timestamp> timestamp) : _combined(static_cast<uint64_t>(minor) | (static_cast<uint64_t>(major) << 32)), - _epoch(epoch) {} + _epoch(epoch), + _timestamp(std::move(timestamp)) {} - ChunkVersion() : ChunkVersion(0, 0, OID()) {} + ChunkVersion() : ChunkVersion(0, 0, OID(), boost::none) {} static StatusWith<ChunkVersion> parseFromCommand(const BSONObj& obj) { return parseWithField(obj, kShardVersionField); @@ -166,6 +170,10 @@ public: return _epoch; } + boost::optional<Timestamp> getTimestamp() const { + return _timestamp; + } + // // Explicit comparison operators - versions with epochs have non-trivial comparisons. // > < operators do not check epoch cases. Generally if using == we need to handle @@ -242,6 +250,7 @@ public: private: uint64_t _combined; OID _epoch; + boost::optional<Timestamp> _timestamp; // Temporary flag to indicate shards that a router is able to process and retry multi-write // operations diff --git a/src/mongo/s/config_server_catalog_cache_loader.cpp b/src/mongo/s/config_server_catalog_cache_loader.cpp index 370e429b439..f0ddca35f39 100644 --- a/src/mongo/s/config_server_catalog_cache_loader.cpp +++ b/src/mongo/s/config_server_catalog_cache_loader.cpp @@ -89,7 +89,7 @@ CollectionAndChangedChunks getChangedChunks(OperationContext* opCtx, // If the collection's epoch has changed, do a full refresh const ChunkVersion startingCollectionVersion = (sinceVersion.epoch() == coll.getEpoch()) ? sinceVersion - : ChunkVersion(0, 0, coll.getEpoch()); + : ChunkVersion(0, 0, coll.getEpoch(), coll.getTimestamp()); // Diff tracker should *always* find at least one chunk if collection exists const auto diffQuery = createConfigDiffQuery(nss, startingCollectionVersion); |