Skip to content

Commit 535e48e

Browse files
committed
revert fix
1 parent 776316a commit 535e48e

1 file changed

Lines changed: 19 additions & 29 deletions

File tree

‎be/src/cloud/cloud_tablet_mgr.cpp‎

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -201,17 +201,8 @@ Result<std::shared_ptr<CloudTablet>> CloudTabletMgr::get_tablet(int64_t tablet_i
201201
if (sync_stats) {
202202
++sync_stats->tablet_meta_cache_miss;
203203
}
204-
// Insert into cache and tablet_map inside SingleFlight lambda to ensure
205-
// only the leader caller does this. Moving these outside the lambda causes
206-
// a race condition: when multiple concurrent callers share the same CloudTablet*
207-
// from SingleFlight, each creates a competing LRU cache entry. Delayed Value
208-
// destructors then erase the tablet_map entry (the raw pointer safety check
209-
// passes since all callers share the same pointer), and the tablet permanently
210-
// disappears from tablet_map. Subsequent get_tablet() calls hit the LRU cache
211-
// directly (cache hit path) which never re-inserts into tablet_map, making the
212-
// tablet invisible to the compaction scheduler.
213-
auto load_tablet = [this, &key, warmup_data, sync_delete_bitmap, sync_stats, cache_on_miss](
214-
int64_t tablet_id) -> Result<std::shared_ptr<CloudTablet>> {
204+
auto load_tablet = [this, warmup_data, sync_delete_bitmap,
205+
sync_stats](int64_t tablet_id) -> Result<std::shared_ptr<CloudTablet>> {
215206
TabletMetaSharedPtr tablet_meta;
216207
auto start = std::chrono::steady_clock::now();
217208
auto st = _engine.meta_mgr().get_tablet_meta(tablet_id, &tablet_meta);
@@ -235,22 +226,7 @@ Result<std::shared_ptr<CloudTablet>> CloudTabletMgr::get_tablet(int64_t tablet_i
235226
LOG(WARNING) << "failed to sync tablet " << tablet_id << ": " << st;
236227
return ResultError(st);
237228
}
238-
239-
if (!cache_on_miss) {
240-
set_tablet_access_time_ms(tablet.get());
241-
return tablet;
242-
}
243-
244-
auto value = std::make_unique<Value>(tablet, *_tablet_map);
245-
auto* insert_handle = _cache->insert(key, value.release(), 1, sizeof(CloudTablet),
246-
CachePriority::NORMAL);
247-
auto ret = std::shared_ptr<CloudTablet>(tablet.get(),
248-
[this, insert_handle](CloudTablet* tablet_ptr) {
249-
set_tablet_access_time_ms(tablet_ptr);
250-
_cache->release(insert_handle);
251-
});
252-
_tablet_map->put(std::move(tablet));
253-
return ret;
229+
return tablet;
254230
};
255231

256232
auto load_result = s_singleflight_load_tablet.load(tablet_id, std::move(load_tablet));
@@ -259,8 +235,22 @@ Result<std::shared_ptr<CloudTablet>> CloudTabletMgr::get_tablet(int64_t tablet_i
259235
load_result.error()));
260236
}
261237
auto tablet = load_result.value();
262-
set_tablet_access_time_ms(tablet.get());
263-
return tablet;
238+
if (!cache_on_miss) {
239+
set_tablet_access_time_ms(tablet.get());
240+
return tablet;
241+
}
242+
243+
auto value = std::make_unique<Value>(tablet, *_tablet_map);
244+
auto* insert_handle =
245+
_cache->insert(key, value.release(), 1, sizeof(CloudTablet), CachePriority::NORMAL);
246+
auto ret = std::shared_ptr<CloudTablet>(tablet.get(),
247+
[this, insert_handle](CloudTablet* tablet_ptr) {
248+
set_tablet_access_time_ms(tablet_ptr);
249+
_cache->release(insert_handle);
250+
});
251+
_tablet_map->put(std::move(tablet));
252+
set_tablet_access_time_ms(ret.get());
253+
return ret;
264254
}
265255
if (sync_stats) {
266256
++sync_stats->tablet_meta_cache_hit;

0 commit comments

Comments
 (0)