Revert "Move SegmentUpdater::list_files() to Index"

This commit is contained in:
Paul Masurel
2020-11-20 13:53:50 +09:00
committed by GitHub
parent 0335c7353d
commit 8d0e049261
2 changed files with 19 additions and 16 deletions

View File

@@ -233,20 +233,6 @@ impl Index {
self.inventory.all()
}
/// List the files that are useful to the index.
///
/// This does not include lock files, or files that are obsolete
/// but have not yet been deleted by the garbage collector.
pub fn list_files(&self) -> HashSet<PathBuf> {
let mut files: HashSet<PathBuf> = self
.list_all_segment_metas()
.into_iter()
.flat_map(|segment_meta| segment_meta.list_files())
.collect();
files.insert(META_FILEPATH.to_path_buf());
files
}
/// Creates a new segment_meta (Advanced user only).
///
/// As long as the `SegmentMeta` lives, the files associated with the

View File

@@ -27,6 +27,7 @@ use std::borrow::BorrowMut;
use std::collections::HashSet;
use std::io::Write;
use std::ops::Deref;
use std::path::PathBuf;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::sync::RwLock;
@@ -98,8 +99,9 @@ async fn garbage_collect_files(
) -> crate::Result<GarbageCollectionResult> {
info!("Running garbage collection");
let mut index = segment_updater.index.clone();
let files = index.list_files();
index.directory_mut().garbage_collect(move || files)
index
.directory_mut()
.garbage_collect(move || segment_updater.list_files())
}
/// Merges a list of segments the list of segment givens in the `segment_entries`.
@@ -310,6 +312,21 @@ impl SegmentUpdater {
self.schedule_future(garbage_collect_future)
}
/// List the files that are useful to the index.
///
/// This does not include lock files, or files that are obsolete
/// but have not yet been deleted by the garbage collector.
fn list_files(&self) -> HashSet<PathBuf> {
let mut files: HashSet<PathBuf> = self
.index
.list_all_segment_metas()
.into_iter()
.flat_map(|segment_meta| segment_meta.list_files())
.collect();
files.insert(META_FILEPATH.to_path_buf());
files
}
pub fn schedule_commit(
&self,
opstamp: Opstamp,