Details
-
Improvement
-
Resolution: Fixed
-
Major - P3
-
None
-
None
-
None
-
Fully Compatible
-
Execution Team 2023-05-29
Description
When we insert entries into the oplog, we always parse the BSON of the oplog entry so that we can use the "ts" field to generate the RecordId. Not only is this a layering violation, but we have access to the Timestamp being used inside the same function. We could generate the RecordId much faster by just using the provided timestamp.
Something like this:
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
|
index 5dcfb780c76..cf4b4080e58 100644
|
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
|
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
|
@@ -954,8 +954,8 @@ Status WiredTigerRecordStore::_insertRecords(OperationContext* opCtx,
|
for (size_t i = 0; i < nRecords; i++) { |
auto& record = records[i];
|
if (_isOplog) { |
- StatusWith<RecordId> status =
|
- record_id_helpers::extractKeyOptime(record.data.data(), record.data.size());
|
+ Timestamp ts = timestamps[i];
|
+ StatusWith<RecordId> status = record_id_helpers::keyForOptime(ts, KeyFormat::Long);
|
if (!status.isOK()) |
return status.getStatus(); |
record.id = std::move(status.getValue());
|
We could keep this for debug builds as a double-check that it matches the timestamp.