diff options
author | Jordi Serra Torrens <jordi.serra-torrens@mongodb.com> | 2021-02-04 15:52:26 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-02-05 10:17:07 +0000 |
commit | 52d6f11c459b8d3666379431a6accf7fef4e852f (patch) | |
tree | 852c5a12080a2c69c7344470ad2edeb82ff9a07b /src/mongo/db | |
parent | 7883bfe8349b4439f55fd8d4199fab1455b6d67d (diff) | |
download | mongo-52d6f11c459b8d3666379431a6accf7fef4e852f.tar.gz |
SERVER-53274 Avoid bumping all chunk versions after writing 'history' field on FCV upgrade to 4.0.
Instead, bump only one chunk per shard to satisfy the reqirements
imposed by SERVER-33356
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp | 28 |
1 files changed, 10 insertions, 18 deletions
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 033a96c6a25..564b3dcf4e7 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 @@ -51,6 +51,7 @@ #include "mongo/s/client/shard_registry.h" #include "mongo/s/grid.h" #include "mongo/s/shard_key_pattern.h" +#include "mongo/stdx/unordered_set.h" #include "mongo/util/fail_point_service.h" #include "mongo/util/log.h" #include "mongo/util/mongoutils/str.h" @@ -940,6 +941,7 @@ Status ShardingCatalogManager::upgradeChunksHistory(OperationContext* opCtx, 0, currentCollectionVersion.getValue().epoch()); + stdx::unordered_set<ShardId, ShardId::Hasher> bumpedShards; for (const auto& chunk : chunksVector) { auto swChunk = ChunkType::fromConfigBSON(chunk); if (!swChunk.isOK()) { @@ -948,10 +950,14 @@ Status ShardingCatalogManager::upgradeChunksHistory(OperationContext* opCtx, auto& upgradeChunk = swChunk.getValue(); if (upgradeChunk.getHistory().empty()) { - - // Bump the version. - upgradeChunk.setVersion(newCollectionVersion); - newCollectionVersion.incMajor(); + // Bump the version for only one chunk per shard to satisfy the requirement imposed by + // SERVER-33356 + const auto& shardId = upgradeChunk.getShard(); + if (!bumpedShards.count(shardId)) { + upgradeChunk.setVersion(newCollectionVersion); + newCollectionVersion.incMajor(); + bumpedShards.emplace(shardId); + } // Construct the fresh history. upgradeChunk.setHistory({ChunkHistory{validAfter, upgradeChunk.getShard()}}); @@ -1004,16 +1010,6 @@ Status ShardingCatalogManager::downgradeChunksHistory(OperationContext* opCtx, << ", but found no chunks"}; } - const auto currentCollectionVersion = _findCollectionVersion(opCtx, nss, collectionEpoch); - if (!currentCollectionVersion.isOK()) { - return currentCollectionVersion.getStatus(); - } - - // Bump the version. - auto newCollectionVersion = ChunkVersion(currentCollectionVersion.getValue().majorVersion() + 1, - 0, - currentCollectionVersion.getValue().epoch()); - for (const auto& chunk : chunksVector) { auto swChunk = ChunkType::fromConfigBSON(chunk); if (!swChunk.isOK()) { @@ -1021,10 +1017,6 @@ Status ShardingCatalogManager::downgradeChunksHistory(OperationContext* opCtx, } auto& downgradeChunk = swChunk.getValue(); - // Bump the version. - downgradeChunk.setVersion(newCollectionVersion); - newCollectionVersion.incMajor(); - // Clear the history. downgradeChunk.setHistory({}); |