summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/resharding/resharding_recipient_service.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/s/resharding/resharding_recipient_service.cpp')
-rw-r--r--src/mongo/db/s/resharding/resharding_recipient_service.cpp37
1 files changed, 15 insertions, 22 deletions
diff --git a/src/mongo/db/s/resharding/resharding_recipient_service.cpp b/src/mongo/db/s/resharding/resharding_recipient_service.cpp
index 25c87941614..1f62ed5c3ae 100644
--- a/src/mongo/db/s/resharding/resharding_recipient_service.cpp
+++ b/src/mongo/db/s/resharding/resharding_recipient_service.cpp
@@ -49,21 +49,15 @@ namespace mongo {
namespace resharding {
void createTemporaryReshardingCollectionLocally(OperationContext* opCtx,
- const NamespaceString& reshardingNss,
+ const NamespaceString& originalNss,
+ const UUID& reshardingUUID,
+ const UUID& existingUUID,
Timestamp fetchTimestamp) {
LOGV2_DEBUG(
- 5002300, 1, "Creating temporary resharding collection", "namespace"_attr = reshardingNss);
+ 5002300, 1, "Creating temporary resharding collection", "originalNss"_attr = originalNss);
auto catalogCache = Grid::get(opCtx)->catalogCache();
- auto reshardingCm =
- uassertStatusOK(catalogCache->getCollectionRoutingInfo(opCtx, reshardingNss));
- uassert(
- 5002301,
- "Expected cached metadata for resharding temporary collection to have resharding fields",
- reshardingCm.getReshardingFields() &&
- reshardingCm.getReshardingFields()->getRecipientFields());
- auto originalNss =
- reshardingCm.getReshardingFields()->getRecipientFields()->getOriginalNamespace();
+ auto reshardingNss = constructTemporaryReshardingNss(originalNss.db(), existingUUID);
// Load the original collection's options from the database's primary shard.
auto [collOptions, uuid] = sharded_agg_helpers::shardVersionRetry(
@@ -74,12 +68,9 @@ void createTemporaryReshardingCollectionLocally(OperationContext* opCtx,
[&]() -> MigrationDestinationManager::CollectionOptionsAndUUID {
auto originalCm =
uassertStatusOK(catalogCache->getCollectionRoutingInfo(opCtx, originalNss));
- uassert(ErrorCodes::InvalidUUID,
- "Expected cached metadata for resharding temporary collection to have a UUID",
- originalCm.getUUID());
return MigrationDestinationManager::getCollectionOptions(
opCtx,
- NamespaceStringOrUUID(originalNss.db().toString(), *originalCm.getUUID()),
+ NamespaceStringOrUUID(originalNss.db().toString(), existingUUID),
originalCm.dbPrimary(),
originalCm,
fetchTimestamp);
@@ -97,13 +88,10 @@ void createTemporaryReshardingCollectionLocally(OperationContext* opCtx,
uassert(ErrorCodes::NamespaceNotSharded,
str::stream() << "Expected collection " << originalNss << " to be sharded",
originalCm.isSharded());
- uassert(ErrorCodes::InvalidUUID,
- "Expected cached metadata for resharding temporary collection to have a UUID",
- originalCm.getUUID());
auto indexShardId = originalCm.getMinKeyShardIdWithSimpleCollation();
return MigrationDestinationManager::getCollectionIndexes(
opCtx,
- NamespaceStringOrUUID(originalNss.db().toString(), *originalCm.getUUID()),
+ NamespaceStringOrUUID(originalNss.db().toString(), existingUUID),
indexShardId,
originalCm,
fetchTimestamp);
@@ -111,7 +99,6 @@ void createTemporaryReshardingCollectionLocally(OperationContext* opCtx,
// Set the temporary resharding collection's UUID to the resharding UUID. Note that
// BSONObj::addFields() replaces any fields that already exist.
- auto reshardingUUID = reshardingCm.getReshardingFields()->getUuid();
collOptions = collOptions.addFields(BSON("uuid" << reshardingUUID));
CollectionOptionsAndIndexes optionsAndIndexes = {reshardingUUID, indexes, idIndex, collOptions};
@@ -216,8 +203,14 @@ void ReshardingRecipientService::RecipientStateMachine::
return;
}
- // TODO SERVER-51217: Call
- // resharding_recipient_service_util::createTemporaryReshardingCollectionLocally()
+ {
+ auto opCtx = cc().makeOperationContext();
+ resharding::createTemporaryReshardingCollectionLocally(opCtx.get(),
+ _recipientDoc.getNss(),
+ _recipientDoc.get_id(),
+ _recipientDoc.getExistingUUID(),
+ *_recipientDoc.getFetchTimestamp());
+ }
_transitionState(RecipientStateEnum::kCloning);
}