-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v1.16: Shares accounts hash cache data between full and incremental (backport of #33164) #33212
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,29 +140,32 @@ impl CacheHashDataFile { | |
} | ||
} | ||
|
||
pub type PreExistingCacheFiles = HashSet<PathBuf>; | ||
pub struct CacheHashData { | ||
cache_dir: PathBuf, | ||
pre_existing_cache_files: Arc<Mutex<PreExistingCacheFiles>>, | ||
pre_existing_cache_files: Arc<Mutex<HashSet<PathBuf>>>, | ||
should_delete_old_cache_files_on_drop: bool, | ||
Comment on lines
+145
to
+146
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the inconsistent terminology here isn't great "old" vs. "pre-existing" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, it's non-intuitive. When an instance of So, on So the tl;dr is that on drop, "pre-existing" means "old", which is why both the method ( We could tweak that names to reflect this, or add documentation, or a second HashSet/Container for the pre-existing vs the old files. I would image that those changes should go to |
||
pub stats: Arc<Mutex<CacheHashDataStats>>, | ||
} | ||
|
||
impl Drop for CacheHashData { | ||
fn drop(&mut self) { | ||
self.delete_old_cache_files(); | ||
if self.should_delete_old_cache_files_on_drop { | ||
self.delete_old_cache_files(); | ||
} | ||
self.stats.lock().unwrap().report(); | ||
} | ||
} | ||
|
||
impl CacheHashData { | ||
pub fn new(cache_dir: PathBuf) -> CacheHashData { | ||
pub fn new(cache_dir: PathBuf, should_delete_old_cache_files_on_drop: bool) -> CacheHashData { | ||
std::fs::create_dir_all(&cache_dir).unwrap_or_else(|err| { | ||
panic!("error creating cache dir {}: {err}", cache_dir.display()) | ||
}); | ||
|
||
let result = CacheHashData { | ||
cache_dir, | ||
pre_existing_cache_files: Arc::new(Mutex::new(PreExistingCacheFiles::default())), | ||
pre_existing_cache_files: Arc::new(Mutex::new(HashSet::default())), | ||
should_delete_old_cache_files_on_drop, | ||
stats: Arc::new(Mutex::new(CacheHashDataStats::default())), | ||
}; | ||
|
||
|
@@ -386,7 +389,7 @@ pub mod tests { | |
data_this_pass.push(this_bin_data); | ||
} | ||
} | ||
let cache = CacheHashData::new(cache_dir.clone()); | ||
let cache = CacheHashData::new(cache_dir.clone(), true); | ||
let file_name = PathBuf::from("test"); | ||
cache.save(&file_name, &data_this_pass).unwrap(); | ||
cache.get_cache_files(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This temp dir is only used by the accounts hash cache. By using it directly, we don't need to create a subdir within it.