@@ -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,15 @@ 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 ( ) ;
138+
145139 let max_allowed_hot_tier_size =
146140 ( ( 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 ;
141+ - ( ( used_disk_space - total_hot_tier_used_size - existing_hot_tier_used_size)
142+ - total_hot_tier_size ) as f64 ;
149143
150- if usage_percentage > CONFIG . parseable . max_disk_usage {
144+ if stream_hot_tier_size > max_allowed_hot_tier_size as u64 {
151145 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
146+ "{} 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 )
153147 ) ) ) ) ;
154148 }
155149 }
0 commit comments