summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/migration_source_manager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/s/migration_source_manager.cpp')
-rw-r--r--src/mongo/db/s/migration_source_manager.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/mongo/db/s/migration_source_manager.cpp b/src/mongo/db/s/migration_source_manager.cpp
index 5e59b07115f..02539348de4 100644
--- a/src/mongo/db/s/migration_source_manager.cpp
+++ b/src/mongo/db/s/migration_source_manager.cpp
@@ -145,15 +145,14 @@ MigrationSourceManager::MigrationSourceManager(OperationContext* opCtx,
onShardVersionMismatch(_opCtx, getNss(), boost::none);
// Snapshot the committed metadata from the time the migration starts
- const auto collectionMetadataAndUUID = [&] {
+ const auto [collectionMetadata, collectionUUID] = [&] {
UninterruptibleLockGuard noInterrupt(_opCtx->lockState());
AutoGetCollection autoColl(_opCtx, getNss(), MODE_IS);
uassert(ErrorCodes::InvalidOptions,
"cannot move chunks for a collection that doesn't exist",
autoColl.getCollection());
- boost::optional<UUID> collectionUUID;
- collectionUUID = autoColl.getCollection()->uuid();
+ UUID collectionUUID = autoColl.getCollection()->uuid();
auto optMetadata =
CollectionShardingRuntime::get(_opCtx, getNss())->getCurrentMetadataIfKnown();
@@ -169,8 +168,6 @@ MigrationSourceManager::MigrationSourceManager(OperationContext* opCtx,
return std::make_tuple(std::move(metadata), std::move(collectionUUID));
}();
- const auto& collectionMetadata = std::get<0>(collectionMetadataAndUUID);
-
const auto collectionVersion = collectionMetadata.getCollVersion();
const auto shardVersion = collectionMetadata.getShardVersion();
@@ -195,11 +192,12 @@ MigrationSourceManager::MigrationSourceManager(OperationContext* opCtx,
str::stream() << "Unable to move chunk with arguments '"
<< redact(_args.toString()));
+ _collectionEpoch = collectionVersion.epoch();
+ _collectionUUID = collectionUUID;
+
_chunkVersion = collectionMetadata.getChunkManager()
->findIntersectingChunkWithSimpleCollation(_args.getMinKey())
.getLastmod();
- _collectionEpoch = collectionVersion.epoch();
- _collectionUuid = std::get<1>(collectionMetadataAndUUID);
}
MigrationSourceManager::~MigrationSourceManager() {
@@ -259,7 +257,7 @@ Status MigrationSourceManager::startClone() {
_args.getFromShardId(),
_args.getToShardId(),
getNss(),
- _collectionUuid.get(),
+ *_collectionUUID,
ChunkRange(_args.getMinKey(), _args.getMaxKey()),
_chunkVersion,
_args.getWaitForDelete());
@@ -617,10 +615,10 @@ CollectionMetadata MigrationSourceManager::_getCurrentMetadataAndCheckEpoch() {
uassert(ErrorCodes::ConflictingOperationInProgress,
str::stream() << "The collection's epoch has changed since the migration began. "
"Expected collection epoch: "
- << _collectionEpoch.toString() << ", but found: "
+ << _collectionEpoch->toString() << ", but found: "
<< (metadata.isSharded() ? metadata.getCollVersion().epoch().toString()
: "unsharded collection"),
- metadata.isSharded() && metadata.getCollVersion().epoch() == _collectionEpoch);
+ metadata.isSharded() && metadata.getCollVersion().epoch() == *_collectionEpoch);
return metadata;
}
@@ -649,7 +647,7 @@ void MigrationSourceManager::_notifyChangeStreamsOnRecipientFirstChunk(
_opCtx, "migrateChunkToNewShard", NamespaceString::kRsOplogNamespace.ns(), [&] {
WriteUnitOfWork uow(_opCtx);
serviceContext->getOpObserver()->onInternalOpMessage(
- _opCtx, getNss(), _collectionUuid, BSON("msg" << dbgMessage), o2Message);
+ _opCtx, getNss(), *_collectionUUID, BSON("msg" << dbgMessage), o2Message);
uow.commit();
});
}