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

Recreating a dropped capped collection allocates more physical space

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.5.2
    • Affects Version/s: 2.4.2
    • Component/s: Storage
    • Fully Compatible
    • ALL

      After dropping capped collection of certain size, I would expect recreating it to reuse the space but dropping a 5GB capped collection and then recreating it always allocates two new physical 2GB db.x files.

      > db.stats(1024*1024)
      {
      	"db" : "cap",
      	"collections" : 9,
      	"objects" : 8732496,
      	"avgObjSize" : 203.08234896414496,
      	"dataSize" : 1691,
      	"storageSize" : 5130,
      	"numExtents" : 12,
      	"indexes" : 19,
      	"indexSize" : 1947,
      	"fileSize" : 10299,
      	"nsSizeMB" : 16,
      	"dataFileVersion" : {
      		"major" : 4,
      		"minor" : 5
      	},
      	"ok" : 1
      }
      > db.sms_message_event.stats(1024*1024)
      {
      	"ns" : "cap.sms_message_event",
      	"count" : 0,
      	"size" : 0,
      	"storageSize" : 5120,
      	"numExtents" : 4,
      	"nindexes" : 1,
      	"lastExtentSize" : 0,
      	"paddingFactor" : 1,
      	"systemFlags" : 1,
      	"userFlags" : 0,
      	"totalIndexSize" : 0,
      	"indexSizes" : {
      		"_id_" : 0
      	},
      	"capped" : true,
      	"max" : NumberLong("9223372036854775807"),
      	"ok" : 1
      }
      > db.sms_message_event.drop()
      true
      cap@local(2.4.2-rc0) > db.stats(1024*1024)
      {
      	"db" : "cap",
      	"collections" : 8,
      	"objects" : 83,
      	"avgObjSize" : 58.795180722891565,
      	"dataSize" : 0,
      	"storageSize" : 10,
      	"numExtents" : 8,
      	"indexes" : 13,
      	"indexSize" : 0,
      	"fileSize" : 12346,
      	"nsSizeMB" : 16,
      	"dataFileVersion" : {
      		"major" : 4,
      		"minor" : 5
      	},
      	"ok" : 1
      }
      cap@local(2.4.2-rc0) > db.createCollection("sms_message_event",{capped:true, size:5*1024*1024*1024})
      { "ok" : 1 }
      cap@local(2.4.2-rc0) > db.stats(1024*1024)
      {
      	"db" : "cap",
      	"collections" : 9,
      	"objects" : 86,
      	"avgObjSize" : 59.395348837209305,
      	"dataSize" : 0,
      	"storageSize" : 5130,
      	"numExtents" : 12,
      	"indexes" : 14,
      	"indexSize" : 0,
      	"fileSize" : 16440,
      	"nsSizeMB" : 16,
      	"dataFileVersion" : {
      		"major" : 4,
      		"minor" : 5
      	},
      	"ok" : 1
      }
      

      Looking in my /data/db after each new drop followed by create I have a new file for that DB:

      asyasmacbook:db asya13$ ls -lhu cap*
      -rw-------  1 asya13  staff    64M Apr 27 10:16 cap.0
      -rw-------  1 asya13  staff   2.0G Apr 27 10:16 cap.1
      -rw-------  1 asya13  staff   2.0G Apr 27 10:09 cap.2
      -rw-------  1 asya13  staff   2.0G Apr 27 10:09 cap.3
      -rw-------  1 asya13  staff   2.0G Apr 27 10:09 cap.4
      -rw-------  1 asya13  staff   2.0G Apr 27 10:09 cap.5
      -rw-------  1 asya13  staff   2.0G Apr 27 10:09 cap.6
      -rw-------  1 asya13  staff    16M Apr 27 10:16 cap.ns
      asyasmacbook:db asya13$ ls -lhu cap*
      -rw-------  1 asya13  staff    64M Apr 27 10:16 cap.0
      -rw-------  1 asya13  staff   2.0G Apr 27 10:16 cap.1
      -rw-------  1 asya13  staff   2.0G Apr 27 10:09 cap.2
      -rw-------  1 asya13  staff   2.0G Apr 27 10:09 cap.3
      -rw-------  1 asya13  staff   2.0G Apr 27 10:09 cap.4
      -rw-------  1 asya13  staff   2.0G Apr 27 10:09 cap.5
      -rw-------  1 asya13  staff   2.0G Apr 27 10:09 cap.6
      -rw-------  1 asya13  staff   2.0G Apr 27 10:16 cap.7
      -rw-------  1 asya13  staff    16M Apr 27 10:16 cap.ns
      asyasmacbook:db asya13$ ls -lhu cap*
      -rw-------  1 asya13  staff    64M Apr 27 10:22 cap.0
      -rw-------  1 asya13  staff   2.0G Apr 27 10:16 cap.1
      -rw-------  1 asya13  staff   2.0G Apr 27 10:09 cap.2
      -rw-------  1 asya13  staff   2.0G Apr 27 10:16 cap.3
      -rw-------  1 asya13  staff   2.0G Apr 27 10:09 cap.4
      -rw-------  1 asya13  staff   2.0G Apr 27 10:22 cap.5
      -rw-------  1 asya13  staff   2.0G Apr 27 10:16 cap.6
      -rw-------  1 asya13  staff   2.0G Apr 27 10:16 cap.7
      -rw-------  1 asya13  staff   2.0G Apr 27 10:16 cap.8
      -rw-------  1 asya13  staff    16M Apr 27 10:22 cap.ns
      

      Here is a repeat showing two more files and times of creation to the second:

      asyasmacbook:db asya13$ ls -ltrhUT cap*
      -rw-------  1 asya13  staff    16M Apr 27 08:45:19 2013 cap.ns
      -rw-------  1 asya13  staff    64M Apr 27 08:45:19 2013 cap.0
      -rw-------  1 asya13  staff   2.0G Apr 27 09:02:42 2013 cap.1
      -rw-------  1 asya13  staff   2.0G Apr 27 09:02:48 2013 cap.2
      -rw-------  1 asya13  staff   2.0G Apr 27 09:02:54 2013 cap.3
      -rw-------  1 asya13  staff   2.0G Apr 27 09:39:48 2013 cap.4
      -rw-------  1 asya13  staff   2.0G Apr 27 09:39:54 2013 cap.5
      -rw-------  1 asya13  staff   2.0G Apr 27 10:08:57 2013 cap.6
      -rw-------  1 asya13  staff   2.0G Apr 27 10:16:22 2013 cap.7
      -rw-------  1 asya13  staff   2.0G Apr 27 10:16:27 2013 cap.8
      -rw-------  1 asya13  staff   2.0G Apr 27 10:25:11 2013 cap.9
      -rw-------  1 asya13  staff   2.0G Apr 27 10:25:16 2013 cap.10
      

        1. cappedreuse.js
          0.6 kB
          Asya Kamsky

            Assignee:
            Unassigned Unassigned
            Reporter:
            asya.kamsky@mongodb.com Asya Kamsky
            Votes:
            4 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated:
              Resolved: