This commit is contained in:
Guillaume Tassery 2020-03-12 13:09:15 +01:00
parent 245d90a894
commit 88a5dd3049
3 changed files with 12 additions and 8 deletions

View File

@ -14,7 +14,7 @@ namespace CurrentStatusInfo
constexpr Metric END = __COUNTER__;
std::mutex locks[END] {};
std::unordered_map<String, String> values[END] {};
std::unordered_map<String, Int8> values[END] {};
const char * getName(Metric event)

View File

@ -11,24 +11,19 @@
namespace CurrentStatusInfo
{
/// Metric identifier (index in array).
using Metric = size_t;
using Key = std::string;
/// Get name of metric by identifier. Returns statically allocated string.
const char * getName(Metric event);
/// Get text description of metric by identifier. Returns statically allocated string.
const char * getDocumentation(Metric event);
const std::vector<std::pair<String, Int8>> & getAllPossibleValues(Metric event);
extern std::unordered_map<String, String> values[];
extern std::unordered_map<String, Int8> values[];
extern std::mutex locks[];
/// Get index just after last metric identifier.
Metric end();
/// Set status of specified.
inline void set(Metric metric, Key key, String value)
inline void set(Metric metric, Key key, Int8 value)
{
std::lock_guard<std::mutex> lock(locks[metric]);
values[metric][key] = value;

View File

@ -1,4 +1,5 @@
#include <Databases/DatabaseWithDictionaries.h>
#include <Common/CurrentStatusInfo.h>
#include <Interpreters/ExternalDictionariesLoader.h>
#include <Interpreters/ExternalLoaderTempConfigRepository.h>
#include <Interpreters/ExternalLoaderDatabaseConfigRepository.h>
@ -10,6 +11,11 @@
#include <ext/scope_guard.h>
namespace CurrentStatusInfo
{
extern const Metric DictionaryStatus;
}
namespace DB
{
@ -31,6 +37,7 @@ void DatabaseWithDictionaries::attachDictionary(const String & dictionary_name,
throw Exception("Dictionary " + full_name + " already exists.", ErrorCodes::DICTIONARY_ALREADY_EXISTS);
}
CurrentStatusInfo::set(CurrentStatusInfo::DictionaryStatus, full_name, static_cast<Int8>(ExternalLoader::Status::NOT_LOADED));
/// ExternalLoader::reloadConfig() will find out that the dictionary's config has been added
/// and in case `dictionaries_lazy_load == false` it will load the dictionary.
const auto & external_loader = context.getExternalDictionariesLoader();
@ -48,6 +55,7 @@ void DatabaseWithDictionaries::detachDictionary(const String & dictionary_name,
dictionaries.erase(it);
}
CurrentStatusInfo::unset(CurrentStatusInfo::DictionaryStatus, full_name);
/// ExternalLoader::reloadConfig() will find out that the dictionary's config has been removed
/// and therefore it will unload the dictionary.
const auto & external_loader = context.getExternalDictionariesLoader();
@ -146,6 +154,7 @@ void DatabaseWithDictionaries::removeDictionary(const Context & context, const S
try
{
Poco::File(dictionary_metadata_path).remove();
CurrentStatusInfo::unset(CurrentStatusInfo::DictionaryStatus, getDatabaseName() + "." + dictionary_name);
}
catch (...)
{