summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/migration_util.cpp
diff options
context:
space:
mode:
authorLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
committerLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
commit4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch)
tree1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/db/s/migration_util.cpp
parentaa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff)
parent8f0827553e09872941945a093b647a4211a9db7f (diff)
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0' with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/db/s/migration_util.cpp')
-rw-r--r--src/mongo/db/s/migration_util.cpp59
1 files changed, 18 insertions, 41 deletions
diff --git a/src/mongo/db/s/migration_util.cpp b/src/mongo/db/s/migration_util.cpp
index f0058b60318..ec63e7477af 100644
--- a/src/mongo/db/s/migration_util.cpp
+++ b/src/mongo/db/s/migration_util.cpp
@@ -42,7 +42,7 @@
#include "mongo/db/catalog/collection_catalog_helper.h"
#include "mongo/db/catalog_raii.h"
#include "mongo/db/commands.h"
-#include "mongo/db/concurrency/exception_util.h"
+#include "mongo/db/concurrency/write_conflict_exception.h"
#include "mongo/db/dbdirectclient.h"
#include "mongo/db/logical_session_cache.h"
#include "mongo/db/namespace_string.h"
@@ -521,27 +521,14 @@ void resubmitRangeDeletionsOnStepUp(ServiceContext* serviceContext) {
FindCommandRequest findCommand(NamespaceString::kRangeDeletionNamespace);
findCommand.setFilter(BSON(RangeDeletionTask::kProcessingFieldName << true));
auto cursor = client.find(std::move(findCommand));
-
- auto retFuture = ExecutorFuture<void>(getMigrationUtilExecutor(serviceContext));
-
- int rangeDeletionsMarkedAsProcessing = 0;
- while (cursor->more()) {
- retFuture = migrationutil::submitRangeDeletionTask(
+ if (cursor->more()) {
+ return migrationutil::submitRangeDeletionTask(
opCtx.get(),
RangeDeletionTask::parse(IDLParserErrorContext("rangeDeletionRecovery"),
cursor->next()));
- rangeDeletionsMarkedAsProcessing++;
- }
-
- if (rangeDeletionsMarkedAsProcessing > 1) {
- LOGV2_WARNING(
- 6695800,
- "Rescheduling several range deletions marked as processing. Orphans count "
- "may be off while they are not drained",
- "numRangeDeletionsMarkedAsProcessing"_attr = rangeDeletionsMarkedAsProcessing);
+ } else {
+ return ExecutorFuture<void>(getMigrationUtilExecutor(serviceContext));
}
-
- return retFuture;
})
.then([serviceContext] {
ThreadClient tc("ResubmitRangeDeletions", serviceContext);
@@ -661,8 +648,9 @@ void submitOrphanRangesForCleanup(OperationContext* opCtx) {
if (tenantDbName.dbName() == NamespaceString::kLocalDb)
continue;
- for (auto&& coll : catalog->range(tenantDbName)) {
- auto uuid = coll->uuid();
+ for (auto collIt = catalog->begin(opCtx, tenantDbName); collIt != catalog->end(opCtx);
+ ++collIt) {
+ auto uuid = collIt.uuid().get();
auto nss = catalog->lookupNSSByUUID(opCtx, uuid).get();
LOGV2_DEBUG(22034,
2,
@@ -718,8 +706,8 @@ void persistUpdatedNumOrphans(OperationContext* opCtx,
<< BSON("$exists" << true));
try {
PersistentTaskStore<RangeDeletionTask> store(NamespaceString::kRangeDeletionNamespace);
- ScopedRangeDeleterLock rangeDeleterLock(opCtx, MODE_IX);
- // TODO (SERVER-65996) Remove writeConflictRetry loop
+ ScopedRangeDeleterLock rangeDeleterLock(opCtx, collectionUuid);
+ // TODO (SERVER-54284) Remove writeConflictRetry loop
writeConflictRetry(
opCtx, "updateOrphanCount", NamespaceString::kRangeDeletionNamespace.ns(), [&] {
store.update(opCtx,
@@ -843,7 +831,6 @@ void persistCommitDecision(OperationContext* opCtx,
store.upsert(opCtx,
BSON(MigrationCoordinatorDocument::kIdFieldName << migrationDoc.getId()),
migrationDoc.toBSON());
- ShardingStatistics::get(opCtx).countDonorMoveChunkCommitted.addAndFetch(1);
if (hangInPersistMigrateCommitDecisionThenSimulateErrorUninterruptible.shouldFail()) {
hangInPersistMigrateCommitDecisionThenSimulateErrorUninterruptible.pauseWhileSet(opCtx);
@@ -863,7 +850,6 @@ void persistAbortDecision(OperationContext* opCtx,
store.upsert(opCtx,
BSON(MigrationCoordinatorDocument::kIdFieldName << migrationDoc.getId()),
migrationDoc.toBSON());
- ShardingStatistics::get(opCtx).countDonorMoveChunkAborted.addAndFetch(1);
if (hangInPersistMigrateAbortDecisionThenSimulateErrorUninterruptible.shouldFail()) {
hangInPersistMigrateAbortDecisionThenSimulateErrorUninterruptible.pauseWhileSet(opCtx);
@@ -1000,6 +986,11 @@ void markAsReadyRangeDeletionTaskLocally(OperationContext* opCtx, const UUID& mi
}
void deleteMigrationCoordinatorDocumentLocally(OperationContext* opCtx, const UUID& migrationId) {
+ // Before deleting the migration coordinator document, ensure that in the case of a crash, the
+ // node will start-up from at least the configTime, which it obtained as part of recovery of the
+ // shardVersion, which will ensure that it will see at least the same shardVersion.
+ VectorClockMutable::get(opCtx)->waitForDurableConfigTime().get(opCtx);
+
PersistentTaskStore<MigrationCoordinatorDocument> store(
NamespaceString::kMigrationCoordinatorsNamespace);
store.remove(opCtx,
@@ -1135,7 +1126,7 @@ void recoverMigrationCoordinations(OperationContext* opCtx,
hangInRefreshFilteringMetadataUntilSuccessThenSimulateErrorUninterruptible
.pauseWhileSet();
uasserted(ErrorCodes::InternalError,
- "simulate an error response for forceGetCurrentMetadata");
+ "simulate an error response for forceShardFilteringMetadataRefresh");
}
auto setFilteringMetadata = [&opCtx, &currentMetadata, &doc, &cancellationToken]() {
@@ -1175,15 +1166,6 @@ void recoverMigrationCoordinations(OperationContext* opCtx,
"coordinatorDocumentUUID"_attr = doc.getCollectionUuid());
}
- // TODO SERVER-71918 once the drop collection coordinator starts persisting the
- // config time we can remove this. Since the collection has been dropped,
- // persist config time inclusive of the drop collection event before deleting
- // leftover migration metadata.
- // This will ensure that in case of stepdown the new
- // primary won't read stale data from config server and think that the sharded
- // collection still exists.
- VectorClockMutable::get(opCtx)->waitForDurableConfigTime().get(opCtx);
-
deleteRangeDeletionTaskOnRecipient(opCtx, doc.getRecipientShardId(), doc.getId());
deleteRangeDeletionTaskLocally(opCtx, doc.getId());
coordinator.forgetMigration(opCtx);
@@ -1316,15 +1298,10 @@ void resumeMigrationRecipientsOnStepUp(OperationContext* opCtx) {
const auto& nss = doc.getNss();
// Register this receiveChunk on the ActiveMigrationsRegistry before completing step-up
- // to prevent a new migration from starting while a receiveChunk was ongoing. Wait for
- // any migrations that began in a previous term to complete if there are any.
+ // to prevent a new migration from starting while a receiveChunk was ongoing.
auto scopedReceiveChunk(
uassertStatusOK(ActiveMigrationsRegistry::get(opCtx).registerReceiveChunk(
- opCtx,
- nss,
- doc.getRange(),
- doc.getDonorShardIdForLoggingPurposesOnly(),
- true /* waitForOngoingMigrations */)));
+ opCtx, nss, doc.getRange(), doc.getDonorShardIdForLoggingPurposesOnly())));
const auto mdm = MigrationDestinationManager::get(opCtx);
uassertStatusOK(