Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-376

Unordered batch incorrectly tracks batch size when switching batch types

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.0.22
    • Affects Version/s: 2.0.17, 2.0.18
    • Component/s: None
    • Environment:
      Node

      There are two a few issues with in the unordered bulk operation implementation in addToOperationsList: 1) currentBatchSize is updated twice in the function so the batch size will be half of maxWriteBatchSize. 2) currentBatchSize and currentBatchSizeBytes are not reset when switching batches for batch types. As a result it's incorrectly creating a new batch because it thinks it's reached maxWriteBatchSize when it has not. This can result in an empty batch and an "insert must contain at least one document" error. 3) There is some redundant code in the addToOperation function.

      I've attached a test script test.js. There are two variables at the top, insertFirst and batchSize. With insertFirst = false, and batchSize = 1000, the test will fail. If you change batchSize to 999 or insertFirst to true, the test will run without error. This demonstrates issue #2 above. The fix is to track the batch size in the batch instead of in the operation.

      I've attached two files, common.js and unordered.js that fix all problems listed above.

        1. unordered.js
          14 kB
        2. test.js
          2 kB
        3. common.js
          10 kB

            Assignee:
            christkv Christian Amor Kvalheim
            Reporter:
            mcg11 Meir Gottlieb
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: