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

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

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.8.0-rc3
    • Affects Version/s: 2.6.1, 2.7.0
    • Component/s: Storage
    • Labels:
    • 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') });

      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@mongodb.com Mathias Stearn
            Reporter:
            kamran.khan Kamran K.
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: