ObjectReplaceExecutor::ObjectReplaceExecutor(BSONObj replacement)
|
: _replacementDoc(replacement.getOwned()), _containsId(false) {
|
// Replace all zero-valued timestamps with the current time and check for the existence of _id.
|
for (auto&& elem : _replacementDoc) {
|
// Do not change the _id field.
|
if (elem.fieldNameStringData() == kIdFieldName) {
|
_containsId = true;
|
continue;
|
}
|
if (elem.type() == BSONType::bsonTimestamp) {
|
auto timestampView = DataView(const_cast<char*>(elem.value()));
|
// We don't need to do an endian-safe read here, because 0 is 0 either way.
|
unsigned long long timestamp = timestampView.read<unsigned long long>();
|
if (timestamp == 0) {
|
ServiceContext* service = getGlobalServiceContext();
|
auto ts = LogicalClock::get(service)->reserveTicks(1).asTimestamp();
|
timestampView.write(tagLittleEndian(ts.asULL()));
|
}
|
}
|
}
|
}
|
|