| 444 | } |
| 445 | |
| 446 | void FileCache::initializeImpl(bool load_metadata) |
| 447 | { |
| 448 | std::lock_guard lock(init_mutex); |
| 449 | |
| 450 | if (is_initialized) |
| 451 | return; |
| 452 | |
| 453 | try |
| 454 | { |
| 455 | /// Publish the invalidate notifier before loadMetadata spawns threads that can invalidate entries. |
| 456 | main_priority->startup(Context::getGlobalContextInstance()->getSchedulePool(), cache_guard); |
| 457 | |
| 458 | if (load_metadata) |
| 459 | loadMetadata(); |
| 460 | |
| 461 | metadata.startup(); |
| 462 | } |
| 463 | catch (...) |
| 464 | { |
| 465 | /// startup() may have scheduled the background cleanup task; stop it so a retried |
| 466 | /// initialization does not leave an orphaned task rescheduling on `this`. |
| 467 | main_priority->deactivateBackgroundOperations(); |
| 468 | init_exception = std::current_exception(); |
| 469 | tryLogCurrentException(__PRETTY_FUNCTION__); |
| 470 | throw; |
| 471 | } |
| 472 | |
| 473 | if (keep_current_size_to_max_ratio != 1 || keep_current_elements_to_max_ratio != 1) |
| 474 | { |
| 475 | keep_up_free_space_ratio_task = Context::getGlobalContextInstance()->getSchedulePool().createTask(StorageID::createEmpty(), log->name(), [this] { freeSpaceRatioKeepingThreadFunc(); }); |
| 476 | keep_up_free_space_ratio_task->schedule(); |
| 477 | } |
| 478 | |
| 479 | is_initialized = true; |
| 480 | LOG_TEST(log, "Initialized cache from {}", metadata.getBaseDirectory()); |
| 481 | } |
| 482 | |
| 483 | CachePriorityGuard::WriteLock FileCache::lockCache() const |
| 484 | { |
nothing calls this directly
no test coverage detected