diff options
author | Jordi Serra Torrens <jordi.serra-torrens@mongodb.com> | 2021-05-27 14:43:48 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-10-27 14:56:23 +0000 |
commit | b5a5e2b2099034a712098939bfc153dfcd33dd2d (patch) | |
tree | 3ed8a04204aeaac130573879548ee8164d91912e | |
parent | f4b960d252c784da7739d988be711cd051bcbbe3 (diff) | |
download | mongo-b5a5e2b2099034a712098939bfc153dfcd33dd2d.tar.gz |
SERVER-55557 Range deletion of aborted migration can fail after a refine shard key
-rw-r--r-- | src/mongo/base/error_codes.yml | 2 | ||||
-rw-r--r-- | src/mongo/db/keypattern.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/s/migration_util.cpp | 27 | ||||
-rw-r--r-- | src/mongo/db/s/range_deletion_util.cpp | 1 |
4 files changed, 30 insertions, 2 deletions
diff --git a/src/mongo/base/error_codes.yml b/src/mongo/base/error_codes.yml index fcf13293125..183891d5d5a 100644 --- a/src/mongo/base/error_codes.yml +++ b/src/mongo/base/error_codes.yml @@ -442,6 +442,8 @@ error_codes: - {code: 353, name: NonRetryableTenantMigrationConflict, extra: NonRetryableTenantMigrationConflictInfo, categories: [TenantMigrationError, TenantMigrationConflictError]} + - {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 c8040d20e15..1916bb0abff 100644 --- a/src/mongo/db/s/migration_util.cpp +++ b/src/mongo/db/s/migration_util.cpp @@ -445,7 +445,32 @@ ExecutorFuture<void> submitRangeDeletionTask(OperationContext* opCtx, refreshFilteringMetadataUntilSuccess(opCtx, deletionTask.getNss()); } - 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 5cd1a837648..f45cb97d561 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()); }) |