@@ -288,6 +288,63 @@ TEST_F(FSFileCacheLeakCleanerTest, remove_orphan_and_tmp_files) {
288288 fs::remove_all (dir, ec);
289289}
290290
291+ TEST_F (FSFileCacheLeakCleanerTest, remove_cleans_empty_v2_and_v3_key_directories) {
292+ auto dir = prepare_test_dir ();
293+ FileCacheSettings settings = default_settings ();
294+ BlockFileCache mgr (dir.string (), settings);
295+ FSFileCacheStorage storage;
296+ setup_storage (storage, mgr, dir);
297+
298+ FileCacheKey key;
299+ key.hash = BlockFileCache::hash (" remove_empty_v3_dir" );
300+ key.offset = 0 ;
301+ key.meta .expiration_time = 123456789 ;
302+ key.meta .type = FileCacheType::NORMAL ;
303+ key.meta .tablet_id = 0 ;
304+
305+ auto key_dir = storage.get_path_in_local_cache_v3 (key.hash );
306+ auto block_path = FSFileCacheStorage::get_path_in_local_cache_v3 (key_dir, key.offset );
307+ auto old_key_dir = storage.get_path_in_local_cache_v2 (key.hash , key.meta .expiration_time );
308+ auto old_block_path =
309+ FSFileCacheStorage::get_path_in_local_cache_v2 (old_key_dir, key.offset , key.meta .type );
310+ create_regular_file (block_path, ' r' );
311+ create_regular_file (old_block_path, ' o' );
312+
313+ ASSERT_TRUE (storage.remove (key).ok ());
314+
315+ EXPECT_FALSE (fs::exists (block_path));
316+ EXPECT_FALSE (fs::exists (key_dir));
317+ EXPECT_FALSE (fs::exists (old_block_path));
318+ EXPECT_FALSE (fs::exists (old_key_dir));
319+ }
320+
321+ TEST_F (FSFileCacheLeakCleanerTest, remove_v3_block_when_v2_directory_missing) {
322+ auto dir = prepare_test_dir ();
323+ FileCacheSettings settings = default_settings ();
324+ BlockFileCache mgr (dir.string (), settings);
325+ FSFileCacheStorage storage;
326+ setup_storage (storage, mgr, dir);
327+
328+ FileCacheKey key;
329+ key.hash = BlockFileCache::hash (" remove_v3_without_v2_dir" );
330+ key.offset = 0 ;
331+ key.meta .expiration_time = 123456789 ;
332+ key.meta .type = FileCacheType::NORMAL ;
333+ key.meta .tablet_id = 0 ;
334+
335+ auto key_dir = storage.get_path_in_local_cache_v3 (key.hash );
336+ auto block_path = FSFileCacheStorage::get_path_in_local_cache_v3 (key_dir, key.offset );
337+ auto old_key_dir = storage.get_path_in_local_cache_v2 (key.hash , key.meta .expiration_time );
338+ create_regular_file (block_path, ' r' );
339+ ASSERT_FALSE (fs::exists (old_key_dir));
340+
341+ ASSERT_TRUE (storage.remove (key).ok ());
342+
343+ EXPECT_FALSE (fs::exists (block_path));
344+ EXPECT_FALSE (fs::exists (key_dir));
345+ EXPECT_FALSE (fs::exists (old_key_dir));
346+ }
347+
291348TEST_F (FSFileCacheLeakCleanerTest, snapshot_metadata_for_hash_offsets_handles_missing_hash) {
292349 auto dir = prepare_test_dir ();
293350 FileCacheSettings settings = default_settings ();
0 commit comments