2013-09-03 20:21:28 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Core/Defines.h>
|
2017-11-24 13:55:31 +00:00
|
|
|
#include <IO/Progress.h>
|
2019-05-17 14:34:25 +00:00
|
|
|
#include <Interpreters/CancellationCode.h>
|
|
|
|
#include <Interpreters/ClientInfo.h>
|
|
|
|
#include <Interpreters/QueryPriorities.h>
|
2022-08-31 17:17:31 +00:00
|
|
|
#include <Interpreters/TemporaryDataOnDisk.h>
|
|
|
|
#include <Interpreters/Context.h>
|
2021-11-26 11:44:39 +00:00
|
|
|
#include <QueryPipeline/BlockIO.h>
|
|
|
|
#include <QueryPipeline/ExecutionSpeedLimits.h>
|
2019-05-17 14:34:25 +00:00
|
|
|
#include <Storages/IStorage_fwd.h>
|
|
|
|
#include <Poco/Condition.h>
|
2021-12-29 14:25:56 +00:00
|
|
|
#include <Parsers/IAST.h>
|
2018-02-01 17:55:08 +00:00
|
|
|
#include <Common/CurrentMetrics.h>
|
2019-05-17 14:34:25 +00:00
|
|
|
#include <Common/CurrentThread.h>
|
|
|
|
#include <Common/MemoryTracker.h>
|
2018-02-01 17:55:08 +00:00
|
|
|
#include <Common/ProfileEvents.h>
|
2019-05-17 14:34:25 +00:00
|
|
|
#include <Common/Stopwatch.h>
|
2018-02-01 17:55:08 +00:00
|
|
|
#include <Common/Throttler.h>
|
2021-10-22 12:56:09 +00:00
|
|
|
#include <Common/OvercommitTracker.h>
|
2019-05-17 14:34:25 +00:00
|
|
|
|
|
|
|
#include <condition_variable>
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
|
|
|
#include <mutex>
|
|
|
|
#include <unordered_map>
|
2021-07-27 09:52:45 +00:00
|
|
|
#include <vector>
|
2013-09-03 20:21:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-01-21 04:24:28 +00:00
|
|
|
struct Settings;
|
2017-01-27 17:27:33 +00:00
|
|
|
class IAST;
|
2021-07-27 09:52:45 +00:00
|
|
|
class PipelineExecutor;
|
2018-02-01 17:55:08 +00:00
|
|
|
|
2017-08-29 13:23:04 +00:00
|
|
|
struct ProcessListForUser;
|
2018-05-14 16:09:00 +00:00
|
|
|
class QueryStatus;
|
|
|
|
class ThreadStatus;
|
|
|
|
class ProcessListEntry;
|
2017-01-21 04:24:28 +00:00
|
|
|
|
|
|
|
|
2016-10-24 04:06:27 +00:00
|
|
|
/** List of currently executing queries.
|
|
|
|
* Also implements limit on their number.
|
2013-09-03 20:21:28 +00:00
|
|
|
*/
|
|
|
|
|
2016-10-24 04:06:27 +00:00
|
|
|
/** Information of process list element.
|
|
|
|
* To output in SHOW PROCESSLIST query. Does not contain any complex objects, that do something on copy or destructor.
|
2016-01-20 21:32:01 +00:00
|
|
|
*/
|
2018-02-01 17:55:08 +00:00
|
|
|
struct QueryStatusInfo
|
2016-01-20 21:32:01 +00:00
|
|
|
{
|
|
|
|
String query;
|
2023-02-03 01:16:30 +00:00
|
|
|
IAST::QueryKind query_kind{};
|
2022-12-28 20:01:41 +00:00
|
|
|
UInt64 elapsed_microseconds;
|
2016-12-06 20:55:13 +00:00
|
|
|
size_t read_rows;
|
|
|
|
size_t read_bytes;
|
2016-01-20 21:32:01 +00:00
|
|
|
size_t total_rows;
|
2016-12-06 20:55:13 +00:00
|
|
|
size_t written_rows;
|
|
|
|
size_t written_bytes;
|
2016-01-20 21:32:01 +00:00
|
|
|
Int64 memory_usage;
|
2018-03-09 23:04:26 +00:00
|
|
|
Int64 peak_memory_usage;
|
2016-10-24 21:40:39 +00:00
|
|
|
ClientInfo client_info;
|
2018-03-09 21:12:52 +00:00
|
|
|
bool is_cancelled;
|
2022-04-26 06:17:17 +00:00
|
|
|
bool is_all_data_sent;
|
2018-03-01 16:52:24 +00:00
|
|
|
|
2020-02-02 02:27:15 +00:00
|
|
|
/// Optional fields, filled by query
|
2020-02-02 20:01:13 +00:00
|
|
|
std::vector<UInt64> thread_ids;
|
2023-09-07 01:32:39 +00:00
|
|
|
size_t peak_threads_usage;
|
2021-10-11 15:56:23 +00:00
|
|
|
std::shared_ptr<ProfileEvents::Counters::Snapshot> profile_counters;
|
2018-05-17 16:01:41 +00:00
|
|
|
std::shared_ptr<Settings> query_settings;
|
2021-03-30 13:35:33 +00:00
|
|
|
std::string current_database;
|
2016-01-20 21:32:01 +00:00
|
|
|
};
|
|
|
|
|
2016-10-24 04:06:27 +00:00
|
|
|
/// Query and information about its execution.
|
2021-04-10 23:33:54 +00:00
|
|
|
class QueryStatus : public WithContext
|
2013-09-03 20:21:28 +00:00
|
|
|
{
|
2018-05-14 16:09:00 +00:00
|
|
|
protected:
|
2018-03-09 23:04:26 +00:00
|
|
|
friend class ProcessList;
|
2018-05-14 16:09:00 +00:00
|
|
|
friend class ThreadStatus;
|
2018-05-29 18:14:31 +00:00
|
|
|
friend class CurrentThread;
|
2018-05-14 16:09:00 +00:00
|
|
|
friend class ProcessListEntry;
|
2021-10-26 12:32:17 +00:00
|
|
|
friend struct ::GlobalOvercommitTracker;
|
2018-03-09 23:04:26 +00:00
|
|
|
|
2015-04-16 06:12:35 +00:00
|
|
|
String query;
|
2016-10-24 21:40:39 +00:00
|
|
|
ClientInfo client_info;
|
2018-05-31 15:54:08 +00:00
|
|
|
|
2018-06-19 20:30:35 +00:00
|
|
|
/// Info about all threads involved in query execution
|
2023-04-07 13:13:21 +00:00
|
|
|
ThreadGroupPtr thread_group;
|
2018-06-19 20:30:35 +00:00
|
|
|
|
2015-04-16 06:12:35 +00:00
|
|
|
Stopwatch watch;
|
2013-09-03 20:21:28 +00:00
|
|
|
|
2016-12-06 20:55:13 +00:00
|
|
|
/// Progress of input stream
|
|
|
|
Progress progress_in;
|
|
|
|
/// Progress of output stream
|
|
|
|
Progress progress_out;
|
2014-02-12 17:31:02 +00:00
|
|
|
|
2021-11-26 11:44:39 +00:00
|
|
|
/// Used to externally check for the query time limits
|
|
|
|
/// They are saved in the constructor to limit the overhead of each call to checkTimeLimit()
|
|
|
|
ExecutionSpeedLimits limits;
|
|
|
|
OverflowMode overflow_mode;
|
2018-02-01 17:55:08 +00:00
|
|
|
|
2021-12-06 14:02:43 +00:00
|
|
|
QueryPriorities::Handle priority_handle = nullptr;
|
2016-01-20 21:32:01 +00:00
|
|
|
|
2022-09-18 13:46:14 +00:00
|
|
|
/// True if query cancellation is in progress right now
|
|
|
|
/// ProcessListEntry should not be destroyed if is_cancelling is true
|
|
|
|
/// Flag changes is synced with ProcessListBase::mutex and notified with ProcessList::cancelled_cv
|
|
|
|
bool is_cancelling { false };
|
|
|
|
/// KILL was send to the query
|
2018-04-07 03:49:49 +00:00
|
|
|
std::atomic<bool> is_killed { false };
|
2015-09-04 20:52:00 +00:00
|
|
|
|
2022-04-30 00:04:12 +00:00
|
|
|
/// All data to the client already had been sent.
|
|
|
|
/// Including EndOfStream or Exception.
|
2022-04-26 06:17:17 +00:00
|
|
|
std::atomic<bool> is_all_data_sent { false };
|
|
|
|
|
2018-02-01 17:55:08 +00:00
|
|
|
void setUserProcessList(ProcessListForUser * user_process_list_);
|
|
|
|
/// Be careful using it. For example, queries field of ProcessListForUser could be modified concurrently.
|
|
|
|
const ProcessListForUser * getUserProcessList() const { return user_process_list; }
|
2017-08-29 13:23:04 +00:00
|
|
|
|
2021-09-16 17:40:42 +00:00
|
|
|
mutable std::mutex executors_mutex;
|
2017-02-03 16:15:12 +00:00
|
|
|
|
2023-03-02 17:20:29 +00:00
|
|
|
struct ExecutorHolder
|
|
|
|
{
|
|
|
|
ExecutorHolder(PipelineExecutor * e) : executor(e) {}
|
|
|
|
|
|
|
|
void cancel();
|
|
|
|
|
|
|
|
void remove();
|
|
|
|
|
|
|
|
PipelineExecutor * executor;
|
|
|
|
std::mutex mutex;
|
|
|
|
};
|
|
|
|
|
|
|
|
using ExecutorHolderPtr = std::shared_ptr<ExecutorHolder>;
|
|
|
|
|
2023-03-27 13:19:45 +00:00
|
|
|
/// Container of PipelineExecutors to be cancelled when a cancelQuery is received
|
|
|
|
std::unordered_map<PipelineExecutor *, ExecutorHolderPtr> executors;
|
2021-07-27 09:52:45 +00:00
|
|
|
|
2018-04-17 15:16:32 +00:00
|
|
|
enum QueryStreamsStatus
|
|
|
|
{
|
|
|
|
NotInitialized,
|
|
|
|
Initialized,
|
|
|
|
Released
|
|
|
|
};
|
|
|
|
|
|
|
|
QueryStreamsStatus query_streams_status{NotInitialized};
|
2016-11-30 17:31:05 +00:00
|
|
|
|
2018-02-01 17:55:08 +00:00
|
|
|
ProcessListForUser * user_process_list = nullptr;
|
|
|
|
|
2022-10-21 22:19:06 +00:00
|
|
|
OvercommitTracker * global_overcommit_tracker = nullptr;
|
|
|
|
|
2023-02-01 02:11:54 +00:00
|
|
|
/// This is used to control the maximum number of SELECT or INSERT queries.
|
2023-02-03 01:16:30 +00:00
|
|
|
IAST::QueryKind query_kind{};
|
2021-12-12 08:07:06 +00:00
|
|
|
|
2022-02-01 12:06:49 +00:00
|
|
|
/// This field is unused in this class, but it
|
|
|
|
/// increments/decrements metric in constructor/destructor.
|
|
|
|
CurrentMetrics::Increment num_queries_increment;
|
|
|
|
|
2016-11-30 17:31:05 +00:00
|
|
|
public:
|
2018-02-01 17:55:08 +00:00
|
|
|
QueryStatus(
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr context_,
|
2016-10-24 21:40:39 +00:00
|
|
|
const String & query_,
|
|
|
|
const ClientInfo & client_info_,
|
2021-12-16 13:46:15 +00:00
|
|
|
QueryPriorities::Handle && priority_handle_,
|
2023-04-07 13:13:21 +00:00
|
|
|
ThreadGroupPtr && thread_group_,
|
2023-02-01 02:31:31 +00:00
|
|
|
IAST::QueryKind query_kind_,
|
2023-06-23 21:42:31 +00:00
|
|
|
const Settings & query_settings_,
|
2022-12-28 20:01:41 +00:00
|
|
|
UInt64 watch_start_nanoseconds);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2018-05-31 15:54:08 +00:00
|
|
|
~QueryStatus();
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2018-03-09 23:04:26 +00:00
|
|
|
const ClientInfo & getClientInfo() const
|
|
|
|
{
|
|
|
|
return client_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProgressValues getProgressIn() const
|
|
|
|
{
|
|
|
|
return progress_in.getValues();
|
|
|
|
}
|
|
|
|
|
|
|
|
ProgressValues getProgressOut() const
|
|
|
|
{
|
|
|
|
return progress_out.getValues();
|
|
|
|
}
|
|
|
|
|
|
|
|
ThrottlerPtr getUserNetworkThrottler();
|
|
|
|
|
2021-10-22 12:56:09 +00:00
|
|
|
MemoryTracker * getMemoryTracker() const
|
|
|
|
{
|
2021-12-14 13:39:53 +00:00
|
|
|
if (!thread_group)
|
|
|
|
return nullptr;
|
2021-10-22 12:56:09 +00:00
|
|
|
return &thread_group->memory_tracker;
|
|
|
|
}
|
|
|
|
|
2016-12-06 20:55:13 +00:00
|
|
|
bool updateProgressIn(const Progress & value)
|
2015-04-16 06:12:35 +00:00
|
|
|
{
|
2018-05-31 15:54:08 +00:00
|
|
|
CurrentThread::updateProgressIn(value);
|
2016-12-06 20:55:13 +00:00
|
|
|
progress_in.incrementPiecewiseAtomically(value);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2015-06-21 06:06:04 +00:00
|
|
|
if (priority_handle)
|
2016-10-24 04:06:27 +00:00
|
|
|
priority_handle->waitIfNeed(std::chrono::seconds(1)); /// NOTE Could make timeout customizable.
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2018-04-07 03:49:49 +00:00
|
|
|
return !is_killed.load(std::memory_order_relaxed);
|
2015-04-16 06:12:35 +00:00
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2016-12-06 20:55:13 +00:00
|
|
|
bool updateProgressOut(const Progress & value)
|
|
|
|
{
|
2018-05-31 15:54:08 +00:00
|
|
|
CurrentThread::updateProgressOut(value);
|
2016-12-06 20:55:13 +00:00
|
|
|
progress_out.incrementPiecewiseAtomically(value);
|
2018-05-31 15:54:08 +00:00
|
|
|
|
2018-04-07 03:49:49 +00:00
|
|
|
return !is_killed.load(std::memory_order_relaxed);
|
2016-12-06 20:55:13 +00:00
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2018-05-17 16:01:41 +00:00
|
|
|
QueryStatusInfo getInfo(bool get_thread_list = false, bool get_profile_events = false, bool get_settings = false) const;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2019-02-01 01:48:25 +00:00
|
|
|
CancellationCode cancelQuery(bool kill);
|
|
|
|
|
2018-11-01 14:56:37 +00:00
|
|
|
bool isKilled() const { return is_killed; }
|
2021-07-27 09:52:45 +00:00
|
|
|
|
2022-04-26 06:17:17 +00:00
|
|
|
bool isAllDataSent() const { return is_all_data_sent; }
|
|
|
|
void setAllDataSent() { is_all_data_sent = true; }
|
|
|
|
|
2021-07-27 09:52:45 +00:00
|
|
|
/// Adds a pipeline to the QueryStatus
|
|
|
|
void addPipelineExecutor(PipelineExecutor * e);
|
|
|
|
|
|
|
|
/// Removes a pipeline to the QueryStatus
|
|
|
|
void removePipelineExecutor(PipelineExecutor * e);
|
2021-11-26 11:44:39 +00:00
|
|
|
|
|
|
|
/// Checks the query time limits (cancelled or timeout)
|
|
|
|
bool checkTimeLimit();
|
2021-12-02 13:53:55 +00:00
|
|
|
/// Same as checkTimeLimit but it never throws
|
2021-12-02 14:09:53 +00:00
|
|
|
[[nodiscard]] bool checkTimeLimitSoft();
|
2022-12-28 20:01:41 +00:00
|
|
|
|
|
|
|
/// Get the reference for the start of the query. Used to synchronize with other Stopwatches
|
|
|
|
UInt64 getQueryCPUStartTime() { return watch.getStart(); }
|
2015-04-16 06:12:35 +00:00
|
|
|
};
|
|
|
|
|
2022-10-17 02:21:08 +00:00
|
|
|
using QueryStatusPtr = std::shared_ptr<QueryStatus>;
|
|
|
|
|
2015-04-16 06:12:35 +00:00
|
|
|
|
2020-03-20 17:27:17 +00:00
|
|
|
/// Information of process list for user.
|
|
|
|
struct ProcessListForUserInfo
|
|
|
|
{
|
|
|
|
Int64 memory_usage;
|
|
|
|
Int64 peak_memory_usage;
|
|
|
|
|
|
|
|
// Optional field, filled by request.
|
2021-10-11 15:56:23 +00:00
|
|
|
std::shared_ptr<ProfileEvents::Counters::Snapshot> profile_counters;
|
2020-03-20 17:27:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-10-24 04:06:27 +00:00
|
|
|
/// Data about queries for one user.
|
2015-12-30 15:39:11 +00:00
|
|
|
struct ProcessListForUser
|
|
|
|
{
|
2022-09-21 12:51:46 +00:00
|
|
|
explicit ProcessListForUser(ProcessList * global_process_list);
|
|
|
|
|
|
|
|
ProcessListForUser(ContextPtr global_context, ProcessList * global_process_list);
|
2018-02-01 17:55:08 +00:00
|
|
|
|
2018-03-09 22:11:42 +00:00
|
|
|
/// query_id -> ProcessListElement(s). There can be multiple queries with the same query_id as long as all queries except one are cancelled.
|
2022-10-17 02:21:08 +00:00
|
|
|
using QueryToElement = std::unordered_map<String, QueryStatusPtr>;
|
2015-12-30 15:39:11 +00:00
|
|
|
QueryToElement queries;
|
2016-01-13 02:38:30 +00:00
|
|
|
|
2018-06-09 15:29:08 +00:00
|
|
|
ProfileEvents::Counters user_performance_counters{VariableContext::User, &ProfileEvents::global_counters};
|
2016-10-24 04:06:27 +00:00
|
|
|
/// Limit and counter for memory of all simultaneously running queries of single user.
|
2018-06-09 15:29:08 +00:00
|
|
|
MemoryTracker user_memory_tracker{VariableContext::User};
|
2017-08-29 13:23:04 +00:00
|
|
|
|
2022-09-15 10:19:39 +00:00
|
|
|
TemporaryDataOnDiskScopePtr user_temp_data_on_disk;
|
2022-08-31 17:17:31 +00:00
|
|
|
|
2021-10-22 12:56:09 +00:00
|
|
|
UserOvercommitTracker user_overcommit_tracker;
|
|
|
|
|
2017-08-29 20:20:21 +00:00
|
|
|
/// Count network usage for all simultaneously running queries of single user.
|
2017-08-29 13:23:04 +00:00
|
|
|
ThrottlerPtr user_throttler;
|
2018-03-09 22:11:42 +00:00
|
|
|
|
2020-03-20 17:27:17 +00:00
|
|
|
ProcessListForUserInfo getInfo(bool get_profile_events = false) const;
|
|
|
|
|
2018-03-09 22:11:42 +00:00
|
|
|
/// Clears MemoryTracker for the user.
|
|
|
|
/// Sometimes it is important to reset the MemoryTracker, because it may accumulate skew
|
|
|
|
/// due to the fact that there are cases when memory can be allocated while processing the query, but released later.
|
|
|
|
/// Clears network bandwidth Throttler, so it will not count periods of inactivity.
|
2018-06-19 20:30:35 +00:00
|
|
|
void resetTrackers()
|
2018-03-09 22:11:42 +00:00
|
|
|
{
|
2022-08-31 17:17:31 +00:00
|
|
|
/// TODO: should we drop user_temp_data_on_disk here?
|
2018-03-09 22:11:42 +00:00
|
|
|
user_memory_tracker.reset();
|
|
|
|
if (user_throttler)
|
2018-03-29 13:24:36 +00:00
|
|
|
user_throttler.reset();
|
2018-03-09 22:11:42 +00:00
|
|
|
}
|
2015-12-30 15:39:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-06-21 06:06:04 +00:00
|
|
|
class ProcessList;
|
|
|
|
|
|
|
|
|
2016-10-24 04:06:27 +00:00
|
|
|
/// Keeps iterator to process list and removes element in destructor.
|
2015-06-21 06:06:04 +00:00
|
|
|
class ProcessListEntry
|
|
|
|
{
|
|
|
|
private:
|
2022-10-17 02:21:08 +00:00
|
|
|
using Container = std::list<QueryStatusPtr>;
|
2015-06-21 06:06:04 +00:00
|
|
|
|
|
|
|
ProcessList & parent;
|
|
|
|
Container::iterator it;
|
2018-05-14 16:09:00 +00:00
|
|
|
|
2015-06-21 06:06:04 +00:00
|
|
|
public:
|
|
|
|
ProcessListEntry(ProcessList & parent_, Container::iterator it_)
|
|
|
|
: parent(parent_), it(it_) {}
|
|
|
|
|
|
|
|
~ProcessListEntry();
|
|
|
|
|
2022-10-17 02:21:08 +00:00
|
|
|
QueryStatusPtr getQueryStatus() { return *it; }
|
|
|
|
const QueryStatusPtr getQueryStatus() const { return *it; }
|
2015-06-21 06:06:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-08-29 18:24:35 +00:00
|
|
|
class ProcessListBase
|
|
|
|
{
|
|
|
|
mutable std::mutex mutex;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
using Lock = std::unique_lock<std::mutex>;
|
|
|
|
struct LockAndBlocker
|
|
|
|
{
|
|
|
|
Lock lock;
|
|
|
|
OvercommitTrackerBlockerInThread blocker;
|
|
|
|
};
|
|
|
|
|
2022-08-29 18:26:37 +00:00
|
|
|
// It is forbidden to do allocations/deallocations with acquired mutex and
|
2022-08-29 18:24:35 +00:00
|
|
|
// enabled OvercommitTracker. This leads to deadlock in the case of OOM.
|
|
|
|
LockAndBlocker safeLock() const noexcept { return { std::unique_lock{mutex}, {} }; }
|
|
|
|
Lock unsafeLock() const noexcept { return std::unique_lock{mutex}; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ProcessList : public ProcessListBase
|
2015-04-16 06:12:35 +00:00
|
|
|
{
|
|
|
|
public:
|
2022-10-17 02:21:08 +00:00
|
|
|
using Element = QueryStatusPtr;
|
2015-06-21 06:06:04 +00:00
|
|
|
using Entry = ProcessListEntry;
|
2021-12-12 08:07:06 +00:00
|
|
|
using QueryAmount = UInt64;
|
2013-09-03 20:21:28 +00:00
|
|
|
|
2016-10-24 04:06:27 +00:00
|
|
|
/// list, for iterators not to invalidate. NOTE: could replace with cyclic buffer, but not worth.
|
2015-06-21 06:06:04 +00:00
|
|
|
using Container = std::list<Element>;
|
2018-02-01 17:55:08 +00:00
|
|
|
using Info = std::vector<QueryStatusInfo>;
|
2020-03-20 17:27:17 +00:00
|
|
|
using UserInfo = std::unordered_map<String, ProcessListForUserInfo>;
|
|
|
|
|
2016-01-13 02:38:30 +00:00
|
|
|
/// User -> queries
|
|
|
|
using UserToQueries = std::unordered_map<String, ProcessListForUser>;
|
2013-09-03 20:21:28 +00:00
|
|
|
|
2022-01-10 12:49:53 +00:00
|
|
|
using QueryKindAmounts = std::unordered_map<IAST::QueryKind, QueryAmount>;
|
2021-12-12 08:07:06 +00:00
|
|
|
|
2018-05-14 16:09:00 +00:00
|
|
|
protected:
|
|
|
|
friend class ProcessListEntry;
|
2022-08-29 18:24:35 +00:00
|
|
|
friend struct ::OvercommitTracker;
|
2022-02-16 20:02:14 +00:00
|
|
|
friend struct ::UserOvercommitTracker;
|
|
|
|
friend struct ::GlobalOvercommitTracker;
|
2018-05-14 16:09:00 +00:00
|
|
|
|
2018-04-18 20:18:18 +00:00
|
|
|
mutable std::condition_variable have_space; /// Number of currently running queries has become less than maximum.
|
2014-09-10 11:34:26 +00:00
|
|
|
|
2017-08-29 13:23:04 +00:00
|
|
|
/// List of queries
|
2018-02-01 17:55:08 +00:00
|
|
|
Container processes;
|
2022-09-18 13:46:14 +00:00
|
|
|
/// Notify about cancelled queries (done with ProcessListBase::mutex acquired).
|
|
|
|
mutable std::condition_variable cancelled_cv;
|
|
|
|
|
2021-05-08 22:09:16 +00:00
|
|
|
size_t max_size = 0; /// 0 means no limit. Otherwise, when limit exceeded, an exception is thrown.
|
2017-08-29 13:23:04 +00:00
|
|
|
|
|
|
|
/// Stores per-user info: queries, statistics and limits
|
2014-02-14 13:22:45 +00:00
|
|
|
UserToQueries user_to_queries;
|
2017-08-29 13:23:04 +00:00
|
|
|
|
|
|
|
/// Stores info about queries grouped by their priority
|
2015-06-21 06:06:04 +00:00
|
|
|
QueryPriorities priorities;
|
2013-09-03 20:21:28 +00:00
|
|
|
|
2018-03-29 13:24:36 +00:00
|
|
|
/// Limit network bandwidth for all users
|
|
|
|
ThrottlerPtr total_network_throttler;
|
|
|
|
|
2017-01-24 16:28:24 +00:00
|
|
|
/// Call under lock. Finds process with specified current_user and current_query_id.
|
2022-10-17 02:21:08 +00:00
|
|
|
QueryStatusPtr tryGetProcessListElement(const String & current_query_id, const String & current_user);
|
2017-01-24 15:11:36 +00:00
|
|
|
|
2021-12-12 08:07:06 +00:00
|
|
|
/// limit for insert. 0 means no limit. Otherwise, when limit exceeded, an exception is thrown.
|
|
|
|
size_t max_insert_queries_amount = 0;
|
|
|
|
|
|
|
|
/// limit for select. 0 means no limit. Otherwise, when limit exceeded, an exception is thrown.
|
|
|
|
size_t max_select_queries_amount = 0;
|
|
|
|
|
|
|
|
/// amount of queries by query kind.
|
2022-01-10 12:49:53 +00:00
|
|
|
QueryKindAmounts query_kind_amounts;
|
2021-12-12 08:07:06 +00:00
|
|
|
|
2022-01-10 12:49:53 +00:00
|
|
|
void increaseQueryKindAmount(const IAST::QueryKind & query_kind);
|
|
|
|
void decreaseQueryKindAmount(const IAST::QueryKind & query_kind);
|
2021-12-29 14:25:56 +00:00
|
|
|
QueryAmount getQueryKindAmount(const IAST::QueryKind & query_kind) const;
|
2021-12-12 08:07:06 +00:00
|
|
|
|
2013-09-03 20:21:28 +00:00
|
|
|
public:
|
2016-01-13 03:59:24 +00:00
|
|
|
using EntryPtr = std::shared_ptr<ProcessListEntry>;
|
2013-09-03 20:21:28 +00:00
|
|
|
|
2016-10-24 04:06:27 +00:00
|
|
|
/** Register running query. Returns refcounted object, that will remove element from list in destructor.
|
2017-11-15 19:47:49 +00:00
|
|
|
* If too many running queries - wait for not more than specified (see settings) amount of time.
|
2016-10-24 04:06:27 +00:00
|
|
|
* If timeout is passed - throw an exception.
|
2023-06-19 11:39:30 +00:00
|
|
|
* Don't count KILL QUERY queries or async insert flush queries
|
2013-09-07 04:54:59 +00:00
|
|
|
*/
|
2023-06-20 09:37:56 +00:00
|
|
|
EntryPtr insert(const String & query_, const IAST * ast, ContextMutablePtr query_context, UInt64 watch_start_nanoseconds);
|
2013-09-03 20:21:28 +00:00
|
|
|
|
2016-10-24 04:06:27 +00:00
|
|
|
/// Number of currently executing queries.
|
2018-02-01 17:55:08 +00:00
|
|
|
size_t size() const { return processes.size(); }
|
2013-09-03 20:21:28 +00:00
|
|
|
|
2016-10-24 04:06:27 +00:00
|
|
|
/// Get current state of process list.
|
2018-05-17 16:01:41 +00:00
|
|
|
Info getInfo(bool get_thread_list = false, bool get_profile_events = false, bool get_settings = false) const;
|
2013-09-03 20:21:28 +00:00
|
|
|
|
2020-03-20 17:27:17 +00:00
|
|
|
/// Get current state of process list per user.
|
|
|
|
UserInfo getUserInfo(bool get_profile_events = false) const;
|
|
|
|
|
2013-09-03 20:21:28 +00:00
|
|
|
void setMaxSize(size_t max_size_)
|
|
|
|
{
|
2022-08-29 18:24:35 +00:00
|
|
|
auto lock = unsafeLock();
|
2013-09-03 20:21:28 +00:00
|
|
|
max_size = max_size_;
|
|
|
|
}
|
2015-09-04 20:52:00 +00:00
|
|
|
|
2023-08-03 06:33:33 +00:00
|
|
|
size_t getMaxSize() const
|
|
|
|
{
|
|
|
|
auto lock = unsafeLock();
|
|
|
|
return max_size;
|
|
|
|
}
|
|
|
|
|
2021-12-12 08:07:06 +00:00
|
|
|
void setMaxInsertQueriesAmount(size_t max_insert_queries_amount_)
|
|
|
|
{
|
2022-08-29 18:24:35 +00:00
|
|
|
auto lock = unsafeLock();
|
2021-12-12 08:07:06 +00:00
|
|
|
max_insert_queries_amount = max_insert_queries_amount_;
|
|
|
|
}
|
|
|
|
|
2023-08-03 06:33:33 +00:00
|
|
|
size_t getMaxInsertQueriesAmount() const
|
|
|
|
{
|
|
|
|
auto lock = unsafeLock();
|
|
|
|
return max_insert_queries_amount;
|
|
|
|
}
|
|
|
|
|
2021-12-12 08:07:06 +00:00
|
|
|
void setMaxSelectQueriesAmount(size_t max_select_queries_amount_)
|
|
|
|
{
|
2022-08-29 18:24:35 +00:00
|
|
|
auto lock = unsafeLock();
|
2021-12-12 08:07:06 +00:00
|
|
|
max_select_queries_amount = max_select_queries_amount_;
|
|
|
|
}
|
|
|
|
|
2023-08-03 06:33:33 +00:00
|
|
|
size_t getMaxSelectQueriesAmount() const
|
|
|
|
{
|
|
|
|
auto lock = unsafeLock();
|
|
|
|
return max_select_queries_amount;
|
|
|
|
}
|
|
|
|
|
2016-11-30 17:31:05 +00:00
|
|
|
/// Try call cancel() for input and output streams of query with specified id and user
|
2018-03-05 21:09:39 +00:00
|
|
|
CancellationCode sendCancelToQuery(const String & current_query_id, const String & current_user, bool kill = false);
|
2019-07-30 23:12:04 +00:00
|
|
|
|
|
|
|
void killAllQueries();
|
2013-09-03 20:21:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|