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

[CQF] Correct shard filter documents with missing shard key

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major - P3 Major - P3
    • 7.2.0-rc0
    • None
    • None
    • None
    • Fully Compatible
    • ALL
    • QO 2023-09-04

    Description

      const st = new ShardingTest({
          shards: 1,
      });
      const dbName = "foo";
      const collName = "bar";
      const ns = dbName + "." + collName;
      assert.commandWorked(st.s.adminCommand({enableSharding: dbName}));
      assert.commandWorked(st.s.adminCommand({shardCollection: ns, key: {skey: 1}}));
      assert.commandWorked(st.s.getCollection(ns).insert({_id: 1, x: 1}));
      assert.sameMembers(st.s.getCollection(ns).find({x: 1}).toArray(), [{_id: 1, x: 1}]);
      st.stop(); 

      When the following test-case is run under Bonsai, we currently incorrectly omit the document. Inserting some print statements into the code, I observed that the plan which Bonsai generates ends up invoking ShardFilterer::keyBelongsToMe with an empty BSONObj, rather than {skey: null}. Based on the API contract of keyBelongsToMe, this is undefined behavior.

      This is confirmed when looking at the plan generated by the SBE stage builders:

      shardFilter(s1, makeBsonObj(MakeObjSpec([\"skey\" = Arg(0)], Open), Nothing, (s2 ?: null))) 

      The plan produced by Bonsai looks like:

      shardFilter(s1, makeBsonObj(MakeObjSpec([\"skey\" = Arg(0)], Open), Nothing, s3)) 

      Attachments

        Activity

          People

            ben.shteinfeld@mongodb.com Ben Shteinfeld
            ben.shteinfeld@mongodb.com Ben Shteinfeld
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: