[SERVER-48503] index_signature.js should not assert that numIndexesAfter is numIndexesBefore + 1 if Created: 29/May/20  Updated: 29/Oct/23  Resolved: 22/Jun/20

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: 4.7.0

Type: Bug Priority: Major - P3
Reporter: Cheahuychou Mao Assignee: David Storch
Resolution: Fixed Votes: 0
Labels: qexec-team
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:
Linked BF Score: 8

 Description   

This test assumes that a createIndex command that created an index always returns a response with numIndexesAfter equals to numIndexesBefore + 1. This assumption is not true when the command is run on a mongos which retries on stale shard version errors. For example, in the case where there are two shards, the command can fail with StaleConfig on one of the shards but succeed on the other shard on the first try. The command will succeed on the second try after a refresh but the response from the shard that has already built the index on the first try will have numIndexesAfter equals to numIndexesBefore. 



 Comments   
Comment by Githook User [ 22/Jun/20 ]

Author:

{'name': 'David Storch', 'email': 'david.storch@mongodb.com', 'username': 'dstorch'}

Message: SERVER-48503 Fix how index_signature.js calculates number of pre-existing indexes
Branch: master
https://github.com/mongodb/mongo/commit/e285eaade15ad17c672f634b45936ce1cce74844

Comment by David Storch [ 05/Jun/20 ]

This simplified jstest seems to demonstrate the problem consistently:

// Repro for SERVER-48503.
(function() {
"use strict";
 
let cmdRes;
 
const st = new ShardingTest({shards: 2});
const mongosDb = st.s.getDB("test");
const coll = mongosDb.c;
coll.drop();
 
assert.commandWorked(coll.insert([{_id: -1}, {_id: 1}]));
 
st.shardColl(coll.getName(), {_id: 1}, {_id: 0}, {_id: 1}, mongosDb.getName(), true);
st.printShardingStatus();
 
// Verifies that the number of indexes changed in accordance with the 'expectedChange' argument.
function assertNumIndexesAfterComparedToBefore(cmdRes, expectedChange) {
    // In a sharded cluster, the results from all shards are returned in cmdRes.raw.
    assert(cmdRes.numIndexesBefore != null || Object.values(cmdRes.raw), tojson(cmdRes));
    const numIndexesBefore =
        (cmdRes.numIndexesBefore != null ? cmdRes.numIndexesBefore
                                         : Object.values(cmdRes.raw)[0].numIndexesBefore);
    const numIndexesAfter =
        (cmdRes.numIndexesAfter != null ? cmdRes.numIndexesAfter
                                        : Object.values(cmdRes.raw)[0].numIndexesAfter);
    assert.eq(numIndexesAfter, numIndexesBefore + expectedChange, cmdRes);
}
 
cmdRes = assert.commandWorked(coll.createIndex({"$**": 1}, {name: "wildcard_index_default_opts"}));
assertNumIndexesAfterComparedToBefore(cmdRes, 1);
 
st.stop();
})();

Generated at Thu Feb 08 05:17:18 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.