Search code examples
mongodbchunks

mongo chunk not delete after documents TTL


mongo config infomations:

  • mongo version: 3.2.10
  • mongo shard with key: {secretTaskId:1, time: 1}
  • TTL index: {time: 1}, {expireAfterSeconds: 60 * 60 * 24 * 8, background: true} # 8 days
  • mongo balancer is enable & running: sh.isBalancerRunning() ===> true

problem description

The TTL config works correctly, and the documents are auto removed on timeout. But the chunks in config database got not updated (deleted), the chunks remained as the documents are gone.

e.g. : js // chunks in config database // As the date is 2017-06-07 now, documents create in 2016 had removed, but the chunks for them are still remain. ( more old chunks can be found, not single.) { "_id": "****", "lastmod": Timestamp(3, 0), "lastmodEpoch": ObjectId("58253bbffbb3d96a85eccef1"), "ns": "***", "min": {"secretTaskId": "***", "time": ISODate("2016-11-11T03:32:40.045Z")}, "max": {"secretTaskId": "***", "time": ISODate("2016-11-14T09:20:45.684Z")}, "shard": "***" }

As the chunks not delete, the mongo shard cluster is not balance property. I think the balancer get no ideal about the actual documents distributed, and work uncorrectly base on the errror chunks.

I got no solution after lots search. Anyone can help? Thanks.


Solution

  • Chunk ranges in MongoDB do not disappear when the documents contained in them are removed. Think of chunk ranges as buckets, even though you emptied the water from the bucket, the bucket itself still exists. Chunks are very similar. They will get split as they fill up to support better balancing, but they do not automatically go away when emptied.

    If you wish to "get rid" of these chunks, you must merge them. You can find more information on merging chunks using the mergeChunks command in the MongoDB Docs.