Uploaded image for project: 'Drivers'
  1. Drivers
  2. DRIVERS-289

Aggregation command cursor corner case using $sample operator

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • $i18n.getText("admin.common.words.hide")
      Key Status/Resolution FixVersion
      CDRIVER-1159 Done 1.4.0
      $i18n.getText("admin.common.words.show")
      #scriptField, #scriptField *{ border: 1px solid black; } #scriptField{ border-collapse: collapse; } #scriptField td { text-align: center; /* Center-align text in table cells */ } #scriptField td.key { text-align: left; /* Left-align text in the Key column */ } #scriptField a { text-decoration: none; /* Remove underlines from links */ border: none; /* Remove border from links */ } /* Add green background color to cells with FixVersion */ #scriptField td.hasFixVersion { background-color: #00FF00; /* Green color code */ } /* Center-align the first row headers */ #scriptField th { text-align: center; } Key Status/Resolution FixVersion CDRIVER-1159 Done 1.4.0

    Description

      When using the $sample operator with the aggregate command on 3.2.1 the command will sometimes return a first result with the following structure regardless of the batchSize passed to the aggregate command.

      { waitedMS: 0,
        cursor:
         { id: 15827158826,
           ns: 'integration_tests.bigdocs_aggregate_sample_issue',
           firstBatch: [] },
        ok: 1 }
      

      No initial results but a live cursor. Drivers must ensure they do not treat this as an empty cursor but correctly exhaust the cursor issuing getMore commands. Below is the node.js test case used to reproduce the issue with 3.2.1

      var co = require('co');
       
      co(function*() {
        var db = configure.newDbInstance({w:1}, {poolSize:1});
        db = yield db.open();
        var string = new Array(6000000).join('x');
        // var string = new Array(600000).join('x');
        // Get the collection
        var collection = db.collection('bigdocs_aggregate_sample_issue');
       
        // Go over the number of
        for(var i = 0; i < 100; i++) {
          var r = yield collection.insertOne({
            s: string
          });
        }
       
        // count just to make sure we're getting something back
        var count = yield collection.count();
        console.log('counting %d docs.', count);
       
        var options = {
          maxTimeMS: 10000,
          allowDiskUse: true
        };
       
        var index = 0;
       
        collection.aggregate([{
            $sample: {
              size: 100
            }
          }], options)
          .batchSize(10)
       
          .on('error', function(err) {
            console.error('error: ', err);
            db.close();
            process.exit(1);
          })
       
          .on('data', function(data) {
            console.log('data received :: ' + (index++));
          })
       
          // `end` sometimes emits before any `data` events have been emitted,
          // depending on document size.
          .on('end', function() {
            console.log('end received');
       
            db.close();
            test.done();
          });
      });
      

      Attachments

        Activity

          People

            barrie Barrie Segal
            christkv Christian Amor Kvalheim
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: