Skip to content

Commit 0aa52b0

Browse files
unexgeVlad Volodkin
authored andcommitted
Add retry around removal of cache sub-directory in the background thread
Signed-off-by: Burak Varlı <burakvar@amazon.co.uk>
1 parent 5762755 commit 0aa52b0

1 file changed

Lines changed: 23 additions & 8 deletions

File tree

mountpoint-s3-fs/src/data_cache/cache_directory.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,14 @@ pub enum ManagedCacheDirError {
4040
}
4141

4242
impl ManagedCacheDir {
43+
// This is the sub-directory where Mountpoint will store cache contents for the current Mountpoint instance.
4344
const MOUNTPOINT_CACHE_DIR_NAME: &str = "mountpoint-cache";
45+
// This is the sub-directory prefix where Mountpoint will rename any leftover cache sub-directory from any previous Mountpoint instances
46+
// and then will attempt to clean up in a background thread.
4447
const MOUNTPOINT_OLD_CACHE_DIR_PREFIX: &str = "old-mountpoint-cache.";
48+
// This is the maximum number of retries Mountpoint will try to clean up the old cache folder in the background thread.
49+
// Mountpoint will log any errors if clean up fails.
50+
const MOUNTPOINT_OLD_CACHE_DIR_CLEANUP_MAX_RETRY: usize = 3;
4551

4652
/// Create a new directory inside the provided parent path.
4753
///
@@ -115,15 +121,24 @@ impl ManagedCacheDir {
115121
fs::rename(&self.mountpoint_cache_path, &renamed_cache_path)?;
116122

117123
std::thread::spawn(move || {
118-
if let Err(err) = remove_dir_all_ignore_not_found(&renamed_cache_path) {
119-
tracing::error!(
120-
renamed_cache_subdirectory = ?renamed_cache_path,
121-
error = ?err,
122-
"failed to remove cache sub-directory in background");
123-
return;
124+
for attempt in 1..=ManagedCacheDir::MOUNTPOINT_OLD_CACHE_DIR_CLEANUP_MAX_RETRY {
125+
match remove_dir_all_ignore_not_found(&renamed_cache_path) {
126+
Ok(()) => {
127+
tracing::debug!(
128+
attempt = attempt,
129+
renamed_cache_subdirectory = ?renamed_cache_path,
130+
"cache sub-directory removal complete");
131+
return;
132+
}
133+
Err(err) => {
134+
tracing::error!(
135+
attempt = attempt,
136+
renamed_cache_subdirectory = ?renamed_cache_path,
137+
error = ?err,
138+
"failed to remove cache sub-directory in background");
139+
}
140+
}
124141
}
125-
126-
tracing::debug!(renamed_cache_subdirectory = ?renamed_cache_path, "cache sub-directory removal complete");
127142
});
128143

129144
Ok(())

0 commit comments

Comments
 (0)