diff --git a/be/src/service/staros_worker.cpp b/be/src/service/staros_worker.cpp index 7d519fab4424b1..fff5932835ed9f 100644 --- a/be/src/service/staros_worker.cpp +++ b/be/src/service/staros_worker.cpp @@ -221,9 +221,15 @@ absl::StatusOr> StarOSWorker::get_shard_files return build_filesystem_on_demand(id, conf); } - auto fs = lookup_fs_cache(it->second.fs_cache_key); - if (fs != nullptr) { - return fs; + // Cache miss: reset the fs_cache_key to ensure a new shared_ptr will be created + { + std::lock_guard reset_lock(_fs_cache_key_reset_mtx); + auto fs = lookup_fs_cache(it->second.fs_cache_key); + if (fs != nullptr) { + return fs; + } + + it->second.fs_cache_key.reset(); } shard_info = it->second.shard_info; } diff --git a/be/src/service/staros_worker.h b/be/src/service/staros_worker.h index 497916c5a1a542..06eca3bc2c42a5 100644 --- a/be/src/service/staros_worker.h +++ b/be/src/service/staros_worker.h @@ -138,6 +138,7 @@ class StarOSWorker : public staros::starlet::Worker { private: mutable std::shared_mutex _mtx; std::shared_mutex _cache_mtx; + std::mutex _fs_cache_key_reset_mtx; // Protects fs_cache_key reset operations std::unordered_map _shards; std::unique_ptr _fs_cache; add_shard_listener _add_shard_listener;