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

    • Improvement
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 4.4.7, 5.0.0-rc2, 5.1.0-rc0
    • None
    • None
    • Fully Compatible
    • v5.0, v4.4
    • Execution Team 2021-06-14
    • 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
          28 kB
          Luke Pearson
        2. repro.js
          1 kB
          Louis Williams
        3. Screen Shot 2021-05-24 at 9.44.50 PM.png
          627 kB
          Louis Williams

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: