diff options
author | Dianna Hohensee <dianna.hohensee@10gen.com> | 2017-01-11 19:17:02 -0500 |
---|---|---|
committer | Dianna Hohensee <dianna.hohensee@10gen.com> | 2017-01-17 14:36:53 -0500 |
commit | fdec6ed545c0045646c7cca33eb4094385bc9429 (patch) | |
tree | 3e39040e2e5cea9c11fff94c6fe5da085558fd26 /src/mongo/db/s | |
parent | 686069d0fbde93c1bf8b2fe15fad001e98dcc25d (diff) | |
download | mongo-fdec6ed545c0045646c7cca33eb4094385bc9429.tar.gz |
SERVER-25673 Remove redundant ChunkManager access in MigrationManager
Diffstat (limited to 'src/mongo/db/s')
4 files changed, 9 insertions, 42 deletions
diff --git a/src/mongo/db/s/active_migrations_registry_test.cpp b/src/mongo/db/s/active_migrations_registry_test.cpp index c5eb63f71a3..7907434e0d0 100644 --- a/src/mongo/db/s/active_migrations_registry_test.cpp +++ b/src/mongo/db/s/active_migrations_registry_test.cpp @@ -65,19 +65,17 @@ protected: }; MoveChunkRequest createMoveChunkRequest(const NamespaceString& nss) { - const ChunkVersion collectionVersion(2, 3, OID::gen()); const ChunkVersion chunkVersion(1, 2, OID::gen()); BSONObjBuilder builder; MoveChunkRequest::appendAsCommand( &builder, nss, - collectionVersion, + chunkVersion, assertGet(ConnectionString::parse("TestConfigRS/CS1:12345,CS2:12345,CS3:12345")), ShardId("shard0001"), ShardId("shard0002"), ChunkRange(BSON("Key" << -100), BSON("Key" << 100)), - chunkVersion, 1024, MigrationSecondaryThrottleOptions::create(MigrationSecondaryThrottleOptions::kOff), true); diff --git a/src/mongo/db/s/balancer/migration_manager.cpp b/src/mongo/db/s/balancer/migration_manager.cpp index 6bccabf7326..02c9fece761 100644 --- a/src/mongo/db/s/balancer/migration_manager.cpp +++ b/src/mongo/db/s/balancer/migration_manager.cpp @@ -454,29 +454,6 @@ shared_ptr<Notification<RemoteCommandResponse>> MigrationManager::_schedule( } } - - // Sanity checks that the chunk being migrated is actually valid. These will be repeated at the - // shard as well, but doing them here saves an extra network call, which might otherwise fail. - auto statusWithScopedChunkManager = ScopedChunkManager::refreshAndGet(txn, nss); - if (!statusWithScopedChunkManager.isOK()) { - return std::make_shared<Notification<RemoteCommandResponse>>( - std::move(statusWithScopedChunkManager.getStatus())); - } - - ChunkManager* const chunkManager = statusWithScopedChunkManager.getValue().cm(); - - auto chunk = chunkManager->findIntersectingChunkWithSimpleCollation(txn, migrateInfo.minKey); - invariant(chunk); - - // If the chunk is not found exactly as requested, the caller must have stale data - if (SimpleBSONObjComparator::kInstance.evaluate(chunk->getMin() != migrateInfo.minKey) || - SimpleBSONObjComparator::kInstance.evaluate(chunk->getMax() != migrateInfo.maxKey)) { - return std::make_shared<Notification<RemoteCommandResponse>>(Status( - ErrorCodes::IncompatibleShardingMetadata, - stream() << "Chunk " << ChunkRange(migrateInfo.minKey, migrateInfo.maxKey).toString() - << " does not exist.")); - } - const auto fromShardStatus = Grid::get(txn)->shardRegistry()->getShard(txn, migrateInfo.from); if (!fromShardStatus.isOK()) { return std::make_shared<Notification<RemoteCommandResponse>>( @@ -495,12 +472,11 @@ shared_ptr<Notification<RemoteCommandResponse>> MigrationManager::_schedule( MoveChunkRequest::appendAsCommand( &builder, nss, - chunkManager->getVersion(), + migrateInfo.version, Grid::get(txn)->shardRegistry()->getConfigServerConnectionString(), migrateInfo.from, migrateInfo.to, ChunkRange(migrateInfo.minKey, migrateInfo.maxKey), - chunk->getLastmod(), maxChunkSizeBytes, secondaryThrottle, waitForDelete); diff --git a/src/mongo/db/s/migration_chunk_cloner_source_legacy_test.cpp b/src/mongo/db/s/migration_chunk_cloner_source_legacy_test.cpp index fa83a3bd69e..94188337f6b 100644 --- a/src/mongo/db/s/migration_chunk_cloner_source_legacy_test.cpp +++ b/src/mongo/db/s/migration_chunk_cloner_source_legacy_test.cpp @@ -142,7 +142,6 @@ protected: kDonorConnStr.getSetName(), kRecipientConnStr.getSetName(), chunkRange, - ChunkVersion(1, 0, OID::gen()), 1024 * 1024, MigrationSecondaryThrottleOptions::create(MigrationSecondaryThrottleOptions::kDefault), false); diff --git a/src/mongo/db/s/migration_source_manager.cpp b/src/mongo/db/s/migration_source_manager.cpp index a66e6d63e72..22d6d259dab 100644 --- a/src/mongo/db/s/migration_source_manager.cpp +++ b/src/mongo/db/s/migration_source_manager.cpp @@ -91,15 +91,8 @@ MigrationSourceManager::MigrationSourceManager(OperationContext* txn, "Destination shard cannot be the same as source", _args.getFromShardId() != _args.getToShardId()); - const auto& oss = OperationShardingState::get(txn); - uassert(ErrorCodes::InvalidOptions, "collection version is missing", oss.hasShardVersion()); - - // Even though the moveChunk command transmits a value in the operation's shardVersion field, - // this value does not actually contain the shard version, but the global collection version. - const ChunkVersion expectedCollectionVersion = oss.getShardVersion(getNss()); - log() << "Starting chunk migration " << redact(_args.toString()) - << " with expected collection version " << expectedCollectionVersion; + << " with expected collection version epoch" << _args.getVersionEpoch(); // Now that the collection is locked, snapshot the metadata and fetch the latest versions ShardingState* const shardingState = ShardingState::get(txn); @@ -134,13 +127,13 @@ MigrationSourceManager::MigrationSourceManager(OperationContext* txn, const ChunkVersion collectionVersion = _collectionMetadata->getCollVersion(); uassert(ErrorCodes::StaleEpoch, - str::stream() << "cannot move chunk " << _args.toString() + str::stream() << "cannot move chunk " << redact(_args.toString()) << " because collection may have been dropped. " << "current epoch: " << collectionVersion.epoch() << ", cmd epoch: " - << expectedCollectionVersion.epoch(), - expectedCollectionVersion.epoch() == collectionVersion.epoch()); + << _args.getVersionEpoch(), + _args.getVersionEpoch() == collectionVersion.epoch()); // With nonzero shard version, we must have a coll version >= our shard version invariant(collectionVersion >= shardVersion); @@ -155,9 +148,10 @@ MigrationSourceManager::MigrationSourceManager(OperationContext* txn, Status chunkValidateStatus = _collectionMetadata->checkChunkIsValid(chunkToMove); if (!chunkValidateStatus.isOK()) { uasserted(chunkValidateStatus.code(), - str::stream() << "Unable to move chunk with arguments '" << _args.toString() + str::stream() << "Unable to move chunk with arguments '" + << redact(_args.toString()) << "' due to error " - << chunkValidateStatus.reason()); + << redact(chunkValidateStatus.reason())); } } |