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

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

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.4.7, 5.0.0-rc2, 5.1.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Fully Compatible
    • v5.0, v4.4
    • Execution Team 2021-06-14
    • 180

      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.

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

            Assignee:
            louis.williams@mongodb.com Louis Williams
            Reporter:
            luke.pearson@mongodb.com Luke Pearson
            Votes:
            0 Vote for this issue
            Watchers:
            30 Start watching this issue

              Created:
              Updated:
              Resolved: