@@ -161,7 +161,8 @@ void set_tablet_access_time_ms(CloudTablet* tablet) {
161161Result<std::shared_ptr<CloudTablet>> CloudTabletMgr::get_tablet (int64_t tablet_id, bool warmup_data,
162162 bool sync_delete_bitmap,
163163 SyncRowsetStats* sync_stats,
164- bool force_use_only_cached) {
164+ bool force_use_only_cached,
165+ bool cache_on_miss) {
165166 // LRU value type. `Value`'s lifetime MUST NOT be longer than `CloudTabletMgr`
166167 class Value : public LRUCacheValueBase {
167168 public:
@@ -196,7 +197,7 @@ Result<std::shared_ptr<CloudTablet>> CloudTabletMgr::get_tablet(int64_t tablet_i
196197 if (sync_stats) {
197198 ++sync_stats->tablet_meta_cache_miss ;
198199 }
199- auto load_tablet = [this , &key, warmup_data, sync_delete_bitmap,
200+ auto load_tablet = [this , warmup_data, sync_delete_bitmap,
200201 sync_stats](int64_t tablet_id) -> Result<std::shared_ptr<CloudTablet>> {
201202 TabletMetaSharedPtr tablet_meta;
202203 auto start = std::chrono::steady_clock::now ();
@@ -212,7 +213,6 @@ Result<std::shared_ptr<CloudTablet>> CloudTabletMgr::get_tablet(int64_t tablet_i
212213 }
213214
214215 auto tablet = std::make_shared<CloudTablet>(_engine, std::move (tablet_meta));
215- auto value = std::make_unique<Value>(tablet, *_tablet_map);
216216 // MUST sync stats to let compaction scheduler work correctly
217217 SyncOptions options;
218218 options.warmup_delta_data = warmup_data;
@@ -222,16 +222,7 @@ Result<std::shared_ptr<CloudTablet>> CloudTabletMgr::get_tablet(int64_t tablet_i
222222 LOG (WARNING ) << " failed to sync tablet " << tablet_id << " : " << st;
223223 return ResultError (st);
224224 }
225-
226- auto * handle = _cache->insert (key, value.release (), 1 , sizeof (CloudTablet),
227- CachePriority::NORMAL );
228- auto ret =
229- std::shared_ptr<CloudTablet>(tablet.get (), [this , handle](CloudTablet* tablet) {
230- set_tablet_access_time_ms (tablet);
231- _cache->release (handle);
232- });
233- _tablet_map->put (std::move (tablet));
234- return ret;
225+ return tablet;
235226 };
236227
237228 auto load_result = s_singleflight_load_tablet.load (tablet_id, std::move (load_tablet));
@@ -240,8 +231,22 @@ Result<std::shared_ptr<CloudTablet>> CloudTabletMgr::get_tablet(int64_t tablet_i
240231 load_result.error ()));
241232 }
242233 auto tablet = load_result.value ();
243- set_tablet_access_time_ms (tablet.get ());
244- return tablet;
234+ if (!cache_on_miss) {
235+ set_tablet_access_time_ms (tablet.get ());
236+ return tablet;
237+ }
238+
239+ auto value = std::make_unique<Value>(tablet, *_tablet_map);
240+ auto * insert_handle =
241+ _cache->insert (key, value.release (), 1 , sizeof (CloudTablet), CachePriority::NORMAL );
242+ auto ret = std::shared_ptr<CloudTablet>(tablet.get (),
243+ [this , insert_handle](CloudTablet* tablet_ptr) {
244+ set_tablet_access_time_ms (tablet_ptr);
245+ _cache->release (insert_handle);
246+ });
247+ _tablet_map->put (std::move (tablet));
248+ set_tablet_access_time_ms (ret.get ());
249+ return ret;
245250 }
246251 if (sync_stats) {
247252 ++sync_stats->tablet_meta_cache_hit ;
@@ -255,6 +260,18 @@ Result<std::shared_ptr<CloudTablet>> CloudTabletMgr::get_tablet(int64_t tablet_i
255260 return tablet;
256261}
257262
263+ bool CloudTabletMgr::peek_tablet_meta (int64_t tablet_id, TabletMetaSharedPtr* tablet_meta) {
264+ if (tablet_meta == nullptr ) {
265+ return false ;
266+ }
267+ auto tablet = _tablet_map->get (tablet_id);
268+ if (!tablet) {
269+ return false ;
270+ }
271+ *tablet_meta = tablet->tablet_meta ();
272+ return true ;
273+ }
274+
258275void CloudTabletMgr::erase_tablet (int64_t tablet_id) {
259276 auto tablet_id_str = std::to_string (tablet_id);
260277 CacheKey key (tablet_id_str.data (), tablet_id_str.size ());
0 commit comments