Uploaded image for project: 'MongoDB Database Tools'
  1. MongoDB Database Tools
  2. TOOLS-2256

Refactor mongodump oplog iterator byte copying

    XMLWordPrintable

Details

    • Task
    • Status: Closed
    • Minor - P4
    • Resolution: Fixed
    • None
    • 4.1.11
    • None

    Description

      Currently, mongodump has a function dumpFilteredIterToWriter with this section of code:

      				out, err := filter(iter.Current)
      				if err != nil {
      					termErr = err
      					close(buffChan)
      					return
      				}
      				buffChan <- out
      

      Because iter.Current isn't valid for long, the code relies on filter to return a copy. This isn't apparent in this code and the filtering code appears to make copies for no apparent reason. I'm not sure if any filter actually modifies oplog entries, but even if so, i think the code would be clearer if we made the copy close to iter.Current:

      				out := make([]byte, len(iter.Current))
      				copy(out, iter.Current)
      				out, err := filter(out)
      				if err != nil {
      					termErr = err
      					close(buffChan)
      					return
      				}
      				buffChan <- out
      

      If we knew that filters never modify, filter could consume iter.Current and return only an error and the copy could be done only if the filter doesn't error.

      Attachments

        Activity

          People

            divjot.arora@mongodb.com Divjot Arora
            david.golden@mongodb.com David Golden
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: