diff options
author | Sergi Mateo Bellido <sergi.mateo-bellido@mongodb.com> | 2021-01-19 09:08:08 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-01-20 08:21:57 +0000 |
commit | 9250170d1cbad15319a1ae164adbb54d0b366b47 (patch) | |
tree | 39908eacff1906856a0d6696685c4ecae59e3566 /src | |
parent | acc6320118ac673fbc21babef7cb5eba546f14f7 (diff) | |
download | mongo-9250170d1cbad15319a1ae164adbb54d0b366b47.tar.gz |
SERVER-53868 Update the timestamp of docs in config.chunks when refining a shard key
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp | 21 | ||||
-rw-r--r-- | src/mongo/s/catalog/type_chunk.cpp | 1 | ||||
-rw-r--r-- | src/mongo/s/catalog/type_chunk.h | 1 |
3 files changed, 17 insertions, 6 deletions
diff --git a/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp index 3eff16a0bcd..5959c4c8788 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp @@ -459,7 +459,9 @@ void ShardingCatalogManager::ensureDropCollectionCompleted(OperationContext* opC // }} // }}] std::pair<std::vector<BSONObj>, std::vector<BSONObj>> makeChunkAndTagUpdatesForRefine( - const BSONObj& newShardKeyFields, OID newEpoch) { + const BSONObj& newShardKeyFields, + OID newEpoch, + const boost::optional<Timestamp>& newTimestamp) { // Make the $literal objects used in the $set below to add new fields to the boundaries of the // existing chunks and tags that may include "." characters. // @@ -505,11 +507,16 @@ std::pair<std::vector<BSONObj>, std::vector<BSONObj>> makeChunkAndTagUpdatesForR << "then" << literalMaxObject << "else" << literalMinObject)))))))); - // The chunk updates change the min and max fields, and additionally set the new epoch and unset - // the jumbo field. + // The chunk updates change the min and max fields, and additionally set the new epoch and the + // new timestamp and unset the jumbo field. std::vector<BSONObj> chunkUpdates; chunkUpdates.emplace_back( BSON("$set" << extendMinAndMaxModifier.addFields(BSON(ChunkType::epoch(newEpoch))))); + + if (newTimestamp) { + chunkUpdates.emplace_back(BSON("$set" << extendMinAndMaxModifier.addFields( + BSON(ChunkType::timestamp(*newTimestamp))))); + } chunkUpdates.emplace_back(BSON("$unset" << ChunkType::jumbo())); // The tag updates only change the min and max fields. @@ -550,11 +557,12 @@ void ShardingCatalogManager::refineCollectionShardKey(OperationContext* opCtx, collType.setEpoch(newEpoch); collType.setKeyPattern(newShardKeyPattern.getKeyPattern()); + boost::optional<Timestamp> newTimestamp; if (feature_flags::gShardingFullDDLSupportTimestampedVersion.isEnabled( serverGlobalParams.featureCompatibility)) { auto now = VectorClock::get(opCtx)->getTime(); - auto newClusterTime = now.clusterTime().asTimestamp(); - collType.setTimestamp(newClusterTime); + newTimestamp = now.clusterTime().asTimestamp(); + collType.setTimestamp(newTimestamp); } auto updateCollectionAndChunksFn = [&](OperationContext* opCtx, TxnNumber txnNumber) { @@ -576,7 +584,8 @@ void ShardingCatalogManager::refineCollectionShardKey(OperationContext* opCtx, hangRefineCollectionShardKeyBeforeUpdatingChunks.pauseWhileSet(opCtx); } - auto [chunkUpdates, tagUpdates] = makeChunkAndTagUpdatesForRefine(newFields, newEpoch); + auto [chunkUpdates, tagUpdates] = + makeChunkAndTagUpdatesForRefine(newFields, newEpoch, newTimestamp); // Update all config.chunks entries for the given namespace by setting (i) their epoch // to the newly-generated objectid, (ii) their bounds for each new field in the refined diff --git a/src/mongo/s/catalog/type_chunk.cpp b/src/mongo/s/catalog/type_chunk.cpp index 9269381f2d8..8646e164c6d 100644 --- a/src/mongo/s/catalog/type_chunk.cpp +++ b/src/mongo/s/catalog/type_chunk.cpp @@ -58,6 +58,7 @@ const BSONField<std::string> ChunkType::shard("shard"); const BSONField<bool> ChunkType::jumbo("jumbo"); const BSONField<Date_t> ChunkType::lastmod("lastmod"); const BSONField<OID> ChunkType::epoch("lastmodEpoch"); +const BSONField<Timestamp> ChunkType::timestamp("lastmodTimestamp"); const BSONField<BSONObj> ChunkType::history("history"); namespace { diff --git a/src/mongo/s/catalog/type_chunk.h b/src/mongo/s/catalog/type_chunk.h index bf6876d5254..c43e6f1d6e5 100644 --- a/src/mongo/s/catalog/type_chunk.h +++ b/src/mongo/s/catalog/type_chunk.h @@ -209,6 +209,7 @@ public: static const BSONField<bool> jumbo; static const BSONField<Date_t> lastmod; static const BSONField<OID> epoch; + static const BSONField<Timestamp> timestamp; static const BSONField<BSONObj> history; ChunkType(); |