xp icon indicating copy to clipboard operation
xp copied to clipboard

Delete empty directories during Vaccum

Open gbbirkisson opened this issue 4 years ago • 7 comments

It has been observed that after vaccum, there can be potentially a lot of empty directories left. This eats up inodes. It would be a great addition to clean up empty directories during vaccum.

gbbirkisson avatar Aug 24 '20 10:08 gbbirkisson

There is a concurrency problem which makes this issue non trivial.

There is a small time gap between "Vacuum" sees directory is empty and issues a delete directory call. If anything gets written into that folder during that small time vacuum process will fail. (or worse can delete new item recursively together with the directory)

Workaround. Stop XP and call something like suggested in https://unix.stackexchange.com/questions/8430/how-to-remove-all-empty-directories-in-a-subtree

rymsha avatar Aug 24 '20 13:08 rymsha

Non empty directories cannot be deleted unless issuing a recursive command, so this should not be a problem imho? Also, we should only clean away level 3 directories, this is where things explode.

sigdestad avatar Aug 24 '20 14:08 sigdestad

Also, should not be a problem running the specified command at the end of vacuum imho

sigdestad avatar Aug 24 '20 14:08 sigdestad

Specified command is Linux only and super heavy.

~~Removing only last level (no recursive) is not a bad idea, actually.~~ Code becomes straight forward.

rymsha avatar Aug 24 '20 15:08 rymsha

There will be a race between cleanup and non-atomic file creation. T1 directly created for new blobfile T2 vacuum removes empty directory T1 blobfile gets created (but direcory is already deleted) 💥

rymsha avatar Sep 15 '20 07:09 rymsha

This continues to be a problem for us. Today, we run the following command to clean the dirs, after running vacuum.

Could we have a separate step that performs something similar?

find <PATH_TO_REPO_DIRECTORY> -type d -empty -mmin +1 -delete BTW: Are you 100% sure it is possible to create files in a deleted directory? I would assume FS would not allow this?

sigdestad avatar Jul 04 '22 07:07 sigdestad

Are you 100% sure it is possible to create files in a deleted directory? I would assume FS would not allow this?

I'm sure FS won't allow this - leading to a catastrophic failure - blob file won't be created leaving node half-created.

find <PATH_TO_REPO_DIRECTORY> -type d -empty -mmin +1 -delete

This is fine to run on read-only repository (or when XP is stopped). Otherwise it may lead to the problem described above.

rymsha avatar Jul 27 '22 09:07 rymsha