diff options
author | Robert Guo <robert.guo@10gen.com> | 2016-04-14 15:57:42 -0400 |
---|---|---|
committer | Robert Guo <robert.guo@10gen.com> | 2016-04-15 22:11:57 -0400 |
commit | 608cdcd96012b4759008b11cbee32b18927f85ba (patch) | |
tree | 0c74dbf990b383760e05b405425ef8ad6c0b37ca | |
parent | de534119c84dfd07ecf9401de94d3524268ec6fa (diff) | |
download | mongo-608cdcd96012b4759008b11cbee32b18927f85ba.tar.gz |
SERVER-23730 better handling of partial indexes in validate()
-rw-r--r-- | buildscripts/resmokeconfig/suites/jstestfuzz.yml | 4 | ||||
-rw-r--r-- | buildscripts/resmokeconfig/suites/jstestfuzz_replication.yml | 2 | ||||
-rw-r--r-- | jstests/core/index_partial_validate.js | 21 | ||||
-rw-r--r-- | src/mongo/db/catalog/collection.cpp | 15 |
4 files changed, 32 insertions, 10 deletions
diff --git a/buildscripts/resmokeconfig/suites/jstestfuzz.yml b/buildscripts/resmokeconfig/suites/jstestfuzz.yml index 792839dc0d2..3efd7408370 100644 --- a/buildscripts/resmokeconfig/suites/jstestfuzz.yml +++ b/buildscripts/resmokeconfig/suites/jstestfuzz.yml @@ -8,8 +8,8 @@ executor: config: shell_options: readMode: commands - # hooks: - # - class: ValidateCollections + hooks: + - class: ValidateCollections fixture: class: MongoDFixture mongod_options: diff --git a/buildscripts/resmokeconfig/suites/jstestfuzz_replication.yml b/buildscripts/resmokeconfig/suites/jstestfuzz_replication.yml index 88ac0cf927e..6027a2cb2bc 100644 --- a/buildscripts/resmokeconfig/suites/jstestfuzz_replication.yml +++ b/buildscripts/resmokeconfig/suites/jstestfuzz_replication.yml @@ -9,7 +9,7 @@ executor: shell_options: readMode: commands hooks: - # - class: ValidateCollections + - class: ValidateCollections - class: CheckReplDBHash fixture: class: ReplicaSetFixture diff --git a/jstests/core/index_partial_validate.js b/jstests/core/index_partial_validate.js new file mode 100644 index 00000000000..bd854de9751 --- /dev/null +++ b/jstests/core/index_partial_validate.js @@ -0,0 +1,21 @@ +// Tests that the validate command works with partial indexes and a document that does not have +// an indexed field. For details, see SERVER-23730. +'use strict'; + +(function() { + var t = db.index_partial_validate; + t.drop(); + + var res = t.ensureIndex({a: 1}, {partialFilterExpression: {a: {$lte: 1}}}); + assert.commandWorked(res); + + res = t.ensureIndex({b: 1}); + assert.commandWorked(res); + + res = t.insert({non_indexed_field: 'x'}); + assert.writeOK(res); + + res = t.validate(true); + assert.commandWorked(res); + assert(res.valid, 'Validate failed with response:\n' + tojson(res)); +})(); diff --git a/src/mongo/db/catalog/collection.cpp b/src/mongo/db/catalog/collection.cpp index 2a4e3aaaee4..e5a4fc35b5d 100644 --- a/src/mongo/db/catalog/collection.cpp +++ b/src/mongo/db/catalog/collection.cpp @@ -1000,9 +1000,16 @@ public: IndexAccessMethod* iam = indexCatalog.getIndex(descriptor); invariant(iam); + BSONObj documentData = document->data.toBson(); + if (descriptor->isPartial()) { + const IndexCatalogEntry* ice = indexCatalog.getEntry(descriptor); + if (!ice->getFilterExpression()->matchesBSON(documentData)) { + continue; + } + } BSONObjSet documentKeySet; - iam->getKeys(document->data.toBson(), &documentKeySet); + iam->getKeys(documentData, &documentKeySet); if (documentKeySet.size() > 1) { if (!descriptor->isMultikey(txn)) { @@ -1028,12 +1035,6 @@ public: if ((*_ikc)[indexEntryHash] == 0) { _ikc->erase(indexEntryHash); } - } else if (descriptor->isPartial()) { - // Partial indexes are treated as regular indexes in - // IndexAccessMethod::getKeys, so documents whose - // field(s) don't match the partial expression are - // still returned. - continue; } else { allIndexesValid = false; results.valid = false; |