diff options
author | Allison Easton <allison.easton@mongodb.com> | 2022-03-03 07:08:16 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-03-03 07:35:37 +0000 |
commit | 6ef05b6b0aee211291593e53cce17f8b341fbe0e (patch) | |
tree | 9a3336e05d7672511f579975641fd5b4484e91e4 /src/mongo/db | |
parent | 3ac741ee813a03fa516dcf4419f37852a26c3df2 (diff) | |
download | mongo-6ef05b6b0aee211291593e53cce17f8b341fbe0e.tar.gz |
SERVER-63763 Track initial number of orphans in range deletion task documents (donor-side)
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/s/migration_coordinator.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/s/migration_util.cpp | 28 | ||||
-rw-r--r-- | src/mongo/db/s/migration_util.h | 6 |
3 files changed, 46 insertions, 0 deletions
diff --git a/src/mongo/db/s/migration_coordinator.cpp b/src/mongo/db/s/migration_coordinator.cpp index dfab697554e..5096442f56e 100644 --- a/src/mongo/db/s/migration_coordinator.cpp +++ b/src/mongo/db/s/migration_coordinator.cpp @@ -231,6 +231,18 @@ SemiFuture<void> MigrationCoordinator::_commitMigrationOnDonorAndRecipient( hangBeforeSendingCommitDecision.pauseWhileSet(); + LOGV2_DEBUG(6376300, + 2, + "Retrieving number of orphan documents from recipient", + "migrationId"_attr = _migrationInfo.getId()); + + auto numOrphans = migrationutil::retrieveNumOrphansFromRecipient(opCtx, _migrationInfo); + + if (numOrphans > 0) { + migrationutil::persistUpdatedNumOrphans( + opCtx, BSON("_id" << _migrationInfo.getId()), numOrphans); + } + LOGV2_DEBUG(23896, 2, "Deleting range deletion task on recipient", diff --git a/src/mongo/db/s/migration_util.cpp b/src/mongo/db/s/migration_util.cpp index dffa086da60..364f5813f0a 100644 --- a/src/mongo/db/s/migration_util.cpp +++ b/src/mongo/db/s/migration_util.cpp @@ -678,6 +678,34 @@ void persistUpdatedNumOrphans(OperationContext* opCtx, WriteConcernOptions()); } +int retrieveNumOrphansFromRecipient(OperationContext* opCtx, + const MigrationCoordinatorDocument& migrationInfo) { + const auto recipientShard = uassertStatusOK( + Grid::get(opCtx)->shardRegistry()->getShard(opCtx, migrationInfo.getRecipientShardId())); + FindCommandRequest findCommand(NamespaceString::kRangeDeletionNamespace); + findCommand.setFilter(BSON("_id" << migrationInfo.getId())); + findCommand.setReadConcern(BSONObj()); + Shard::QueryResponse rangeDeletionResponse = + uassertStatusOK(recipientShard->runExhaustiveCursorCommand( + opCtx, + ReadPreferenceSetting(ReadPreference::PrimaryOnly), + NamespaceString::kRangeDeletionNamespace.db().toString(), + findCommand.toBSON(BSONObj()), + Milliseconds(-1))); + if (rangeDeletionResponse.docs.empty()) { + // In case of shutdown/stepdown, the recipient may have already deleted its range deletion + // document. A previous call to this function will have already returned the correct number + // of orphans, so we can simply return 0. + LOGV2_DEBUG(6376301, + 2, + "No matching document found for migration", + "recipientId"_attr = migrationInfo.getRecipientShardId(), + "migrationId"_attr = migrationInfo.getId()); + return 0; + } + return rangeDeletionResponse.docs[0].getIntField("numOrphanDocs"); +} + void persistCommitDecision(OperationContext* opCtx, const MigrationCoordinatorDocument& migrationDoc) { invariant(migrationDoc.getDecision() && diff --git a/src/mongo/db/s/migration_util.h b/src/mongo/db/s/migration_util.h index 43d2c71cff4..73012403600 100644 --- a/src/mongo/db/s/migration_util.h +++ b/src/mongo/db/s/migration_util.h @@ -152,6 +152,12 @@ void persistUpdatedNumOrphans(OperationContext* opCtx, const int& changeInOrphans); /** + * Retrieves the value of 'numOrphanedDocs' from the recipient shard's range deletion task document. + */ +int retrieveNumOrphansFromRecipient(OperationContext* opCtx, + const MigrationCoordinatorDocument& migrationInfo); + +/** * Updates the migration coordinator document to set the decision field to "committed" and waits for * majority writeConcern. */ |