From dc00dce842ad5e6b4681b6502e2611e421713b87 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Wed, 8 Feb 2017 22:01:00 -0500 Subject: [PATCH] context: purge FD cache every COMMIT_INTERVAL Holding file FDs open for long periods of time delays inode destruction. For very large files this can lead to excessive delays while bees dedups data that will cease to be reachable. Use the same workaround for file FDs (in the root_ino cache) that is used for subvols (in the root cache): forcibly close all cached FDs at regular intervals. The FD cache will reacquire FDs from files that still have existing paths, and will abandon FDs from files that no longer have existing paths. The non-existing-path case is not new (bees has always been able to discover deleted inodes) so it is already handled by existing code. Fixes: https://github.com/Zygo/bees/issues/18 Signed-off-by: Zygo Blaxell --- src/bees-context.cc | 6 ++++++ src/bees.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/bees-context.cc b/src/bees-context.cc index 1c82bd7..ada5a1c 100644 --- a/src/bees-context.cc +++ b/src/bees-context.cc @@ -55,6 +55,12 @@ BeesFdCache::open_root(shared_ptr ctx, uint64_t root) Fd BeesFdCache::open_root_ino(shared_ptr ctx, uint64_t root, uint64_t ino) { + if (m_file_cache_timer.age() > BEES_COMMIT_INTERVAL) { + BEESINFO("Clearing open FD cache to enable file delete"); + m_file_cache.clear(); + m_file_cache_timer.reset(); + BEESCOUNT(open_clear); + } return m_file_cache(ctx, root, ino); } diff --git a/src/bees.h b/src/bees.h index 8a17960..8c74ca2 100644 --- a/src/bees.h +++ b/src/bees.h @@ -659,6 +659,7 @@ class BeesFdCache { LRUCache, uint64_t> m_root_cache; LRUCache, uint64_t, uint64_t> m_file_cache; Timer m_root_cache_timer; + Timer m_file_cache_timer; public: BeesFdCache();