Skip to content

Commit 26f818d

Browse files
author
Devdutt Shenoi
committed
refactor: get disk usage as method
1 parent 3c388c5 commit 26f818d

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

src/hottier.rs

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ impl HotTierManager {
133133
total_space,
134134
used_space,
135135
..
136-
} = get_disk_usage().expect("Codepath should only be hit if hottier is enabled");
136+
} = self
137+
.get_disk_usage()
138+
.expect("Codepath should only be hit if hottier is enabled");
137139

138140
let (total_hot_tier_size, total_hot_tier_used_size) =
139141
self.get_hot_tiers_size(stream).await?;
@@ -642,7 +644,7 @@ impl HotTierManager {
642644
total_space,
643645
available_space,
644646
used_space,
645-
}) = get_disk_usage()
647+
}) = self.get_disk_usage()
646648
{
647649
if available_space < size_to_download {
648650
return Ok(false);
@@ -726,6 +728,34 @@ impl HotTierManager {
726728
}
727729
Ok(())
728730
}
731+
732+
/// Get the disk usage for the hot tier storage path. If we have a three disk paritions
733+
/// mounted as follows:
734+
/// 1. /
735+
/// 2. /home/parseable
736+
/// 3. /home/example/ignore
737+
///
738+
/// And parseable is running with `P_HOT_TIER_DIR` pointing to a directory in
739+
/// `/home/parseable`, we should return the usage stats of the disk mounted there.
740+
fn get_disk_usage(&self) -> Option<DiskUtil> {
741+
let mut disks = Disks::new_with_refreshed_list();
742+
// Order the disk partitions by decreasing length of mount path
743+
disks.sort_by_key(|disk| disk.mount_point().to_str().unwrap().len());
744+
disks.reverse();
745+
746+
for disk in disks.iter() {
747+
// Returns disk utilisation of first matching mount point
748+
if self.hot_tier_path.starts_with(disk.mount_point()) {
749+
return Some(DiskUtil {
750+
total_space: disk.total_space(),
751+
available_space: disk.available_space(),
752+
used_space: disk.total_space() - disk.available_space(),
753+
});
754+
}
755+
}
756+
757+
None
758+
}
729759
}
730760

731761
/// get the hot tier file path for the stream
@@ -743,35 +773,6 @@ struct DiskUtil {
743773
used_space: u64,
744774
}
745775

746-
/// Get the disk usage for the hot tier storage path. If we have a three disk paritions
747-
/// mounted as follows:
748-
/// 1. /
749-
/// 2. /home/parseable
750-
/// 3. /home/example/ignore
751-
///
752-
/// And parseable is running with `P_HOT_TIER_DIR` pointing to a directory in
753-
/// `/home/parseable`, we should return the usage stats of the disk mounted there.
754-
fn get_disk_usage() -> Option<DiskUtil> {
755-
let path = CONFIG.options.hot_tier_storage_path.as_ref()?;
756-
let mut disks = Disks::new_with_refreshed_list();
757-
// Order the disk partitions by decreasing length of mount path
758-
disks.sort_by_key(|disk| disk.mount_point().to_str().unwrap().len());
759-
disks.reverse();
760-
761-
for disk in disks.iter() {
762-
// Returns disk utilisation of first matching mount point
763-
if path.starts_with(disk.mount_point()) {
764-
return Some(DiskUtil {
765-
total_space: disk.total_space(),
766-
available_space: disk.available_space(),
767-
used_space: disk.total_space() - disk.available_space(),
768-
});
769-
}
770-
}
771-
772-
None
773-
}
774-
775776
async fn delete_empty_directory_hot_tier(path: &Path) -> io::Result<()> {
776777
async fn delete_helper(path: &Path) -> io::Result<()> {
777778
if path.is_dir() {

0 commit comments

Comments
 (0)