diff options
author | Gregory Noma <gregory.noma@gmail.com> | 2022-09-02 14:25:41 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-09-02 16:33:20 +0000 |
commit | bf9c77c2330f0414cde0c83e83dc5e7dd38cb312 (patch) | |
tree | b98face3948a651342e974873b674b85d72f6373 | |
parent | e05c628e0bb27cffcd57a796e3a328b219ab36f2 (diff) | |
download | mongo-bf9c77c2330f0414cde0c83e83dc5e7dd38cb312.tar.gz |
SERVER-67611 Remove storage usages of `ErrorCategory::Interruption`
-rw-r--r-- | jstests/noPassthrough/index_failover_key_errors.js | 2 | ||||
-rw-r--r-- | jstests/noPassthrough/index_failover_resolved_key_errors.js | 2 | ||||
-rw-r--r-- | jstests/noPassthrough/index_failover_resolved_key_errors_after_stepdown.js | 2 | ||||
-rw-r--r-- | jstests/noPassthrough/index_stepdown_failover.js | 2 | ||||
-rw-r--r-- | src/mongo/db/catalog/catalog_stats.cpp | 17 | ||||
-rw-r--r-- | src/mongo/db/catalog/collection_validation.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/catalog/multi_index_block.cpp | 127 | ||||
-rw-r--r-- | src/mongo/db/commands/create_indexes.cpp | 78 | ||||
-rw-r--r-- | src/mongo/db/concurrency/d_concurrency.cpp | 11 | ||||
-rw-r--r-- | src/mongo/db/curop.cpp | 28 | ||||
-rw-r--r-- | src/mongo/db/index/index_access_method.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/stats/storage_stats.cpp | 16 | ||||
-rw-r--r-- | src/mongo/db/storage/oplog_cap_maintainer_thread.cpp | 13 | ||||
-rw-r--r-- | src/mongo/db/storage/storage_engine_impl.cpp | 24 | ||||
-rw-r--r-- | src/mongo/db/ttl.cpp | 15 | ||||
-rw-r--r-- | src/mongo/dbtests/indexupdatetests.cpp | 4 |
17 files changed, 171 insertions, 182 deletions
diff --git a/jstests/noPassthrough/index_failover_key_errors.js b/jstests/noPassthrough/index_failover_key_errors.js index 2a476075902..03a3d912879 100644 --- a/jstests/noPassthrough/index_failover_key_errors.js +++ b/jstests/noPassthrough/index_failover_key_errors.js @@ -66,7 +66,7 @@ const stepDown = startParallelShell(() => { // the index build will continue in the background. const exitCode = createIdx({checkExitSuccess: false}); assert.neq(0, exitCode, 'expected shell to exit abnormally due to index build being terminated'); -checkLog.containsJson(primary, 20441); +checkLog.containsJson(primary, 20444); // Wait for stepdown to complete. stepDown(); diff --git a/jstests/noPassthrough/index_failover_resolved_key_errors.js b/jstests/noPassthrough/index_failover_resolved_key_errors.js index e081b091752..e9f55ce4239 100644 --- a/jstests/noPassthrough/index_failover_resolved_key_errors.js +++ b/jstests/noPassthrough/index_failover_resolved_key_errors.js @@ -77,7 +77,7 @@ const stepDown = startParallelShell(() => { // the index build will continue in the background. const exitCode = createIdx({checkExitSuccess: false}); assert.neq(0, exitCode, 'expected shell to exit abnormally due to index build being terminated'); -checkLog.containsJson(primary, 20441); +checkLog.containsJson(primary, 20444); // Unblock the index build on the old primary during the collection scanning phase, this lets // stepdown complete. diff --git a/jstests/noPassthrough/index_failover_resolved_key_errors_after_stepdown.js b/jstests/noPassthrough/index_failover_resolved_key_errors_after_stepdown.js index c6d7a49f15f..4a137763458 100644 --- a/jstests/noPassthrough/index_failover_resolved_key_errors_after_stepdown.js +++ b/jstests/noPassthrough/index_failover_resolved_key_errors_after_stepdown.js @@ -69,7 +69,7 @@ const stepDown = startParallelShell(() => { // the index build will continue in the background. const exitCode = createIdx({checkExitSuccess: false}); assert.neq(0, exitCode, 'expected shell to exit abnormally due to index build being terminated'); -checkLog.containsJson(primary, 20441); +checkLog.containsJson(primary, 20444); // Wait for stepdown to complete. stepDown(); diff --git a/jstests/noPassthrough/index_stepdown_failover.js b/jstests/noPassthrough/index_stepdown_failover.js index 18b44b269e0..96deceabcd8 100644 --- a/jstests/noPassthrough/index_stepdown_failover.js +++ b/jstests/noPassthrough/index_stepdown_failover.js @@ -49,7 +49,7 @@ const newPrimaryColl = secondaryColl; assert.commandWorked(primary.adminCommand({replSetStepDown: 60, force: true})); const exitCode = createIdx({checkExitSuccess: false}); assert.neq(0, exitCode, 'expected shell to exit abnormally due to index build being terminated'); -checkLog.containsJson(primary, 20441); +checkLog.containsJson(primary, 20444); // Unblock the index build on the old primary during the collection scanning phase. // This index build will not complete because it has to wait for a commitIndexBuild oplog diff --git a/src/mongo/db/catalog/catalog_stats.cpp b/src/mongo/db/catalog/catalog_stats.cpp index 9b1c0f075a3..4c456a8d7fa 100644 --- a/src/mongo/db/catalog/catalog_stats.cpp +++ b/src/mongo/db/catalog/catalog_stats.cpp @@ -92,17 +92,12 @@ public: const auto viewCatalogDbNames = catalog->getViewCatalogDbNames(opCtx); for (const auto& dbName : viewCatalogDbNames) { - try { - const auto viewStats = catalog->getViewStatsForDatabase(opCtx, dbName); - invariant(viewStats); - - stats.timeseries += viewStats->userTimeseries; - stats.views += viewStats->userViews; - stats.internalViews += viewStats->internal; - } catch (ExceptionForCat<ErrorCategory::Interruption>&) { - LOGV2_DEBUG( - 5578400, 2, "Failed to collect view catalog statistics", "db"_attr = dbName); - } + const auto viewStats = catalog->getViewStatsForDatabase(opCtx, dbName); + invariant(viewStats); + + stats.timeseries += viewStats->userTimeseries; + stats.views += viewStats->userViews; + stats.internalViews += viewStats->internal; } BSONObjBuilder builder; diff --git a/src/mongo/db/catalog/collection_validation.cpp b/src/mongo/db/catalog/collection_validation.cpp index 17c1a3148e0..7b39f823443 100644 --- a/src/mongo/db/catalog/collection_validation.cpp +++ b/src/mongo/db/catalog/collection_validation.cpp @@ -626,13 +626,14 @@ Status validate(OperationContext* opCtx, logAttrs(validateState.nss()), logAttrs(validateState.uuid())); } catch (const DBException& e) { - if (ErrorCodes::isInterruption(e.code())) { + if (opCtx->isKillPending() || e.code() == ErrorCodes::Interrupted) { LOGV2_OPTIONS(5160301, {LogComponent::kIndex}, "Validation interrupted", - "namespace"_attr = validateState.nss()); + logAttrs(validateState.nss())); return e.toStatus(); } + string err = str::stream() << "exception during collection validation: " << e.toString(); results->errors.push_back(err); results->valid = false; diff --git a/src/mongo/db/catalog/multi_index_block.cpp b/src/mongo/db/catalog/multi_index_block.cpp index 2df5e30f295..04201563477 100644 --- a/src/mongo/db/catalog/multi_index_block.cpp +++ b/src/mongo/db/catalog/multi_index_block.cpp @@ -470,10 +470,42 @@ Status MultiIndexBlock::insertAllDocumentsInCollection( size_t numScanRestarts = 0; bool restartCollectionScan = false; + Timer timer; + + auto restart = [&](const DBException& ex) { + // Forced replica set re-configs will clear the majority committed snapshot, which may be + // used by the collection scan. The collection scan will restart from the beginning in this + // case. Capped cursors are invalidated when the document they were positioned on gets + // deleted. The collection scan will restart in both cases. + restartCollectionScan = true; + logAndBackoff(5470300, + ::mongo::logv2::LogComponent::kIndex, + logv2::LogSeverity::Info(), + ++numScanRestarts, + "Index build: collection scan restarting", + "buildUUID"_attr = _buildUUID, + "collectionUUID"_attr = _collectionUUID, + "totalRecords"_attr = progress->hits(), + "duration"_attr = duration_cast<Milliseconds>(timer.elapsed()), + "phase"_attr = IndexBuildPhase_serializer(_phase), + "collectionScanPosition"_attr = _lastRecordIdInserted, + "readSource"_attr = + RecoveryUnit::toString(opCtx->recoveryUnit()->getTimestampReadSource()), + "error"_attr = ex); + + _lastRecordIdInserted = boost::none; + for (auto& index : _indexes) { + index.bulk = + index.real->initiateBulk(getEachIndexBuildMaxMemoryUsageBytes(_indexes.size()), + /*stateInfo=*/boost::none, + collection->ns().db()); + } + }; + do { restartCollectionScan = false; progress->reset(collection->numRecords(opCtx)); - Timer timer; + timer.reset(); try { // Resumable index builds can only be resumed prior to the oplog recovery phase of @@ -491,71 +523,36 @@ Status MultiIndexBlock::insertAllDocumentsInCollection( "totalRecords"_attr = progress->hits(), "readSource"_attr = RecoveryUnit::toString(opCtx->recoveryUnit()->getTimestampReadSource()), - "duration"_attr = duration_cast<Milliseconds>(Seconds(timer.seconds()))); + "duration"_attr = duration_cast<Milliseconds>(timer.elapsed())); + } catch (const ExceptionFor<ErrorCodes::ReadConcernMajorityNotAvailableYet>& ex) { + restart(ex); + } catch (const ExceptionFor<ErrorCodes::CappedPositionLost>& ex) { + restart(ex); } catch (DBException& ex) { - if (ex.code() == ErrorCodes::ReadConcernMajorityNotAvailableYet || - ex.code() == ErrorCodes::CappedPositionLost) { - // Forced replica set re-configs will clear the majority committed snapshot, - // which may be used by the collection scan. The collection scan will restart - // from the beginning in this case. Capped cursors are invalidated when the document - // they were positioned on gets deleted. The collection scan will restart in both - // cases. - restartCollectionScan = true; - logAndBackoff( - 5470300, - ::mongo::logv2::LogComponent::kIndex, - logv2::LogSeverity::Info(), - ++numScanRestarts, - "Index build: collection scan restarting", - "buildUUID"_attr = _buildUUID, - "collectionUUID"_attr = _collectionUUID, - "totalRecords"_attr = progress->hits(), - "duration"_attr = duration_cast<Milliseconds>(Seconds(timer.seconds())), - "phase"_attr = IndexBuildPhase_serializer(_phase), - "collectionScanPosition"_attr = _lastRecordIdInserted, - "readSource"_attr = - RecoveryUnit::toString(opCtx->recoveryUnit()->getTimestampReadSource()), - "error"_attr = ex); - - _lastRecordIdInserted = boost::none; - for (auto& index : _indexes) { - index.bulk = index.real->initiateBulk( - getEachIndexBuildMaxMemoryUsageBytes(_indexes.size()), - /*stateInfo=*/boost::none, - collection->ns().db()); - } - } else { - if (ex.isA<ErrorCategory::Interruption>() || - ex.isA<ErrorCategory::ShutdownError>() || - ErrorCodes::IndexBuildAborted == ex.code()) { - // If the collection scan is stopped due to an interrupt or shutdown event, we - // leave the internal state intact to ensure we have the correct information for - // resuming this index build during startup and rollback. - } else { - // Restore pre-collection scan state. - _phase = IndexBuildPhaseEnum::kInitialized; - } - - auto readSource = opCtx->recoveryUnit()->getTimestampReadSource(); - LOGV2(4984704, - "Index build: collection scan stopped", - "buildUUID"_attr = _buildUUID, - "collectionUUID"_attr = _collectionUUID, - "totalRecords"_attr = progress->hits(), - "duration"_attr = duration_cast<Milliseconds>(Seconds(timer.seconds())), - "phase"_attr = IndexBuildPhase_serializer(_phase), - "collectionScanPosition"_attr = _lastRecordIdInserted, - "readSource"_attr = RecoveryUnit::toString(readSource), - "error"_attr = ex); - ex.addContext(str::stream() - << "collection scan stopped. totalRecords: " << progress->hits() - << "; durationMillis: " - << duration_cast<Milliseconds>(Seconds(timer.seconds())) - << "; phase: " << IndexBuildPhase_serializer(_phase) - << "; collectionScanPosition: " << _lastRecordIdInserted - << "; readSource: " << RecoveryUnit::toString(readSource)); - return ex.toStatus(); + // If the index build may be resumed, leave the internal state intact. Otherwise, + // restore the state from before the collection scan. + if (!opCtx->isKillPending() && ErrorCodes::IndexBuildAborted != ex.code()) { + _phase = IndexBuildPhaseEnum::kInitialized; } + + auto readSource = opCtx->recoveryUnit()->getTimestampReadSource(); + LOGV2(4984704, + "Index build: collection scan stopped", + "buildUUID"_attr = _buildUUID, + "collectionUUID"_attr = _collectionUUID, + "totalRecords"_attr = progress->hits(), + "duration"_attr = duration_cast<Milliseconds>(timer.elapsed()), + "phase"_attr = IndexBuildPhase_serializer(_phase), + "collectionScanPosition"_attr = _lastRecordIdInserted, + "readSource"_attr = RecoveryUnit::toString(readSource), + "error"_attr = ex); + ex.addContext(str::stream() + << "collection scan stopped. totalRecords: " << progress->hits() + << "; durationMillis: " << duration_cast<Milliseconds>(timer.elapsed()) + << "; phase: " << IndexBuildPhase_serializer(_phase) + << "; collectionScanPosition: " << _lastRecordIdInserted + << "; readSource: " << RecoveryUnit::toString(readSource)); + return ex.toStatus(); } } while (restartCollectionScan); @@ -1201,7 +1198,7 @@ Status MultiIndexBlock::_failPointHangDuringBuild(OperationContext* opCtx, return UUID::parse(elem.String()) == buildUUID; }); }); - } catch (const ExceptionForCat<ErrorCategory::Interruption>& ex) { + } catch (const DBException& ex) { return ex.toStatus(str::stream() << "Interrupted failpoint " << fp->getName()); } diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp index 6be62b121f1..9dbb6a8cef7 100644 --- a/src/mongo/db/commands/create_indexes.cpp +++ b/src/mongo/db/commands/create_indexes.cpp @@ -585,24 +585,47 @@ CreateIndexesReply runCreateIndexesWithCoordinator(OperationContext* opCtx, // Throws on error. try { stats = buildIndexFuture.get(opCtx); - } catch (const ExceptionForCat<ErrorCategory::Interruption>& interruptionEx) { + } catch (const ExceptionForCat<ErrorCategory::NotPrimaryError>& ex) { + LOGV2(20444, + "Index build: received interrupt signal due to change in replication state", + "buildUUID"_attr = buildUUID, + "ex"_attr = ex); + + // If this node is no longer a primary, the index build will continue to run in the + // background and will complete when this node receives a commitIndexBuild oplog + // entry from the new primary. + if (IndexBuildProtocol::kTwoPhase == protocol) { + shouldContinueInBackground = true; + throw; + } + + std::string abortReason(str::stream() << "Index build aborted: " << buildUUID << ": " + << ex.toString()); + if (indexBuildsCoord->abortIndexBuildByBuildUUID( + opCtx, buildUUID, IndexBuildAction::kPrimaryAbort, abortReason)) { + LOGV2(20446, + "Index build: aborted due to NotPrimary error", + "buildUUID"_attr = buildUUID); + } else { + // The index build may already be in the midst of tearing down. + LOGV2(5010501, + "Index build: failed to abort index build", + "buildUUID"_attr = buildUUID); + } + + throw; + } catch (const DBException& ex) { + if (!opCtx->isKillPending()) { + throw; + } + LOGV2(20441, "Index build: received interrupt signal", "buildUUID"_attr = buildUUID, - "signal"_attr = interruptionEx); + "signal"_attr = ex); hangBeforeIndexBuildAbortOnInterrupt.pauseWhileSet(); - if (IndexBuildProtocol::kTwoPhase == protocol) { - // If this node is no longer a primary, the index build will continue to run in the - // background and will complete when this node receives a commitIndexBuild oplog - // entry from the new primary. - if (ErrorCodes::InterruptedDueToReplStateChange == interruptionEx.code()) { - shouldContinueInBackground = true; - throw; - } - } - // It is unclear whether the interruption originated from the current opCtx instance // for the createIndexes command or that the IndexBuildsCoordinator task was interrupted // independently of this command invocation. We'll defensively abort the index build @@ -616,7 +639,7 @@ CreateIndexesReply runCreateIndexesWithCoordinator(OperationContext* opCtx, const auto abortCtx = cc().makeOperationContext(); std::string abortReason(str::stream() << "Index build aborted: " << buildUUID - << ": " << interruptionEx.toString()); + << ": " << ex.toString()); if (indexBuildsCoord->abortIndexBuildByBuildUUID( abortCtx.get(), buildUUID, IndexBuildAction::kPrimaryAbort, abortReason)) { LOGV2(20443, @@ -630,35 +653,6 @@ CreateIndexesReply runCreateIndexesWithCoordinator(OperationContext* opCtx, } } throw; - } catch (const ExceptionForCat<ErrorCategory::NotPrimaryError>& ex) { - LOGV2(20444, - "Index build: received interrupt signal due to change in replication state", - "buildUUID"_attr = buildUUID, - "ex"_attr = ex); - - // If this node is no longer a primary, the index build will continue to run in the - // background and will complete when this node receives a commitIndexBuild oplog - // entry from the new primary. - if (IndexBuildProtocol::kTwoPhase == protocol) { - shouldContinueInBackground = true; - throw; - } - - std::string abortReason(str::stream() << "Index build aborted: " << buildUUID << ": " - << ex.toString()); - if (indexBuildsCoord->abortIndexBuildByBuildUUID( - opCtx, buildUUID, IndexBuildAction::kPrimaryAbort, abortReason)) { - LOGV2(20446, - "Index build: aborted due to NotPrimary error", - "buildUUID"_attr = buildUUID); - } else { - // The index build may already be in the midst of tearing down. - LOGV2(5010501, - "Index build: failed to abort index build", - "buildUUID"_attr = buildUUID); - } - - throw; } LOGV2(20447, "Index build: completed", "buildUUID"_attr = buildUUID); diff --git a/src/mongo/db/concurrency/d_concurrency.cpp b/src/mongo/db/concurrency/d_concurrency.cpp index 3f463f0f800..b20e9ba2b9f 100644 --- a/src/mongo/db/concurrency/d_concurrency.cpp +++ b/src/mongo/db/concurrency/d_concurrency.cpp @@ -170,10 +170,15 @@ Lock::GlobalLock::GlobalLock(OperationContext* opCtx, unlockFCVLock.dismiss(); unlockPBWM.dismiss(); - } catch (const ExceptionForCat<ErrorCategory::Interruption>&) { - // The kLeaveUnlocked behavior suppresses this exception. - if (_interruptBehavior == InterruptBehavior::kThrow) + } catch (const DBException& ex) { + // If our opCtx was killed or we got a LockTimeout or MaxTimeMSExpired, either throw or + // suppress the exception depending on the specified interrupt behavior. For any other + // exception, always throw. + if ((!opCtx->isKillPending() && ex.code() != ErrorCodes::LockTimeout && + ex.code() != ErrorCodes::MaxTimeMSExpired) || + _interruptBehavior == InterruptBehavior::kThrow) { throw; + } } auto acquiredLockMode = _opCtx->lockState()->getLockMode(resourceIdGlobal); _opCtx->lockState()->setGlobalLockTakenInMode(acquiredLockMode); diff --git a/src/mongo/db/curop.cpp b/src/mongo/db/curop.cpp index 23bb5ee9830..b5e53e339d3 100644 --- a/src/mongo/db/curop.cpp +++ b/src/mongo/db/curop.cpp @@ -455,26 +455,14 @@ bool CurOp::completeAndLogOperation(OperationContext* opCtx, Lock::GlobalLock lk(opCtx, MODE_IS, Date_t::now() + Milliseconds(500), - Lock::InterruptBehavior::kLeaveUnlocked); - if (lk.isLocked()) { - _debug.storageStats = opCtx->recoveryUnit()->getOperationStatistics(); - } else { - LOGV2_WARNING_OPTIONS( - 20525, - {component}, - "Failed to gather storage statistics for {opId} due to {reason}", - "Failed to gather storage statistics for slow operation", - "opId"_attr = opCtx->getOpID(), - "error"_attr = "lock acquire timeout"_sd); - } - } catch (const ExceptionForCat<ErrorCategory::Interruption>& ex) { - LOGV2_WARNING_OPTIONS( - 20526, - {component}, - "Failed to gather storage statistics for {opId} due to {reason}", - "Failed to gather storage statistics for slow operation", - "opId"_attr = opCtx->getOpID(), - "error"_attr = redact(ex)); + Lock::InterruptBehavior::kThrow); + _debug.storageStats = opCtx->recoveryUnit()->getOperationStatistics(); + } catch (const DBException& ex) { + LOGV2_WARNING_OPTIONS(20526, + {component}, + "Failed to gather storage statistics for slow operation", + "opId"_attr = opCtx->getOpID(), + "error"_attr = redact(ex)); } } diff --git a/src/mongo/db/index/index_access_method.cpp b/src/mongo/db/index/index_access_method.cpp index cac540aae8f..4ddf9247918 100644 --- a/src/mongo/db/index/index_access_method.cpp +++ b/src/mongo/db/index/index_access_method.cpp @@ -1012,7 +1012,7 @@ void SortedDataIndexAccessMethod::getKeys(OperationContext* opCtx, multikeyPaths->clear(); } - if (ex.isA<ErrorCategory::Interruption>() || ex.isA<ErrorCategory::ShutdownError>()) { + if (opCtx->isKillPending()) { throw; } diff --git a/src/mongo/db/index_builds_coordinator.cpp b/src/mongo/db/index_builds_coordinator.cpp index a8494b8215e..b6c7d7c1cae 100644 --- a/src/mongo/db/index_builds_coordinator.cpp +++ b/src/mongo/db/index_builds_coordinator.cpp @@ -2395,9 +2395,8 @@ void IndexBuildsCoordinator::_runIndexBuildInner( "error"_attr = status); fassertFailedNoTrace(5642402); } - invariant(status.isA<ErrorCategory::Interruption>() || - status.isA<ErrorCategory::ShutdownError>() || - status.code() == ErrorCodes::CannotCreateIndex, + // TODO (SERVER-69264): Remove ErrorCodes::CannotCreateIndex. + invariant(opCtx->isKillPending() || status.code() == ErrorCodes::CannotCreateIndex, str::stream() << "Unexpected error code during index build cleanup: " << status); if (IndexBuildProtocol::kSinglePhase == replState->protocol) { _cleanUpSinglePhaseAfterFailure(opCtx, collection, replState, indexBuildOptions, status); diff --git a/src/mongo/db/stats/storage_stats.cpp b/src/mongo/db/stats/storage_stats.cpp index 2be6bd5af8f..497285f940e 100644 --- a/src/mongo/db/stats/storage_stats.cpp +++ b/src/mongo/db/stats/storage_stats.cpp @@ -68,15 +68,25 @@ Status appendCollectionStorageStats(OperationContext* opCtx, const auto collNss = (isTimeseries && !nss.isTimeseriesBucketsCollection()) ? std::move(bucketNss) : nss; + auto failed = [&](const DBException& ex) { + LOGV2_DEBUG(3088801, + 2, + "Failed to retrieve storage statistics", + logAttrs(collNss), + "error"_attr = ex); + return Status::OK(); + }; + boost::optional<AutoGetCollectionForReadCommandMaybeLockFree> autoColl; try { autoColl.emplace(opCtx, collNss, AutoGetCollectionViewMode::kViewsForbidden, waitForLock ? Date_t::max() : Date_t::now()); - } catch (const ExceptionForCat<ErrorCategory::Interruption>&) { - LOGV2_DEBUG(3088801, 2, "Failed to retrieve storage statistics", logAttrs(collNss)); - return Status::OK(); + } catch (const ExceptionFor<ErrorCodes::LockTimeout>& ex) { + return failed(ex); + } catch (const ExceptionFor<ErrorCodes::MaxTimeMSExpired>& ex) { + return failed(ex); } const auto& collection = autoColl->getCollection(); // Will be set if present diff --git a/src/mongo/db/storage/oplog_cap_maintainer_thread.cpp b/src/mongo/db/storage/oplog_cap_maintainer_thread.cpp index 30444730ee4..b2f7ef1a07f 100644 --- a/src/mongo/db/storage/oplog_cap_maintainer_thread.cpp +++ b/src/mongo/db/storage/oplog_cap_maintainer_thread.cpp @@ -87,13 +87,14 @@ bool OplogCapMaintainerThread::_deleteExcessDocuments() { "Caught an InterruptedDueToStorageChange exception, " "but this thread can safely continue", "error"_attr = e.toStatus()); - } catch (const ExceptionForCat<ErrorCategory::Interruption>&) { - return false; + } catch (const DBException& ex) { + if (opCtx->isKillPending()) { + return false; + } + + LOGV2_FATAL_NOTRACE(6761100, "Error in OplogCapMaintainerThread", "error"_attr = ex); } catch (const std::exception& e) { - LOGV2_FATAL_NOTRACE(22243, - "error in OplogCapMaintainerThread: {error}", - "Error in OplogCapMaintainerThread", - "error"_attr = e.what()); + LOGV2_FATAL_NOTRACE(22243, "Error in OplogCapMaintainerThread", "error"_attr = e.what()); } catch (...) { LOGV2_FATAL_NOTRACE(5184100, "Unknown error in OplogCapMaintainerThread"); } diff --git a/src/mongo/db/storage/storage_engine_impl.cpp b/src/mongo/db/storage/storage_engine_impl.cpp index 19e2f7622f7..872ffff82b7 100644 --- a/src/mongo/db/storage/storage_engine_impl.cpp +++ b/src/mongo/db/storage/storage_engine_impl.cpp @@ -1268,24 +1268,20 @@ void StorageEngineImpl::TimestampMonitor::_startup() { } } - } catch (const ExceptionForCat<ErrorCategory::Interruption>& ex) { - if (ex.code() == ErrorCodes::Interrupted) { - LOGV2(6183600, "Timestamp monitor got interrupted, retrying"); + } catch (const ExceptionFor<ErrorCodes::Interrupted>&) { + LOGV2(6183600, "Timestamp monitor got interrupted, retrying"); + return; + } catch (const ExceptionFor<ErrorCodes::InterruptedAtShutdown>& ex) { + if (_shuttingDown) { return; } - if (ex.code() == ErrorCodes::InterruptedAtShutdown) { - if (_shuttingDown) { - return; - } - _shuttingDown = true; - LOGV2(22263, "Timestamp monitor is stopping", "error"_attr = ex); - } - if (!ErrorCodes::isCancellationError(ex)) { - throw; - } + _shuttingDown = true; + LOGV2(22263, "Timestamp monitor is stopping", "error"_attr = ex); + } catch (const ExceptionForCat<ErrorCategory::CancellationError>&) { + return; } catch (const DBException& ex) { // Logs and rethrows the exceptions of other types. - LOGV2_ERROR(5802500, "Timestamp monitor throws an exception", "error"_attr = ex); + LOGV2_ERROR(5802500, "Timestamp monitor threw an exception", "error"_attr = ex); throw; } }, diff --git a/src/mongo/db/ttl.cpp b/src/mongo/db/ttl.cpp index ee94a03d228..89768d16380 100644 --- a/src/mongo/db/ttl.cpp +++ b/src/mongo/db/ttl.cpp @@ -298,10 +298,10 @@ void TTLMonitor::run() { _doTTLPass(); } catch (const WriteConflictException&) { LOGV2_DEBUG(22531, 1, "got WriteConflictException"); - } catch (const ExceptionForCat<ErrorCategory::Interruption>& interruption) { + } catch (const DBException& ex) { LOGV2_WARNING(22537, "TTLMonitor was interrupted, waiting before doing another pass", - "interruption"_attr = interruption, + "interruption"_attr = ex, "wait"_attr = Milliseconds(Seconds(ttlMonitorSleepSecs.load()))); } } @@ -458,10 +458,6 @@ bool TTLMonitor::_doTTLIndexDelete(OperationContext* opCtx, return _deleteExpiredWithIndex( opCtx, ttlCollectionCache, collection, info.getIndexName()); } - } catch (const ExceptionForCat<ErrorCategory::Interruption>&) { - // The exception is relevant to the entire TTL monitoring process, not just the specific TTL - // index. Let the exception escape so it can be addressed at the higher monitoring layer. - throw; } catch (const ExceptionForCat<ErrorCategory::StaleShardVersionError>& ex) { // The TTL index tried to delete some information from a sharded collection // through a direct operation against the shard but the filtering metadata was @@ -497,6 +493,13 @@ bool TTLMonitor::_doTTLIndexDelete(OperationContext* opCtx, "error"_attr = ex); return false; } catch (const DBException& ex) { + if (opCtx->isKillPending()) { + // The exception is relevant to the entire TTL monitoring process, not just the specific + // TTL index. Let the exception escape so it can be addressed at the higher monitoring + // layer. + throw; + } + LOGV2_ERROR( 5400703, "Error running TTL job on collection", logAttrs(*nss), "error"_attr = ex); return false; diff --git a/src/mongo/dbtests/indexupdatetests.cpp b/src/mongo/dbtests/indexupdatetests.cpp index f29fad7cabb..393a3f75853 100644 --- a/src/mongo/dbtests/indexupdatetests.cpp +++ b/src/mongo/dbtests/indexupdatetests.cpp @@ -101,8 +101,8 @@ protected: MultiIndexBlock::kNoopOnCommitFn)); wunit.commit(); abortOnExit.dismiss(); - } catch (const DBException& e) { - if (ErrorCodes::isInterruption(e.code())) + } catch (const DBException&) { + if (_opCtx->isKillPending()) return true; throw; |