Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-84368

CreateIndex fails with StaleConfig if run from a stale mongos against a sharded non-empty collection

    • Catalog and Routing
    • Fully Compatible
    • ALL
    • v7.3, v7.0, v6.0, v5.0
    • Hide

      const dbName = 'testDB';
      const collName = 'testColl';
      const bucketsCollName = 'system.buckets.' + collName;
      const timeField = 'time';
      const metaField = 'hostid';
      // Connections.
       
      const st = new ShardingTest({mongos: 2, shards: 2, rs: {nodes: 2}});
      const mongos0 = st.s0.getDB(dbName);
      const mongos1 = st.s1.getDB(dbName);
      const shard0DB = st.shard0.getDB(dbName);
      const shard1DB = st.shard1.getDB(dbName);
       
      // Insert some dummy data using 'mongos1' as the router, so that the cache is
      // initialized on the mongos while the collection is unsharded.
      assert.commandWorked(
      mongos1.adminCommand({shardCollection: `${dbName}.${collName}`, key: {_id: 1}}));
      assert.commandWorked(mongos1.getCollection(collName).insert({_id: "aaa"}));
       
      // Drop and shard the collection with 'mongos0' as the router.
      assert(mongos0.getCollection(collName).drop());
       
      const shardKey =

      { [metaField]: 1 }

      ;
      assert.commandWorked(mongos0.adminCommand({
      shardCollection: `${dbName}.${collName}`,
      key: shardKey,
      timeseries: {timeField: timeField, metaField: metaField}
      }));
       
      let cmdObj = {createIndexes: collName, indexes: [{key:

      {[timeField]: 1}

      , name: "index_on_time"}]};
      assert.commandWorked(mongos1.runCommand(cmdObj));
       
      st.stop();

      Show
      const dbName = 'testDB'; const collName = 'testColl'; const bucketsCollName = 'system.buckets.' + collName; const timeField = 'time'; const metaField = 'hostid'; // Connections.   const st = new ShardingTest({mongos: 2, shards: 2, rs: {nodes: 2}}); const mongos0 = st.s0.getDB(dbName); const mongos1 = st.s1.getDB(dbName); const shard0DB = st.shard0.getDB(dbName); const shard1DB = st.shard1.getDB(dbName);   // Insert some dummy data using 'mongos1' as the router, so that the cache is // initialized on the mongos while the collection is unsharded. assert.commandWorked( mongos1.adminCommand({shardCollection: `${dbName}.${collName}`, key: {_id: 1}})); assert.commandWorked(mongos1.getCollection(collName).insert({_id: "aaa"}));   // Drop and shard the collection with 'mongos0' as the router. assert(mongos0.getCollection(collName).drop());   const shardKey = { [metaField]: 1 } ; assert.commandWorked(mongos0.adminCommand({ shardCollection: `${dbName}.${collName}`, key: shardKey, timeseries: {timeField: timeField, metaField: metaField} }));   let cmdObj = {createIndexes: collName, indexes: [{key: {[timeField]: 1} , name: "index_on_time"}]}; assert.commandWorked(mongos1.runCommand(cmdObj));   st.stop();
    • CAR Team 2024-01-22, CAR Team 2024-02-05
    • 2

      Currently spotted a bug where given 2 mongos:

      • mongos1 : create a non-empty sharded collection
      • mongos2: drop the collection and shards it as timeseries

      in case mongos1 (which is now stale) runs createIndex it will fail 10 times without trying a refresh. 

      I attached a test to reproduce the error which is unclear.
      The goal of the ticket is to investigate what is causing this issue.

      Important notes:

      • the issue does not happen if mongos1 creates an empty sharded collection (skip the insert)
      • the issue does not happen if mongos2 creates a non-timeseries sharded collection
      • the issue only happens because mongos1 does not refresh, but attempts again with the same version for 10 times

      The ticket is necessary for track unsharded collection since after SERVER-81190 it will happen even if mongos1 just runs a insert. 

      Once the ticket is done, please fix the TODO

            Assignee:
            marcos.grillo@mongodb.com Marcos José Grillo Ramirez
            Reporter:
            enrico.golfieri@mongodb.com Enrico Golfieri
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: