2017-10-06 11:10:01 +00:00
|
|
|
#pragma once
|
2017-12-04 12:15:21 +00:00
|
|
|
|
2017-10-06 10:31:06 +00:00
|
|
|
#include <string>
|
|
|
|
#include <memory>
|
2019-01-19 23:27:52 +00:00
|
|
|
#include <boost/noncopyable.hpp>
|
2019-08-30 09:50:38 +00:00
|
|
|
#include <pcg_random.hpp>
|
2020-09-15 09:55:57 +00:00
|
|
|
#include <common/types.h>
|
2017-10-06 10:31:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace Poco::Util
|
|
|
|
{
|
2017-10-06 11:10:01 +00:00
|
|
|
class AbstractConfiguration;
|
2017-10-06 10:31:06 +00:00
|
|
|
}
|
|
|
|
|
2017-10-06 11:10:01 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-10-06 10:31:06 +00:00
|
|
|
/// Min and max lifetimes for a loadable object or it's entry
|
2019-06-02 12:11:01 +00:00
|
|
|
struct ExternalLoadableLifetime
|
2017-10-06 10:31:06 +00:00
|
|
|
{
|
2020-05-05 23:43:06 +00:00
|
|
|
UInt64 min_sec = 0;
|
|
|
|
UInt64 max_sec = 0;
|
2017-10-06 10:31:06 +00:00
|
|
|
|
|
|
|
ExternalLoadableLifetime(const Poco::Util::AbstractConfiguration & config, const std::string & config_prefix);
|
2020-05-05 23:43:06 +00:00
|
|
|
ExternalLoadableLifetime() {}
|
2017-10-06 10:31:06 +00:00
|
|
|
};
|
|
|
|
|
2019-09-26 10:08:38 +00:00
|
|
|
/// Get delay before trying to load again after error.
|
|
|
|
UInt64 calculateDurationWithBackoff(pcg64 & rnd_engine, size_t error_count = 1);
|
2019-08-30 09:50:38 +00:00
|
|
|
|
2017-10-26 18:30:28 +00:00
|
|
|
/// Basic interface for external loadable objects. Is used in ExternalLoader.
|
2019-01-19 23:27:52 +00:00
|
|
|
class IExternalLoadable : public std::enable_shared_from_this<IExternalLoadable>, private boost::noncopyable
|
2017-10-06 10:31:06 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~IExternalLoadable() = default;
|
|
|
|
|
|
|
|
virtual const ExternalLoadableLifetime & getLifetime() const = 0;
|
|
|
|
|
2019-12-25 23:12:12 +00:00
|
|
|
virtual const std::string & getLoadableName() const = 0;
|
2017-10-26 18:30:28 +00:00
|
|
|
/// True if object can be updated when lifetime exceeded.
|
2017-10-06 10:31:06 +00:00
|
|
|
virtual bool supportUpdates() const = 0;
|
2019-03-04 18:19:48 +00:00
|
|
|
/// If lifetime exceeded and isModified(), ExternalLoader replace current object with the result of clone().
|
2017-10-06 10:31:06 +00:00
|
|
|
virtual bool isModified() const = 0;
|
2017-10-26 18:30:28 +00:00
|
|
|
/// Returns new object with the same configuration. Is used to update modified object when lifetime exceeded.
|
2019-06-02 12:11:01 +00:00
|
|
|
virtual std::shared_ptr<const IExternalLoadable> clone() const = 0;
|
2017-10-06 10:31:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|