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

Add more test coverage for unique indexes

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Priority: Critical - P2
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 5.1.0-rc0
    • Component/s: None
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible
    • Sprint:
      Execution Team 2021-08-09, Execution Team 2021-08-23, Execution Team 2021-09-06

      Description

      SERVER-56509 introduced a bug where the unique index constraint was not enforced in some cases. We should add more test coverage for this.

      The issue could be reproduced with the following script that we can base additional testing on:

      function repro1() {
       
          db.c.drop()
          db.c.createIndex({t: 1, i: 1}, {unique: true})
       
          const n = 10000
          const t = 0
          for (var i = 0; i < n; i++)
              db.c.insert({t, i})
          for (iter = 0; ; iter++) {
              print("iter", iter)
              for (var i = 0; i < n; i++) {
                  r = db.c.insert({t, i, x: 'x'})
                  if (r.nInserted != 0)
                      print("dup!", t, i, "iter", iter, "count", db.c.count({t, i}))
              }
          }
      }
      

      Which reproduces the issue after a couple of iterations:

      iter 0
      iter 1
      dup! 0 9999 iter 1 count 2
      

      A multithreaded version also reproduces:

      function repro() {
       
          db.c.drop()
          db.c.createIndex({t: 1, i: 1}, {unique: true})
       
          nthreads = 100
          threads = []
          for (var t=0; t<nthreads; t++) {
              thread = new Thread(function(t) {
                  for (var i = 0; i < 100; i++)
                      db.c.insert({t, i, x: 'x'})
                  while (true) {
                      for (var i = 0; i < 100; i++) {
                          r = db.c.insert({t, i, x: 'x'})
                          if (r.nInserted != 0)
                              print("dup!", t, i, "count", db.c.count({t, i}))
                      }
                  }
              }, t)
              threads.push(thread)
              thread.start()
          }
          for (var t = 0; t < nthreads; t++)
              threads[t].join()
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              haley.connelly Haley Connelly
              Reporter:
              henrik.edin Henrik Edin
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              17 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: