MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / getDatabaseDisk

Method getDatabaseDisk

src/Interpreters/Context.cpp:1452–1486  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1450}
1451
1452std::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
1488String Context::getFilesystemCacheUser() const
1489{

Callers 14

DatabaseOrdinaryMethod · 0.80
renameDatabaseMethod · 0.80
getDiskMethod · 0.80
createDatabaseMethod · 0.80
loadDatabaseFunction · 0.80
checkUnsupportedVersionFunction · 0.80
loadMetadataFunction · 0.80
loadSystemDatabaseImplFunction · 0.80

Calls 6

backQuoteFunction · 0.85
ExceptionClass · 0.70
getStringMethod · 0.45
findMethod · 0.45
endMethod · 0.45
getPathMethod · 0.45

Tested by

no test coverage detected