summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorJordi Serra Torrens <jordi.serra-torrens@mongodb.com>2021-05-28 08:45:16 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-05-31 12:55:34 +0000
commit51be24f57ef81ce36f5ad3b88003fa51eaed7725 (patch)
tree217c6b097875b7c19426d40e7391ae49f7160f94 /src/mongo/db
parentbe505f3601c0fe8c7c29411f09927b0d153a22db (diff)
downloadmongo-51be24f57ef81ce36f5ad3b88003fa51eaed7725.tar.gz
SERVER-57204 Extend the _configsvrSetAllowMigrations command to take the collection uuid to make it idempotent
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/s/config/configsvr_set_allow_migrations_command.cpp3
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager.h1
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp39
3 files changed, 32 insertions, 11 deletions
diff --git a/src/mongo/db/s/config/configsvr_set_allow_migrations_command.cpp b/src/mongo/db/s/config/configsvr_set_allow_migrations_command.cpp
index 8ab105f72e6..e467753f864 100644
--- a/src/mongo/db/s/config/configsvr_set_allow_migrations_command.cpp
+++ b/src/mongo/db/s/config/configsvr_set_allow_migrations_command.cpp
@@ -64,9 +64,10 @@ public:
repl::ReadConcernArgs(repl::ReadConcernLevel::kLocalReadConcern);
const auto allowMigrations = request().getAllowMigrations();
+ const auto& collectionUUID = request().getCollectionUUID();
ShardingCatalogManager::get(opCtx)->setAllowMigrationsAndBumpOneChunk(
- opCtx, nss, allowMigrations);
+ opCtx, nss, collectionUUID, allowMigrations);
}
private:
diff --git a/src/mongo/db/s/config/sharding_catalog_manager.h b/src/mongo/db/s/config/sharding_catalog_manager.h
index 4e7f4f1ef35..47e01831332 100644
--- a/src/mongo/db/s/config/sharding_catalog_manager.h
+++ b/src/mongo/db/s/config/sharding_catalog_manager.h
@@ -312,6 +312,7 @@ public:
*/
void setAllowMigrationsAndBumpOneChunk(OperationContext* opCtx,
const NamespaceString& nss,
+ const boost::optional<UUID>& collectionUUID,
bool allowMigrations);
//
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 7dc2a338a33..97aaf4cb686 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
@@ -1519,9 +1519,11 @@ void ShardingCatalogManager::splitOrMarkJumbo(OperationContext* opCtx,
}
}
-void ShardingCatalogManager::setAllowMigrationsAndBumpOneChunk(OperationContext* opCtx,
- const NamespaceString& nss,
- bool allowMigrations) {
+void ShardingCatalogManager::setAllowMigrationsAndBumpOneChunk(
+ OperationContext* opCtx,
+ const NamespaceString& nss,
+ const boost::optional<UUID>& collectionUUID,
+ bool allowMigrations) {
std::set<ShardId> shardsIds;
{
// Take _kChunkOpLock in exclusive mode to prevent concurrent chunk splits, merges, and
@@ -1531,6 +1533,13 @@ void ShardingCatalogManager::setAllowMigrationsAndBumpOneChunk(OperationContext*
const auto cm = uassertStatusOK(
Grid::get(opCtx)->catalogCache()->getShardedCollectionRoutingInfoWithRefresh(opCtx,
nss));
+
+ uassert(ErrorCodes::InvalidUUID,
+ str::stream() << "Collection uuid " << collectionUUID
+ << " in the request does not match the current uuid " << cm.getUUID()
+ << " for ns " << nss,
+ !collectionUUID || collectionUUID == cm.getUUID());
+
cm.getAllShardIds(&shardsIds);
withTransaction(
opCtx, CollectionType::ConfigNS, [&](OperationContext* opCtx, TxnNumber txnNumber) {
@@ -1541,16 +1550,26 @@ void ShardingCatalogManager::setAllowMigrationsAndBumpOneChunk(OperationContext*
? BSON("$unset" << BSON(CollectionType::kAllowMigrationsFieldName << ""))
: BSON("$set" << BSON(CollectionType::kAllowMigrationsFieldName << false));
- writeToConfigDocumentInTxn(
+ BSONObj query = BSON(CollectionType::kNssFieldName << nss.ns());
+ if (collectionUUID) {
+ query =
+ query.addFields(BSON(CollectionType::kUuidFieldName << *collectionUUID));
+ }
+
+ const auto res = writeToConfigDocumentInTxn(
opCtx,
CollectionType::ConfigNS,
- BatchedCommandRequest::buildUpdateOp(
- CollectionType::ConfigNS,
- BSON(CollectionType::kNssFieldName << nss.ns()) /* query */,
- update /* update */,
- false /* upsert */,
- false /* multi */),
+ BatchedCommandRequest::buildUpdateOp(CollectionType::ConfigNS,
+ query,
+ update /* update */,
+ false /* upsert */,
+ false /* multi */),
txnNumber);
+ const auto numDocsModified = UpdateOp::parseResponse(res).getN();
+ uassert(5720400,
+ str::stream() << "Expected to match one doc for query " << query
+ << " but matched " << numDocsModified,
+ numDocsModified == 1);
// Bump the chunk version for one single chunk
invariant(!shardsIds.empty());