diff options
author | Arun Banala <arun.banala@10gen.com> | 2020-01-10 19:38:48 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-01-27 14:41:53 +0000 |
commit | 62574ad6ca8d4d7c47d1252de9857c21633744d7 (patch) | |
tree | dd8054c81962b15203afe0966a016cd739107650 | |
parent | f2eee7f4879a0dda72b281c8d1d25f2afc4c5eb7 (diff) | |
download | mongo-62574ad6ca8d4d7c47d1252de9857c21633744d7.tar.gz |
SERVER-45486 Add information to debug index key count mismatch issue in 'hashed_index_bad_keys_cleanup.js'
(cherry picked from commit 5ebed8698873294ec0dc98395787d3caafa8b6af)
-rw-r--r-- | jstests/multiVersion/hashed_index_bad_keys_cleanup.js | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/jstests/multiVersion/hashed_index_bad_keys_cleanup.js b/jstests/multiVersion/hashed_index_bad_keys_cleanup.js index e43141365d6..d7eaac28ef4 100644 --- a/jstests/multiVersion/hashed_index_bad_keys_cleanup.js +++ b/jstests/multiVersion/hashed_index_bad_keys_cleanup.js @@ -37,6 +37,19 @@ assert.commandWorked(coll.insert({_id: 4, a: 1, p: [{q: 1}]})); assert.commandWorked(coll.insert({_id: 5, a: 1, p: [{q: 1}]})); + // Assert that the collection has expected number of documents and index keys. + function assertCollectionHasExpectedDocs(expectedNumDocs) { + const collState = { + documents: coll.find().toArray(), + indexKeys: coll.find().hint({"p.q.r": "hashed"}).returnKey().toArray() + }; + assert.eq(collState.documents.length, expectedNumDocs, collState); + assert.eq(collState.indexKeys.length, expectedNumDocs, collState); + } + + // Verify that the documents inserted have the corresponding index keys. + assertCollectionHasExpectedDocs(5); + // Helper function which runs validate() on primary and secondary nodes, then verifies that the // command returned the expected result. function assertValidateCmdReturned(expectedResult) { @@ -58,9 +71,8 @@ testDB = rst.getPrimary().getDB(jsTestName()); coll = testDB.coll; - // Verify that the five documents inserted earlier have their index keys. - let res = coll.find().hint({"p.q.r": "hashed"}).returnKey().itcount(); - assert.eq(res, 5); + // Verify that the five documents inserted earlier have their index keys after the upgrade. + assertCollectionHasExpectedDocs(5); // Verify that after upgrade, inserting bad documents is not allowed. const arrayAlongPathFailCode = 16766; @@ -97,7 +109,7 @@ assert.commandWorked(coll.update({_id: 2}, {p: {q: {r: 4}}})); // Verify that the index key is updated correctly by quering with hashed index. - res = coll.find({"p.q.r": 4}).hint({"p.q.r": "hashed"}).toArray(); + let res = coll.find({"p.q.r": 4}).hint({"p.q.r": "hashed"}).toArray(); assert.eq(res, [{_id: 2, p: {q: {r: 4}}}]); // Validate should still fail since a bad document {_id: 3} exists. |