2011-08-09 19:19:25 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-03-11 14:01:45 +00:00
|
|
|
#include <Core/Block.h>
|
|
|
|
#include <Core/NamesAndTypes.h>
|
2019-05-17 14:34:25 +00:00
|
|
|
#include <Core/Settings.h>
|
2019-03-11 14:01:45 +00:00
|
|
|
#include <Core/Types.h>
|
2019-05-17 14:34:25 +00:00
|
|
|
#include <DataStreams/IBlockStream_fwd.h>
|
2019-03-11 14:01:45 +00:00
|
|
|
#include <Interpreters/ClientInfo.h>
|
|
|
|
#include <Parsers/IAST_fwd.h>
|
|
|
|
#include <Common/LRUCache.h>
|
|
|
|
#include <Common/MultiVersion.h>
|
|
|
|
#include <Common/ThreadPool.h>
|
2019-06-24 11:17:15 +00:00
|
|
|
#include "config_core.h"
|
2019-05-17 14:34:25 +00:00
|
|
|
#include <Storages/IStorage_fwd.h>
|
2019-03-11 14:01:45 +00:00
|
|
|
#include <atomic>
|
2017-06-02 18:48:33 +00:00
|
|
|
#include <chrono>
|
|
|
|
#include <condition_variable>
|
2015-04-16 06:12:35 +00:00
|
|
|
#include <functional>
|
|
|
|
#include <memory>
|
2017-06-02 18:48:33 +00:00
|
|
|
#include <mutex>
|
2018-11-07 11:46:39 +00:00
|
|
|
#include <optional>
|
2019-03-11 14:01:45 +00:00
|
|
|
#include <thread>
|
2015-04-16 06:12:35 +00:00
|
|
|
|
|
|
|
|
2017-01-21 04:24:28 +00:00
|
|
|
namespace Poco
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
namespace Net
|
|
|
|
{
|
|
|
|
class IPAddress;
|
|
|
|
}
|
2017-01-21 04:24:28 +00:00
|
|
|
}
|
2011-08-09 19:19:25 +00:00
|
|
|
|
2015-04-16 07:22:29 +00:00
|
|
|
namespace zkutil
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
class ZooKeeper;
|
2015-04-16 07:22:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-09 19:19:25 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2016-03-07 05:05:42 +00:00
|
|
|
struct ContextShared;
|
2018-06-01 15:32:27 +00:00
|
|
|
class Context;
|
2017-11-27 21:31:13 +00:00
|
|
|
class IRuntimeComponentsFactory;
|
2015-04-16 06:12:35 +00:00
|
|
|
class QuotaForIntervals;
|
2017-01-21 04:24:28 +00:00
|
|
|
class EmbeddedDictionaries;
|
2015-04-16 06:12:35 +00:00
|
|
|
class ExternalDictionaries;
|
2017-10-17 10:44:46 +00:00
|
|
|
class ExternalModels;
|
2015-04-16 06:12:35 +00:00
|
|
|
class InterserverIOHandler;
|
|
|
|
class BackgroundProcessingPool;
|
2017-12-29 22:32:04 +00:00
|
|
|
class BackgroundSchedulePool;
|
2015-04-16 06:12:35 +00:00
|
|
|
class MergeList;
|
|
|
|
class Cluster;
|
|
|
|
class Compiler;
|
|
|
|
class MarkCache;
|
|
|
|
class UncompressedCache;
|
|
|
|
class ProcessList;
|
2018-05-14 16:09:00 +00:00
|
|
|
class QueryStatus;
|
2015-04-16 06:12:35 +00:00
|
|
|
class Macros;
|
2016-03-07 04:31:10 +00:00
|
|
|
struct Progress;
|
2015-04-30 12:43:16 +00:00
|
|
|
class Clusters;
|
2015-06-26 20:48:10 +00:00
|
|
|
class QueryLog;
|
2018-05-31 15:54:08 +00:00
|
|
|
class QueryThreadLog;
|
2017-03-07 17:13:54 +00:00
|
|
|
class PartLog;
|
2015-07-16 21:32:51 +00:00
|
|
|
struct MergeTreeSettings;
|
2016-03-19 01:18:49 +00:00
|
|
|
class IDatabase;
|
2016-03-21 12:57:12 +00:00
|
|
|
class DDLGuard;
|
2017-04-13 13:42:29 +00:00
|
|
|
class DDLWorker;
|
2018-03-01 01:49:36 +00:00
|
|
|
class ITableFunction;
|
2017-01-21 04:24:28 +00:00
|
|
|
class Block;
|
2018-05-21 13:49:54 +00:00
|
|
|
class ActionLocksManager;
|
|
|
|
using ActionLocksManagerPtr = std::shared_ptr<ActionLocksManager>;
|
2018-11-22 15:59:00 +00:00
|
|
|
class ShellCommand;
|
2018-12-21 12:17:30 +00:00
|
|
|
class ICompressionCodec;
|
2019-04-24 22:52:08 +00:00
|
|
|
class SettingsConstraints;
|
|
|
|
|
2014-01-28 16:45:10 +00:00
|
|
|
|
2018-08-30 16:31:20 +00:00
|
|
|
#if USE_EMBEDDED_COMPILER
|
|
|
|
|
2018-09-03 10:14:05 +00:00
|
|
|
class CompiledExpressionCache;
|
2018-08-30 16:31:20 +00:00
|
|
|
|
|
|
|
#endif
|
2011-08-19 18:31:14 +00:00
|
|
|
|
2017-06-02 21:37:28 +00:00
|
|
|
/// (database name, table name)
|
2016-03-21 12:57:12 +00:00
|
|
|
using DatabaseAndTableName = std::pair<String, String>;
|
2013-11-08 17:43:03 +00:00
|
|
|
|
2017-06-02 21:37:28 +00:00
|
|
|
/// Table -> set of table-views that make SELECT from it.
|
2016-03-21 12:57:12 +00:00
|
|
|
using ViewDependencies = std::map<DatabaseAndTableName, std::set<DatabaseAndTableName>>;
|
|
|
|
using Dependencies = std::vector<DatabaseAndTableName>;
|
2013-11-08 17:43:03 +00:00
|
|
|
|
2018-02-14 04:00:37 +00:00
|
|
|
using TableAndCreateAST = std::pair<StoragePtr, ASTPtr>;
|
|
|
|
using TableAndCreateASTs = std::map<String, TableAndCreateAST>;
|
|
|
|
|
2018-06-01 15:32:27 +00:00
|
|
|
/// Callback for external tables initializer
|
|
|
|
using ExternalTablesInitializer = std::function<void(Context &)>;
|
|
|
|
|
2019-03-06 16:41:35 +00:00
|
|
|
/// An empty interface for an arbitrary object that may be attached by a shared pointer
|
|
|
|
/// to query context, when using ClickHouse as a library.
|
|
|
|
struct IHostContext
|
|
|
|
{
|
|
|
|
virtual ~IHostContext() = default;
|
|
|
|
};
|
|
|
|
|
|
|
|
using IHostContextPtr = std::shared_ptr<IHostContext>;
|
|
|
|
|
2017-06-02 21:37:28 +00:00
|
|
|
/** A set of known objects that can be used in the query.
|
|
|
|
* Consists of a shared part (always common to all sessions and queries)
|
|
|
|
* and copied part (which can be its own for each session or query).
|
2012-08-02 17:33:31 +00:00
|
|
|
*
|
2017-06-02 21:37:28 +00:00
|
|
|
* Everything is encapsulated for all sorts of checks and locks.
|
2012-08-02 17:33:31 +00:00
|
|
|
*/
|
|
|
|
class Context
|
|
|
|
{
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
using Shared = std::shared_ptr<ContextShared>;
|
|
|
|
Shared shared;
|
2012-06-18 07:49:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ClientInfo client_info;
|
2018-06-01 15:32:27 +00:00
|
|
|
ExternalTablesInitializer external_tables_initializer_callback;
|
2015-06-26 20:48:10 +00:00
|
|
|
|
2017-06-05 13:59:38 +00:00
|
|
|
std::shared_ptr<QuotaForIntervals> quota; /// Current quota. By default - empty quota, that have no limits.
|
2017-04-01 07:20:54 +00:00
|
|
|
String current_database;
|
2017-06-05 13:59:38 +00:00
|
|
|
Settings settings; /// Setting for query execution.
|
2019-04-24 22:52:08 +00:00
|
|
|
std::shared_ptr<const SettingsConstraints> settings_constraints;
|
2017-04-01 07:20:54 +00:00
|
|
|
using ProgressCallback = std::function<void(const Progress & progress)>;
|
2017-06-05 13:59:38 +00:00
|
|
|
ProgressCallback progress_callback; /// Callback for tracking progress of query execution.
|
2018-02-01 17:55:08 +00:00
|
|
|
QueryStatus * process_list_elem = nullptr; /// For tracking total resource usage for query.
|
2018-11-15 15:03:13 +00:00
|
|
|
std::pair<String, String> insertion_table; /// Saved insertion table in query context
|
2016-11-16 05:09:41 +00:00
|
|
|
|
2017-06-02 21:01:17 +00:00
|
|
|
String default_format; /// Format, used when server formats data by itself and if query does not have FORMAT specification.
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Thus, used in HTTP interface. If not specified - then some globally default format is used.
|
2018-02-14 04:00:37 +00:00
|
|
|
TableAndCreateASTs external_tables; /// Temporary tables.
|
2018-03-01 01:49:36 +00:00
|
|
|
Tables table_function_results; /// Temporary tables obtained by execution of table functions. Keyed by AST tree id.
|
2018-03-02 05:44:17 +00:00
|
|
|
Context * query_context = nullptr;
|
2017-04-01 07:20:54 +00:00
|
|
|
Context * session_context = nullptr; /// Session context or nullptr. Could be equal to this.
|
2017-06-05 13:59:38 +00:00
|
|
|
Context * global_context = nullptr; /// Global context or nullptr. Could be equal to this.
|
2012-06-18 07:49:19 +00:00
|
|
|
|
2017-06-05 14:40:44 +00:00
|
|
|
UInt64 session_close_cycle = 0;
|
|
|
|
bool session_is_used = false;
|
2012-06-18 07:49:19 +00:00
|
|
|
|
2018-07-05 23:36:09 +00:00
|
|
|
using SampleBlockCache = std::unordered_map<std::string, Block>;
|
|
|
|
mutable SampleBlockCache sample_block_cache;
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
using DatabasePtr = std::shared_ptr<IDatabase>;
|
|
|
|
using Databases = std::map<String, std::shared_ptr<IDatabase>>;
|
2016-03-19 01:18:49 +00:00
|
|
|
|
2019-06-15 17:52:53 +00:00
|
|
|
NameToNameMap query_parameters; /// Dictionary with query parameters for prepared statements.
|
2019-05-18 21:07:23 +00:00
|
|
|
/// (key=name, value)
|
|
|
|
|
2019-03-06 16:41:35 +00:00
|
|
|
IHostContextPtr host_context; /// Arbitrary object that may used to attach some host specific information to query context,
|
|
|
|
/// when using ClickHouse as a library in some project. For example, it may contain host
|
|
|
|
/// logger, some query identification information, profiling guards, etc. This field is
|
|
|
|
/// to be customized in HTTP and TCP servers by overloading the customizeContext(DB::Context&)
|
|
|
|
/// methods.
|
|
|
|
|
2017-06-19 20:31:23 +00:00
|
|
|
/// Use copy constructor or createGlobal() instead
|
2017-04-01 07:20:54 +00:00
|
|
|
Context();
|
2017-06-19 20:31:23 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
/// Create initial Context with ContextShared and etc.
|
2019-02-04 23:18:04 +00:00
|
|
|
static Context createGlobal(std::unique_ptr<IRuntimeComponentsFactory> runtime_components_factory);
|
2017-06-19 20:31:23 +00:00
|
|
|
static Context createGlobal();
|
|
|
|
|
2019-04-24 22:52:08 +00:00
|
|
|
Context(const Context &);
|
|
|
|
Context & operator=(const Context &);
|
2017-04-01 07:20:54 +00:00
|
|
|
~Context();
|
2015-04-16 06:12:35 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
String getPath() const;
|
|
|
|
String getTemporaryPath() const;
|
|
|
|
String getFlagsPath() const;
|
2018-04-19 05:32:09 +00:00
|
|
|
String getUserFilesPath() const;
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void setPath(const String & path);
|
|
|
|
void setTemporaryPath(const String & path);
|
|
|
|
void setFlagsPath(const String & path);
|
2018-04-19 05:32:09 +00:00
|
|
|
void setUserFilesPath(const String & path);
|
2013-05-05 20:07:11 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
using ConfigurationPtr = Poco::AutoPtr<Poco::Util::AbstractConfiguration>;
|
2015-04-16 06:12:35 +00:00
|
|
|
|
2017-08-24 14:51:13 +00:00
|
|
|
/// Global application configuration settings.
|
|
|
|
void setConfig(const ConfigurationPtr & config);
|
2018-07-08 04:54:37 +00:00
|
|
|
const Poco::Util::AbstractConfiguration & getConfigRef() const;
|
2017-08-24 14:51:13 +00:00
|
|
|
|
2017-06-02 21:37:28 +00:00
|
|
|
/** Take the list of users, quotas and configuration profiles from this config.
|
|
|
|
* The list of users is completely replaced.
|
|
|
|
* The accumulated quota values are not reset if the quota is not deleted.
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
|
|
|
void setUsersConfig(const ConfigurationPtr & config);
|
|
|
|
ConfigurationPtr getUsersConfig();
|
2014-02-13 07:17:22 +00:00
|
|
|
|
2019-03-29 20:31:06 +00:00
|
|
|
// User property is a key-value pair from the configuration entry: users.<username>.databases.<db_name>.<table_name>.<key_name>
|
|
|
|
bool hasUserProperty(const String & database, const String & table, const String & name) const;
|
|
|
|
const String & getUserProperty(const String & database, const String & table, const String & name) const;
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Must be called before getClientInfo.
|
|
|
|
void setUser(const String & name, const String & password, const Poco::Net::SocketAddress & address, const String & quota_key);
|
2017-06-07 12:54:35 +00:00
|
|
|
/// Compute and set actual user settings, client_info.current_user should be set
|
|
|
|
void calculateUserSettings();
|
2015-06-26 20:48:10 +00:00
|
|
|
|
2018-06-14 13:03:23 +00:00
|
|
|
/// We have to copy external tables inside executeQuery() to track limits. Therefore, set callback for it. Must set once.
|
2018-06-01 15:32:27 +00:00
|
|
|
void setExternalTablesInitializer(ExternalTablesInitializer && initializer);
|
|
|
|
/// This method is called in executeQuery() and will call the external tables initializer.
|
|
|
|
void initializeExternalTablesIfSet();
|
|
|
|
|
2018-06-03 17:43:56 +00:00
|
|
|
ClientInfo & getClientInfo() { return client_info; }
|
|
|
|
const ClientInfo & getClientInfo() const { return client_info; }
|
2015-06-26 20:48:10 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void setQuota(const String & name, const String & quota_key, const String & user_name, const Poco::Net::IPAddress & address);
|
|
|
|
QuotaForIntervals & getQuota();
|
2013-08-10 07:46:45 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void addDependency(const DatabaseAndTableName & from, const DatabaseAndTableName & where);
|
|
|
|
void removeDependency(const DatabaseAndTableName & from, const DatabaseAndTableName & where);
|
|
|
|
Dependencies getDependencies(const String & database_name, const String & table_name) const;
|
2013-11-08 17:43:03 +00:00
|
|
|
|
2019-05-09 06:12:02 +00:00
|
|
|
/// Functions where we can lock the context manually
|
|
|
|
void addDependencyUnsafe(const DatabaseAndTableName & from, const DatabaseAndTableName & where);
|
|
|
|
void removeDependencyUnsafe(const DatabaseAndTableName & from, const DatabaseAndTableName & where);
|
|
|
|
|
2017-06-02 21:37:28 +00:00
|
|
|
/// Checking the existence of the table/database. Database can be empty - in this case the current database is used.
|
2017-04-01 07:20:54 +00:00
|
|
|
bool isTableExist(const String & database_name, const String & table_name) const;
|
|
|
|
bool isDatabaseExist(const String & database_name) const;
|
2018-02-14 04:00:37 +00:00
|
|
|
bool isExternalTableExist(const String & table_name) const;
|
2018-08-14 02:18:57 +00:00
|
|
|
bool hasDatabaseAccessRights(const String & database_name) const;
|
2017-04-01 07:20:54 +00:00
|
|
|
void assertTableExists(const String & database_name, const String & table_name) const;
|
2015-10-01 15:10:41 +00:00
|
|
|
|
2017-06-02 21:37:28 +00:00
|
|
|
/** The parameter check_database_access_rights exists to not check the permissions of the database again,
|
|
|
|
* when assertTableDoesntExist or assertDatabaseExists is called inside another function that already
|
|
|
|
* made this check.
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
|
|
|
void assertTableDoesntExist(const String & database_name, const String & table_name, bool check_database_acccess_rights = true) const;
|
|
|
|
void assertDatabaseExists(const String & database_name, bool check_database_acccess_rights = true) const;
|
2015-10-01 15:10:41 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void assertDatabaseDoesntExist(const String & database_name) const;
|
2018-04-17 19:33:58 +00:00
|
|
|
void checkDatabaseAccessRights(const std::string & database_name) const;
|
2012-08-02 17:33:31 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Tables getExternalTables() const;
|
|
|
|
StoragePtr tryGetExternalTable(const String & table_name) const;
|
|
|
|
StoragePtr getTable(const String & database_name, const String & table_name) const;
|
|
|
|
StoragePtr tryGetTable(const String & database_name, const String & table_name) const;
|
2018-02-14 04:00:37 +00:00
|
|
|
void addExternalTable(const String & table_name, const StoragePtr & storage, const ASTPtr & ast = {});
|
2017-08-15 17:00:18 +00:00
|
|
|
StoragePtr tryRemoveExternalTable(const String & table_name);
|
2014-08-22 00:57:20 +00:00
|
|
|
|
2018-03-01 01:49:36 +00:00
|
|
|
StoragePtr executeTableFunction(const ASTPtr & table_expression);
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void addDatabase(const String & database_name, const DatabasePtr & database);
|
|
|
|
DatabasePtr detachDatabase(const String & database_name);
|
2016-03-21 12:57:12 +00:00
|
|
|
|
2017-06-02 21:37:28 +00:00
|
|
|
/// Get an object that protects the table from concurrently executing multiple DDL operations.
|
2018-09-18 18:33:15 +00:00
|
|
|
std::unique_ptr<DDLGuard> getDDLGuard(const String & database, const String & table) const;
|
2012-08-02 17:33:31 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
String getCurrentDatabase() const;
|
|
|
|
String getCurrentQueryId() const;
|
|
|
|
void setCurrentDatabase(const String & name);
|
|
|
|
void setCurrentQueryId(const String & query_id);
|
2012-08-02 17:33:31 +00:00
|
|
|
|
2019-02-01 01:48:25 +00:00
|
|
|
void killCurrentQuery();
|
|
|
|
|
2018-11-15 15:03:13 +00:00
|
|
|
void setInsertionTable(std::pair<String, String> && db_and_table) { insertion_table = db_and_table; }
|
|
|
|
const std::pair<String, String> & getInsertionTable() const { return insertion_table; }
|
|
|
|
|
2017-06-02 21:37:28 +00:00
|
|
|
String getDefaultFormat() const; /// If default_format is not specified, some global default format is returned.
|
2017-04-01 07:20:54 +00:00
|
|
|
void setDefaultFormat(const String & name);
|
2013-06-29 18:03:57 +00:00
|
|
|
|
2018-03-13 23:44:23 +00:00
|
|
|
MultiVersion<Macros>::Version getMacros() const;
|
|
|
|
void setMacros(std::unique_ptr<Macros> && macros);
|
2014-08-11 15:59:01 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Settings getSettings() const;
|
|
|
|
void setSettings(const Settings & settings_);
|
2012-08-02 19:03:32 +00:00
|
|
|
|
2019-04-18 23:29:32 +00:00
|
|
|
/// Set settings by name.
|
|
|
|
void setSetting(const String & name, const String & value);
|
2017-04-01 07:20:54 +00:00
|
|
|
void setSetting(const String & name, const Field & value);
|
2019-04-18 23:29:32 +00:00
|
|
|
void applySettingChange(const SettingChange & change);
|
|
|
|
void applySettingsChanges(const SettingsChanges & changes);
|
2014-02-14 17:38:33 +00:00
|
|
|
|
2019-04-18 23:29:32 +00:00
|
|
|
/// Checks the constraints.
|
|
|
|
void checkSettingsConstraints(const SettingChange & change);
|
|
|
|
void checkSettingsConstraints(const SettingsChanges & changes);
|
2014-02-13 07:17:22 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
const EmbeddedDictionaries & getEmbeddedDictionaries() const;
|
|
|
|
const ExternalDictionaries & getExternalDictionaries() const;
|
2017-10-17 10:44:46 +00:00
|
|
|
const ExternalModels & getExternalModels() const;
|
2017-08-24 18:19:06 +00:00
|
|
|
EmbeddedDictionaries & getEmbeddedDictionaries();
|
|
|
|
ExternalDictionaries & getExternalDictionaries();
|
2017-10-17 10:44:46 +00:00
|
|
|
ExternalModels & getExternalModels();
|
2017-04-01 07:20:54 +00:00
|
|
|
void tryCreateEmbeddedDictionaries() const;
|
2015-03-27 13:11:22 +00:00
|
|
|
|
2017-06-02 21:37:28 +00:00
|
|
|
/// I/O formats.
|
2019-02-10 16:55:12 +00:00
|
|
|
BlockInputStreamPtr getInputFormat(const String & name, ReadBuffer & buf, const Block & sample, UInt64 max_block_size) const;
|
2017-04-01 07:20:54 +00:00
|
|
|
BlockOutputStreamPtr getOutputFormat(const String & name, WriteBuffer & buf, const Block & sample) const;
|
2016-02-13 06:37:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
InterserverIOHandler & getInterserverIOHandler();
|
2014-03-21 13:42:14 +00:00
|
|
|
|
2017-06-02 21:37:28 +00:00
|
|
|
/// How other servers can access this for downloading replicated data.
|
2017-04-01 07:20:54 +00:00
|
|
|
void setInterserverIOAddress(const String & host, UInt16 port);
|
|
|
|
std::pair<String, UInt16> getInterserverIOAddress() const;
|
2018-07-26 15:10:57 +00:00
|
|
|
|
2018-07-30 18:32:21 +00:00
|
|
|
/// Credentials which server will use to communicate with others
|
|
|
|
void setInterserverCredentials(const String & user, const String & password);
|
2018-07-26 15:10:57 +00:00
|
|
|
std::pair<String, String> getInterserverCredentials() const;
|
|
|
|
|
2018-07-30 18:32:21 +00:00
|
|
|
/// Interserver requests scheme (http or https)
|
|
|
|
void setInterserverScheme(const String & scheme);
|
|
|
|
String getInterserverScheme() const;
|
|
|
|
|
2017-06-02 21:37:28 +00:00
|
|
|
/// The port that the server listens for executing SQL queries.
|
2017-04-01 07:20:54 +00:00
|
|
|
UInt16 getTCPPort() const;
|
2014-03-21 19:49:27 +00:00
|
|
|
|
2018-11-06 14:42:30 +00:00
|
|
|
std::optional<UInt16> getTCPPortSecure() const;
|
2014-03-21 19:49:27 +00:00
|
|
|
|
2017-06-02 21:37:28 +00:00
|
|
|
/// Get query for the CREATE table.
|
2018-03-13 13:28:32 +00:00
|
|
|
ASTPtr getCreateTableQuery(const String & database_name, const String & table_name) const;
|
|
|
|
ASTPtr getCreateExternalTableQuery(const String & table_name) const;
|
|
|
|
ASTPtr getCreateDatabaseQuery(const String & database_name) const;
|
2012-08-17 19:53:11 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
const DatabasePtr getDatabase(const String & database_name) const;
|
|
|
|
DatabasePtr getDatabase(const String & database_name);
|
|
|
|
const DatabasePtr tryGetDatabase(const String & database_name) const;
|
|
|
|
DatabasePtr tryGetDatabase(const String & database_name);
|
2016-03-19 01:18:49 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
const Databases getDatabases() const;
|
|
|
|
Databases getDatabases();
|
2016-03-19 01:18:49 +00:00
|
|
|
|
2017-06-02 18:48:33 +00:00
|
|
|
std::shared_ptr<Context> acquireSession(const String & session_id, std::chrono::steady_clock::duration timeout, bool session_check) const;
|
|
|
|
void releaseSession(const String & session_id, std::chrono::steady_clock::duration timeout);
|
|
|
|
|
2017-06-02 21:01:17 +00:00
|
|
|
/// Close sessions, that has been expired. Returns how long to wait for next session to be expired, if no new sessions will be added.
|
|
|
|
std::chrono::steady_clock::duration closeSessions() const;
|
2016-03-19 01:18:49 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// For methods below you may need to acquire a lock by yourself.
|
2018-03-01 01:49:36 +00:00
|
|
|
std::unique_lock<std::recursive_mutex> getLock() const;
|
2012-08-02 17:33:31 +00:00
|
|
|
|
2018-03-02 05:44:17 +00:00
|
|
|
const Context & getQueryContext() const;
|
|
|
|
Context & getQueryContext();
|
|
|
|
bool hasQueryContext() const { return query_context != nullptr; }
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
const Context & getSessionContext() const;
|
|
|
|
Context & getSessionContext();
|
2017-08-15 12:34:28 +00:00
|
|
|
bool hasSessionContext() const { return session_context != nullptr; }
|
2016-11-16 11:29:51 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
const Context & getGlobalContext() const;
|
|
|
|
Context & getGlobalContext();
|
2017-08-15 12:34:28 +00:00
|
|
|
bool hasGlobalContext() const { return global_context != nullptr; }
|
2012-08-02 17:33:31 +00:00
|
|
|
|
2018-03-02 05:44:17 +00:00
|
|
|
void setQueryContext(Context & context_) { query_context = &context_; }
|
2018-03-01 01:49:36 +00:00
|
|
|
void setSessionContext(Context & context_) { session_context = &context_; }
|
|
|
|
void setGlobalContext(Context & context_) { global_context = &context_; }
|
2012-08-02 17:33:31 +00:00
|
|
|
|
2018-06-03 17:43:56 +00:00
|
|
|
const Settings & getSettingsRef() const { return settings; }
|
|
|
|
Settings & getSettingsRef() { return settings; }
|
2013-02-16 14:55:14 +00:00
|
|
|
|
2016-03-19 01:18:49 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void setProgressCallback(ProgressCallback callback);
|
2019-01-23 14:48:50 +00:00
|
|
|
/// Used in InterpreterSelectQuery to pass it to the IBlockInputStream.
|
2017-04-01 07:20:54 +00:00
|
|
|
ProgressCallback getProgressCallback() const;
|
2013-09-03 20:21:28 +00:00
|
|
|
|
2019-01-23 14:48:50 +00:00
|
|
|
/** Set in executeQuery and InterpreterSelectQuery. Then it is used in IBlockInputStream,
|
2017-06-02 21:37:28 +00:00
|
|
|
* to update and monitor information about the total number of resources spent for the query.
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
2018-02-01 17:55:08 +00:00
|
|
|
void setProcessListElement(QueryStatus * elem);
|
2017-06-02 21:37:28 +00:00
|
|
|
/// Can return nullptr if the query was not inserted into the ProcessList.
|
2018-02-01 17:55:08 +00:00
|
|
|
QueryStatus * getProcessListElement() const;
|
2013-11-03 05:32:42 +00:00
|
|
|
|
2017-06-02 21:37:28 +00:00
|
|
|
/// List all queries.
|
2017-04-01 07:20:54 +00:00
|
|
|
ProcessList & getProcessList();
|
|
|
|
const ProcessList & getProcessList() const;
|
2013-09-08 05:53:10 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
MergeList & getMergeList();
|
|
|
|
const MergeList & getMergeList() const;
|
2014-09-10 11:34:26 +00:00
|
|
|
|
2017-06-02 21:37:28 +00:00
|
|
|
/// If the current session is expired at the time of the call, synchronously creates and returns a new session with the startNewSession() call.
|
2018-04-21 18:41:06 +00:00
|
|
|
/// If no ZooKeeper configured, throws an exception.
|
2017-04-01 07:20:54 +00:00
|
|
|
std::shared_ptr<zkutil::ZooKeeper> getZooKeeper() const;
|
2017-06-15 20:08:26 +00:00
|
|
|
/// Has ready or expired ZooKeeper
|
|
|
|
bool hasZooKeeper() const;
|
2019-07-04 14:48:40 +00:00
|
|
|
/// Reset current zookeeper session. Do not create a new one.
|
|
|
|
void resetZooKeeper() const;
|
2013-12-07 16:51:29 +00:00
|
|
|
|
2017-08-07 17:01:04 +00:00
|
|
|
/// Create a cache of uncompressed blocks of specified size. This can be done only once.
|
|
|
|
void setUncompressedCache(size_t max_size_in_bytes);
|
|
|
|
std::shared_ptr<UncompressedCache> getUncompressedCache() const;
|
|
|
|
void dropUncompressedCache() const;
|
|
|
|
|
2017-06-02 21:37:28 +00:00
|
|
|
/// Create a cache of marks of specified size. This can be done only once.
|
2017-04-01 07:20:54 +00:00
|
|
|
void setMarkCache(size_t cache_size_in_bytes);
|
|
|
|
std::shared_ptr<MarkCache> getMarkCache() const;
|
2017-08-07 17:01:04 +00:00
|
|
|
void dropMarkCache() const;
|
|
|
|
|
|
|
|
/** Clear the caches of the uncompressed blocks and marks.
|
|
|
|
* This is usually done when renaming tables, changing the type of columns, deleting a table.
|
|
|
|
* - since caches are linked to file names, and become incorrect.
|
|
|
|
* (when deleting a table - it is necessary, since in its place another can appear)
|
|
|
|
* const - because the change in the cache is not considered significant.
|
|
|
|
*/
|
|
|
|
void dropCaches() const;
|
2014-02-11 13:30:42 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
BackgroundProcessingPool & getBackgroundPool();
|
2017-12-29 22:32:04 +00:00
|
|
|
BackgroundSchedulePool & getSchedulePool();
|
2014-07-02 12:30:38 +00:00
|
|
|
|
2019-02-21 16:41:27 +00:00
|
|
|
void setDDLWorker(std::unique_ptr<DDLWorker> ddl_worker);
|
2017-09-04 17:49:39 +00:00
|
|
|
DDLWorker & getDDLWorker() const;
|
2017-04-13 13:42:29 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Clusters & getClusters() const;
|
|
|
|
std::shared_ptr<Cluster> getCluster(const std::string & cluster_name) const;
|
|
|
|
std::shared_ptr<Cluster> tryGetCluster(const std::string & cluster_name) const;
|
2017-10-13 19:13:41 +00:00
|
|
|
void setClustersConfig(const ConfigurationPtr & config, const String & config_name = "remote_servers");
|
2017-11-03 19:53:10 +00:00
|
|
|
/// Sets custom cluster, but doesn't update configuration
|
|
|
|
void setCluster(const String & cluster_name, const std::shared_ptr<Cluster> & cluster);
|
2018-01-15 14:13:19 +00:00
|
|
|
void reloadClusterConfig();
|
2014-03-03 20:11:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Compiler & getCompiler();
|
2018-03-10 19:57:13 +00:00
|
|
|
|
|
|
|
/// Call after initialization before using system logs. Call for global context.
|
|
|
|
void initializeSystemLogs();
|
|
|
|
|
|
|
|
/// Nullptr if the query log is not ready for this moment.
|
2019-03-21 19:22:38 +00:00
|
|
|
std::shared_ptr<QueryLog> getQueryLog();
|
|
|
|
std::shared_ptr<QueryThreadLog> getQueryThreadLog();
|
2017-06-05 13:59:38 +00:00
|
|
|
|
|
|
|
/// Returns an object used to log opertaions with parts if it possible.
|
|
|
|
/// Provide table name to make required cheks.
|
2019-03-21 19:22:38 +00:00
|
|
|
std::shared_ptr<PartLog> getPartLog(const String & part_database);
|
2018-03-10 19:57:13 +00:00
|
|
|
|
2018-08-10 17:42:12 +00:00
|
|
|
const MergeTreeSettings & getMergeTreeSettings() const;
|
2015-06-26 20:48:10 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Prevents DROP TABLE if its size is greater than max_size (50GB by default, max_size=0 turn off this check)
|
|
|
|
void setMaxTableSizeToDrop(size_t max_size);
|
2019-01-04 12:10:00 +00:00
|
|
|
void checkTableCanBeDropped(const String & database, const String & table, const size_t & table_size) const;
|
2017-01-19 19:11:12 +00:00
|
|
|
|
2018-08-01 17:41:18 +00:00
|
|
|
/// Prevents DROP PARTITION if its size is greater than max_size (50GB by default, max_size=0 turn off this check)
|
2018-08-03 08:33:57 +00:00
|
|
|
void setMaxPartitionSizeToDrop(size_t max_size);
|
2019-01-04 12:10:00 +00:00
|
|
|
void checkPartitionCanBeDropped(const String & database, const String & table, const size_t & partition_size) const;
|
2017-01-19 19:11:12 +00:00
|
|
|
|
2018-12-21 12:17:30 +00:00
|
|
|
/// Lets you select the compression codec according to the conditions described in the configuration file.
|
|
|
|
std::shared_ptr<ICompressionCodec> chooseCompressionCodec(size_t part_size, double part_size_ratio) const;
|
2015-04-17 05:35:53 +00:00
|
|
|
|
2017-06-02 21:37:28 +00:00
|
|
|
/// Get the server uptime in seconds.
|
2017-04-01 07:20:54 +00:00
|
|
|
time_t getUptimeSeconds() const;
|
2016-04-09 07:47:08 +00:00
|
|
|
|
2018-03-13 10:41:47 +00:00
|
|
|
using ConfigReloadCallback = std::function<void()>;
|
|
|
|
void setConfigReloadCallback(ConfigReloadCallback && callback);
|
|
|
|
void reloadConfig() const;
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void shutdown();
|
2015-04-02 16:30:18 +00:00
|
|
|
|
2018-05-21 13:49:54 +00:00
|
|
|
ActionLocksManagerPtr getActionLocksManager();
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
enum class ApplicationType
|
|
|
|
{
|
2017-06-05 13:59:38 +00:00
|
|
|
SERVER, /// The program is run as clickhouse-server daemon (default behavior)
|
|
|
|
CLIENT, /// clickhouse-client
|
2017-07-11 20:12:15 +00:00
|
|
|
LOCAL /// clickhouse-local
|
2017-04-01 07:20:54 +00:00
|
|
|
};
|
2016-11-11 17:01:02 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
ApplicationType getApplicationType() const;
|
|
|
|
void setApplicationType(ApplicationType type);
|
2016-11-11 17:01:02 +00:00
|
|
|
|
2018-02-01 13:52:29 +00:00
|
|
|
/// Sets default_profile and system_profile, must be called once during the initialization
|
|
|
|
void setDefaultProfiles(const Poco::Util::AbstractConfiguration & config);
|
2017-04-01 07:20:54 +00:00
|
|
|
String getDefaultProfileName() const;
|
2018-02-01 13:52:29 +00:00
|
|
|
String getSystemProfileName() const;
|
2017-03-23 14:14:56 +00:00
|
|
|
|
2017-11-10 06:48:28 +00:00
|
|
|
/// Base path for format schemas
|
|
|
|
String getFormatSchemaPath() const;
|
|
|
|
void setFormatSchemaPath(const String & path);
|
|
|
|
|
2017-06-02 21:01:17 +00:00
|
|
|
/// User name and session identifier. Named sessions are local to users.
|
|
|
|
using SessionKey = std::pair<String, String>;
|
|
|
|
|
2018-07-05 23:36:09 +00:00
|
|
|
SampleBlockCache & getSampleBlockCache() const;
|
2018-05-30 19:23:15 +00:00
|
|
|
|
2019-05-18 21:07:23 +00:00
|
|
|
/// Query parameters for prepared statements.
|
2019-05-25 13:43:52 +00:00
|
|
|
bool hasQueryParameters() const;
|
2019-06-15 17:52:53 +00:00
|
|
|
const NameToNameMap & getQueryParameters() const;
|
|
|
|
void setQueryParameter(const String & name, const String & value);
|
2019-05-18 21:07:23 +00:00
|
|
|
|
2018-08-30 16:31:20 +00:00
|
|
|
#if USE_EMBEDDED_COMPILER
|
2018-09-05 11:37:41 +00:00
|
|
|
std::shared_ptr<CompiledExpressionCache> getCompiledExpressionCache() const;
|
2018-09-05 12:42:37 +00:00
|
|
|
void setCompiledExpressionCache(size_t cache_size);
|
2018-09-05 11:37:41 +00:00
|
|
|
void dropCompiledExpressionCache() const;
|
2018-08-30 16:31:20 +00:00
|
|
|
#endif
|
|
|
|
|
2018-11-22 15:59:00 +00:00
|
|
|
/// Add started bridge command. It will be killed after context destruction
|
|
|
|
void addXDBCBridgeCommand(std::unique_ptr<ShellCommand> cmd);
|
|
|
|
|
2019-03-06 16:41:35 +00:00
|
|
|
IHostContextPtr & getHostContext();
|
|
|
|
const IHostContextPtr & getHostContext() const;
|
|
|
|
|
2019-05-16 03:34:04 +00:00
|
|
|
/// MySQL wire protocol state.
|
|
|
|
size_t sequence_id = 0;
|
|
|
|
uint32_t client_capabilities = 0;
|
2019-05-16 17:15:43 +00:00
|
|
|
size_t max_packet_size = 0;
|
2015-04-02 16:30:18 +00:00
|
|
|
private:
|
2017-06-02 21:37:28 +00:00
|
|
|
/** Check if the current client has access to the specified database.
|
|
|
|
* If access is denied, throw an exception.
|
|
|
|
* NOTE: This method should always be called when the `shared->mutex` mutex is acquired.
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
2018-04-17 19:33:58 +00:00
|
|
|
void checkDatabaseAccessRightsImpl(const std::string & database_name) const;
|
2015-10-01 15:10:41 +00:00
|
|
|
|
2019-04-19 00:45:15 +00:00
|
|
|
void setProfile(const String & profile);
|
|
|
|
|
2017-08-24 18:19:06 +00:00
|
|
|
EmbeddedDictionaries & getEmbeddedDictionariesImpl(bool throw_on_error) const;
|
2015-08-19 21:15:27 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
StoragePtr getTableImpl(const String & database_name, const String & table_name, Exception * exception) const;
|
2017-06-02 18:48:33 +00:00
|
|
|
|
|
|
|
SessionKey getSessionKey(const String & session_id) const;
|
2017-06-02 21:01:17 +00:00
|
|
|
|
|
|
|
/// Session will be closed after specified timeout.
|
|
|
|
void scheduleCloseSession(const SessionKey & key, std::chrono::steady_clock::duration timeout);
|
2018-08-06 09:09:45 +00:00
|
|
|
|
2019-01-04 12:10:00 +00:00
|
|
|
void checkCanBeDropped(const String & database, const String & table, const size_t & size, const size_t & max_size_to_drop) const;
|
2011-08-09 19:19:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-09-24 18:02:25 +00:00
|
|
|
/// Allows executing DDL query only in one thread.
|
|
|
|
/// Puts an element into the map, locks tables's mutex, counts how much threads run parallel query on the table,
|
|
|
|
/// when counter is 0 erases element in the destructor.
|
2018-09-19 09:34:07 +00:00
|
|
|
/// If the element already exists in the map, waits, when ddl query will be finished in other thread.
|
2016-03-21 12:57:12 +00:00
|
|
|
class DDLGuard
|
|
|
|
{
|
2017-02-15 19:38:15 +00:00
|
|
|
public:
|
2018-09-24 18:02:25 +00:00
|
|
|
struct Entry
|
|
|
|
{
|
2018-09-18 18:33:15 +00:00
|
|
|
std::unique_ptr<std::mutex> mutex;
|
|
|
|
UInt32 counter;
|
|
|
|
};
|
|
|
|
|
2018-09-19 09:34:07 +00:00
|
|
|
/// Element name -> (mutex, counter).
|
2017-04-01 07:20:54 +00:00
|
|
|
/// NOTE: using std::map here (and not std::unordered_map) to avoid iterator invalidation on insertion.
|
2018-09-18 18:33:15 +00:00
|
|
|
using Map = std::map<String, Entry>;
|
2017-02-15 19:38:15 +00:00
|
|
|
|
2018-09-24 19:08:11 +00:00
|
|
|
DDLGuard(Map & map_, std::unique_lock<std::mutex> guards_lock_, const String & elem);
|
2017-04-01 07:20:54 +00:00
|
|
|
~DDLGuard();
|
2016-03-21 12:57:12 +00:00
|
|
|
|
2017-02-15 19:38:15 +00:00
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
Map & map;
|
|
|
|
Map::iterator it;
|
2018-09-24 19:08:11 +00:00
|
|
|
std::unique_lock<std::mutex> guards_lock;
|
2018-09-18 18:33:15 +00:00
|
|
|
std::unique_lock<std::mutex> table_lock;
|
2016-03-21 12:57:12 +00:00
|
|
|
};
|
|
|
|
|
2017-06-02 18:48:33 +00:00
|
|
|
|
|
|
|
class SessionCleaner
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SessionCleaner(Context & context_)
|
|
|
|
: context{context_}
|
|
|
|
{
|
|
|
|
}
|
|
|
|
~SessionCleaner();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void run();
|
|
|
|
|
|
|
|
Context & context;
|
|
|
|
|
|
|
|
std::mutex mutex;
|
|
|
|
std::condition_variable cond;
|
|
|
|
std::atomic<bool> quit{false};
|
2019-01-14 19:22:09 +00:00
|
|
|
ThreadFromGlobalPool thread{&SessionCleaner::run, this};
|
2017-06-02 18:48:33 +00:00
|
|
|
};
|
|
|
|
|
2011-08-09 19:19:25 +00:00
|
|
|
}
|