Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-101003

Provide BSON views that keep the buffer alive

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Server Programmability
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      BSONElement is an unowned view of one element of a BSONObj.  This makes it difficult to use in another data structure, because whoever holds a BSONElement also has to keep the original BSON alive somehow.

      Instead I wish BSONElement would contribute to the refcount of the underlying BSON. Or, it could be a separate type like SharedBSONElement. Then when I embed a SharedBSONElement in some larger data structure (MatchExpression or IDL types maybe), whoever holds that larger data structure isn't forced to separately manage the lifetime of the original BSONObj.

      SharedBSONElement would not create a new allocation: it would contribute to the refcount of the same underlying buffer.

       

      The same thing can apply to BSONObj.  Today when you want to extract a subdocument from a larger BSONObj, your choices are:

      • allocate a new copy using BSONObj::getOwned()
      • avoid a copy but explicitly manage the lifetime of the original BSON

      This leads to workarounds like SERVER-87277 where we want to retain the buffer and view a slice of it, but because BSONObj doesn't support this we end up juggling two separate BSONObj instances (one owned, one unowned).

            Assignee:
            Unassigned Unassigned
            Reporter:
            david.percy@mongodb.com David Percy
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              None
              None
              None
              None