2017-11-24 13:55:31 +00:00
|
|
|
#include "Progress.h"
|
2017-01-22 15:03:55 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/ReadBuffer.h>
|
|
|
|
#include <IO/WriteBuffer.h>
|
|
|
|
#include <IO/ReadHelpers.h>
|
|
|
|
#include <IO/WriteHelpers.h>
|
2021-10-03 09:47:38 +00:00
|
|
|
#include <Core/ProtocolDefines.h>
|
2017-01-22 15:03:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2019-05-13 04:48:09 +00:00
|
|
|
void ProgressValues::read(ReadBuffer & in, UInt64 server_revision)
|
2017-01-22 15:03:55 +00:00
|
|
|
{
|
2022-08-08 04:55:41 +00:00
|
|
|
readVarUInt(read_rows, in);
|
|
|
|
readVarUInt(read_bytes, in);
|
|
|
|
readVarUInt(total_rows_to_read, in);
|
2019-05-13 07:18:02 +00:00
|
|
|
if (server_revision >= DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO)
|
2019-05-13 04:48:09 +00:00
|
|
|
{
|
2022-08-08 04:55:41 +00:00
|
|
|
readVarUInt(written_rows, in);
|
|
|
|
readVarUInt(written_bytes, in);
|
|
|
|
}
|
|
|
|
if (server_revision >= DBMS_MIN_PROTOCOL_VERSION_WITH_SERVER_QUERY_TIME_IN_PROGRESS)
|
|
|
|
{
|
|
|
|
readVarUInt(elapsed_ns, in);
|
2019-05-13 04:48:09 +00:00
|
|
|
}
|
2019-05-06 06:57:48 +00:00
|
|
|
}
|
2017-01-22 15:03:55 +00:00
|
|
|
|
|
|
|
|
2019-05-13 04:48:09 +00:00
|
|
|
void ProgressValues::write(WriteBuffer & out, UInt64 client_revision) const
|
2017-01-22 15:03:55 +00:00
|
|
|
{
|
2023-04-11 07:47:33 +00:00
|
|
|
writeVarUInt(read_rows, out);
|
|
|
|
writeVarUInt(read_bytes, out);
|
|
|
|
writeVarUInt(total_rows_to_read, out);
|
2019-05-13 04:48:09 +00:00
|
|
|
if (client_revision >= DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO)
|
|
|
|
{
|
2023-04-11 07:47:33 +00:00
|
|
|
writeVarUInt(written_rows, out);
|
|
|
|
writeVarUInt(written_bytes, out);
|
2022-08-08 04:55:41 +00:00
|
|
|
}
|
|
|
|
if (client_revision >= DBMS_MIN_PROTOCOL_VERSION_WITH_SERVER_QUERY_TIME_IN_PROGRESS)
|
|
|
|
{
|
|
|
|
writeVarUInt(elapsed_ns, out);
|
2019-05-13 04:48:09 +00:00
|
|
|
}
|
2017-01-22 15:03:55 +00:00
|
|
|
}
|
|
|
|
|
2019-05-13 04:48:09 +00:00
|
|
|
void ProgressValues::writeJSON(WriteBuffer & out) const
|
2017-01-22 15:03:55 +00:00
|
|
|
{
|
|
|
|
/// Numbers are written in double quotes (as strings) to avoid loss of precision
|
|
|
|
/// of 64-bit integers after interpretation by JavaScript.
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-01-22 15:03:55 +00:00
|
|
|
writeCString("{\"read_rows\":\"", out);
|
2022-08-08 04:55:41 +00:00
|
|
|
writeText(read_rows, out);
|
2017-01-22 15:03:55 +00:00
|
|
|
writeCString("\",\"read_bytes\":\"", out);
|
2022-08-08 04:55:41 +00:00
|
|
|
writeText(read_bytes, out);
|
2019-05-13 04:48:09 +00:00
|
|
|
writeCString("\",\"written_rows\":\"", out);
|
2022-08-08 04:55:41 +00:00
|
|
|
writeText(written_rows, out);
|
2019-05-13 04:48:09 +00:00
|
|
|
writeCString("\",\"written_bytes\":\"", out);
|
2022-08-08 04:55:41 +00:00
|
|
|
writeText(written_bytes, out);
|
2019-05-20 11:37:41 +00:00
|
|
|
writeCString("\",\"total_rows_to_read\":\"", out);
|
2022-08-08 04:55:41 +00:00
|
|
|
writeText(total_rows_to_read, out);
|
2022-07-25 16:12:41 +00:00
|
|
|
writeCString("\",\"result_rows\":\"", out);
|
2022-08-08 04:55:41 +00:00
|
|
|
writeText(result_rows, out);
|
2022-07-25 16:12:41 +00:00
|
|
|
writeCString("\",\"result_bytes\":\"", out);
|
2022-08-08 04:55:41 +00:00
|
|
|
writeText(result_bytes, out);
|
2017-01-22 15:03:55 +00:00
|
|
|
writeCString("\"}", out);
|
|
|
|
}
|
|
|
|
|
2021-05-13 22:56:42 +00:00
|
|
|
bool Progress::incrementPiecewiseAtomically(const Progress & rhs)
|
|
|
|
{
|
|
|
|
read_rows += rhs.read_rows;
|
|
|
|
read_bytes += rhs.read_bytes;
|
|
|
|
|
2022-05-11 12:21:44 +00:00
|
|
|
total_rows_to_read += rhs.total_rows_to_read;
|
|
|
|
total_bytes_to_read += rhs.total_bytes_to_read;
|
2021-05-13 22:56:42 +00:00
|
|
|
|
|
|
|
written_rows += rhs.written_rows;
|
|
|
|
written_bytes += rhs.written_bytes;
|
|
|
|
|
2022-07-25 16:12:41 +00:00
|
|
|
result_rows += rhs.result_rows;
|
|
|
|
result_bytes += rhs.result_bytes;
|
|
|
|
|
2022-08-08 04:55:41 +00:00
|
|
|
elapsed_ns += rhs.elapsed_ns;
|
|
|
|
|
2021-05-13 22:56:42 +00:00
|
|
|
return rhs.read_rows || rhs.written_rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Progress::reset()
|
|
|
|
{
|
|
|
|
read_rows = 0;
|
|
|
|
read_bytes = 0;
|
|
|
|
|
|
|
|
total_rows_to_read = 0;
|
2022-05-06 15:04:03 +00:00
|
|
|
total_bytes_to_read = 0;
|
2021-05-13 22:56:42 +00:00
|
|
|
|
|
|
|
written_rows = 0;
|
|
|
|
written_bytes = 0;
|
2022-07-25 16:12:41 +00:00
|
|
|
|
|
|
|
result_rows = 0;
|
|
|
|
result_bytes = 0;
|
2022-08-08 04:55:41 +00:00
|
|
|
|
|
|
|
elapsed_ns = 0;
|
2021-05-13 22:56:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ProgressValues Progress::getValues() const
|
|
|
|
{
|
|
|
|
ProgressValues res;
|
|
|
|
|
|
|
|
res.read_rows = read_rows.load(std::memory_order_relaxed);
|
|
|
|
res.read_bytes = read_bytes.load(std::memory_order_relaxed);
|
|
|
|
|
|
|
|
res.total_rows_to_read = total_rows_to_read.load(std::memory_order_relaxed);
|
2022-05-06 15:04:03 +00:00
|
|
|
res.total_bytes_to_read = total_bytes_to_read.load(std::memory_order_relaxed);
|
2021-05-13 22:56:42 +00:00
|
|
|
|
|
|
|
res.written_rows = written_rows.load(std::memory_order_relaxed);
|
|
|
|
res.written_bytes = written_bytes.load(std::memory_order_relaxed);
|
|
|
|
|
2022-07-25 16:12:41 +00:00
|
|
|
res.result_rows = result_rows.load(std::memory_order_relaxed);
|
|
|
|
res.result_bytes = result_bytes.load(std::memory_order_relaxed);
|
|
|
|
|
2022-08-08 04:55:41 +00:00
|
|
|
res.elapsed_ns = elapsed_ns.load(std::memory_order_relaxed);
|
|
|
|
|
2021-05-13 22:56:42 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2022-05-06 15:04:03 +00:00
|
|
|
ProgressValues Progress::fetchValuesAndResetPiecewiseAtomically()
|
2021-05-13 22:56:42 +00:00
|
|
|
{
|
|
|
|
ProgressValues res;
|
|
|
|
|
|
|
|
res.read_rows = read_rows.fetch_and(0);
|
|
|
|
res.read_bytes = read_bytes.fetch_and(0);
|
|
|
|
|
|
|
|
res.total_rows_to_read = total_rows_to_read.fetch_and(0);
|
2022-05-06 15:04:03 +00:00
|
|
|
res.total_bytes_to_read = total_bytes_to_read.fetch_and(0);
|
|
|
|
|
|
|
|
res.written_rows = written_rows.fetch_and(0);
|
|
|
|
res.written_bytes = written_bytes.fetch_and(0);
|
|
|
|
|
2022-07-25 16:12:41 +00:00
|
|
|
res.result_rows = result_rows.fetch_and(0);
|
|
|
|
res.result_bytes = result_bytes.fetch_and(0);
|
|
|
|
|
2022-08-08 04:55:41 +00:00
|
|
|
res.elapsed_ns = elapsed_ns.fetch_and(0);
|
|
|
|
|
2022-05-06 15:04:03 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
Progress Progress::fetchAndResetPiecewiseAtomically()
|
|
|
|
{
|
|
|
|
Progress res;
|
|
|
|
|
|
|
|
res.read_rows = read_rows.fetch_and(0);
|
|
|
|
res.read_bytes = read_bytes.fetch_and(0);
|
|
|
|
|
|
|
|
res.total_rows_to_read = total_rows_to_read.fetch_and(0);
|
|
|
|
res.total_bytes_to_read = total_bytes_to_read.fetch_and(0);
|
2021-05-13 22:56:42 +00:00
|
|
|
|
|
|
|
res.written_rows = written_rows.fetch_and(0);
|
|
|
|
res.written_bytes = written_bytes.fetch_and(0);
|
|
|
|
|
2022-07-25 16:12:41 +00:00
|
|
|
res.result_rows = result_rows.fetch_and(0);
|
|
|
|
res.result_bytes = result_bytes.fetch_and(0);
|
|
|
|
|
2022-08-08 04:55:41 +00:00
|
|
|
res.elapsed_ns = elapsed_ns.fetch_and(0);
|
|
|
|
|
2021-05-13 22:56:42 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2022-02-25 19:04:48 +00:00
|
|
|
Progress & Progress::operator=(Progress && other) noexcept
|
2021-05-13 22:56:42 +00:00
|
|
|
{
|
|
|
|
read_rows = other.read_rows.load(std::memory_order_relaxed);
|
|
|
|
read_bytes = other.read_bytes.load(std::memory_order_relaxed);
|
|
|
|
|
|
|
|
total_rows_to_read = other.total_rows_to_read.load(std::memory_order_relaxed);
|
2022-05-06 15:04:03 +00:00
|
|
|
total_bytes_to_read = other.total_bytes_to_read.load(std::memory_order_relaxed);
|
2021-05-13 22:56:42 +00:00
|
|
|
|
|
|
|
written_rows = other.written_rows.load(std::memory_order_relaxed);
|
|
|
|
written_bytes = other.written_bytes.load(std::memory_order_relaxed);
|
|
|
|
|
2022-07-25 16:12:41 +00:00
|
|
|
result_rows = other.result_rows.load(std::memory_order_relaxed);
|
|
|
|
result_bytes = other.result_bytes.load(std::memory_order_relaxed);
|
|
|
|
|
2022-08-08 04:55:41 +00:00
|
|
|
elapsed_ns = other.elapsed_ns.load(std::memory_order_relaxed);
|
|
|
|
|
2021-05-13 22:56:42 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-05-13 04:48:09 +00:00
|
|
|
void Progress::read(ReadBuffer & in, UInt64 server_revision)
|
2019-05-06 06:14:37 +00:00
|
|
|
{
|
2019-05-13 04:48:09 +00:00
|
|
|
ProgressValues values;
|
|
|
|
values.read(in, server_revision);
|
|
|
|
|
2019-05-20 11:37:41 +00:00
|
|
|
read_rows.store(values.read_rows, std::memory_order_relaxed);
|
|
|
|
read_bytes.store(values.read_bytes, std::memory_order_relaxed);
|
|
|
|
total_rows_to_read.store(values.total_rows_to_read, std::memory_order_relaxed);
|
2022-05-06 15:04:03 +00:00
|
|
|
|
2019-05-20 11:37:41 +00:00
|
|
|
written_rows.store(values.written_rows, std::memory_order_relaxed);
|
|
|
|
written_bytes.store(values.written_bytes, std::memory_order_relaxed);
|
2022-08-08 04:55:41 +00:00
|
|
|
|
|
|
|
elapsed_ns.store(values.elapsed_ns, std::memory_order_relaxed);
|
2019-05-06 06:57:48 +00:00
|
|
|
}
|
2019-05-06 06:14:37 +00:00
|
|
|
|
2019-05-13 04:48:09 +00:00
|
|
|
void Progress::write(WriteBuffer & out, UInt64 client_revision) const
|
2019-05-06 06:14:37 +00:00
|
|
|
{
|
2019-05-13 04:48:09 +00:00
|
|
|
getValues().write(out, client_revision);
|
2019-05-06 06:14:37 +00:00
|
|
|
}
|
|
|
|
|
2019-05-13 04:48:09 +00:00
|
|
|
void Progress::writeJSON(WriteBuffer & out) const
|
2019-04-26 03:38:39 +00:00
|
|
|
{
|
2019-05-13 04:48:09 +00:00
|
|
|
getValues().writeJSON(out);
|
2018-03-09 23:04:26 +00:00
|
|
|
}
|
|
|
|
|
2017-01-22 15:03:55 +00:00
|
|
|
}
|