From 998ac8f741693e3facec91e95789fc29ee23f7fb Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Tue, 17 May 2022 19:53:14 +0800 Subject: [PATCH 1/9] add a try catch statement for convert Poco::Dynamic::Var to Int64 Signed-off-by: Lloyd-Pottiger --- dbms/src/Storages/Transaction/TiDB.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dbms/src/Storages/Transaction/TiDB.cpp b/dbms/src/Storages/Transaction/TiDB.cpp index 23342ac0dfa..c59acaf3740 100644 --- a/dbms/src/Storages/Transaction/TiDB.cpp +++ b/dbms/src/Storages/Transaction/TiDB.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -48,14 +49,19 @@ Field ColumnInfo::defaultValueToField() const } switch (tp) { - // TODO: Consider unsigned? // Integer Type. case TypeTiny: case TypeShort: case TypeLong: case TypeLongLong: case TypeInt24: - return value.convert(); + { + try { + return value.convert(); + } catch (...) { + return static_cast(std::stoull(value.convert())); + } + } case TypeBit: { // TODO: We shall use something like `orig_default_bit`, which will never change once created, From f2a673e2ee7496e9aa52977d62edc0092805fba8 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Tue, 17 May 2022 19:55:27 +0800 Subject: [PATCH 2/9] remove useless include Signed-off-by: Lloyd-Pottiger --- dbms/src/Storages/Transaction/TiDB.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/dbms/src/Storages/Transaction/TiDB.cpp b/dbms/src/Storages/Transaction/TiDB.cpp index c59acaf3740..cb3c3664aa3 100644 --- a/dbms/src/Storages/Transaction/TiDB.cpp +++ b/dbms/src/Storages/Transaction/TiDB.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include From fc5e2a3a33dae7fadf5e94bbd84320bf9ef32d41 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Tue, 17 May 2022 19:56:49 +0800 Subject: [PATCH 3/9] fix remove mistakenly Signed-off-by: Lloyd-Pottiger --- dbms/src/Storages/Transaction/TiDB.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbms/src/Storages/Transaction/TiDB.cpp b/dbms/src/Storages/Transaction/TiDB.cpp index cb3c3664aa3..6d73554786c 100644 --- a/dbms/src/Storages/Transaction/TiDB.cpp +++ b/dbms/src/Storages/Transaction/TiDB.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include #include From 197d3963fb5df100cf7194b3b01cc090fbdb233d Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Wed, 18 May 2022 15:08:13 +0800 Subject: [PATCH 4/9] format --- dbms/src/Storages/Transaction/TiDB.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dbms/src/Storages/Transaction/TiDB.cpp b/dbms/src/Storages/Transaction/TiDB.cpp index 6d73554786c..26ee2717deb 100644 --- a/dbms/src/Storages/Transaction/TiDB.cpp +++ b/dbms/src/Storages/Transaction/TiDB.cpp @@ -55,9 +55,12 @@ Field ColumnInfo::defaultValueToField() const case TypeLongLong: case TypeInt24: { - try { + try + { return value.convert(); - } catch (...) { + } + catch (...) + { return static_cast(std::stoull(value.convert())); } } From 6de339b0c9ae4d0d364b9e9f6d7c636b4e96ded9 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Fri, 27 May 2022 12:33:04 +0800 Subject: [PATCH 5/9] fix Signed-off-by: Lloyd-Pottiger --- dbms/src/Storages/Transaction/TiDB.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dbms/src/Storages/Transaction/TiDB.cpp b/dbms/src/Storages/Transaction/TiDB.cpp index 26ee2717deb..b1938d38268 100644 --- a/dbms/src/Storages/Transaction/TiDB.cpp +++ b/dbms/src/Storages/Transaction/TiDB.cpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace DB { @@ -46,8 +47,10 @@ Field ColumnInfo::defaultValueToField() const return DB::GenDefaultField(*this); return Field(); } + // switch (tp) { + // TODO: Consider unsigned? // Integer Type. case TypeTiny: case TypeShort: @@ -61,7 +64,9 @@ Field ColumnInfo::defaultValueToField() const } catch (...) { - return static_cast(std::stoull(value.convert())); + // due to https://github.com/pingcap/tidb/issues/34881 + // we do this to avoid exception in older version of TiDB. + return static_cast(std::llround(value.convert())); } } case TypeBit: From c2e59e7572cec3e05cb2e4224beba313e3a6e754 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Fri, 27 May 2022 12:34:30 +0800 Subject: [PATCH 6/9] remove useless comment Signed-off-by: Lloyd-Pottiger --- dbms/src/Storages/Transaction/TiDB.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/dbms/src/Storages/Transaction/TiDB.cpp b/dbms/src/Storages/Transaction/TiDB.cpp index b1938d38268..f23fdba802c 100644 --- a/dbms/src/Storages/Transaction/TiDB.cpp +++ b/dbms/src/Storages/Transaction/TiDB.cpp @@ -47,7 +47,6 @@ Field ColumnInfo::defaultValueToField() const return DB::GenDefaultField(*this); return Field(); } - // switch (tp) { // TODO: Consider unsigned? From 579b917e63229a331c5c47b9e236b03d1490ee1b Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Fri, 27 May 2022 14:37:27 +0800 Subject: [PATCH 7/9] add comments for unsigned Signed-off-by: Lloyd-Pottiger --- dbms/src/Storages/Transaction/TiDB.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dbms/src/Storages/Transaction/TiDB.cpp b/dbms/src/Storages/Transaction/TiDB.cpp index f23fdba802c..cef86707409 100644 --- a/dbms/src/Storages/Transaction/TiDB.cpp +++ b/dbms/src/Storages/Transaction/TiDB.cpp @@ -49,7 +49,6 @@ Field ColumnInfo::defaultValueToField() const } switch (tp) { - // TODO: Consider unsigned? // Integer Type. case TypeTiny: case TypeShort: @@ -57,6 +56,10 @@ Field ColumnInfo::defaultValueToField() const case TypeLongLong: case TypeInt24: { + // In c++, cast a unsigned integer to signed integer will not change the value. + // like 9223372036854775808 which is larger than the maximum value of Int64, + // static_cast(static_cast(9223372036854775808)) == 9223372036854775808 + // so we don't need consider unsigned here. try { return value.convert(); From f29025f9c717f28292b54db83da48e668cea0474 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Fri, 27 May 2022 16:40:14 +0800 Subject: [PATCH 8/9] format --- dbms/src/Storages/Transaction/TiDB.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/dbms/src/Storages/Transaction/TiDB.cpp b/dbms/src/Storages/Transaction/TiDB.cpp index cef86707409..69561b51348 100644 --- a/dbms/src/Storages/Transaction/TiDB.cpp +++ b/dbms/src/Storages/Transaction/TiDB.cpp @@ -9,6 +9,7 @@ #include #include #include + #include namespace DB From 99c3a489a04983ca4dd6174c6baf033fa2433580 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Fri, 27 May 2022 17:55:53 +0800 Subject: [PATCH 9/9] clear tidy --- dbms/src/Storages/Transaction/TiDB.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/dbms/src/Storages/Transaction/TiDB.cpp b/dbms/src/Storages/Transaction/TiDB.cpp index 69561b51348..958e7ceb2f0 100644 --- a/dbms/src/Storages/Transaction/TiDB.cpp +++ b/dbms/src/Storages/Transaction/TiDB.cpp @@ -569,6 +569,8 @@ catch (const Poco::Exception & e) /////////////////////// IndexColumnInfo::IndexColumnInfo(Poco::JSON::Object::Ptr json) + : offset() + , length() { deserialize(json); } @@ -618,6 +620,13 @@ catch (const Poco::Exception & e) /////////////////////// IndexInfo::IndexInfo(Poco::JSON::Object::Ptr json) + : id() + , state() + , index_type() + , is_unique() + , is_primary() + , is_invisible() + , is_global() { deserialize(json); }