Skip to content

Commit 9c187e8

Browse files
fix: validation error messages and update hot tier (#874)
1. fetch used size from existing hot tier while updating the hot tier 2. refine the error messages for validation failures in hot tier
1 parent a570127 commit 9c187e8

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

server/src/handlers/http/logstream.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use crate::handlers::{
3030
use crate::hottier::{HotTierManager, StreamHotTier};
3131
use crate::metadata::STREAM_INFO;
3232
use crate::metrics::{EVENTS_INGESTED_DATE, EVENTS_INGESTED_SIZE_DATE, EVENTS_STORAGE_SIZE_DATE};
33+
use crate::option::validation::bytes_to_human_size;
3334
use crate::option::{Mode, CONFIG};
3435
use crate::static_schema::{convert_static_schema_to_arrow_schema, StaticSchema};
3536
use crate::stats::{event_labels_date, storage_size_labels_date, Stats};
@@ -960,10 +961,10 @@ pub async fn put_stream_hot_tier(
960961

961962
STREAM_INFO.set_hot_tier(&stream_name, true)?;
962963
if let Some(hot_tier_manager) = HotTierManager::global() {
963-
hot_tier_manager
964+
let existing_hot_tier_used_size = hot_tier_manager
964965
.validate_hot_tier_size(&stream_name, &hottier.size)
965966
.await?;
966-
hottier.used_size = Some("0GiB".to_string());
967+
hottier.used_size = Some(bytes_to_human_size(existing_hot_tier_used_size));
967968
hottier.available_size = Some(hottier.size.clone());
968969
hot_tier_manager
969970
.put_hot_tier(&stream_name, &mut hottier)

server/src/hottier.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,18 @@ impl HotTierManager {
111111
&self,
112112
stream: &str,
113113
size: &str,
114-
) -> Result<(), HotTierError> {
114+
) -> Result<u64, HotTierError> {
115115
let mut existing_hot_tier_used_size = 0;
116+
let mut existing_hot_tier_size = 0;
116117
if self.check_stream_hot_tier_exists(stream) {
117118
//delete existing hot tier if its size is less than the updated hot tier size else return error
118119
let existing_hot_tier = self.get_hot_tier(stream).await?;
119120
existing_hot_tier_used_size =
120121
human_size_to_bytes(&existing_hot_tier.used_size.unwrap()).unwrap();
122+
existing_hot_tier_size = human_size_to_bytes(&existing_hot_tier.size).unwrap();
121123
if human_size_to_bytes(size) < human_size_to_bytes(&existing_hot_tier.size) {
122124
return Err(HotTierError::ObjectStorageError(ObjectStorageError::Custom(format!(
123-
"The hot tier size for the stream is already set to {} which is greater than the updated hot tier size of {}, reducing the hot tier size is not allowed",
125+
"Reducing hot tier size is not supported, failed to reduce the hot tier size from {} to {}",
124126
existing_hot_tier.size,
125127
size
126128
))));
@@ -129,7 +131,7 @@ impl HotTierManager {
129131

130132
let (total_disk_space, available_disk_space, used_disk_space) = get_disk_usage();
131133

132-
if let (Some(total_disk_space), Some(available_disk_space), Some(used_disk_space)) =
134+
if let (Some(total_disk_space), _, Some(used_disk_space)) =
133135
(total_disk_space, available_disk_space, used_disk_space)
134136
{
135137
let stream_hot_tier_size = human_size_to_bytes(size).unwrap();
@@ -140,20 +142,19 @@ impl HotTierManager {
140142
- total_hot_tier_used_size;
141143
let usage_percentage =
142144
((projected_disk_usage as f64 / total_disk_space as f64) * 100.0).round();
145+
let max_allowed_hot_tier_size =
146+
((CONFIG.parseable.max_disk_usage * total_disk_space as f64) / 100.0)
147+
- (used_disk_space + total_hot_tier_used_size + existing_hot_tier_used_size
148+
- existing_hot_tier_size) as f64;
149+
143150
if usage_percentage > CONFIG.parseable.max_disk_usage {
144151
return Err(HotTierError::ObjectStorageError(ObjectStorageError::Custom(format!(
145-
"Including the hot tier size of all the streams, the projected disk usage will be {}% which is above the set threshold of {}%, hence unable to set the hot tier for the stream. Total Disk Size: {}, Available Disk Size: {}, Used Disk Size: {}, Total Hot Tier Size (all other streams): {}",
146-
usage_percentage,
147-
CONFIG.parseable.max_disk_usage,
148-
bytes_to_human_size(total_disk_space),
149-
bytes_to_human_size(available_disk_space),
150-
bytes_to_human_size(used_disk_space),
151-
bytes_to_human_size(total_hot_tier_size)
152+
"{} is the total usable disk space for hot tier, cannot set a bigger value.", max_allowed_hot_tier_size
152153
))));
153154
}
154155
}
155156

156-
Ok(())
157+
Ok(existing_hot_tier_used_size)
157158
}
158159

159160
///get the hot tier metadata file for the stream

server/src/validator.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,7 @@ pub fn user_name(username: &str) -> Result<(), UsernameValidationError> {
150150

151151
pub fn hot_tier(size: &str) -> Result<(), HotTierValidationError> {
152152
if human_size_to_bytes(size).is_err() {
153-
return Err(HotTierValidationError::Size(bytes_to_human_size(
154-
MIN_STREAM_HOT_TIER_SIZE_BYTES,
155-
)));
153+
return Err(HotTierValidationError::InvalidFormat);
156154
}
157155

158156
if human_size_to_bytes(size).unwrap() < MIN_STREAM_HOT_TIER_SIZE_BYTES {
@@ -213,7 +211,10 @@ pub mod error {
213211

214212
#[derive(Debug, thiserror::Error)]
215213
pub enum HotTierValidationError {
216-
#[error("Invalid size given for hot tier, please provide size in human readable format, e.g 1GiB, 2GiB, minimum {0}")]
214+
#[error("Please provide size in human readable format, e.g 10GiB, 20GiB")]
215+
InvalidFormat,
216+
217+
#[error("Stream should have atleast {0} size")]
217218
Size(String),
218219

219220
#[error("While generating times for 'now' failed to parse duration")]

0 commit comments

Comments
 (0)