summaryrefslogtreecommitdiff
path: root/jstests/disk
diff options
context:
space:
mode:
authorYuhong Zhang <yuhong.zhang@mongodb.com>2022-07-27 18:24:08 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-07-27 19:56:36 +0000
commit016b23d13ebbecc374534c54eecbcd3d6bbb89c6 (patch)
tree8d369e27f08b5946e13066209c364a4d93f1c275 /jstests/disk
parent958ad9abfc80861d3f43f44da694e83464b01e1d (diff)
downloadmongo-016b23d13ebbecc374534c54eecbcd3d6bbb89c6.tar.gz
SERVER-67522 Return warnings about the use of deprecated types in BSON documents in validation
Diffstat (limited to 'jstests/disk')
-rw-r--r--jstests/disk/libs/wt_file_helper.js20
-rw-r--r--jstests/disk/validate_bson_inconsistency.js47
2 files changed, 66 insertions, 1 deletions
diff --git a/jstests/disk/libs/wt_file_helper.js b/jstests/disk/libs/wt_file_helper.js
index e06cf0731c0..afcb3b2e06c 100644
--- a/jstests/disk/libs/wt_file_helper.js
+++ b/jstests/disk/libs/wt_file_helper.js
@@ -244,11 +244,12 @@ let truncateUriAndRestartMongod = function(uri, conn, mongodOptions) {
* Stops the given mongod, dumps the table with the uri, modifies the content, and loads it back to
* the table.
*/
+let count = 0;
let rewriteTable = function(uri, conn, modifyData) {
MongoRunner.stopMongod(conn, null, {skipValidation: true});
const separator = _isWindows() ? '\\' : '/';
const tempDumpFile = conn.dbpath + separator + "temp_dump";
- const newTableFile = conn.dbpath + separator + "new_table_file";
+ const newTableFile = conn.dbpath + separator + "new_table_file" + count++;
runWiredTigerTool("-h",
conn.dbpath,
"-r",
@@ -288,4 +289,21 @@ let insertDocDuplicateFieldName = function(coll, uri, conn, numDocs) {
}
};
rewriteTable(uri, conn, makeDuplicateFieldNames);
+};
+
+let insertDocSymbolField = function(coll, uri, conn, numDocs) {
+ for (let i = 0; i < numDocs; ++i) {
+ coll.insert({a: "aaaaaaa"});
+ }
+ let makeSymbolField = function(lines) {
+ // The offset of the type of field 'a' in the hex string dumped by wt tool.
+ const offsetToFieldAType = 43;
+ // Each record takes two lines with a key and a value. We will only modify the values.
+ for (let i = wtHeaderLines; i < lines.length; i += 2) {
+ // Switch the field type from string to symbol.
+ lines[i] = lines[i].substring(0, offsetToFieldAType) + "e" +
+ lines[i].substring(offsetToFieldAType + 1);
+ }
+ };
+ rewriteTable(uri, conn, makeSymbolField);
}; \ No newline at end of file
diff --git a/jstests/disk/validate_bson_inconsistency.js b/jstests/disk/validate_bson_inconsistency.js
index a91eb8d7695..f72fd163487 100644
--- a/jstests/disk/validate_bson_inconsistency.js
+++ b/jstests/disk/validate_bson_inconsistency.js
@@ -1,5 +1,7 @@
/**
* Tests that the validate command detects various types of BSON inconsistencies.
+ *
+ * @tags: [featureFlagExtendValidateCommand]
*/
(function() {
@@ -36,4 +38,49 @@ resetDbpath(dbpath);
MongoRunner.stopMongod(mongod, null, {skipValidation: true});
})();
+
+(function validateDocumentsDeprecatedTypes() {
+ jsTestLog("Validate documents with deprecated types");
+
+ let mongod = startMongodOnExistingPath(dbpath);
+ let db = mongod.getDB(baseName);
+ const collName = collNamePrefix + count++;
+ db.createCollection(collName);
+ let testColl = db[collName];
+
+ let uri = getUriForColl(testColl);
+ const numDocs = 1;
+ insertDocSymbolField(testColl, uri, mongod, numDocs);
+
+ mongod = startMongodOnExistingPath(dbpath);
+ db = mongod.getDB(baseName);
+ testColl = db[collName];
+
+ assert.commandWorked(testColl.insert({a: undefined}));
+ assert.commandWorked(
+ testColl.insert({b: DBPointer("db", new ObjectId("dbdbdbdbdbdbdbdbdbdbdbdb"))}));
+ assert.commandWorked(testColl.insert({c: Code("function(){return 1;}", {})}));
+ assert.commandWorked(testColl.insert(
+ {d: BinData(2, "KwAAAFRoZSBxdWljayBicm93biBmb3gganVtcHMgb3ZlciB0aGUgbGF6eSBkb2c=")}));
+ assert.commandWorked(testColl.insert({e: BinData(3, "000102030405060708090a0b0c0d0e0f")}));
+ assert.commandWorked(testColl.insert({
+ a: undefined,
+ b: DBPointer("db", new ObjectId("dbdbdbdbdbdbdbdbdbdbdbdb")),
+ c: Code("function(){return 1;}", {}),
+ d: BinData(2, "KwAAAFRoZSBxdWljayBicm93biBmb3gganVtcHMgb3ZlciB0aGUgbGF6eSBkb2c="),
+ e: BinData(3, "000102030405060708090a0b0c0d0e0f")
+ }));
+
+ let res = assert.commandWorked(testColl.validate());
+ assert(res.valid, tojson(res));
+ assert.eq(res.nNonCompliantDocuments, 7);
+ assert.eq(res.warnings.length, 1);
+
+ res = assert.commandWorked(testColl.validate({checkBSONConsistency: true}));
+ assert(res.valid, tojson(res));
+ assert.eq(res.nNonCompliantDocuments, 7);
+ assert.eq(res.warnings.length, 1);
+
+ MongoRunner.stopMongod(mongod, null, {skipValidation: true});
+})();
})();