Removing all the orphan chunks when using gridfs?

741 views
Skip to first unread message

Jeff Oh

unread,
Feb 23, 2011, 8:52:40 PM2/23/11
to mongodb-user
I know that in some situations while using gridfs, we can have
orphaned chunks.
(related discussion :
https://groups.google.com/group/mongodb-user/browse_thread/thread/4a7419e07c73537/c172c97eabf20d30?lnk=gst&q=orphaned#c172c97eabf20d30)

So I thought it might be good to find and remove all the orphan
chunks, whose parent document in .files collection does not exist
anymore.

Is there any simple way to achieve this? All I can think of now is
iterating "all" the rows of chunks and check if their parent file
still exist. (which is really bad idea)

Thanks.

Kyle Banker

unread,
Feb 24, 2011, 10:04:57 AM2/24/11
to mongod...@googlegroups.com
Unfortunately, there's no other good way of finding orphaned chunks.
Under most circumstances, orphaned chunks should be a rare case.

If you want, you could implement a transaction-like device to ensure
that you can easily locate orphaned chunks when they exist, but you'd
have to hack your GridFS implementation. But basically, you could
write the files_id to a document in another collection (call it
fs.tmp), then write the chunks, then write the metadata to fs.files,
and then delete the tmp document from fs.tmp.

Later, a document in fs.tmp will indicate the possibility of orphaned
chunks with the given files_id.

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>

Kyle Banker

unread,
Feb 24, 2011, 10:21:13 AM2/24/11
to mongod...@googlegroups.com
Of course, when checking your fs.tmp collection for orphans, you'd
first want to make sure that corresponding doc in the fs.files
collection does not exist.
Reply all
Reply to author
Forward
0 new messages