@@ -21,6 +21,7 @@ use std::{io, path::PathBuf};
2121use fs_extra:: file:: CopyOptions ;
2222use futures_util:: TryFutureExt ;
2323use hashlru:: Cache ;
24+ use human_size:: { Byte , Gigibyte , SpecificSize } ;
2425use itertools:: { Either , Itertools } ;
2526use object_store:: { local:: LocalFileSystem , ObjectStore } ;
2627use once_cell:: sync:: OnceCell ;
@@ -30,6 +31,7 @@ use crate::option::CONFIG;
3031
3132pub const STREAM_CACHE_FILENAME : & str = ".cache.json" ;
3233pub const CACHE_META_FILENAME : & str = ".cache_meta.json" ;
34+ pub const CURRENT_CACHE_VERSION : & str = "v1" ;
3335
3436#[ derive( Debug , serde:: Deserialize , serde:: Serialize ) ]
3537pub struct LocalCache {
@@ -42,7 +44,7 @@ pub struct LocalCache {
4244impl LocalCache {
4345 fn new ( ) -> Self {
4446 Self {
45- version : "v1" . to_string ( ) ,
47+ version : CURRENT_CACHE_VERSION . to_string ( ) ,
4648 current_size : 0 ,
4749 files : Cache :: new ( 100 ) ,
4850 }
@@ -58,7 +60,7 @@ pub struct CacheMeta {
5860impl CacheMeta {
5961 fn new ( ) -> Self {
6062 Self {
61- version : "v1" . to_string ( ) ,
63+ version : CURRENT_CACHE_VERSION . to_string ( ) ,
6264 size_capacity : 0 ,
6365 }
6466 }
@@ -97,7 +99,8 @@ impl LocalCacheManager {
9799
98100 pub async fn validate ( & self , config_capacity : u64 ) -> Result < ( ) , CacheError > {
99101 fs:: create_dir_all ( & self . cache_path ) . await ?;
100- let path = cache_meta_path ( & self . cache_path ) . unwrap ( ) ;
102+ let path = cache_meta_path ( & self . cache_path )
103+ . map_err ( |err| CacheError :: ObjectStoreError ( err. into ( ) ) ) ?;
101104 let resp = self
102105 . filesystem
103106 . get ( & path)
@@ -107,7 +110,21 @@ impl LocalCacheManager {
107110 let updated_cache = match resp {
108111 Ok ( bytes) => {
109112 let mut meta: CacheMeta = serde_json:: from_slice ( & bytes) ?;
110- if !meta. size_capacity == config_capacity {
113+ if meta. size_capacity != config_capacity {
114+ // log the change in cache size
115+ let configured_size_human: SpecificSize < Gigibyte > =
116+ SpecificSize :: new ( config_capacity as f64 , Byte )
117+ . unwrap ( )
118+ . into ( ) ;
119+ let current_size_human: SpecificSize < Gigibyte > =
120+ SpecificSize :: new ( meta. size_capacity as f64 , Byte )
121+ . unwrap ( )
122+ . into ( ) ;
123+ log:: warn!(
124+ "Cache size is updated from {} to {}" ,
125+ current_size_human,
126+ configured_size_human
127+ ) ;
111128 meta. size_capacity = config_capacity;
112129 Some ( meta)
113130 } else {
@@ -123,10 +140,6 @@ impl LocalCacheManager {
123140 } ;
124141
125142 if let Some ( updated_cache) = updated_cache {
126- log:: info!(
127- "Cache is updated to new size of {} Bytes" ,
128- & updated_cache. size_capacity
129- ) ;
130143 self . filesystem
131144 . put ( & path, serde_json:: to_vec ( & updated_cache) ?. into ( ) )
132145 . await ?
0 commit comments