summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/validate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/commands/validate.cpp')
-rw-r--r--src/mongo/db/commands/validate.cpp104
1 files changed, 2 insertions, 102 deletions
diff --git a/src/mongo/db/commands/validate.cpp b/src/mongo/db/commands/validate.cpp
index 1ca15aca557..c6724076b9f 100644
--- a/src/mongo/db/commands/validate.cpp
+++ b/src/mongo/db/commands/validate.cpp
@@ -31,29 +31,15 @@
#include "mongo/platform/basic.h"
-
-#include "mongo/base/error_codes.h"
-#include "mongo/base/status.h"
-#include "mongo/base/string_data.h"
-#include "mongo/bson/bson_validate_gen.h"
-#include "mongo/bson/bsonelement.h"
-#include "mongo/bson/bsonmisc.h"
-#include "mongo/bson/bsonobj.h"
-#include "mongo/bson/bsonobjbuilder.h"
-#include "mongo/db/auth/action_type.h"
-#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/catalog/collection.h"
#include "mongo/db/catalog/collection_validation.h"
#include "mongo/db/client.h"
#include "mongo/db/commands.h"
-#include "mongo/db/commands/test_commands_enabled.h"
-#include "mongo/db/dbdirectclient.h"
#include "mongo/db/query/internal_plans.h"
#include "mongo/db/storage/record_store.h"
#include "mongo/logv2/log.h"
#include "mongo/util/fail_point.h"
#include "mongo/util/scopeguard.h"
-#include "mongo/util/testing_proctor.h"
namespace mongo {
@@ -75,79 +61,6 @@ std::set<std::string> _validationsInProgress;
// finishes on any namespace.
stdx::condition_variable _validationNotifier;
-/**
- * Creates an aggregation command with a $collStats pipeline that fetches 'storageStats' and
- * 'count'.
- */
-BSONObj makeCollStatsCommand(StringData collectionNameOnly) {
- BSONArrayBuilder pipelineBuilder;
- pipelineBuilder << BSON("$collStats"
- << BSON("storageStats" << BSONObj() << "count" << BSONObj()));
- return BSON("aggregate" << collectionNameOnly << "pipeline" << pipelineBuilder.arr() << "cursor"
- << BSONObj());
-}
-
-/**
- * $collStats never returns more than a single document. If that ever changes in future, validate
- * must invariant so that the handling can be updated, but only invariant in testing environments,
- * never invariant because of debug logging in production situations.
- */
-void verifyCommandResponse(const BSONObj& collStatsResult) {
- if (TestingProctor::instance().isEnabled()) {
- invariant(
- !collStatsResult.getObjectField("cursor").isEmpty() &&
- !collStatsResult.getObjectField("cursor").getObjectField("firstBatch").isEmpty(),
- str::stream() << "Expected a cursor to be present in the $collStats results: "
- << collStatsResult.toString());
- invariant(collStatsResult.getObjectField("cursor").getIntField("id") == 0,
- str::stream() << "Expected cursor ID to be 0: " << collStatsResult.toString());
- } else {
- uassert(
- 7463202,
- str::stream() << "Expected a cursor to be present in the $collStats results: "
- << collStatsResult.toString(),
- !collStatsResult.getObjectField("cursor").isEmpty() &&
- !collStatsResult.getObjectField("cursor").getObjectField("firstBatch").isEmpty());
- uassert(7463203,
- str::stream() << "Expected cursor ID to be 0: " << collStatsResult.toString(),
- collStatsResult.getObjectField("cursor").getIntField("id") == 0);
- }
-}
-
-/**
- * Log the $collStats results for 'nss' to provide additional debug information for validation
- * failures.
- */
-void logCollStats(OperationContext* opCtx, const NamespaceString& nss) {
- DBDirectClient client(opCtx);
-
- BSONObj collStatsResult;
- try {
- // Run $collStats via aggregation.
- client.runCommand(nss.db().toString(),
- makeCollStatsCommand(nss.coll()),
- collStatsResult /* command return results */);
- // Logging $collStats information is best effort. If the collection doesn't exist, for
- // example, then the $collStats query will fail and the failure reason will be logged.
- uassertStatusOK(getStatusFromWriteCommandReply(collStatsResult));
- verifyCommandResponse(collStatsResult);
-
- LOGV2_OPTIONS(7463200,
- logv2::LogTruncation::Disabled,
- "Corrupt namespace $collStats results",
- "namespace"_attr = nss,
- "collStats"_attr =
- collStatsResult.getObjectField("cursor").getObjectField("firstBatch"));
- } catch (const DBException& ex) {
- // Catch the error so that the validate error does not get overwritten by the attempt to add
- // debug logging.
- LOGV2_WARNING(7463201,
- "Failed to fetch $collStats for validation error",
- "namespace"_attr = nss,
- "error"_attr = ex.toStatus());
- }
-}
-
} // namespace
/**
@@ -210,7 +123,6 @@ public:
const NamespaceString nss(CommandHelpers::parseNsCollectionRequired(dbname, cmdObj));
bool background = cmdObj["background"].trueValue();
- bool logDiagnostics = cmdObj["logDiagnostics"].trueValue();
// Background validation is not supported on the ephemeralForTest storage engine due to its
// lack of support for timestamps. Switch the mode to foreground validation instead.
@@ -342,20 +254,9 @@ public:
PrepareConflictBehavior::kIgnoreConflictsAllowWrites);
}
- CollectionValidation::AdditionalOptions additionalOptions;
- additionalOptions.validationVersion = getTestCommandsEnabled()
- ? (ValidationVersion)bsonTestValidationVersion
- : currentValidationVersion;
-
ValidateResults validateResults;
- Status status = CollectionValidation::validate(opCtx,
- nss,
- mode,
- repairMode,
- additionalOptions,
- &validateResults,
- &result,
- logDiagnostics);
+ Status status =
+ CollectionValidation::validate(opCtx, nss, mode, repairMode, &validateResults, &result);
if (!status.isOK()) {
return CommandHelpers::appendCommandStatusNoThrow(result, status);
}
@@ -366,7 +267,6 @@ public:
result.append("advice",
"A corrupt namespace has been detected. See "
"http://dochub.mongodb.org/core/data-recovery for recovery steps.");
- logCollStats(opCtx, nss);
}
return true;