0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 01:21:03 +01:00

SERVER-23789 make validate() work with MaxKey and MinKey

This commit is contained in:
Robert Guo 2016-04-22 11:50:22 -04:00
parent 2423026ef0
commit 992ef367f5
2 changed files with 37 additions and 7 deletions

View File

@ -0,0 +1,32 @@
// Tests that the validate command works with MinKey and MaxKey.
'use strict';
(function() {
var t = db.index_boundary_values_validate;
t.drop();
assert.writeOK(t.insert({a: MaxKey, b: MaxKey}));
assert.writeOK(t.insert({a: MaxKey, b: MinKey}));
assert.writeOK(t.insert({a: MinKey, b: MaxKey}));
assert.writeOK(t.insert({a: MinKey, b: MinKey}));
assert.writeOK(t.insert({a: {}}));
assert.writeOK(t.insert({b: {}}));
assert.writeOK(t.insert({unindexed_field: {}}));
assert.writeOK(t.insert({a: {}, b: {}}));
assert.commandWorked(t.createIndex({a: 1, b: 1}));
assert.commandWorked(t.createIndex({a: 1, b: -1}));
assert.commandWorked(t.createIndex({a: -1, b: 1}));
assert.commandWorked(t.createIndex({a: -1, b: -1}));
var res = t.validate(true);
assert.commandWorked(res);
assert.eq(
res.nrecords, 8, 'the collection had an unexpected number of records:\n' + tojson(res));
assert.eq(
res.nIndexes, 5, 'the collection had an unexpected number of indexes:\n' + tojson(res));
assert.eq(res.valid, true, 'the collection failed validation:\n' + tojson(res));
})();

View File

@ -987,15 +987,13 @@ public:
_keyCounts[descriptor->indexNamespace()] = numKeys;
if (_full) {
const auto& key = descriptor->keyPattern();
const bool forward = key.firstElement().number() >= 0;
std::unique_ptr<SortedDataInterface::Cursor> cursor = iam->newCursor(txn, forward);
cursor->setEndPosition(kMaxBSONKey, true);
auto indexEntry = cursor->seek(kMinBSONKey, true);
while (indexEntry) {
std::unique_ptr<SortedDataInterface::Cursor> cursor = iam->newCursor(txn, true);
// Seeking to BSONObj() is equivalent to seeking to the first entry of an index.
for (auto indexEntry = cursor->seek(BSONObj(), true); indexEntry;
indexEntry = cursor->next()) {
uint32_t keyHash = hashIndexEntry(indexEntry->key, indexEntry->loc);
(*_ikc)[keyHash]++;
indexEntry = cursor->next();
}
}
}