summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/validate.cpp
diff options
context:
space:
mode:
authorDaniel Gómez Ferro <daniel.gomezferro@mongodb.com>2021-11-30 09:10:54 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-11-30 09:52:35 +0000
commitf84899b472bef1dbb1fd47a069f1dd77503d8c6d (patch)
tree8dd3c3f7a1972c5f862b67000020f32753bf6c3b /src/mongo/db/commands/validate.cpp
parentd77aec3d56a3ec9be56fb71982729589588a131e (diff)
downloadmongo-f84899b472bef1dbb1fd47a069f1dd77503d8c6d.tar.gz
SERVER-61509 Avoid repairing read-only databases
Diffstat (limited to 'src/mongo/db/commands/validate.cpp')
-rw-r--r--src/mongo/db/commands/validate.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/mongo/db/commands/validate.cpp b/src/mongo/db/commands/validate.cpp
index fb494ab74eb..c6724076b9f 100644
--- a/src/mongo/db/commands/validate.cpp
+++ b/src/mongo/db/commands/validate.cpp
@@ -148,15 +148,20 @@ public:
}
const bool repair = cmdObj["repair"].trueValue();
+ if (storageGlobalParams.readOnly && repair) {
+ uasserted(ErrorCodes::InvalidOptions,
+ str::stream() << "Running the validate command with { repair: true } in"
+ << " read-only mode is not supported.");
+ }
if (background && repair) {
uasserted(ErrorCodes::InvalidOptions,
- str::stream() << "Running the validate command with both {background: true }"
+ str::stream() << "Running the validate command with both { background: true }"
<< " and { repair: true } is not supported.");
}
if (enforceFastCount && repair) {
uasserted(ErrorCodes::InvalidOptions,
str::stream()
- << "Running the validate command with both {enforceFastCount: true }"
+ << "Running the validate command with both { enforceFastCount: true }"
<< " and { repair: true } is not supported.");
}
repl::ReplicationCoordinator* replCoord = repl::ReplicationCoordinator::get(opCtx);
@@ -221,6 +226,10 @@ public:
}();
auto repairMode = [&] {
+ if (storageGlobalParams.readOnly) {
+ // On read-only mode we can't make any adjustments.
+ return CollectionValidation::RepairMode::kNone;
+ }
switch (mode) {
case CollectionValidation::ValidateMode::kForeground:
case CollectionValidation::ValidateMode::kForegroundFull: