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

Sharded timeseries collection can uassert on valid $group queries with $count

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Integration
    • ALL
    • Hide
      import {ShardingTest} from "jstests/libs/shardingtest.js";
      
      // Using chunkSize=1 is not necessary to repro the issue, but makes it easier since we need less documents to get data on both shards.
      const st = new ShardingTest({shards: 2, other: {chunkSize: 1}});
      const sDB = st.s.getDB('test');
      assert(sDB.coll.drop());
      assert.commandWorked(sDB.adminCommand({enableSharding: 'test', primaryShard: st.shard0.shardName}));
      assert.commandWorked(sDB.adminCommand({
          shardCollection: `test.coll`,
          key: {m: 1},
          timeseries: {timeField: 't', metaField: 'm'}
      }));
      
      const coll = sDB.coll;
      st.startBalancer();
      
      // Insert some docs
      const alphabet = 'abcdefghijklmnop';
      const docs = [];
      for(let i = 0; i < 100; i++){
          docs.push({t: new Date(i * 1000), m: i % 100, otherField: alphabet.repeat(1000)});
      }
      assert.commandWorked(coll.insert(docs));
      // Let the balancer move documents so we have data on both shards
      st.awaitBalancerRound();
      
      coll.aggregate([{$group: {_id: null, document_count: {$count: {}}, max_time: {$max: '$t'}}}]).toArray()
      // uassert 9961600: Unexpected type on the merging pass of the $sum. This likely happened due to a malformed query.
      
      st.stop();
      
      Show
      import {ShardingTest} from "jstests/libs/shardingtest.js" ; // Using chunkSize=1 is not necessary to repro the issue, but makes it easier since we need less documents to get data on both shards. const st = new ShardingTest({shards: 2, other: {chunkSize: 1}}); const sDB = st.s.getDB( 'test' ); assert (sDB.coll.drop()); assert .commandWorked(sDB.adminCommand({enableSharding: 'test' , primaryShard: st.shard0.shardName})); assert .commandWorked(sDB.adminCommand({ shardCollection: `test.coll`, key: {m: 1}, timeseries: {timeField: 't' , metaField: 'm' } })); const coll = sDB.coll; st.startBalancer(); // Insert some docs const alphabet = 'abcdefghijklmnop' ; const docs = []; for (let i = 0; i < 100; i++){ docs.push({t: new Date(i * 1000), m: i % 100, otherField: alphabet.repeat(1000)}); } assert .commandWorked(coll.insert(docs)); // Let the balancer move documents so we have data on both shards st.awaitBalancerRound(); coll.aggregate([{$group: {_id: null , document_count: {$count: {}}, max_time: {$max: '$t' }}}]).toArray() // uassert 9961600: Unexpected type on the merging pass of the $sum. This likely happened due to a malformed query. st.stop();
    • None
    • 3
    • TBD
    • None
    • None
    • None
    • None
    • None
    • None

      The repro below shows that a time-series collection sharded on the meta field can assert on valid $group queries.

      The error seems specific to $count, from here. The sum accumulator (translated from the $count) expects an array when merging, but receives a number.

            Assignee:
            arun.banala@mongodb.com Arun Banala
            Reporter:
            matt.boros@mongodb.com Matt Boros
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: