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

Ephemeral for test, capped collection, unindexed sort hang.

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major - P3 Major - P3
    • 3.6.0-rc4
    • None
    • Storage
    • None
    • Fully Compatible
    • ALL
    • Hide

      db.createCollection("capped", {capped: true, size: 50 * 1024});
      db.capped.ensureIndex({a: -1});
      for (var idx = 0; idx < 5000; ++idx) {
          db.capped.insert({_id: 1000 - idx, a: idx, b: Random.srand()});
      }
       
      var cursor = db.capped.find().sort({b: 1}).batchSize(1);
      for (var idx = 0; idx < 10; ++idx) {
          cursor.hasNext();
          cursor.next();
      }
       
      for (var idx = 0; idx < 5000; ++idx) {
          db.capped.insert({_idx: idx, a: -idx, b: Random.srand()});
      }
      

      Show
      db.createCollection("capped", {capped: true, size: 50 * 1024}); db.capped.ensureIndex({a: -1}); for (var idx = 0; idx < 5000; ++idx) { db.capped.insert({_id: 1000 - idx, a: idx, b: Random.srand()}); }   var cursor = db.capped.find().sort({b: 1}).batchSize(1); for (var idx = 0; idx < 10; ++idx) { cursor.hasNext(); cursor.next(); }   for (var idx = 0; idx < 5000; ++idx) { db.capped.insert({_idx: idx, a: -idx, b: Random.srand()}); }
    • Storage 2017-11-13
    • 0

    Description

      Ephemeral for test record stores use a mutex to protect concurrent access to their data. Technically, because ephemeral for test is not a document locking record store, this shouldn't be needed for data collections, just the _mdb_catalog. Unfortunately knowing whether a record store is for the _mdb_catalog is a layering violation.

      The problem that can arise is that an insert into a capped collection can trigger a delete. A delete on a record goes through a callback, which is ultimately managed by the CursorManager and forwarded to all the individual plans being run. This BF found that the in-memory, non-indexed sorting stage queries the record store for the deleted record (presumably to ensure the query does not return the capped-deleted document in the result set?)

      Re-entering the same ephemeral for test record store causes its internal mutex to be double locked. For informational purposes (i.e: not a mandated solution), another example of a callback in this class unlocks the mutex before calling the arbitrary code, and relocks when returning: https://github.com/mongodb/mongo/blob/9e8cce334f74d4e70661bcb3921e069c9a0b248b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_record_store.cpp#L488-L493

      Attachments

        Activity

          People

            xiangyu.yao@mongodb.com Xiangyu Yao (Inactive)
            daniel.gottlieb@mongodb.com Daniel Gottlieb (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: