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

Refactor mongodump oplog iterator byte copying

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 4.1.11
    • Affects Version/s: None
    • Component/s: None

      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.

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

              Created:
              Updated:
              Resolved: