Skip to content

Commit

Permalink
Restore sort on HotCache file list
Browse files Browse the repository at this point in the history
  • Loading branch information
rdettai committed Dec 5, 2024
1 parent 56362da commit 8ca6e39
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
29 changes: 21 additions & 8 deletions quickwit/quickwit-directories/src/hot_directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ impl StaticDirectoryCache {
pub fn get_file_length(&self, path: &Path) -> Option<u64> {
self.file_lengths.get(path).copied()
}

pub fn get_file_lengths(&self) -> Vec<(PathBuf, u64)> {
let mut entries = self
.file_lengths
.iter()
.map(|(k, v)| (k.clone(), *v))
.collect::<Vec<_>>();
entries.sort_by_key(|el| el.0.to_owned());
entries
}
}

/// A SliceCache is a static toring
Expand Down Expand Up @@ -360,14 +370,12 @@ impl HotDirectory {
}),
})
}
/// Get all the directory files and their sizes.
pub fn get_file_sizes(&self) -> Vec<(PathBuf, u64)> {
self.inner
.cache
.file_lengths
.iter()
.map(|(k, v)| (k.clone(), *v))
.collect()

/// Get all the files in the directory and their sizes.
///
/// The actual cached data is a very small fraction of this length.
pub fn get_file_lengths(&self) -> Vec<(PathBuf, u64)> {
self.inner.cache.get_file_lengths()
}
}

Expand Down Expand Up @@ -690,6 +698,11 @@ mod tests {
assert_eq!(directory_cache.get_file_length(three_path), Some(300));
assert_eq!(directory_cache.get_file_length(four_path), None);

let file_lengths = directory_cache.get_file_lengths();
assert_eq!(file_lengths[0], (one_path.to_owned(), 100));
assert_eq!(file_lengths[1], (three_path.to_owned(), 300));
assert_eq!(file_lengths[2], (two_path.to_owned(), 200));

assert_eq!(
directory_cache
.get_slice(one_path)
Expand Down
2 changes: 1 addition & 1 deletion quickwit/quickwit-search/src/leaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ fn get_leaf_resp_from_count(count: u64) -> LeafSearchResponse {
/// Compute the size of the index, store excluded.
fn compute_index_size(hot_directory: &HotDirectory) -> ByteSize {
let size_bytes = hot_directory
.get_file_sizes()
.get_file_lengths()
.iter()
.filter(|(path, _)| !path.to_string_lossy().ends_with("store"))
.map(|(_, size)| *size)
Expand Down

0 comments on commit 8ca6e39

Please sign in to comment.