@@ -113,13 +113,11 @@ impl HotTierManager {
113113 size : & str ,
114114 ) -> Result < u64 , HotTierError > {
115115 let mut existing_hot_tier_used_size = 0 ;
116- let mut existing_hot_tier_size = 0 ;
117116 if self . check_stream_hot_tier_exists ( stream) {
118117 //delete existing hot tier if its size is less than the updated hot tier size else return error
119118 let existing_hot_tier = self . get_hot_tier ( stream) . await ?;
120119 existing_hot_tier_used_size =
121120 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 ( ) ;
123121 if human_size_to_bytes ( size) < human_size_to_bytes ( & existing_hot_tier. size ) {
124122 return Err ( HotTierError :: ObjectStorageError ( ObjectStorageError :: Custom ( format ! (
125123 "Reducing hot tier size is not supported, failed to reduce the hot tier size from {} to {}" ,
@@ -137,19 +135,19 @@ impl HotTierManager {
137135 let stream_hot_tier_size = human_size_to_bytes ( size) . unwrap ( ) ;
138136 let ( total_hot_tier_size, total_hot_tier_used_size) =
139137 self . get_hot_tiers_size ( stream) . await ?;
140- let projected_disk_usage = total_hot_tier_size + stream_hot_tier_size + used_disk_space
141- - existing_hot_tier_used_size
142- - total_hot_tier_used_size ;
143- let usage_percentage =
144- ( ( 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-
150- if usage_percentage > CONFIG . parseable . max_disk_usage {
138+ let disk_threshold =
139+ ( CONFIG . parseable . max_disk_usage * total_disk_space as f64 ) / 100.0 ;
140+ let max_allowed_hot_tier_size = disk_threshold
141+ - total_hot_tier_size as f64
142+ - ( used_disk_space as f64
143+ - total_hot_tier_used_size as f64
144+ - existing_hot_tier_used_size as f64 ) ;
145+
146+ if stream_hot_tier_size as f64 > max_allowed_hot_tier_size {
147+ log :: error! ( "disk_threshold: {}, used_disk_space: {}, total_hot_tier_used_size: {}, existing_hot_tier_used_size: {}, total_hot_tier_size: {}" ,
148+ disk_threshold , used_disk_space , total_hot_tier_used_size , existing_hot_tier_used_size , total_hot_tier_size ) ;
151149 return Err ( HotTierError :: ObjectStorageError ( ObjectStorageError :: Custom ( format ! (
152- "{} is the total usable disk space for hot tier, cannot set a bigger value." , max_allowed_hot_tier_size
150+ "{} is the total usable disk space for hot tier, cannot set a bigger value." , bytes_to_human_size ( max_allowed_hot_tier_size as u64 )
153151 ) ) ) ) ;
154152 }
155153 }
0 commit comments