From 62574ad6ca8d4d7c47d1252de9857c21633744d7 Mon Sep 17 00:00:00 2001 From: Arun Banala Date: Fri, 10 Jan 2020 19:38:48 +0000 Subject: SERVER-45486 Add information to debug index key count mismatch issue in 'hashed_index_bad_keys_cleanup.js' (cherry picked from commit 5ebed8698873294ec0dc98395787d3caafa8b6af) --- .../multiVersion/hashed_index_bad_keys_cleanup.js | 20 ++++++++++++++++---- 1 file 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. -- cgit v1.2.1