2012-05-16 18:03:00 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-01-22 15:03:55 +00:00
|
|
|
#include <atomic>
|
2019-01-09 17:31:30 +00:00
|
|
|
#include <cstddef>
|
2021-07-17 20:15:16 +00:00
|
|
|
#include <functional>
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/types.h>
|
2017-01-22 15:03:55 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Core/Defines.h>
|
2012-05-16 18:03:00 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-01-22 15:03:55 +00:00
|
|
|
class ReadBuffer;
|
|
|
|
class WriteBuffer;
|
|
|
|
|
2018-03-09 23:04:26 +00:00
|
|
|
/// See Progress.
|
|
|
|
struct ProgressValues
|
|
|
|
{
|
2019-05-20 11:37:41 +00:00
|
|
|
size_t read_rows;
|
|
|
|
size_t read_bytes;
|
2021-05-13 22:56:42 +00:00
|
|
|
size_t read_raw_bytes;
|
|
|
|
|
2019-05-20 11:37:41 +00:00
|
|
|
size_t total_rows_to_read;
|
2021-05-13 22:56:42 +00:00
|
|
|
size_t total_raw_bytes_to_read;
|
|
|
|
|
2019-05-20 11:37:41 +00:00
|
|
|
size_t written_rows;
|
|
|
|
size_t written_bytes;
|
2018-03-09 23:04:26 +00:00
|
|
|
|
2019-05-13 04:48:09 +00:00
|
|
|
void read(ReadBuffer & in, UInt64 server_revision);
|
|
|
|
void write(WriteBuffer & out, UInt64 client_revision) const;
|
|
|
|
void writeJSON(WriteBuffer & out) const;
|
2018-03-09 23:04:26 +00:00
|
|
|
};
|
|
|
|
|
2019-04-25 11:25:49 +00:00
|
|
|
struct ReadProgress
|
|
|
|
{
|
2019-05-20 11:37:41 +00:00
|
|
|
size_t read_rows;
|
|
|
|
size_t read_bytes;
|
|
|
|
size_t total_rows_to_read;
|
2019-04-25 11:25:49 +00:00
|
|
|
|
2019-05-20 11:37:41 +00:00
|
|
|
ReadProgress(size_t read_rows_, size_t read_bytes_, size_t total_rows_to_read_ = 0)
|
|
|
|
: read_rows(read_rows_), read_bytes(read_bytes_), total_rows_to_read(total_rows_to_read_) {}
|
2019-04-25 11:25:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct WriteProgress
|
|
|
|
{
|
2019-05-20 11:37:41 +00:00
|
|
|
size_t written_rows;
|
|
|
|
size_t written_bytes;
|
2019-04-25 11:25:49 +00:00
|
|
|
|
2019-05-20 11:37:41 +00:00
|
|
|
WriteProgress(size_t written_rows_, size_t written_bytes_)
|
|
|
|
: written_rows(written_rows_), written_bytes(written_bytes_) {}
|
2019-04-25 11:25:49 +00:00
|
|
|
};
|
2018-03-09 23:04:26 +00:00
|
|
|
|
2021-04-28 16:25:14 +00:00
|
|
|
struct FileProgress
|
2021-04-26 13:34:44 +00:00
|
|
|
{
|
2021-05-13 22:56:42 +00:00
|
|
|
/// Here read_bytes (raw bytes) - do not equal ReadProgress::read_bytes, which are calculated according to column types.
|
|
|
|
size_t read_bytes;
|
|
|
|
size_t total_bytes_to_read;
|
2021-04-26 13:34:44 +00:00
|
|
|
|
2021-05-13 22:56:42 +00:00
|
|
|
FileProgress(size_t read_bytes_, size_t total_bytes_to_read_ = 0) : read_bytes(read_bytes_), total_bytes_to_read(total_bytes_to_read_) {}
|
2021-04-26 13:34:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-08-17 06:41:43 +00:00
|
|
|
/** Progress of query execution.
|
|
|
|
* Values, transferred over network are deltas - how much was done after previously sent value.
|
|
|
|
* The same struct is also used for summarized values.
|
2014-10-25 18:33:52 +00:00
|
|
|
*/
|
2012-05-16 18:03:00 +00:00
|
|
|
struct Progress
|
|
|
|
{
|
2019-05-20 11:37:41 +00:00
|
|
|
std::atomic<size_t> read_rows {0}; /// Rows (source) processed.
|
|
|
|
std::atomic<size_t> read_bytes {0}; /// Bytes (uncompressed, source) processed.
|
2021-05-13 22:56:42 +00:00
|
|
|
std::atomic<size_t> read_raw_bytes {0}; /// Raw bytes processed.
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2021-05-13 22:56:42 +00:00
|
|
|
/** How much rows/bytes must be processed, in total, approximately. Non-zero value is sent when there is information about
|
|
|
|
* some new part of job. Received values must be summed to get estimate of total rows to process.
|
|
|
|
* `total_raw_bytes_to_process` is used for file table engine or when reading from file descriptor.
|
2017-04-01 07:20:54 +00:00
|
|
|
* Used for rendering progress bar on client.
|
|
|
|
*/
|
2019-05-20 11:37:41 +00:00
|
|
|
std::atomic<size_t> total_rows_to_read {0};
|
2021-05-13 22:56:42 +00:00
|
|
|
std::atomic<size_t> total_raw_bytes_to_read {0};
|
2019-04-25 11:25:49 +00:00
|
|
|
|
2019-05-20 11:37:41 +00:00
|
|
|
std::atomic<size_t> written_rows {0};
|
|
|
|
std::atomic<size_t> written_bytes {0};
|
2019-04-25 11:25:49 +00:00
|
|
|
|
2021-03-11 14:04:59 +00:00
|
|
|
Progress() = default;
|
2021-05-13 22:56:42 +00:00
|
|
|
|
2019-05-20 11:37:41 +00:00
|
|
|
Progress(size_t read_rows_, size_t read_bytes_, size_t total_rows_to_read_ = 0)
|
|
|
|
: read_rows(read_rows_), read_bytes(read_bytes_), total_rows_to_read(total_rows_to_read_) {}
|
2021-05-13 22:56:42 +00:00
|
|
|
|
2021-03-11 14:04:59 +00:00
|
|
|
explicit Progress(ReadProgress read_progress)
|
2019-05-20 11:37:41 +00:00
|
|
|
: read_rows(read_progress.read_rows), read_bytes(read_progress.read_bytes), total_rows_to_read(read_progress.total_rows_to_read) {}
|
2021-05-13 22:56:42 +00:00
|
|
|
|
2021-03-11 14:04:59 +00:00
|
|
|
explicit Progress(WriteProgress write_progress)
|
2019-05-20 11:37:41 +00:00
|
|
|
: written_rows(write_progress.written_rows), written_bytes(write_progress.written_bytes) {}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2021-05-13 22:56:42 +00:00
|
|
|
explicit Progress(FileProgress file_progress)
|
|
|
|
: read_raw_bytes(file_progress.read_bytes), total_raw_bytes_to_read(file_progress.total_bytes_to_read) {}
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void read(ReadBuffer & in, UInt64 server_revision);
|
2021-05-13 22:56:42 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void write(WriteBuffer & out, UInt64 client_revision) const;
|
2021-05-13 22:56:42 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Progress in JSON format (single line, without whitespaces) is used in HTTP headers.
|
|
|
|
void writeJSON(WriteBuffer & out) const;
|
|
|
|
|
|
|
|
/// Each value separately is changed atomically (but not whole object).
|
2021-05-13 22:56:42 +00:00
|
|
|
bool incrementPiecewiseAtomically(const Progress & rhs);
|
2019-02-07 13:47:16 +00:00
|
|
|
|
2021-05-13 22:56:42 +00:00
|
|
|
void reset();
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2021-05-13 22:56:42 +00:00
|
|
|
ProgressValues getValues() const;
|
2018-03-09 23:04:26 +00:00
|
|
|
|
2021-05-13 22:56:42 +00:00
|
|
|
ProgressValues fetchAndResetPiecewiseAtomically();
|
2018-03-09 23:04:26 +00:00
|
|
|
|
2021-05-13 22:56:42 +00:00
|
|
|
Progress & operator=(Progress && other);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
Progress(Progress && other)
|
|
|
|
{
|
|
|
|
*this = std::move(other);
|
|
|
|
}
|
2012-05-16 18:03:00 +00:00
|
|
|
};
|
|
|
|
|
2021-07-17 18:06:46 +00:00
|
|
|
|
|
|
|
/** Callback to track the progress of the query.
|
|
|
|
* Used in IBlockInputStream and Context.
|
|
|
|
* The function takes the number of rows in the last block, the number of bytes in the last block.
|
|
|
|
* Note that the callback can be called from different threads.
|
|
|
|
*/
|
|
|
|
using ProgressCallback = std::function<void(const Progress & progress)>;
|
|
|
|
|
2012-05-16 18:03:00 +00:00
|
|
|
}
|