diff options
author | Tommaso Tocci <tommaso.tocci@mongodb.com> | 2021-03-29 12:07:46 +0200 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-04-07 21:34:13 +0000 |
commit | 469b1101cea8cf0c5b34437cdeb391b7002f7d19 (patch) | |
tree | 8af798a2cae69c4a85fca7ac99566d60e588af25 | |
parent | 6c57dcf3d18574116ee9f1bdb3d8197b2716e6b3 (diff) | |
download | mongo-469b1101cea8cf0c5b34437cdeb391b7002f7d19.tar.gz |
SERVER-53973 Migration manager recovery should handle failed findIntersectingChunk during refineShardKey
-rw-r--r-- | src/mongo/db/s/balancer/migration_manager.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/mongo/db/s/balancer/migration_manager.cpp b/src/mongo/db/s/balancer/migration_manager.cpp index 44df685b310..08f6641ea7b 100644 --- a/src/mongo/db/s/balancer/migration_manager.cpp +++ b/src/mongo/db/s/balancer/migration_manager.cpp @@ -360,12 +360,19 @@ void MigrationManager::finishRecovery(OperationContext* opCtx, auto waitForDelete = migrationType.getWaitForDelete(); migrateInfos.pop_front(); - const auto chunk = - routingInfo.cm()->findIntersectingChunkWithSimpleCollation(migrationInfo.minKey); - - if (chunk.getShardId() != migrationInfo.from) { - // Chunk is no longer on the source shard specified by this migration. Erase the - // migration recovery document associated with it. + try { + const auto chunk = routingInfo.cm()->findIntersectingChunkWithSimpleCollation( + migrationInfo.minKey); + + if (chunk.getShardId() != migrationInfo.from) { + // Chunk is no longer on the source shard specified by this migration. Erase the + // migration recovery document associated with it. + ScopedMigrationRequest::createForRecovery(opCtx, nss, migrationInfo.minKey); + continue; + } + } catch (const ExceptionFor<ErrorCodes::ShardKeyNotFound>&) { + // The shard key for the collection has changed. + // Abandon this migration and remove the document associated with it. ScopedMigrationRequest::createForRecovery(opCtx, nss, migrationInfo.minKey); continue; } |