diff options
author | Robert Guo <robert.guo@10gen.com> | 2016-02-09 13:47:28 -0500 |
---|---|---|
committer | Robert Guo <robert.guo@10gen.com> | 2016-02-09 13:47:28 -0500 |
commit | aff0ad5caf150d1ee547806b45db074eb0ec18d3 (patch) | |
tree | 12a7215910c9a09ddc3860495a3f943f7235e390 | |
parent | 066d5c3f49c415af84607603f6cbce82590c4da1 (diff) | |
download | mongo-aff0ad5caf150d1ee547806b45db074eb0ec18d3.tar.gz |
add tests
-rw-r--r-- | buildscripts/resmokeconfig/suites/sharded_collections_jscore_passthrough.yml | 1 | ||||
-rw-r--r-- | buildscripts/resmokeconfig/suites/sharding_jscore_passthrough.yml | 1 | ||||
-rw-r--r-- | jstests/core/index_bigkeys_validation.js | 28 | ||||
-rw-r--r-- | jstests/libs/parallelTester.js | 5 | ||||
-rw-r--r-- | src/mongo/db/catalog/collection.cpp | 27 | ||||
-rw-r--r-- | src/mongo/db/commands/validate.cpp | 7 |
6 files changed, 52 insertions, 17 deletions
diff --git a/buildscripts/resmokeconfig/suites/sharded_collections_jscore_passthrough.yml b/buildscripts/resmokeconfig/suites/sharded_collections_jscore_passthrough.yml index 6b51a5f17f5..c8aa4df0857 100644 --- a/buildscripts/resmokeconfig/suites/sharded_collections_jscore_passthrough.yml +++ b/buildscripts/resmokeconfig/suites/sharded_collections_jscore_passthrough.yml @@ -25,6 +25,7 @@ selector: - jstests/core/geo_s2cursorlimitskip.js # profiling. - jstests/core/geo_update_btree2.js # notablescan. - jstests/core/index_bigkeys_nofail.js # failIndexKeyTooLong. + - jstests/core/index_bigkeys_validation.js # failIndexKeyTooLong. - jstests/core/max_time_ms.js # sleep, SERVER-2212. - jstests/core/mr_replaceIntoDB.js # MapReduceResult, SERVER-20495. - jstests/core/notablescan.js # notablescan. diff --git a/buildscripts/resmokeconfig/suites/sharding_jscore_passthrough.yml b/buildscripts/resmokeconfig/suites/sharding_jscore_passthrough.yml index 56a5b581ce8..f217b513534 100644 --- a/buildscripts/resmokeconfig/suites/sharding_jscore_passthrough.yml +++ b/buildscripts/resmokeconfig/suites/sharding_jscore_passthrough.yml @@ -24,6 +24,7 @@ selector: - jstests/core/geo_s2cursorlimitskip.js # profiling. - jstests/core/geo_update_btree2.js # notablescan. - jstests/core/index_bigkeys_nofail.js # failIndexKeyTooLong. + - jstests/core/index_bigkeys_validation.js # failIndexKeyTooLong. - jstests/core/max_time_ms.js # sleep, SERVER-2212. - jstests/core/notablescan.js # notablescan. - jstests/core/profile*.js # profiling. diff --git a/jstests/core/index_bigkeys_validation.js b/jstests/core/index_bigkeys_validation.js new file mode 100644 index 00000000000..88e2816fc8d --- /dev/null +++ b/jstests/core/index_bigkeys_validation.js @@ -0,0 +1,28 @@ +// Tests that index validation succeeds for long keys when failIndexKeyTooLong is set to false. +// See: SERVER-22234 +'use strict'; + +(function() { + var coll = db.longindex; + coll.drop(); + + var longVal = new Array(1025).join('x'); // Keys >= 1024 bytes cannot be indexed. + + assert.commandWorked(db.adminCommand({setParameter: 1, failIndexKeyTooLong: false})); + + assert.writeOK(coll.insert({_id: longVal})); + // Verify that validation succeeds when the failIndexKeyTooLong parameter is set to false, + // even when there are fewer index keys than documents. + var res = coll.validate({full: true, scandata: true}); + assert.commandWorked(res); + assert(res.valid, tojson(res)); + + // Change failIndexKeyTooLong back to the default value. + assert.commandWorked(db.adminCommand({setParameter: 1, failIndexKeyTooLong: true})); + + // Verify that validation fails when the failIndexKeyTooLong parameter is + // reverted to its old value and there are mismatched index keys and documents. + res = coll.validate({full: true, scandata: true}); + assert.commandWorked(res); + assert.eq(res.valid, false, tojson(res)); +})(); diff --git a/jstests/libs/parallelTester.js b/jstests/libs/parallelTester.js index 743d15b9825..39035731449 100644 --- a/jstests/libs/parallelTester.js +++ b/jstests/libs/parallelTester.js @@ -115,9 +115,10 @@ if (typeof _threadInject != "undefined") { "extent.js", "indexb.js", - // sets a failpoint that causes the server to ignore long keys, - // which makes index_bigkeys.js fail + // Tests that set a parameter that causes the server to ignore + // long index keys. "index_bigkeys_nofail.js", + "index_bigkeys_validation.js", // tests turn on profiling "profile1.js", diff --git a/src/mongo/db/catalog/collection.cpp b/src/mongo/db/catalog/collection.cpp index bc14618b4b9..c3ea2c0ed80 100644 --- a/src/mongo/db/catalog/collection.cpp +++ b/src/mongo/db/catalog/collection.cpp @@ -926,24 +926,16 @@ void validateIndexKeyCount(OperationContext* txn, int64_t numIdxKeys, int64_t numRecs, ValidateResults* results) { - if (!failIndexKeyTooLong) { - string warning = - "the server is configured with {failIndexKeyTooLong: false}. Validation failures " - "resulting from having fewer index entries than documents are downgraded from errors " - "to warnings"; - results->warnings.push_back(warning); - } - if (idx.isIdIndex() && numIdxKeys != numRecs) { string msg = str::stream() << "number of _id index entries (" << numIdxKeys << ") does not match the number of documents (" << numRecs << ")"; - if (failIndexKeyTooLong) { + if (!failIndexKeyTooLong && (numIdxKeys < numRecs)) { + results->warnings.push_back(msg); + } else { results->errors.push_back(msg); results->valid = false; - } else { - results->warnings.push_back(msg); } return; // Avoid failing the next two checks, they just add redundant/confusing messages @@ -963,11 +955,11 @@ void validateIndexKeyCount(OperationContext* txn, << " is not sparse or partial, but has fewer entries (" << numIdxKeys << ") than documents (" << numRecs << ")"; - if (failIndexKeyTooLong) { + if (!failIndexKeyTooLong) { + results->warnings.push_back(msg); + } else { results->errors.push_back(msg); results->valid = false; - } else { - results->warnings.push_back(msg); } } } @@ -986,6 +978,13 @@ Status Collection::validate(OperationContext* txn, return status; { // indexes + if (!failIndexKeyTooLong) { + string warning = + "The server is configured with the failIndexKeyTooLong parameter set to false. " + "Validation failures that result from having fewer index entries than documents " + "have been downgraded from errors to warnings"; + results->warnings.push_back(warning); + } output->append("nIndexes", _indexCatalog.numIndexesReady(txn)); int idxn = 0; try { diff --git a/src/mongo/db/commands/validate.cpp b/src/mongo/db/commands/validate.cpp index b4f87e353b7..93693e68c57 100644 --- a/src/mongo/db/commands/validate.cpp +++ b/src/mongo/db/commands/validate.cpp @@ -117,7 +117,12 @@ public: result.append("errors", results.errors); if (!results.valid) { - result.append("advice", "ns corrupt. See http://dochub.mongodb.org/core/data-recovery"); + result.append("advice", + "A corrupt namespace has been detected. See " + "http://dochub.mongodb.org/core/data-recovery for recovery steps. Note " + "that validation failures may also result from running a server with the " + "failIndexKeyTooLong parameter set to false and later disabling the " + "parameter."); } return true; |