Create DecodeBatch() method on cursor & change stream

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • Go Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      Context

      It’s frequently useful to batch the handling of cursor results. For example, we realized a dramatic speed improvement in migration-verifier recently by reading change events as a batch and handling them in parallel.

      I think the pattern [~jian.guan@mongodb.com] implemented is useful enough to warrant inclusion in the driver. For example, mongosync can benefit from it as well for a similar reason: where currently it sends change events to its applier threads in series, it might as well instead send them en masse to facilitate bulk application.

      Definition of done

      The driver should offer some means of decoding the remaining documents in the cursor or change stream’s current batch.

      This needn’t be a method on the Cursor or ChangeStream; instead it could be a freestanding function like:

      type BatchDecodable interface {
          Decode(val any) error
          RemainingBatchLength() int
          Err() error
          TryNext(ctx context.Context) bool
      }
      var _ BatchDecodable = &Cursor
      var _ BatchDecodable = &ChangeStream
      
      func DecodeBatch[T any](batcher BatchDecodable, slicePtr *[]T) error {
      // Iterate/decode until RemainingBatchLength == 0
      }
      

      Documentation for the Decode() methods should point to the batch function’s docs, and vice-versa.

      Pitfalls

      ??

            Assignee:
            Unassigned
            Reporter:
            Felipe Gasper
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: