Repository: ClickHouse/ClickHouse
File: src/Interpreters/Context.cpp (C++)

Code before:

    std::lock_guard lock(shared->mutex);
    if (shared->default_db_disk)
        return shared->default_db_disk;

    return shared->default_db_disk = target_db_disk;
}

String Context::getFilesystemCacheUser() const
{
    SharedLockGuard lock(shared->mutex);
    return shared->filesystem_cache_user;
}

DatabaseAndTable Context::getOrCacheStorage(const StorageID & id, std::function<DatabaseAndTable()> storage_getter, std::optional<Exception> * exception) const
{
    auto & shard = storage_cache.shards[StorageCache::shardIndex(id)];
    std::lock_guard lock(shard.m);

    if (auto it = shard.set.find(id); it != shard.set.end())
    {
        DatabaseAndTable storage = DatabaseCatalog::instance().tryGetByUUID(it->uuid);
        if (exception && !storage.second)
            exception->emplace(Exception(
                ErrorCodes::UNKNOWN_TABLE,
                "Table {} does not exist anymore - maybe it was dropped",
                id.getNameForLogs()));
        return storage;
    }

    auto storage = storage_getter();

    if (storage.second)
    {
        const auto & new_id = storage.second->getStorageID();
        if (new_id.hasUUID())
        {
            shard.set.insert(new_id);
        }
    }

    return storage;
}

std::unordered_map<Context::WarningType, PreformattedMessage> Context::getWarnings() const
{
    std::unordered_map<Context::WarningType, PreformattedMessage> common_warnings;
    {
        SharedLockGuard lock(shared->mutex);
        common_warnings = shared->warnings;


Review comment (suggestion):
Previously, we had a better error message here that suggested other table names in getTableImpl.

Code after:

    std::lock_guard lock(shared->mutex);
    if (shared->default_db_disk)
        return shared->default_db_disk;

    return shared->default_db_disk = target_db_disk;
}

String Context::getFilesystemCacheUser() const
{
    SharedLockGuard lock(shared->mutex);
    return shared->filesystem_cache_user;
}

DatabaseAndTable Context::getOrCacheStorage(const StorageID & id, std::function<DatabaseAndTable()> storage_getter, std::optional<Exception> * exception) const
{
    auto & shard = storage_cache.shards[StorageCache::shardIndex(id)];
    std::lock_guard lock(shard.mutex);

    if (auto it = shard.set.find(id); it != shard.set.end())
    {
        DatabaseAndTable storage = DatabaseCatalog::instance().tryGetByUUID(it->uuid);
        if (exception && !storage.second)
            exception->emplace(Exception(
                ErrorCodes::UNKNOWN_TABLE,
                "Table {} does not exist anymore - maybe it was dropped",
                id.getNameForLogs()));
        return storage;
    }

    auto storage = storage_getter();

    if (storage.second)
    {
        const auto & new_id = storage.second->getStorageID();
        if (new_id.hasUUID())
        {
            shard.set.insert(new_id);
        }
    }

    return storage;
}

std::unordered_map<Context::WarningType, PreformattedMessage> Context::getWarnings() const
{
    std::unordered_map<Context::WarningType, PreformattedMessage> common_warnings;
    {
        SharedLockGuard lock(shared->mutex);
        common_warnings = shared->warnings;