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

Truncating a capped collection may not unindex deleted documents in WiredTiger

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Critical - P2 Critical - P2
    • 3.0.5, 3.1.7
    • Affects Version/s: 3.0.0
    • Component/s: WiredTiger
    • None
    • Fully Compatible
    • ALL
    • Hide
      /**
       * Test 'captrunc' command on indexed capped collections0
       */
      (function() {
          'use strict';
      
          db.cappedb.drop();
          db._dbCommand({ create: "cappedb", capped: true, size: 1000, autoIndexId: true });
          var t = db.cappedb;
      
          for (var j = 1; j < 10; j++) {
              assert.eq(t.insert({x:j}),{nInserted:1});
          }
      
          assert.commandWorked(db.runCommand({ captrunc: "cappedb", n: 5, inc: false }));
          var last = t.find({},{_id:1}).sort({_id:-1}).next();
          assert.neq(null, t.findOne({_id: last._id}), 
                     tojson(last) + " is in _id index, but not in capped collection");
      })();
      
      Show
      /** * Test 'captrunc' command on indexed capped collections0 */ (function() { 'use strict' ; db.cappedb.drop(); db._dbCommand({ create: "cappedb" , capped: true , size: 1000, autoIndexId: true }); var t = db.cappedb; for ( var j = 1; j < 10; j++) { assert .eq(t.insert({x:j}),{nInserted:1}); } assert .commandWorked(db.runCommand({ captrunc: "cappedb" , n: 5, inc: false })); var last = t.find({},{_id:1}).sort({_id:-1}).next(); assert .neq( null , t.findOne({_id: last._id}), tojson(last) + " is in _id index, but not in capped collection" ); })();
    • Quint Iteration 7

      Issue Status as of Jul 22, 2015

      ISSUE SUMMARY
      Truncating a capped collection using the WiredTiger storage engine may not remove the deleted documents from the indexes in the collection.

      USER IMPACT
      When running the captrunc command on a capped collection, or when a member of a replica-set does a rollback of such a collection, the removed documents may not be deleted from the collection's indexes, thus leaving the indexes in an inconsistent state. As a result, a query covered by an index may report results that include deleted documents, and queries using an index in general may fail or return incorrect results. Regular deletions as result of exceeding capped collection capacity are not affected by this issue.

      To determine if a capped collection is impacted by this issue, users can compare the output of the following commands:

      • db.cappedcollection.distinct("_id").length
      • db.cappedcollection.count()

      If the results are equal the capped collection is not impacted by this issue. Alternatively, users can compare the nrecords and keysPerIndex fields of the db.cappedcollection.validate() output in the mongo shell; if the values are equal then the capped collection is not impacted.

      WORKAROUNDS
      Users may run the reIndex command on the affected capped collections. This restores consistency in the collection's indexes, but does not prevent the issue from happening again.

      AFFECTED VERSIONS
      MongoDB versions 3.0.0 through 3.0.4 using the WiredTiger storage engine.

      FIX VERSION
      The fix is included in the 3.0.5 production release.

      Original description

      The captrunc command does not unindex documents removed from a WiredTiger capped collection. As rollback operations in a replicaset are performed using this command, they can leave indexes in an inconsistent state.

            Assignee:
            geert.bosch@mongodb.com Geert Bosch
            Reporter:
            geert.bosch@mongodb.com Geert Bosch
            Votes:
            0 Vote for this issue
            Watchers:
            14 Start watching this issue

              Created:
              Updated:
              Resolved: