| 1450 | } |
| 1451 | |
| 1452 | std::shared_ptr<IDisk> Context::getDatabaseDisk() const |
| 1453 | { |
| 1454 | { |
| 1455 | SharedLockGuard lock(shared->mutex); |
| 1456 | if (shared->default_db_disk) |
| 1457 | return shared->default_db_disk; |
| 1458 | } |
| 1459 | |
| 1460 | // This is called first time early during the initialization. |
| 1461 | // Even if multiple threads try to get target_db_disk, only the first one will initialize the disks as there is another mutex in `getDiskMap()` |
| 1462 | // It is not necessary to introduce a mutex here. |
| 1463 | auto target_db_disk = [&]() -> std::shared_ptr<IDisk> |
| 1464 | { |
| 1465 | const auto & config = shared->getConfigRef(); |
| 1466 | const auto & disk_map = getDisksMap(); |
| 1467 | auto disk_name = config.getString("database_disk.disk", DiskSelector::DEFAULT_DISK_NAME); |
| 1468 | |
| 1469 | LOG_INFO(shared->log, "Database disk name: {}", disk_name); |
| 1470 | |
| 1471 | auto it = disk_map.find(disk_name); |
| 1472 | if (it == disk_map.end()) |
| 1473 | throw Exception(ErrorCodes::UNKNOWN_DISK, "No disk {}", backQuote(disk_name)); |
| 1474 | |
| 1475 | chassert(it->second); |
| 1476 | |
| 1477 | LOG_INFO(shared->log, "Database disk name: {}, path: {}", disk_name, it->second->getPath()); |
| 1478 | return it->second; |
| 1479 | }(); |
| 1480 | |
| 1481 | std::lock_guard lock(shared->mutex); |
| 1482 | if (shared->default_db_disk) |
| 1483 | return shared->default_db_disk; |
| 1484 | |
| 1485 | return shared->default_db_disk = target_db_disk; |
| 1486 | } |
| 1487 | |
| 1488 | String Context::getFilesystemCacheUser() const |
| 1489 | { |
no test coverage detected