summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Noma <gregory.noma@gmail.com>2021-01-12 17:17:53 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-01-13 06:21:49 +0000
commit7f6b537315932239648b2143ff83ea18efcd452c (patch)
tree38ca7aa719b89a237c634d6123edb65ea5b1864c
parent9451bde9bd3374b7b263e7c40e1755c827df9004 (diff)
downloadmongo-7f6b537315932239648b2143ff83ea18efcd452c.tar.gz
SERVER-52609 Append corruptRecords to validate results as an array
-rw-r--r--jstests/noPassthroughWithMongod/validate_repair_mode.js (renamed from jstests/noPassthrough/validate_repair_mode.js)23
-rw-r--r--src/mongo/db/catalog/validate_results.cpp24
-rw-r--r--src/mongo/db/catalog/validate_results.h2
-rw-r--r--src/mongo/db/commands/validate.cpp2
-rw-r--r--src/mongo/db/repair.cpp2
-rw-r--r--src/mongo/db/storage/storage_debug_util.cpp2
6 files changed, 28 insertions, 27 deletions
diff --git a/jstests/noPassthrough/validate_repair_mode.js b/jstests/noPassthroughWithMongod/validate_repair_mode.js
index 170df2c3e29..5a870c68a2d 100644
--- a/jstests/noPassthrough/validate_repair_mode.js
+++ b/jstests/noPassthroughWithMongod/validate_repair_mode.js
@@ -4,21 +4,19 @@
*/
(function() {
+"use strict";
-let conn = MongoRunner.runMongod({});
-db = conn.getDB("validate_repair_mode");
-
-t = db.validate_repair_mode;
-t.drop();
+const coll = db.getCollection(jsTestName());
+coll.drop();
// Corrupt document during insert for testing via failpoint.
assert.commandWorked(
db.adminCommand({configureFailPoint: "corruptDocumentOnInsert", mode: "alwaysOn"}));
-assert.commandWorked(t.insert({a: 1}));
+assert.commandWorked(coll.insert({a: 1}));
assert.commandWorked(db.adminCommand({configureFailPoint: "corruptDocumentOnInsert", mode: "off"}));
// Ensure validate detects corrupt document.
-var output = t.validate({full: true});
+let output = coll.validate({full: true});
assert.eq(
output.valid, false, "validate returned valid true when expected false: " + tojson(output));
assert.eq(output.repaired,
@@ -28,10 +26,13 @@ assert.eq(output.nInvalidDocuments,
1,
"validate returned an invalid number of invalid documents: " + tojson(output));
assert.eq(output.nrecords, 1, "validate returned an invalid number of records: " + tojson(output));
+assert.eq(output.corruptRecords,
+ [NumberLong(1)],
+ "validate returned an invalid corruptRecords: " + tojson(output));
// Ensure validate with repair mode removes the corrupt document. Removing corrupt document results
// in extra entry in index _id. Repair mode should also remove the extra index entry.
-output = t.validate({full: true, repair: true});
+output = coll.validate({full: true, repair: true});
assert.eq(output.valid, true, "validate returned valid false when expected true" + tojson(output));
assert.eq(
output.repaired, true, "validate returned repaired false when expected true" + tojson(output));
@@ -39,6 +40,8 @@ assert.eq(output.nInvalidDocuments,
0,
"validate returned an invalid number of invalid documents" + tojson(output));
assert.eq(output.nrecords, 0, "validate returned an invalid number of records" + tojson(output));
+assert.eq(
+ output.corruptRecords, [], "validate returned an invalid corruptRecords: " + tojson(output));
assert.eq(output.numRemovedCorruptRecords,
1,
"validate returned an invalid number of removed corrupt records" + tojson(output));
@@ -51,9 +54,7 @@ assert.eq(output.indexDetails._id_.valid,
"validate returned indexDetails valid false when expected true" + tojson(output));
// Confirm validate results are valid and repair mode did not silently suppress validation errors.
-output = t.validate({full: true});
+output = coll.validate({full: true});
assert.eq(output.valid, true, "validate returned valid false when expected true");
assert.eq(output.repaired, false, "validate returned repaired true when expected false");
-
-MongoRunner.stopMongod(conn);
}());
diff --git a/src/mongo/db/catalog/validate_results.cpp b/src/mongo/db/catalog/validate_results.cpp
index 2c3c9a4b820..820ddee062e 100644
--- a/src/mongo/db/catalog/validate_results.cpp
+++ b/src/mongo/db/catalog/validate_results.cpp
@@ -31,28 +31,28 @@
namespace mongo {
-void ValidateResults::appendToResultObj(BSONObjBuilder& resultObj, bool debugging) const {
- resultObj.appendBool("valid", valid);
- resultObj.appendBool("repaired", repaired);
+void ValidateResults::appendToResultObj(BSONObjBuilder* resultObj, bool debugging) const {
+ resultObj->appendBool("valid", valid);
+ resultObj->appendBool("repaired", repaired);
if (readTimestamp) {
- resultObj.append("readTimestamp", readTimestamp.get());
+ resultObj->append("readTimestamp", readTimestamp.get());
}
- resultObj.append("warnings", warnings);
- resultObj.append("errors", errors);
- resultObj.append("extraIndexEntries", extraIndexEntries);
- resultObj.append("missingIndexEntries", missingIndexEntries);
+ resultObj->append("warnings", warnings);
+ resultObj->append("errors", errors);
+ resultObj->append("extraIndexEntries", extraIndexEntries);
+ resultObj->append("missingIndexEntries", missingIndexEntries);
// Need to convert RecordId to int64_t to append to BSONObjBuilder
BSONArrayBuilder builder;
for (RecordId corruptRecord : corruptRecords) {
builder.append(corruptRecord.repr());
}
- resultObj.append("corruptRecords", builder.done());
+ resultObj->append("corruptRecords", builder.arr());
if (repaired || debugging) {
- resultObj.appendNumber("numRemovedCorruptRecords", numRemovedCorruptRecords);
- resultObj.appendNumber("numRemovedExtraIndexEntries", numRemovedExtraIndexEntries);
- resultObj.appendNumber("numInsertedMissingIndexEntries", numInsertedMissingIndexEntries);
+ resultObj->appendNumber("numRemovedCorruptRecords", numRemovedCorruptRecords);
+ resultObj->appendNumber("numRemovedExtraIndexEntries", numRemovedExtraIndexEntries);
+ resultObj->appendNumber("numInsertedMissingIndexEntries", numInsertedMissingIndexEntries);
}
}
} // namespace mongo
diff --git a/src/mongo/db/catalog/validate_results.h b/src/mongo/db/catalog/validate_results.h
index 96752f70877..9e0062d8fb3 100644
--- a/src/mongo/db/catalog/validate_results.h
+++ b/src/mongo/db/catalog/validate_results.h
@@ -68,7 +68,7 @@ struct ValidateResults {
// Takes a bool that indicates the context of the caller and a BSONObjBuilder to append with
// validate results.
- void appendToResultObj(BSONObjBuilder& resultObj, bool debugging) const;
+ void appendToResultObj(BSONObjBuilder* resultObj, bool debugging) const;
};
} // namespace mongo
diff --git a/src/mongo/db/commands/validate.cpp b/src/mongo/db/commands/validate.cpp
index a7080fb618b..c1d787a49bb 100644
--- a/src/mongo/db/commands/validate.cpp
+++ b/src/mongo/db/commands/validate.cpp
@@ -227,7 +227,7 @@ public:
return CommandHelpers::appendCommandStatusNoThrow(result, status);
}
- validateResults.appendToResultObj(result, /*debugging=*/false);
+ validateResults.appendToResultObj(&result, /*debugging=*/false);
if (!validateResults.valid) {
result.append("advice",
diff --git a/src/mongo/db/repair.cpp b/src/mongo/db/repair.cpp
index efc23ea847b..44c79ad28b4 100644
--- a/src/mongo/db/repair.cpp
+++ b/src/mongo/db/repair.cpp
@@ -245,7 +245,7 @@ Status repairCollection(OperationContext* opCtx,
BSONObjBuilder detailedResults;
const bool debug = false;
- validateResults.appendToResultObj(detailedResults, debug);
+ validateResults.appendToResultObj(&detailedResults, debug);
LOGV2(21028,
"Collection validation",
diff --git a/src/mongo/db/storage/storage_debug_util.cpp b/src/mongo/db/storage/storage_debug_util.cpp
index a17de8927f4..3b4fe5bc98a 100644
--- a/src/mongo/db/storage/storage_debug_util.cpp
+++ b/src/mongo/db/storage/storage_debug_util.cpp
@@ -130,7 +130,7 @@ void printCollectionAndIndexTableEntries(OperationContext* opCtx, const Namespac
void printValidateResults(const ValidateResults& results) {
BSONObjBuilder resultObj;
- results.appendToResultObj(resultObj, /*debugging=*/true);
+ results.appendToResultObj(&resultObj, /*debugging=*/true);
LOGV2(51812, "Results", "results"_attr = resultObj.done());
}