[SERVER-77212] Don't parse BSON to generate oplog entry RecordIds Created: 17/May/23  Updated: 29/Oct/23  Resolved: 22/May/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.1.0-rc0

Type: Improvement Priority: Major - P3
Reporter: Louis Williams Assignee: Louis Williams
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: Execution Team 2023-05-29
Participants:

 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.



 Comments   
Comment by Githook User [ 22/May/23 ]

Author:

{'name': 'Louis Williams', 'email': 'louis.williams@mongodb.com', 'username': 'louiswilliams'}

Message: SERVER-77212 Don't parse BSON to generate oplog entry RecordIds
Branch: master
https://github.com/mongodb/mongo/commit/04179cbeb3d398d9d817e6d894fb1eb777b94b67

Generated at Thu Feb 08 06:34:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.