xp
xp copied to clipboard
Delete empty directories during Vaccum
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.
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
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.
Also, should not be a problem running the specified command at the end of vacuum imho
Specified command is Linux only and super heavy.
~~Removing only last level (no recursive) is not a bad idea, actually.~~ Code becomes straight forward.
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) 💥
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?
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.