Ephemeral for test, capped collection, unindexed sort hang.

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Major - P3
    • 3.6.0-rc4
    • Affects Version/s: None
    • Component/s: 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
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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

            Assignee:
            Xiangyu Yao (Inactive)
            Reporter:
            Daniel Gottlieb (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: