CollectionUpdateArgs currently has a boost::optional<BSONObj> preImageDoc member representing the state of the document before the update occurred. For storage engines supporting document-level concurrency, the preImage document is always copied out of the storage engine before applying the update. This means that, since the removal of the MMAPv1 storage engine in MongoDB 4.2, CollectionUpdateArgs::preImageDoc can be non-optional.
// Ensure that the BSONObj underlying the WorkingSetMember is owned because saveState() // is allowed to free the memory. member->makeObjOwnedIfNeeded();
As part of these changes we should consider simplifying the places which attempted to carefully get an owned copy of the oldObj and newObj and instead make owned BSONObjs for them available inside and outside UpdateStage in an obvious way. Some areas which are ripe for refactoring include:
- Callers of BSONObj::getOwned() inside of UpdateStage (1 2 3 4 5)
- UpdateStage::checkUpdateChangesShardKeyFields()
- CollectionImpl::updateDocument()
- CollectionImpl::updateDocumentWithDamages()
Note that CollectionUpdateArgs::storeDocOption should continue to be StoreDocOption::kNone when the preImage document doesn't need to be stored in config.image_collection, etc.
Side note: In the MMAPv1 storage engine, in-place updates were truly applied in-place meaning that the address of oldObj and the address of newObj were the same address.
- related to
-
SERVER-69474 Add a helper for finding modified field names from pre and post images
- Closed
-
SERVER-80423 Make the preImage document always available to OplogDeleteEntryArgs
- Closed