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__; constexpr Metric END = __COUNTER__;
std::mutex locks[END] {}; std::mutex locks[END] {};
std::unordered_map<String, String> values[END] {}; std::unordered_map<String, Int8> values[END] {};
const char * getName(Metric event) const char * getName(Metric event)

View File

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

View File

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