summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorJordi Serra Torrens <jordi.serra-torrens@mongodb.com>2021-05-11 08:30:24 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-05-11 08:59:45 +0000
commit70299e858e3f54c01fdb96cdd1c430972500b97f (patch)
tree03599b82752b50a2b9922c6860f5c3e3b3dc4e80 /src/mongo
parent9261befabc2f3e922eec0f15e091e9881deb1960 (diff)
downloadmongo-70299e858e3f54c01fdb96cdd1c430972500b97f.tar.gz
SERVER-56795 Changes from SERVER-53274 were unintentionally reverted
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp28
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 453ae919b72..3072cd94c9c 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"
@@ -963,6 +964,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()) {
@@ -971,10 +973,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()}});
@@ -1027,16 +1033,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()) {
@@ -1044,10 +1040,6 @@ Status ShardingCatalogManager::downgradeChunksHistory(OperationContext* opCtx,
}
auto& downgradeChunk = swChunk.getValue();
- // Bump the version.
- downgradeChunk.setVersion(newCollectionVersion);
- newCollectionVersion.incMajor();
-
// Clear the history.
downgradeChunk.setHistory({});