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

Wrap unique index insertion _keyExists call in a WT cursor reconfigure.

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 4.4.7, 5.0.0-rc2, 5.1.0-rc0
    • Component/s: None
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible
    • Backport Requested:
      v5.0, v4.4
    • Sprint:
      Execution Team 2021-06-14
    • Case:
    • Linked BF Score:
      180

      Description

      Follow on work from WT-7264 which is adding a new cursor flag, the flag allows the search near to exit early instead of walking numerous not visible entries.

      The patch I was using when testing the change is:

      diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp
      index 87bda0ace9..7eef9c8528 100644
      --- a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp
      +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp
      @@ -1520,9 +1520,11 @@ Status WiredTigerIndexUnique::_insert(OperationContext* opCtx,
               setKey(c, prefixKeyItem.Get());
               ret = WT_OP_CHECK(wiredTigerCursorRemove(opCtx, c));
               invariantWTOK(ret);
      -
      +        c->reconfigure(c, "prefix_key=true");
               // Second phase looks up for existence of key to avoid insertion of duplicate key
      -        if (_keyExists(opCtx, c, keyString.getBuffer(), sizeWithoutRecordId)) {
      +        auto key_exists = _keyExists(opCtx, c, keyString.getBuffer(), sizeWithoutRecordId);
      +        c->reconfigure(c, "prefix_key=false");
      +        if (key_exists) {
                   auto key = KeyString::toBson(
                       keyString.getBuffer(), sizeWithoutRecordId, _ordering, keyString.getTypeBits());
                   auto entry = _desc->getEntry(); 

      I think that should be all the required changes.

        Attachments

        1. image-2021-05-26-13-41-06-320.png
          image-2021-05-26-13-41-06-320.png
          28 kB
        2. repro.js
          1 kB
        3. Screen Shot 2021-05-24 at 9.44.50 PM.png
          Screen Shot 2021-05-24 at 9.44.50 PM.png
          627 kB

          Issue Links

            Activity

              People

              Assignee:
              louis.williams Louis Williams
              Reporter:
              luke.pearson Luke Pearson
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              27 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: