ClickHouse/src/Storages/NamedCollections.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

105 lines
2.5 KiB
C++
Raw Normal View History

#pragma once
#include <Interpreters/Context.h>
#include <Poco/Util/AbstractConfiguration.h>
namespace DB
{
class NamedCollection;
using NamedCollectionPtr = std::shared_ptr<const NamedCollection>;
/**
2022-11-10 18:58:07 +00:00
* Class to represent arbitrary-structured named collection object.
* It can be defined via config or via SQL command.
* <named_collections>
* <collection1>
* ...
* </collection1>
* ...
* </named_collections>
2022-11-10 18:58:07 +00:00
*/
class NamedCollection
{
private:
struct Impl;
using ImplPtr = std::unique_ptr<Impl>;
ImplPtr pimpl;
public:
using Key = std::string;
using Keys = std::set<Key>;
static NamedCollectionPtr create(
const Poco::Util::AbstractConfiguration & config,
const std::string & collection_name);
NamedCollection(
const Poco::Util::AbstractConfiguration & config,
const std::string & collection_path,
const Keys & keys);
explicit NamedCollection(ImplPtr pimpl_);
template <typename T> T get(const Key & key) const;
template <typename T> T getOrDefault(const Key & key, const T & default_value) const;
template <typename T> void set(const Key & key, const T & value);
NamedCollectionPtr duplicate() const;
Keys getKeys() const;
std::string dumpStructure() const;
};
/**
* A factory of immutable named collections.
*/
class NamedCollectionFactory : boost::noncopyable
{
public:
static NamedCollectionFactory & instance();
void initialize(const Poco::Util::AbstractConfiguration & server_config);
bool exists(const std::string & collection_name) const;
2022-11-10 18:58:07 +00:00
NamedCollectionPtr get(const std::string & collection_name) const;
2022-11-10 18:58:07 +00:00
NamedCollectionPtr tryGet(const std::string & collection_name) const;
void add(
const std::string & collection_name,
NamedCollectionPtr collection);
void remove(const std::string & collection_name);
using NamedCollections = std::unordered_map<std::string, NamedCollectionPtr>;
NamedCollections getAll() const;
private:
2022-11-10 18:58:07 +00:00
void assertInitialized(std::lock_guard<std::mutex> & lock) const;
NamedCollectionPtr getImpl(
const std::string & collection_name,
std::lock_guard<std::mutex> & lock) const;
bool existsUnlocked(
const std::string & collection_name,
std::lock_guard<std::mutex> & lock) const;
mutable NamedCollections named_collections;
/// FIXME: this will be invalid when config is reloaded
const Poco::Util::AbstractConfiguration * config;
bool is_initialized = false;
mutable std::mutex mutex;
};
}