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
|
|
|
{
|
2019-05-20 11:37:41 +00:00
|
|
|
size_t new_read_rows = 0;
|
|
|
|
size_t new_read_bytes = 0;
|
|
|
|
size_t new_total_rows_to_read = 0;
|
|
|
|
size_t new_written_rows = 0;
|
|
|
|
size_t new_written_bytes = 0;
|
2019-05-06 06:57:48 +00:00
|
|
|
|
2019-05-20 11:37:41 +00:00
|
|
|
readVarUInt(new_read_rows, in);
|
|
|
|
readVarUInt(new_read_bytes, in);
|
|
|
|
readVarUInt(new_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
|
|
|
{
|
2019-05-20 11:37:41 +00:00
|
|
|
readVarUInt(new_written_rows, in);
|
|
|
|
readVarUInt(new_written_bytes, in);
|
2019-05-13 04:48:09 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 11:37:41 +00:00
|
|
|
this->read_rows = new_read_rows;
|
|
|
|
this->read_bytes = new_read_bytes;
|
|
|
|
this->total_rows_to_read = new_total_rows_to_read;
|
|
|
|
this->written_rows = new_written_rows;
|
|
|
|
this->written_bytes = new_written_bytes;
|
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
|
|
|
{
|
2019-05-20 11:37:41 +00:00
|
|
|
writeVarUInt(this->read_rows, out);
|
|
|
|
writeVarUInt(this->read_bytes, out);
|
|
|
|
writeVarUInt(this->total_rows_to_read, out);
|
2019-05-13 04:48:09 +00:00
|
|
|
if (client_revision >= DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO)
|
|
|
|
{
|
2019-05-20 11:37:41 +00:00
|
|
|
writeVarUInt(this->written_rows, out);
|
|
|
|
writeVarUInt(this->written_bytes, 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
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Numbers are written in double quotes (as strings) to avoid loss of precision
|
|
|
|
/// of 64-bit integers after interpretation by JavaScript.
|
|
|
|
|
|
|
|
writeCString("{\"read_rows\":\"", out);
|
2019-05-20 11:37:41 +00:00
|
|
|
writeText(this->read_rows, out);
|
2017-04-01 07:20:54 +00:00
|
|
|
writeCString("\",\"read_bytes\":\"", out);
|
2019-05-20 11:37:41 +00:00
|
|
|
writeText(this->read_bytes, out);
|
2019-05-13 04:48:09 +00:00
|
|
|
writeCString("\",\"written_rows\":\"", out);
|
2019-05-20 11:37:41 +00:00
|
|
|
writeText(this->written_rows, out);
|
2019-05-13 04:48:09 +00:00
|
|
|
writeCString("\",\"written_bytes\":\"", out);
|
2019-05-20 11:37:41 +00:00
|
|
|
writeText(this->written_bytes, out);
|
|
|
|
writeCString("\",\"total_rows_to_read\":\"", out);
|
|
|
|
writeText(this->total_rows_to_read, out);
|
2017-04-01 07:20:54 +00:00
|
|
|
writeCString("\"}", out);
|
2017-01-22 15:03:55 +00:00
|
|
|
}
|
|
|
|
|
2021-05-13 22:56:42 +00:00
|
|
|
bool Progress::incrementPiecewiseAtomically(const Progress & rhs)
|
|
|
|
{
|
|
|
|
read_rows += rhs.read_rows;
|
|
|
|
read_bytes += rhs.read_bytes;
|
|
|
|
read_raw_bytes += rhs.read_raw_bytes;
|
|
|
|
|
|
|
|
total_rows_to_read += rhs.total_rows_to_read;
|
|
|
|
total_raw_bytes_to_read += rhs.total_raw_bytes_to_read;
|
|
|
|
|
|
|
|
written_rows += rhs.written_rows;
|
|
|
|
written_bytes += rhs.written_bytes;
|
|
|
|
|
|
|
|
return rhs.read_rows || rhs.written_rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Progress::reset()
|
|
|
|
{
|
|
|
|
read_rows = 0;
|
|
|
|
read_bytes = 0;
|
|
|
|
read_raw_bytes = 0;
|
|
|
|
|
|
|
|
total_rows_to_read = 0;
|
|
|
|
total_raw_bytes_to_read = 0;
|
|
|
|
|
|
|
|
written_rows = 0;
|
|
|
|
written_bytes = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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.read_raw_bytes = read_raw_bytes.load(std::memory_order_relaxed);
|
|
|
|
|
|
|
|
res.total_rows_to_read = total_rows_to_read.load(std::memory_order_relaxed);
|
|
|
|
res.total_raw_bytes_to_read = total_raw_bytes_to_read.load(std::memory_order_relaxed);
|
|
|
|
|
|
|
|
res.written_rows = written_rows.load(std::memory_order_relaxed);
|
|
|
|
res.written_bytes = written_bytes.load(std::memory_order_relaxed);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProgressValues Progress::fetchAndResetPiecewiseAtomically()
|
|
|
|
{
|
|
|
|
ProgressValues res;
|
|
|
|
|
|
|
|
res.read_rows = read_rows.fetch_and(0);
|
|
|
|
res.read_bytes = read_bytes.fetch_and(0);
|
|
|
|
res.read_raw_bytes = read_raw_bytes.fetch_and(0);
|
|
|
|
|
|
|
|
res.total_rows_to_read = total_rows_to_read.fetch_and(0);
|
|
|
|
res.total_raw_bytes_to_read = total_raw_bytes_to_read.fetch_and(0);
|
|
|
|
|
|
|
|
res.written_rows = written_rows.fetch_and(0);
|
|
|
|
res.written_bytes = written_bytes.fetch_and(0);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
Progress & Progress::operator=(Progress && other)
|
|
|
|
{
|
|
|
|
read_rows = other.read_rows.load(std::memory_order_relaxed);
|
|
|
|
read_bytes = other.read_bytes.load(std::memory_order_relaxed);
|
|
|
|
read_raw_bytes = other.read_raw_bytes.load(std::memory_order_relaxed);
|
|
|
|
|
|
|
|
total_rows_to_read = other.total_rows_to_read.load(std::memory_order_relaxed);
|
|
|
|
total_raw_bytes_to_read = other.total_raw_bytes_to_read.load(std::memory_order_relaxed);
|
|
|
|
|
|
|
|
written_rows = other.written_rows.load(std::memory_order_relaxed);
|
|
|
|
written_bytes = other.written_bytes.load(std::memory_order_relaxed);
|
|
|
|
|
|
|
|
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);
|
|
|
|
written_rows.store(values.written_rows, std::memory_order_relaxed);
|
|
|
|
written_bytes.store(values.written_bytes, 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
|
|
|
}
|