diff options
Diffstat (limited to 'src/mongo/db/exec/document_value/document_internal.h')
| -rw-r--r-- | src/mongo/db/exec/document_value/document_internal.h | 62 |
1 files changed, 17 insertions, 45 deletions
diff --git a/src/mongo/db/exec/document_value/document_internal.h b/src/mongo/db/exec/document_value/document_internal.h index d7fb3b337d6..1387ca908b4 100644 --- a/src/mongo/db/exec/document_value/document_internal.h +++ b/src/mongo/db/exec/document_value/document_internal.h @@ -359,11 +359,11 @@ public: /** * Construct a storage from the BSON. The BSON is lazily processed as fields are requested from - * the document. If we know that the BSON contains metadata fields we can set the - * 'bsonHasMetadata' flag to true. + * the document. If we know that the BSON does not contain any metadata fields we can set the + * 'stripMetadata' flag to false that will speed up the field iteration. */ DocumentStorage(const BSONObj& bson, - bool bsonHasMetadata, + bool stripMetadata, bool modified, uint32_t numBytesFromBSONInCache) : _cache(nullptr), @@ -373,17 +373,17 @@ public: _hashTabMask(0), _bson(bson), _numBytesFromBSONInCache(numBytesFromBSONInCache), - _bsonHasMetadata(bsonHasMetadata), + _stripMetadata(stripMetadata), _modified(modified) {} ~DocumentStorage(); - void reset(const BSONObj& bson, bool bsonHasMetadata); + void reset(const BSONObj& bson, bool stripMetadata); /** - * Returns a cache-only copy of the document with no backing bson. + * Populates the cache by recursively walking the underlying BSON. */ - Document shred() const; + void fillCache() const; static const DocumentStorage& emptyDoc() { return kEmptyDoc; @@ -551,7 +551,7 @@ public: * WorkingSetMember. */ const DocumentMetadataFields& metadata() const { - if (_bsonHasMetadata) { + if (_stripMetadata) { loadLazyMetadata(); } return _metadataFields; @@ -589,8 +589,8 @@ public: return _firstElement ? _firstElement->plusBytes(_usedBytes) : nullptr; } - auto bsonHasMetadata() const { - return _bsonHasMetadata; + auto stripMetadata() const { + return _stripMetadata; } Position constructInCache(const BSONElement& elem); @@ -599,37 +599,10 @@ public: return _modified; } - auto isMetadataModified() const { - return _metadataFields.isModified(); - } - auto bsonObj() const { return _bson; } - size_t currentApproximateSize() const { - size_t size = sizeof(DocumentStorage) + allocatedBytes() + getMetadataApproximateSize() + - bsonObjSize(); - - for (auto it = iteratorCacheOnly(); !it.atEnd(); it.advance()) { - size += it->val.getApproximateSize() - sizeof(Value); - } - - return size; - } - - size_t snapshottedApproximateSize() const { - if (_snapshottedSize == 0) { - const_cast<DocumentStorage*>(this)->_snapshottedSize = currentApproximateSize(); - } - - return _snapshottedSize; - } - - void resetSnapshottedApproximateSize() { - _snapshottedSize = 0; - } - private: /// Returns the position of the named field in the cache or Position() template <typename T> @@ -712,23 +685,22 @@ private: // whole backing BSON, but only the portion of backing BSON that's not already in the cache. uint32_t _numBytesFromBSONInCache = 0; - // Tracks whether or not the metadata has been lazy-loaded from the backing '_bson' object. If - // so, then no attempt will be made to load the metadata again, even if the metadata has been - // released by a call to 'releaseMetadata()'. + // If '_stripMetadata' is true, tracks whether or not the metadata has been lazy-loaded from the + // backing '_bson' object. If so, then no attempt will be made to load the metadata again, even + // if the metadata has been released by a call to 'releaseMetadata()'. mutable bool _haveLazyLoadedMetadata = false; mutable DocumentMetadataFields _metadataFields; - // True if this storage was constructed from BSON with metadata. Serializing this object using - // the 'toBson()' method will omit (strip) the metadata fields. - bool _bsonHasMetadata{false}; + // The storage constructed from a BSON value may contain metadata. When we process the BSON we + // have to move the metadata to the MetadataFields object. If we know that the BSON does not + // have any metadata we can set _stripMetadata to false that will speed up the iteration. + bool _stripMetadata{false}; // This flag is set to true anytime the storage returns a mutable field. It is used to optimize // a conversion to BSON; i.e. if there are not any modifications we can directly return _bson. bool _modified{false}; - size_t _snapshottedSize{0}; - // Defined in document.cpp static const DocumentStorage kEmptyDoc; |
