@@ -27,9 +27,9 @@ use crate::{
27
27
catalog:: manifest:: { File , Manifest } ,
28
28
handlers:: http:: cluster:: INTERNAL_STREAM_NAME ,
29
29
metadata:: { error:: stream_info:: MetadataError , STREAM_INFO } ,
30
- option:: { validation :: bytes_to_human_size , CONFIG } ,
30
+ option:: CONFIG ,
31
31
storage:: { ObjectStorage , ObjectStorageError } ,
32
- utils:: extract_datetime,
32
+ utils:: { extract_datetime, human_size :: bytes_to_human_size } ,
33
33
validator:: error:: HotTierValidationError ,
34
34
} ;
35
35
use chrono:: NaiveDate ;
@@ -56,10 +56,12 @@ pub const CURRENT_HOT_TIER_VERSION: &str = "v2";
56
56
#[ derive( Debug , serde:: Deserialize , serde:: Serialize ) ]
57
57
pub struct StreamHotTier {
58
58
pub version : Option < String > ,
59
- pub size : String ,
60
- pub used_size : String ,
61
- pub available_size : String ,
62
- #[ serde( skip_serializing_if = "Option::is_none" ) ]
59
+ #[ serde( with = "crate::utils::human_size" ) ]
60
+ pub size : u64 ,
61
+ #[ serde( with = "crate::utils::human_size" ) ]
62
+ pub used_size : u64 ,
63
+ #[ serde( with = "crate::utils::human_size" ) ]
64
+ pub available_size : u64 ,
63
65
pub oldest_date_time_entry : Option < String > ,
64
66
}
65
67
@@ -97,8 +99,8 @@ impl HotTierManager {
97
99
for stream in STREAM_INFO . list_streams ( ) {
98
100
if self . check_stream_hot_tier_exists ( & stream) && stream != current_stream {
99
101
let stream_hot_tier = self . get_hot_tier ( & stream) . await ?;
100
- total_hot_tier_size += & stream_hot_tier. size . parse :: < u64 > ( ) . unwrap ( ) ;
101
- total_hot_tier_used_size += stream_hot_tier. used_size . parse :: < u64 > ( ) . unwrap ( ) ;
102
+ total_hot_tier_size += & stream_hot_tier. size ;
103
+ total_hot_tier_used_size += stream_hot_tier. used_size ;
102
104
}
103
105
}
104
106
Ok ( ( total_hot_tier_size, total_hot_tier_used_size) )
@@ -111,14 +113,13 @@ impl HotTierManager {
111
113
pub async fn validate_hot_tier_size (
112
114
& self ,
113
115
stream : & str ,
114
- stream_hot_tier_size : & str ,
116
+ stream_hot_tier_size : u64 ,
115
117
) -> Result < u64 , HotTierError > {
116
- let stream_hot_tier_size = stream_hot_tier_size. parse :: < u64 > ( ) . unwrap ( ) ;
117
118
let mut existing_hot_tier_used_size = 0 ;
118
119
if self . check_stream_hot_tier_exists ( stream) {
119
120
//delete existing hot tier if its size is less than the updated hot tier size else return error
120
121
let existing_hot_tier = self . get_hot_tier ( stream) . await ?;
121
- existing_hot_tier_used_size = existing_hot_tier. used_size . parse :: < u64 > ( ) . unwrap ( ) ;
122
+ existing_hot_tier_used_size = existing_hot_tier. used_size ;
122
123
123
124
if stream_hot_tier_size < existing_hot_tier_used_size {
124
125
return Err ( HotTierError :: ObjectStorageError ( ObjectStorageError :: Custom ( format ! (
@@ -169,20 +170,17 @@ impl HotTierManager {
169
170
) ) ;
170
171
}
171
172
let path = hot_tier_file_path ( & self . hot_tier_path , stream) ?;
172
- let res = self
173
+ let bytes = self
173
174
. filesystem
174
175
. get ( & path)
175
176
. and_then ( |resp| resp. bytes ( ) )
176
- . await ;
177
- match res {
178
- Ok ( bytes) => {
179
- let mut stream_hot_tier: StreamHotTier = serde_json:: from_slice ( & bytes) ?;
180
- let oldest_date_time_entry = self . get_oldest_date_time_entry ( stream) . await ?;
181
- stream_hot_tier. oldest_date_time_entry = oldest_date_time_entry;
182
- Ok ( stream_hot_tier)
183
- }
184
- Err ( err) => Err ( err. into ( ) ) ,
185
- }
177
+ . await ?;
178
+
179
+ let mut stream_hot_tier: StreamHotTier = serde_json:: from_slice ( & bytes) ?;
180
+ let oldest_date_time_entry = self . get_oldest_date_time_entry ( stream) . await ?;
181
+ stream_hot_tier. oldest_date_time_entry = oldest_date_time_entry;
182
+
183
+ Ok ( stream_hot_tier)
186
184
}
187
185
188
186
pub async fn delete_hot_tier ( & self , stream : & str ) -> Result < ( ) , HotTierError > {
@@ -256,7 +254,7 @@ impl HotTierManager {
256
254
/// delete the files from the hot tier directory if the available date range is outside the hot tier range
257
255
async fn process_stream ( & self , stream : String ) -> Result < ( ) , HotTierError > {
258
256
let stream_hot_tier = self . get_hot_tier ( & stream) . await ?;
259
- let mut parquet_file_size = stream_hot_tier. used_size . parse :: < u64 > ( ) . unwrap ( ) ;
257
+ let mut parquet_file_size = stream_hot_tier. used_size ;
260
258
261
259
let object_store = CONFIG . storage ( ) . get_object_store ( ) ;
262
260
let mut s3_manifest_file_list = object_store. list_manifest_files ( & stream) . await ?;
@@ -348,7 +346,7 @@ impl HotTierManager {
348
346
let mut file_processed = false ;
349
347
let mut stream_hot_tier = self . get_hot_tier ( stream) . await ?;
350
348
if !self . is_disk_available ( parquet_file. file_size ) . await ?
351
- || stream_hot_tier. available_size . parse :: < u64 > ( ) . unwrap ( ) <= parquet_file. file_size
349
+ || stream_hot_tier. available_size <= parquet_file. file_size
352
350
{
353
351
if !self
354
352
. cleanup_hot_tier_old_data (
@@ -361,7 +359,7 @@ impl HotTierManager {
361
359
{
362
360
return Ok ( file_processed) ;
363
361
}
364
- * parquet_file_size = stream_hot_tier. used_size . parse :: < u64 > ( ) . unwrap ( ) ;
362
+ * parquet_file_size = stream_hot_tier. used_size ;
365
363
}
366
364
let parquet_file_path = RelativePathBuf :: from ( parquet_file. file_path . clone ( ) ) ;
367
365
fs:: create_dir_all ( parquet_path. parent ( ) . unwrap ( ) ) . await ?;
@@ -373,11 +371,9 @@ impl HotTierManager {
373
371
. await ?;
374
372
file. write_all ( & parquet_data) . await ?;
375
373
* parquet_file_size += parquet_file. file_size ;
376
- stream_hot_tier. used_size = parquet_file_size. to_string ( ) ;
374
+ stream_hot_tier. used_size = * parquet_file_size;
377
375
378
- stream_hot_tier. available_size = ( stream_hot_tier. available_size . parse :: < u64 > ( ) . unwrap ( )
379
- - parquet_file. file_size )
380
- . to_string ( ) ;
376
+ stream_hot_tier. available_size = stream_hot_tier. available_size - parquet_file. file_size ;
381
377
self . put_hot_tier ( stream, & mut stream_hot_tier) . await ?;
382
378
file_processed = true ;
383
379
let path = self . get_stream_path_for_date ( stream, & date) ;
@@ -598,18 +594,12 @@ impl HotTierManager {
598
594
fs:: remove_dir_all ( path_to_delete. parent ( ) . unwrap ( ) ) . await ?;
599
595
delete_empty_directory_hot_tier ( path_to_delete. parent ( ) . unwrap ( ) ) . await ?;
600
596
601
- stream_hot_tier. used_size =
602
- ( stream_hot_tier. used_size . parse :: < u64 > ( ) . unwrap ( ) - file_size)
603
- . to_string ( ) ;
604
- stream_hot_tier. available_size =
605
- ( stream_hot_tier. available_size . parse :: < u64 > ( ) . unwrap ( ) + file_size)
606
- . to_string ( ) ;
597
+ stream_hot_tier. used_size = stream_hot_tier. used_size - file_size;
598
+ stream_hot_tier. available_size = stream_hot_tier. available_size + file_size;
607
599
self . put_hot_tier ( stream, stream_hot_tier) . await ?;
608
600
delete_successful = true ;
609
601
610
- if stream_hot_tier. available_size . parse :: < u64 > ( ) . unwrap ( )
611
- <= parquet_file_size
612
- {
602
+ if stream_hot_tier. available_size <= parquet_file_size {
613
603
continue ' loop_files;
614
604
} else {
615
605
break ' loop_dates;
@@ -699,9 +689,9 @@ impl HotTierManager {
699
689
if !self . check_stream_hot_tier_exists ( INTERNAL_STREAM_NAME ) {
700
690
let mut stream_hot_tier = StreamHotTier {
701
691
version : Some ( CURRENT_HOT_TIER_VERSION . to_string ( ) ) ,
702
- size : INTERNAL_STREAM_HOT_TIER_SIZE_BYTES . to_string ( ) ,
703
- used_size : "0" . to_string ( ) ,
704
- available_size : INTERNAL_STREAM_HOT_TIER_SIZE_BYTES . to_string ( ) ,
692
+ size : INTERNAL_STREAM_HOT_TIER_SIZE_BYTES ,
693
+ used_size : 0 ,
694
+ available_size : INTERNAL_STREAM_HOT_TIER_SIZE_BYTES ,
705
695
oldest_date_time_entry : None ,
706
696
} ;
707
697
self . put_hot_tier ( INTERNAL_STREAM_NAME , & mut stream_hot_tier)
0 commit comments