'no space in capped collection' error when inserting document close to the collection's size

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Minor - P4
    • 2.8.0-rc3
    • Affects Version/s: 2.6.1, 2.7.0
    • Component/s: Storage
    • ALL
    • Hide
      var myDB = db.getSiblingDB('anotherdb');
      myDB.dropDatabase();
      
      myDB.createCollection('foo', {capped: true, size: 8192, usePowerOf2Sizes: false});
      myDB.foo.insert({ a: new Array(8000).join('a') });
      myDB.foo.insert({ a: new Array(8200).join('a') });
      
      Show
      var myDB = db.getSiblingDB('anotherdb'); myDB.dropDatabase(); myDB.createCollection('foo', {capped: true, size: 8192, usePowerOf2Sizes: false}); myDB.foo.insert({ a: new Array(8000).join('a') }); myDB.foo.insert({ a: new Array(8200).join('a') });
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      In 2.6 and master, inserting a document that's almost as large as the entire capped collection results in a 'no space in capped collection' error. There are two potential issues with this:

      1. The status message uses ErrorCodes::InternalError, which makes me think this scenario shouldn't be easily triggered by user input.
      2. The error message is slightly misleading because the capped collection actually does have some space in it. 'no space' implies that the collection is full even though it might be completely empty.

      Output from master:

      > var myDB = db.getSiblingDB('anotherdb');
      > myDB.dropDatabase();
      { "dropped" : "anotherdb", "ok" : 1 }
      
      > myDB.createCollection('foo', {capped: true, size: 8192, usePowerOf2Sizes: false});
      { "ok" : 1 }
      
      > myDB.foo.insert({ a: new Array(8000).join('a') });
      WriteResult({
      	"nInserted" : 0,
      	"writeError" : {
      		"code" : 1,
      		"errmsg" : "no space in capped collection"
      	}
      })
      
      > myDB.foo.insert({ a: new Array(8200).join('a') });
      WriteResult({
      	"nInserted" : 0,
      	"writeError" : {
      		"code" : 2,
      		"errmsg" : "document is larger than capped size 8248 > 8192"
      	}
      })
      

      Version: ce04ab3728edeff71f0c32590558cb980a07fdb3

            Assignee:
            Mathias Stearn
            Reporter:
            Kamran K. (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: