1 | #pragma once |
2 | |
3 | #include <string> |
4 | #include <memory> |
5 | #include <boost/noncopyable.hpp> |
6 | #include <pcg_random.hpp> |
7 | #include <Core/Types.h> |
8 | |
9 | |
10 | namespace Poco::Util |
11 | { |
12 | class AbstractConfiguration; |
13 | } |
14 | |
15 | |
16 | namespace DB |
17 | { |
18 | |
19 | /// Min and max lifetimes for a loadable object or it's entry |
20 | struct ExternalLoadableLifetime |
21 | { |
22 | UInt64 min_sec; |
23 | UInt64 max_sec; |
24 | |
25 | ExternalLoadableLifetime(const Poco::Util::AbstractConfiguration & config, const std::string & config_prefix); |
26 | }; |
27 | |
28 | /// Get delay before trying to load again after error. |
29 | UInt64 calculateDurationWithBackoff(pcg64 & rnd_engine, size_t error_count = 1); |
30 | |
31 | /// Basic interface for external loadable objects. Is used in ExternalLoader. |
32 | class IExternalLoadable : public std::enable_shared_from_this<IExternalLoadable>, private boost::noncopyable |
33 | { |
34 | public: |
35 | virtual ~IExternalLoadable() = default; |
36 | |
37 | virtual const ExternalLoadableLifetime & getLifetime() const = 0; |
38 | |
39 | virtual const std::string & getLoadableName() const = 0; |
40 | /// True if object can be updated when lifetime exceeded. |
41 | virtual bool supportUpdates() const = 0; |
42 | /// If lifetime exceeded and isModified(), ExternalLoader replace current object with the result of clone(). |
43 | virtual bool isModified() const = 0; |
44 | /// Returns new object with the same configuration. Is used to update modified object when lifetime exceeded. |
45 | virtual std::shared_ptr<const IExternalLoadable> clone() const = 0; |
46 | }; |
47 | |
48 | } |
49 | |