From e0bd16c1f4e60d7c62d6e7e6044da08adc4fd2fb Mon Sep 17 00:00:00 2001 From: Guillaume Tassery Date: Mon, 6 May 2019 13:14:37 +0700 Subject: [PATCH] Backward compatibility for write progress with old version of server and client --- dbms/src/Core/Defines.h | 2 ++ dbms/src/IO/Progress.cpp | 24 +++++++++++++++++ dbms/src/IO/Progress.h | 56 ++++++++++++++++++++++++++++++---------- 3 files changed, 68 insertions(+), 14 deletions(-) diff --git a/dbms/src/Core/Defines.h b/dbms/src/Core/Defines.h index 0a3b384797d..3a8af6b81ff 100644 --- a/dbms/src/Core/Defines.h +++ b/dbms/src/Core/Defines.h @@ -56,6 +56,8 @@ #define DBMS_MIN_REVISION_WITH_LOW_CARDINALITY_TYPE 54405 +#define DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO 54421 + /// Version of ClickHouse TCP protocol. Set to git tag with latest protocol change. #define DBMS_TCP_PROTOCOL_VERSION 54226 diff --git a/dbms/src/IO/Progress.cpp b/dbms/src/IO/Progress.cpp index 74c01135181..f6b29a6ceda 100644 --- a/dbms/src/IO/Progress.cpp +++ b/dbms/src/IO/Progress.cpp @@ -57,6 +57,30 @@ void AllProgressValueImpl::writeJSON(const ProgressValues & value, WriteBuffer & writeCString("\"}", out); } +void ReadProgressValueImpl::read(ProgressValues & value, ReadBuffer & in, UInt64 /*server_revision*/) +{ + size_t new_rows = 0; + size_t new_bytes = 0; + size_t new_total_rows = 0; + + readVarUInt(new_rows, in); + readVarUInt(new_bytes, in); + readVarUInt(new_total_rows, in); + + value.rows = new_rows; + value.bytes = new_bytes; + value.total_rows = new_total_rows; +} + + +void ReadProgressValueImpl::write(const ProgressValues & value, WriteBuffer & out, UInt64 /*client_revision*/) +{ + writeVarUInt(value.rows, out); + writeVarUInt(value.bytes, out); + writeVarUInt(value.total_rows, out); +} + + void ReadProgressValueImpl::writeJSON(const ProgressValues & value, WriteBuffer & out) { /// Numbers are written in double quotes (as strings) to avoid loss of precision diff --git a/dbms/src/IO/Progress.h b/dbms/src/IO/Progress.h index 8065b4b5a44..827fa118c63 100644 --- a/dbms/src/IO/Progress.h +++ b/dbms/src/IO/Progress.h @@ -23,34 +23,28 @@ struct ProgressValues size_t write_rows; size_t write_bytes; + template - void read(ReadBuffer & in, UInt64 server_revision) - { - ReadImpl::read(*this, in, server_revision); - } + inline void read(ReadBuffer & in, UInt64 server_revision); template - void write(WriteBuffer & out, UInt64 client_revision) const - { - WriteImpl::write(*this, out, client_revision); - } + inline void write(WriteBuffer & out, UInt64 client_revision) const; template - void writeJSON(WriteBuffer & out) const - { - WriteJSONImpl::writeJSON(*this, out); - } + inline void writeJSON(WriteBuffer & out) const; }; struct AllProgressValueImpl { static void read(ProgressValues & value, ReadBuffer & in, UInt64 server_revision); - static void write(const ProgressValues & value, WriteBuffer & out, UInt64 client_revision) ; + static void write(const ProgressValues & value, WriteBuffer & out, UInt64 client_revision); static void writeJSON(const ProgressValues & value, WriteBuffer & out); }; struct ReadProgressValueImpl : public AllProgressValueImpl { + static void read(ProgressValues & value, ReadBuffer & in, UInt64 server_revision); + static void write(const ProgressValues & value, WriteBuffer & out, UInt64 client_revision); static void writeJSON(const ProgressValues & value, WriteBuffer & out); }; @@ -198,12 +192,46 @@ void Progress::write(WriteBuffer & out, UInt64 client_revision) const getValues().write(out, client_revision); } - template void Progress::writeJSON(WriteBuffer & out) const { getValues().writeJSON(out); } +template +inline void ProgressValues::read(ReadBuffer & in, UInt64 server_revision) +{ + if (server_revision >= DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO) + ReadImpl::read(*this, in, server_revision); + else + read(in, server_revision); +} + +template <> +inline void ProgressValues::read(ReadBuffer & in, UInt64 server_revision) +{ + ReadProgressValueImpl::read(*this, in, server_revision); +} + +template +inline void ProgressValues::write(WriteBuffer & out, UInt64 client_revision) const +{ + if (client_revision >= DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO) + WriteImpl::write(*this, out, client_revision); + else + write(out, client_revision); +} + +template <> +inline void ProgressValues::write(WriteBuffer & out, UInt64 client_revision) const +{ + ReadProgressValueImpl::write(*this, out, client_revision); +} + +template +void ProgressValues::writeJSON(WriteBuffer & out) const +{ + WriteJSONImpl::writeJSON(*this, out); +} }