diff options
author | Arun Banala <arun.banala@10gen.com> | 2020-01-10 19:38:48 +0000 |
---|---|---|
committer | A. Jesse Jiryu Davis <jesse@mongodb.com> | 2020-01-27 15:38:03 -0500 |
commit | e2e7bd4a38f964d6cbf5e44cfcbb45ab48717bc3 (patch) | |
tree | 55bccace14fae8eb377aba6edb67ac5fd7d533a3 | |
parent | a3039b7b49e822f96f7f5699f1d894b4837d03c0 (diff) | |
download | mongo-e2e7bd4a38f964d6cbf5e44cfcbb45ab48717bc3.tar.gz |
SERVER-45486 Add information to debug index key count mismatch issue in 'hashed_index_bad_keys_cleanup.js'
-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 39675fdb730..87785a023b0 100644 --- a/jstests/multiVersion/hashed_index_bad_keys_cleanup.js +++ b/jstests/multiVersion/hashed_index_bad_keys_cleanup.js @@ -43,6 +43,19 @@ assert.commandWorked(coll.insert({_id: 3, p: [{q: 1}]})); 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) { @@ -63,9 +76,8 @@ rst.upgradeSet(nodeOptionsOfLatestVersion); 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 upgrade. +assertCollectionHasExpectedDocs(5); // Verify that after upgrade, inserting bad documents is not allowed. const arrayAlongPathFailCode = 16766; @@ -101,7 +113,7 @@ assert.commandFailedWithCode(testDB.runCommand({ 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. |