mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 16:42:05 +00:00
fac1be9700
- This commit restores statements "SYSTEM RELOAD MODEL(S)" which provide a mechanism to update a model explicitly. It also saves potentially unnecessary reloads of a model from disk after it's initial load. To keep the complexity low, the semantics of "SYSTEM RELOAD MODEL(S) was changed from eager to lazy. This means that both statements previously immedately reloaded the specified/all models, whereas now the statements only trigger an unload and the first call to catboostEvaluate() does the actual load. - Monitoring view SYSTEM.MODELS is also restored but with some obsolete fields removed. The view was not documented in the past and for now it remains undocumented. The commit is thus not considered a breach of ClickHouse's public interface.
76 lines
2.2 KiB
C++
76 lines
2.2 KiB
C++
#include "CatBoostLibraryHandlerFactory.h"
|
|
|
|
#include <Common/logger_useful.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
|
|
CatBoostLibraryHandlerFactory & CatBoostLibraryHandlerFactory::instance()
|
|
{
|
|
static CatBoostLibraryHandlerFactory instance;
|
|
return instance;
|
|
}
|
|
|
|
CatBoostLibraryHandlerPtr CatBoostLibraryHandlerFactory::getOrCreateModel(const String & model_path, const String & library_path, bool create_if_not_found)
|
|
{
|
|
std::lock_guard lock(mutex);
|
|
|
|
auto handler = library_handlers.find(model_path);
|
|
bool found = (handler != library_handlers.end());
|
|
|
|
if (found)
|
|
return handler->second;
|
|
else
|
|
{
|
|
if (create_if_not_found)
|
|
{
|
|
auto new_handler = std::make_shared<CatBoostLibraryHandler>(library_path, model_path);
|
|
library_handlers.emplace(std::make_pair(model_path, new_handler));
|
|
LOG_DEBUG(&Poco::Logger::get("CatBoostLibraryHandlerFactory"), "Loaded catboost library handler for model path '{}'", model_path);
|
|
return new_handler;
|
|
}
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
void CatBoostLibraryHandlerFactory::removeModel(const String & model_path)
|
|
{
|
|
std::lock_guard lock(mutex);
|
|
|
|
bool deleted = library_handlers.erase(model_path);
|
|
if (!deleted)
|
|
{
|
|
LOG_DEBUG(&Poco::Logger::get("CatBoostLibraryHandlerFactory"), "Cannot unload catboost library handler for model path '{}'", model_path);
|
|
return;
|
|
}
|
|
LOG_DEBUG(&Poco::Logger::get("CatBoostLibraryHandlerFactory"), "Unloaded catboost library handler for model path '{}'", model_path);
|
|
}
|
|
|
|
void CatBoostLibraryHandlerFactory::removeAllModels()
|
|
{
|
|
std::lock_guard lock(mutex);
|
|
library_handlers.clear();
|
|
LOG_DEBUG(&Poco::Logger::get("CatBoostLibraryHandlerFactory"), "Unloaded all catboost library handlers");
|
|
}
|
|
|
|
ExternalModelInfos CatBoostLibraryHandlerFactory::getModelInfos()
|
|
{
|
|
std::lock_guard lock(mutex);
|
|
|
|
ExternalModelInfos result;
|
|
|
|
for (const auto & handler : library_handlers)
|
|
result.push_back({
|
|
.model_path = handler.first,
|
|
.model_type = "catboost",
|
|
.loading_start_time = handler.second->getLoadingStartTime(),
|
|
.loading_duration = handler.second->getLoadingDuration()
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|