@@ -44,37 +44,32 @@ Status DataCache::init(const std::vector<StorePath>& store_paths) {
4444 _page_cache = std::make_shared<StoragePageCache>();
4545
4646#if defined(WITH_STARCACHE)
47- if (config::datacache_engine == " " || config::datacache_engine == " starcache" ) {
48- config::datacache_engine = " starcache" ;
49- } else {
50- config::datacache_engine = " lrucache" ;
51- }
52- #else
53- config::datacache_engine = " lrucache" ;
47+ _local_disk_cache_engine = " starcache" ;
5448#endif
49+ _local_mem_cache_engine = " lrucache" ;
5550
5651 if (!config::datacache_enable) {
5752 config::disable_storage_page_cache = true ;
5853 config::block_cache_enable = false ;
5954 return Status::OK ();
6055 }
6156
62- ASSIGN_OR_RETURN (auto cache_options, _init_cache_options ());
57+ ASSIGN_OR_RETURN (auto mem_cache_options, _init_mem_cache_options ());
6358
64- if (config::datacache_engine == " starcache" ) {
6559#if defined(WITH_STARCACHE)
66- RETURN_IF_ERROR ( _init_starcache_engine (&cache_options ));
67- RETURN_IF_ERROR (_init_peer_cache (cache_options ));
60+ ASSIGN_OR_RETURN ( auto disk_cache_options, _init_disk_cache_options ( ));
61+ RETURN_IF_ERROR (_init_starcache_engine (&disk_cache_options ));
6862
69- if (config::block_cache_enable) {
70- RETURN_IF_ERROR (_block_cache->init (cache_options, _local_cache, _remote_cache));
71- }
72- #else
73- return Status::InternalError (" starcache engine is not supported" );
74- #endif
75- } else {
76- RETURN_IF_ERROR (_init_lrucache_engine (cache_options));
63+ auto remote_cache_options = _init_remote_cache_options ();
64+ RETURN_IF_ERROR (_init_peer_cache (remote_cache_options));
65+
66+ if (config::block_cache_enable) {
67+ auto block_cache_options = _init_block_cache_options ();
68+ RETURN_IF_ERROR (_block_cache->init (block_cache_options, _local_disk_cache, _remote_cache));
7769 }
70+ #endif
71+
72+ RETURN_IF_ERROR (_init_lrucache_engine (mem_cache_options));
7873
7974 RETURN_IF_ERROR (_init_page_cache ());
8075
@@ -100,14 +95,15 @@ void DataCache::destroy() {
10095 LOG (INFO) << " pagecache shutdown successfully" ;
10196
10297 _block_cache.reset ();
103- _local_cache.reset ();
98+ _local_mem_cache.reset ();
99+ _local_disk_cache.reset ();
104100 _remote_cache.reset ();
105101 LOG (INFO) << " datacache shutdown successfully" ;
106102}
107103
108104bool DataCache::adjust_mem_capacity (int64_t delta, size_t min_capacity) {
109- if (_local_cache != nullptr ) {
110- Status st = _local_cache ->adjust_mem_quota (delta, min_capacity);
105+ if (_local_mem_cache != nullptr ) {
106+ Status st = _local_mem_cache ->adjust_mem_quota (delta, min_capacity);
111107 if (st.ok ()) {
112108 return true ;
113109 } else {
@@ -119,52 +115,67 @@ bool DataCache::adjust_mem_capacity(int64_t delta, size_t min_capacity) {
119115}
120116
121117size_t DataCache::get_mem_capacity () const {
122- if (_local_cache != nullptr ) {
123- return _local_cache ->mem_quota ();
118+ if (_local_mem_cache != nullptr ) {
119+ return _local_mem_cache ->mem_quota ();
124120 } else {
125121 return 0 ;
126122 }
127123}
128124
129- Status DataCache::_init_lrucache_engine (const CacheOptions & cache_options) {
130- _local_cache = std::make_shared<LRUCacheEngine>();
131- RETURN_IF_ERROR (_local_cache ->init (cache_options));
125+ Status DataCache::_init_lrucache_engine (const MemCacheOptions & cache_options) {
126+ _local_mem_cache = std::make_shared<LRUCacheEngine>();
127+ RETURN_IF_ERROR (reinterpret_cast <LRUCacheEngine*>(_local_mem_cache. get ()) ->init (cache_options));
132128 LOG (INFO) << " lrucache engine init successfully" ;
133129 return Status::OK ();
134130}
135131
136132Status DataCache::_init_page_cache () {
137- _page_cache->init (_local_cache .get ());
133+ _page_cache->init (_local_mem_cache .get ());
138134 _page_cache->init_metrics ();
139135 LOG (INFO) << " storage page cache init successfully" ;
140136 return Status::OK ();
141137}
142138
143139#if defined(WITH_STARCACHE)
144- Status DataCache::_init_starcache_engine (CacheOptions * cache_options) {
140+ Status DataCache::_init_starcache_engine (DiskCacheOptions * cache_options) {
145141 // init starcache & disk monitor
146142 // TODO: DiskSpaceMonitor needs to be decoupled from StarCacheEngine.
147- _local_cache = std::make_shared<StarCacheEngine>();
148- _disk_space_monitor = std::make_shared<DiskSpaceMonitor>(_local_cache .get ());
143+ _local_disk_cache = std::make_shared<StarCacheEngine>();
144+ _disk_space_monitor = std::make_shared<DiskSpaceMonitor>(_local_disk_cache .get ());
149145 RETURN_IF_ERROR (_disk_space_monitor->init (&cache_options->dir_spaces ));
150- RETURN_IF_ERROR (_local_cache ->init (*cache_options));
146+ RETURN_IF_ERROR (reinterpret_cast <StarCacheEngine*>(_local_disk_cache. get ()) ->init (*cache_options));
151147 _disk_space_monitor->start ();
152148 return Status::OK ();
153149}
154150
155- Status DataCache::_init_peer_cache (const CacheOptions & cache_options) {
151+ Status DataCache::_init_peer_cache (const RemoteCacheOptions & cache_options) {
156152 _remote_cache = std::make_shared<PeerCacheEngine>();
157153 return _remote_cache->init (cache_options);
158154}
159155#endif
160156
161- StatusOr<CacheOptions> DataCache::_init_cache_options () {
162- CacheOptions cache_options;
157+ RemoteCacheOptions DataCache::_init_remote_cache_options () {
158+ RemoteCacheOptions cache_options{.skip_read_factor = config::datacache_skip_read_factor};
159+ return cache_options;
160+ }
161+
162+ StatusOr<MemCacheOptions> DataCache::_init_mem_cache_options () {
163+ MemCacheOptions cache_options;
163164 RETURN_IF_ERROR (DataCacheUtils::parse_conf_datacache_mem_size (
164165 config::datacache_mem_size, _global_env->process_mem_limit (), &cache_options.mem_space_size ));
165- cache_options.engine = config::datacache_engine;
166+ return cache_options;
167+ }
168+
169+ BlockCacheOptions DataCache::_init_block_cache_options () {
170+ BlockCacheOptions cache_options;
171+ cache_options.block_size = config::datacache_block_size;
172+ return cache_options;
173+ }
174+
175+ StatusOr<DiskCacheOptions> DataCache::_init_disk_cache_options () {
176+ DiskCacheOptions cache_options;
166177
167- if (config::datacache_engine == " starcache" ) {
178+ if (_local_disk_cache_engine == " starcache" ) {
168179#ifdef USE_STAROS
169180 std::vector<string> corresponding_starlet_dirs;
170181 if (config::datacache_unified_instance_enable && !config::starlet_cache_dir.empty ()) {
@@ -276,8 +287,8 @@ void DataCache::try_release_resource_before_core_dump() {
276287 return release_all || modules.contains (name);
277288 };
278289
279- if (_local_cache != nullptr && need_release (" data_cache" )) {
280- (void )_local_cache ->update_mem_quota (0 , false );
290+ if (_local_mem_cache != nullptr && need_release (" data_cache" )) {
291+ (void )_local_mem_cache ->update_mem_quota (0 , false );
281292 }
282293}
283294
0 commit comments