Skip to content

Commit 82e0f25

Browse files
authored
Merge pull request #3070 from ermineJose/armv7-storage-size-LP
feat: change data type from usize to u64 id disk space for nodes
2 parents a0bc091 + 989a915 commit 82e0f25

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

node-launchpad/src/components/popup/manage_nodes.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ use crate::{
2323

2424
use super::super::{Component, utils::centered_rect_fixed};
2525

26-
pub const GB_PER_NODE: usize = 35;
27-
pub const MB: usize = 1000 * 1000;
28-
pub const GB: usize = MB * 1000;
26+
pub const GB_PER_NODE: u64 = 35;
27+
pub const MB: u64 = 1000 * 1000;
28+
pub const GB: u64 = MB * 1000;
2929
pub const MAX_NODE_COUNT: usize = 50;
3030

3131
pub struct ManageNodes {
@@ -43,7 +43,7 @@ impl ManageNodes {
4343
let nodes_to_start = std::cmp::min(nodes_to_start, MAX_NODE_COUNT);
4444
let new = Self {
4545
active: false,
46-
available_disk_space_gb: get_available_space_b(&storage_mountpoint)? / GB,
46+
available_disk_space_gb: (get_available_space_b(&storage_mountpoint)? / GB) as usize,
4747
nodes_to_start_input: Input::default().with_value(nodes_to_start.to_string()),
4848
old_value: Default::default(),
4949
storage_mountpoint: storage_mountpoint.clone(),
@@ -58,7 +58,10 @@ impl ManageNodes {
5858
// Returns the max number of nodes to start
5959
// It is the minimum of the available disk space and the max nodes limit
6060
fn max_nodes_to_start(&self) -> usize {
61-
std::cmp::min(self.available_disk_space_gb / GB_PER_NODE, MAX_NODE_COUNT)
61+
std::cmp::min(
62+
self.available_disk_space_gb / GB_PER_NODE as usize,
63+
MAX_NODE_COUNT,
64+
)
6265
}
6366
}
6467

@@ -111,7 +114,7 @@ impl Component for ManageNodes {
111114
.parse::<usize>()
112115
.unwrap_or(0);
113116
// if it might exceed the available space or if more than max_node_count, then enter the max
114-
if new_value * GB_PER_NODE > self.available_disk_space_gb
117+
if (new_value as u64) * GB_PER_NODE > (self.available_disk_space_gb as u64) * GB
115118
|| new_value > MAX_NODE_COUNT
116119
{
117120
self.nodes_to_start_input = self
@@ -134,7 +137,9 @@ impl Component for ManageNodes {
134137
if key.code == KeyCode::Up {
135138
if current_val + 1 >= MAX_NODE_COUNT {
136139
MAX_NODE_COUNT
137-
} else if (current_val + 1) * GB_PER_NODE <= self.available_disk_space_gb {
140+
} else if ((current_val + 1) as u64) * GB_PER_NODE
141+
<= (self.available_disk_space_gb as u64) * GB
142+
{
138143
current_val + 1
139144
} else {
140145
current_val
@@ -179,7 +184,7 @@ impl Component for ManageNodes {
179184
},
180185
Action::OptionsActions(OptionsActions::UpdateStorageDrive(mountpoint, _drive_name)) => {
181186
self.storage_mountpoint.clone_from(&mountpoint);
182-
self.available_disk_space_gb = get_available_space_b(&mountpoint)? / GB;
187+
self.available_disk_space_gb = (get_available_space_b(&mountpoint)? / GB) as usize;
183188
None
184189
}
185190
_ => None,
@@ -266,7 +271,10 @@ impl Component for ManageNodes {
266271
let info = Line::from(vec![
267272
Span::styled("Using", info_style),
268273
Span::styled(
269-
format!(" {}GB ", self.get_nodes_to_start_val() * GB_PER_NODE),
274+
format!(
275+
" {}GB ",
276+
(self.get_nodes_to_start_val() as u64) * GB_PER_NODE
277+
),
270278
info_style.bold(),
271279
),
272280
Span::styled(
@@ -319,4 +327,4 @@ impl Component for ManageNodes {
319327

320328
Ok(())
321329
}
322-
}
330+
}

node-launchpad/src/components/status.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ impl Status<'_> {
156156
port_to: config.port_to,
157157
error_popup: None,
158158
storage_mountpoint: config.storage_mountpoint.clone(),
159-
available_disk_space_gb: get_available_space_b(&config.storage_mountpoint)? / GB,
159+
available_disk_space_gb: (get_available_space_b(&config.storage_mountpoint)? / GB)
160+
as usize,
160161
};
161162

162163
// Nodes registry
@@ -924,7 +925,7 @@ impl Component for Status<'_> {
924925
debug!("Got action to Add node");
925926

926927
// Validations - Available space
927-
if GB_PER_NODE > self.available_disk_space_gb {
928+
if (GB_PER_NODE as usize) > self.available_disk_space_gb {
928929
self.error_popup = Some(ErrorPopup::new(
929930
"Cannot Add Node".to_string(),
930931
format!("\nEach Node requires {GB_PER_NODE}GB of available space."),
@@ -1106,7 +1107,7 @@ impl Component for Status<'_> {
11061107
}
11071108
Action::OptionsActions(OptionsActions::UpdateStorageDrive(mountpoint, _drive_name)) => {
11081109
self.storage_mountpoint.clone_from(&mountpoint);
1109-
self.available_disk_space_gb = get_available_space_b(&mountpoint)? / GB;
1110+
self.available_disk_space_gb = (get_available_space_b(&mountpoint)? / GB) as usize;
11101111
}
11111112
_ => {}
11121113
}
@@ -1155,7 +1156,7 @@ impl Component for Status<'_> {
11551156

11561157
let storage_allocated_row = Row::new(vec![
11571158
Cell::new("Storage Allocated".to_string()).fg(GHOST_WHITE),
1158-
Cell::new(format!("{} GB", self.nodes_to_start * GB_PER_NODE)).fg(GHOST_WHITE),
1159+
Cell::new(format!("{} GB", (self.nodes_to_start as u64) * GB_PER_NODE)).fg(GHOST_WHITE),
11591160
]);
11601161
let memory_use_val = if self.node_stats.total_memory_usage_mb as f64 / 1024_f64 > 1.0 {
11611162
format!(

node-launchpad/src/system.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub fn get_primary_mount_point_name() -> Result<String> {
139139
}
140140

141141
// Gets available disk space in bytes for the given mountpoint
142-
pub fn get_available_space_b(storage_mountpoint: &PathBuf) -> Result<usize> {
142+
pub fn get_available_space_b(storage_mountpoint: &PathBuf) -> Result<u64> {
143143
let disks = Disks::new_with_refreshed_list();
144144
if tracing::level_enabled!(tracing::Level::DEBUG) {
145145
for disk in disks.list() {
@@ -156,7 +156,7 @@ pub fn get_available_space_b(storage_mountpoint: &PathBuf) -> Result<usize> {
156156
.iter()
157157
.find(|disk| disk.mount_point() == storage_mountpoint)
158158
.context("Cannot find the primary disk. Configuration file might be wrong.")?
159-
.available_space() as usize;
159+
.available_space();
160160

161161
Ok(available_space_b)
162162
}

0 commit comments

Comments
 (0)