summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/s/config/configsvr_reshard_collection_cmd.cpp4
-rw-r--r--src/mongo/db/s/resharding/resharding_recipient_service.cpp37
-rw-r--r--src/mongo/db/s/resharding/resharding_recipient_service.h4
-rw-r--r--src/mongo/db/s/resharding/resharding_recipient_service_test.cpp10
4 files changed, 24 insertions, 31 deletions
diff --git a/src/mongo/db/s/config/configsvr_reshard_collection_cmd.cpp b/src/mongo/db/s/config/configsvr_reshard_collection_cmd.cpp
index ccebb894ecf..99d097b8528 100644
--- a/src/mongo/db/s/config/configsvr_reshard_collection_cmd.cpp
+++ b/src/mongo/db/s/config/configsvr_reshard_collection_cmd.cpp
@@ -211,9 +211,7 @@ public:
instance->getObserver()->awaitAllDonorsReadyToDonate().wait();
// This promise is currently automatically filled by recipient shards after creating
- // their ReshardingRecipientStateMachines.
- // TODO SERVER-51217 Update this comment to reflect that the temporary collection
- // has been created.
+ // the temporary resharding collection.
instance->getObserver()->awaitAllRecipientsFinishedApplying().wait();
instance->interrupt(
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);
}
diff --git a/src/mongo/db/s/resharding/resharding_recipient_service.h b/src/mongo/db/s/resharding/resharding_recipient_service.h
index 9c53b20ca8a..da04ed475cf 100644
--- a/src/mongo/db/s/resharding/resharding_recipient_service.h
+++ b/src/mongo/db/s/resharding/resharding_recipient_service.h
@@ -44,7 +44,9 @@ namespace resharding {
* respectively.
*/
void createTemporaryReshardingCollectionLocally(OperationContext* opCtx,
- const NamespaceString& reshardingNss,
+ const NamespaceString& originalNss,
+ const UUID& reshardingUUID,
+ const UUID& existingUUID,
Timestamp fetchTimestamp);
} // namespace resharding
diff --git a/src/mongo/db/s/resharding/resharding_recipient_service_test.cpp b/src/mongo/db/s/resharding/resharding_recipient_service_test.cpp
index debfc34017a..341b8c96c26 100644
--- a/src/mongo/db/s/resharding/resharding_recipient_service_test.cpp
+++ b/src/mongo/db/s/resharding/resharding_recipient_service_test.cpp
@@ -251,7 +251,7 @@ TEST_F(ReshardingRecipientServiceTest, CreateLocalReshardingCollectionBasic) {
});
resharding::createTemporaryReshardingCollectionLocally(
- operationContext(), kReshardingNss, kDefaultFetchTimestamp);
+ operationContext(), kOrigNss, kReshardingUUID, kOrigUUID, kDefaultFetchTimestamp);
future.default_timed_get();
@@ -301,7 +301,7 @@ TEST_F(ReshardingRecipientServiceTest,
});
resharding::createTemporaryReshardingCollectionLocally(
- operationContext(), kReshardingNss, kDefaultFetchTimestamp);
+ operationContext(), kOrigNss, kReshardingUUID, kOrigUUID, kDefaultFetchTimestamp);
future.default_timed_get();
@@ -362,7 +362,7 @@ TEST_F(ReshardingRecipientServiceTest,
});
resharding::createTemporaryReshardingCollectionLocally(
- operationContext(), kReshardingNss, kDefaultFetchTimestamp);
+ operationContext(), kOrigNss, kReshardingUUID, kOrigUUID, kDefaultFetchTimestamp);
future.default_timed_get();
@@ -425,7 +425,7 @@ TEST_F(ReshardingRecipientServiceTest,
});
resharding::createTemporaryReshardingCollectionLocally(
- operationContext(), kReshardingNss, kDefaultFetchTimestamp);
+ operationContext(), kOrigNss, kReshardingUUID, kOrigUUID, kDefaultFetchTimestamp);
future.default_timed_get();
@@ -478,7 +478,7 @@ TEST_F(ReshardingRecipientServiceTest,
});
resharding::createTemporaryReshardingCollectionLocally(
- operationContext(), kReshardingNss, kDefaultFetchTimestamp);
+ operationContext(), kOrigNss, kReshardingUUID, kOrigUUID, kDefaultFetchTimestamp);
future.default_timed_get();