-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Internal Code
-
Query Execution
-
135
The DocumentStorage class offers a public static const DocumentStorage& DocumentStorage::emptyDoc() method which returns a reference to a global private static const DocumentStorage::DocumentStorage kEmptyDoc.
This public method is only used in private const DocumentStorage& Document::storage(), which returns a reference to the same global variable for all documents with empty storage pointer. IMHO, the whole thing should be avoided, unless there are some measurable benefits (e.g., performance).
As an additional complication, the way the global variable is initialized exposes it to the theoretically possible "static initialization order fiasco".
As an additional complication, class DocumentStorage contains mutable data members (and data members modified with const_cast), which increases the chance of having a data race.
Moreover, Document::_storage is already an (intrusive) pointer, why to have and additional storage() method instead of pointing to the empty storage directly?
- is related to
-
SERVER-77730 Avoid data race when calculating getApproximateSize of DocumentStorage::kEmptyDoc
-
- Closed
-