Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-77212

Don't parse BSON to generate oplog entry RecordIds

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Major - P3 Major - P3
    • 7.1.0-rc0
    • 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.

      Attachments

        Activity

          People

            louis.williams@mongodb.com Louis Williams
            louis.williams@mongodb.com Louis Williams
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: