diff options
author | Dianna Hohensee <dianna.hohensee@mongodb.com> | 2019-09-05 00:23:40 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-09-05 00:23:40 +0000 |
commit | e8e3f6ff2604e33e2d7fe1ec56d6559df066a452 (patch) | |
tree | 287697bc8e92870dea373ad3c70fae82e2e1280c /src/mongo/db | |
parent | bac2b16a61498a65cbd61da0e15235363e7e77b9 (diff) | |
download | mongo-e8e3f6ff2604e33e2d7fe1ec56d6559df066a452.tar.gz |
SERVER-30357 Allow users to run the validate cmd with {background:true}
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/catalog/collection_validation.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/commands/validate.cpp | 25 |
2 files changed, 22 insertions, 10 deletions
diff --git a/src/mongo/db/catalog/collection_validation.cpp b/src/mongo/db/catalog/collection_validation.cpp index 40c1a3e567e..e1a08a705c0 100644 --- a/src/mongo/db/catalog/collection_validation.cpp +++ b/src/mongo/db/catalog/collection_validation.cpp @@ -390,6 +390,12 @@ Status validate(OperationContext* opCtx, invariant(!opCtx->lockState()->isLocked()); invariant(!(background && (level == kValidateFull))); + if (background) { + // Force a checkpoint to ensure background validation has a checkpoint on which to run. + // TODO (SERVER-43134): to sort out how to do this properly. + opCtx->recoveryUnit()->waitUntilUnjournaledWritesDurable(opCtx); + } + AutoGetDb autoDB(opCtx, nss.db(), MODE_IX); boost::optional<Lock::CollectionLock> collLock; if (background) { @@ -510,6 +516,7 @@ Status validate(OperationContext* opCtx, if (MONGO_FAIL_POINT(pauseCollectionValidationWithLock)) { invariant(opCtx->lockState()->isCollectionLockedForMode(collection->ns(), MODE_IX)); _validationIsPausedForTest.store(true); + log() << "Failpoint 'pauseCollectionValidationWithLock' activated."; MONGO_FAIL_POINT_PAUSE_WHILE_SET(pauseCollectionValidationWithLock); _validationIsPausedForTest.store(false); } diff --git a/src/mongo/db/commands/validate.cpp b/src/mongo/db/commands/validate.cpp index 8fd9e900e74..43c5fcae3b0 100644 --- a/src/mongo/db/commands/validate.cpp +++ b/src/mongo/db/commands/validate.cpp @@ -116,25 +116,30 @@ public: const NamespaceString nss(CommandHelpers::parseNsCollectionRequired(dbname, cmdObj)); - const bool full = cmdObj["full"].trueValue(); - - ValidateCmdLevel level = kValidateNormal; - if (full) { - level = kValidateFull; - } - - // TODO (SERVER-30357): Add support for background validation. - const bool background = false; + const bool background = cmdObj["background"].trueValue(); // Background validation requires the storage engine to support checkpoints because it // performs the validation on a checkpoint using checkpoint cursors. if (background && !opCtx->getServiceContext()->getStorageEngine()->supportsCheckpoints()) { - uasserted(ErrorCodes::CommandFailed, + uasserted(ErrorCodes::CommandNotSupported, str::stream() << "Running validate on collection " << nss << " with { background: true } is not supported on the " << storageGlobalParams.engine << " storage engine"); } + const bool full = cmdObj["full"].trueValue(); + + if (background && full) { + uasserted(ErrorCodes::CommandNotSupported, + str::stream() << "Running the validate command with both { background: true }" + << " and { full: true } is not supported."); + } + + ValidateCmdLevel level = kValidateNormal; + if (full) { + level = kValidateFull; + } + if (!serverGlobalParams.quiet.load()) { LOG(0) << "CMD: validate " << nss.ns(); } |