[CQF] Correct shard filter documents with missing shard key

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Major - P3
    • 7.2.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Fully Compatible
    • ALL
    • QO 2023-09-04
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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)) 

            Assignee:
            Ben Shteinfeld
            Reporter:
            Ben Shteinfeld
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: