summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordi Serra Torrens <jordi.serra-torrens@mongodb.com>2021-05-27 14:43:48 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-05-28 09:00:58 +0000
commit2e0261a28fc78379a0394ee5925d409ae8988af9 (patch)
tree4fa7f4ed8c914da4c059296067f3ba07308a7302
parent40b52236aa0cf8c7901b33b57360417732805fd8 (diff)
downloadmongo-2e0261a28fc78379a0394ee5925d409ae8988af9.tar.gz
SERVER-55557 Range deletion of aborted migration can fail after a refine shard key
-rw-r--r--src/mongo/base/error_codes.yml2
-rw-r--r--src/mongo/db/keypattern.cpp2
-rw-r--r--src/mongo/db/s/migration_util.cpp27
-rw-r--r--src/mongo/db/s/range_deletion_util.cpp1
4 files changed, 30 insertions, 2 deletions
diff --git a/src/mongo/base/error_codes.yml b/src/mongo/base/error_codes.yml
index 061dc16d8ff..5208c434cb4 100644
--- a/src/mongo/base/error_codes.yml
+++ b/src/mongo/base/error_codes.yml
@@ -440,6 +440,8 @@ error_codes:
- {code: 348,name: ChangeStreamTopologyChange, extra: ChangeStreamTopologyChangeInfo}
+ - {code: 349, name: KeyPatternShorterThanBound}
+
# Error codes 4000-8999 are reserved.
# Non-sequential error codes for compatibility only)
diff --git a/src/mongo/db/keypattern.cpp b/src/mongo/db/keypattern.cpp
index bba2f3424e0..8e91e561c01 100644
--- a/src/mongo/db/keypattern.cpp
+++ b/src/mongo/db/keypattern.cpp
@@ -79,7 +79,7 @@ BSONObj KeyPattern::extendRangeBound(const BSONObj& bound, bool makeUpperInclusi
BSONObjIterator pat(_pattern);
while (src.more()) {
- massert(16649,
+ massert(ErrorCodes::KeyPatternShorterThanBound,
str::stream() << "keyPattern " << _pattern << " shorter than bound " << bound,
pat.more());
BSONElement srcElt = src.next();
diff --git a/src/mongo/db/s/migration_util.cpp b/src/mongo/db/s/migration_util.cpp
index e766e7ec99e..c6578126cf3 100644
--- a/src/mongo/db/s/migration_util.cpp
+++ b/src/mongo/db/s/migration_util.cpp
@@ -408,7 +408,32 @@ ExecutorFuture<void> submitRangeDeletionTask(OperationContext* opCtx,
}
}
- return cleanUpRange(serviceContext, executor, deletionTask);
+ return AsyncTry([=]() {
+ return cleanUpRange(serviceContext, executor, deletionTask)
+ .onError<ErrorCodes::KeyPatternShorterThanBound>([=](Status status) {
+ ThreadClient tc(kRangeDeletionThreadName, serviceContext);
+ {
+ stdx::lock_guard<Client> lk(*tc.get());
+ tc->setSystemOperationKillableByStepdown(lk);
+ }
+ auto uniqueOpCtx = tc->makeOperationContext();
+ uniqueOpCtx->setAlwaysInterruptAtStepDownOrUp();
+
+ LOGV2(55557,
+ "cleanUpRange failed due to keyPattern shorter than range "
+ "deletion bounds. Refreshing collection metadata to retry.",
+ "nss"_attr = deletionTask.getNss(),
+ "status"_attr = redact(status));
+
+ onShardVersionMismatch(
+ uniqueOpCtx.get(), deletionTask.getNss(), boost::none);
+
+ return status;
+ });
+ })
+ .until(
+ [](Status status) { return status != ErrorCodes::KeyPatternShorterThanBound; })
+ .on(executor, CancellationToken::uncancelable());
})
.onError([=](const Status status) {
ThreadClient tc(kRangeDeletionThreadName, serviceContext);
diff --git a/src/mongo/db/s/range_deletion_util.cpp b/src/mongo/db/s/range_deletion_util.cpp
index a8d29853478..8cf10df7718 100644
--- a/src/mongo/db/s/range_deletion_util.cpp
+++ b/src/mongo/db/s/range_deletion_util.cpp
@@ -352,6 +352,7 @@ ExecutorFuture<void> deleteRangeInBatches(const std::shared_ptr<executor::TaskEx
ErrorCodes::RangeDeletionAbandonedBecauseCollectionWithUUIDDoesNotExist ||
swNumDeleted.getStatus() ==
ErrorCodes::RangeDeletionAbandonedBecauseTaskDocumentDoesNotExist ||
+ swNumDeleted.getStatus().code() == ErrorCodes::KeyPatternShorterThanBound ||
ErrorCodes::isShutdownError(swNumDeleted.getStatus()) ||
ErrorCodes::isNotPrimaryError(swNumDeleted.getStatus());
})