Return getUpdateTime method to interface

This commit is contained in:
alesapin 2019-10-01 11:58:47 +03:00
parent 709783a1bc
commit 8429f46f3c
4 changed files with 13 additions and 22 deletions

View File

@ -84,6 +84,7 @@ public:
private: private:
struct LoadablesInfos struct LoadablesInfos
{ {
Poco::Timestamp last_update_time = 0;
std::vector<std::pair<String, ObjectConfig>> configs; // Parsed file's contents. std::vector<std::pair<String, ObjectConfig>> configs; // Parsed file's contents.
bool in_use = true; // Whether the ` LoadablesInfos` should be destroyed because the correspondent file is deleted. bool in_use = true; // Whether the ` LoadablesInfos` should be destroyed because the correspondent file is deleted.
}; };
@ -150,7 +151,10 @@ private:
return false; return false;
} }
if (!repository.isUpdated(path)) auto update_time_from_repository = repository.getUpdateTime(path);
/// Actually it can't be less, but for sure we check less or equal
if (update_time_from_repository <= loadable_info.last_update_time)
{ {
loadable_info.in_use = true; loadable_info.in_use = true;
return false; return false;
@ -184,6 +188,7 @@ private:
} }
loadable_info.configs = std::move(configs_from_file); loadable_info.configs = std::move(configs_from_file);
loadable_info.last_update_time = update_time_from_repository;
loadable_info.in_use = true; loadable_info.in_use = true;
return true; return true;
} }

View File

@ -12,18 +12,9 @@
namespace DB namespace DB
{ {
bool ExternalLoaderXMLConfigRepository::isUpdated(const std::string & definition_entity_name) Poco::Timestamp ExternalLoaderXMLConfigRepository::getUpdateTime(const std::string & definition_entity_name)
{ {
Poco::Timestamp last_modified = Poco::File(definition_entity_name).getLastModified(); return Poco::File(definition_entity_name).getLastModified();
auto itr = update_time_mapping.find(definition_entity_name);
if (itr == update_time_mapping.end() || last_modified > itr->second)
{
update_time_mapping[definition_entity_name] = last_modified;
return true;
}
return false;
} }
std::set<std::string> ExternalLoaderXMLConfigRepository::getAllLoadablesDefinitionNames() const std::set<std::string> ExternalLoaderXMLConfigRepository::getAllLoadablesDefinitionNames() const

View File

@ -26,18 +26,13 @@ public:
/// Checks that file with name exists on filesystem /// Checks that file with name exists on filesystem
bool exists(const std::string & definition_entity_name) const override; bool exists(const std::string & definition_entity_name) const override;
/// Checks that file was updated since last check /// Return xml-file modification time via stat call
bool isUpdated(const std::string & definition_entity_name) override; Poco::Timestamp getUpdateTime(const std::string & definition_entity_name) override;
/// May contain definition about several entities (several dictionaries in one .xml file) /// May contain definition about several entities (several dictionaries in one .xml file)
LoadablesConfigurationPtr load(const std::string & definition_entity_name) const override; LoadablesConfigurationPtr load(const std::string & definition_entity_name) const override;
private: private:
/// Simple map with last modification time with path -> timestamp,
/// modification time received by stat.
std::unordered_map<std::string, Poco::Timestamp> update_time_mapping;
/// Main server config (config.xml). /// Main server config (config.xml).
const Poco::Util::AbstractConfiguration & main_config; const Poco::Util::AbstractConfiguration & main_config;

View File

@ -2,6 +2,7 @@
#include <Poco/AutoPtr.h> #include <Poco/AutoPtr.h>
#include <Poco/Util/AbstractConfiguration.h> #include <Poco/Util/AbstractConfiguration.h>
#include <Poco/Timestamp.h>
#include <memory> #include <memory>
#include <string> #include <string>
@ -28,9 +29,8 @@ public:
/// Checks that source of loadables configuration exist. /// Checks that source of loadables configuration exist.
virtual bool exists(const std::string & loadable_definition_name) const = 0; virtual bool exists(const std::string & loadable_definition_name) const = 0;
/// Checks that entity was updated since last call of this method. /// Returns entity last update time
/// Assumes usage of some state and probably some mutex. virtual Poco::Timestamp getUpdateTime(const std::string & loadable_definition_name) = 0;
virtual bool isUpdated(const std::string & loadable_definition_name) = 0;
/// Load configuration from some concrete source to AbstractConfiguration /// Load configuration from some concrete source to AbstractConfiguration
virtual LoadablesConfigurationPtr load(const std::string & loadable_definition_name) const = 0; virtual LoadablesConfigurationPtr load(const std::string & loadable_definition_name) const = 0;