Skip to content

Commit

Permalink
Fix an invalid default value cause bootstrap failed (pingcap#4916) (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Nov 8, 2022
1 parent f3952aa commit 5b6910f
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions dbms/src/Storages/Transaction/TiDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <Storages/Transaction/SchemaNameMapper.h>
#include <Storages/Transaction/TiDB.h>

#include <cmath>

namespace DB
{
extern const UInt8 TYPE_CODE_LITERAL;
Expand Down Expand Up @@ -48,14 +50,28 @@ Field ColumnInfo::defaultValueToField() const
}
switch (tp)
{
// TODO: Consider unsigned?
// Integer Type.
case TypeTiny:
case TypeShort:
case TypeLong:
case TypeLongLong:
case TypeInt24:
return value.convert<Int64>();
{
// 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<UInt64>(static_cast<Int64>(9223372036854775808)) == 9223372036854775808
// so we don't need consider unsigned here.
try
{
return value.convert<Int64>();
}
catch (...)
{
// due to https://github.com/pingcap/tidb/issues/34881
// we do this to avoid exception in older version of TiDB.
return static_cast<Int64>(std::llround(value.convert<double>()));
}
}
case TypeBit:
{
// TODO: We shall use something like `orig_default_bit`, which will never change once created,
Expand Down Expand Up @@ -553,6 +569,8 @@ catch (const Poco::Exception & e)
///////////////////////

IndexColumnInfo::IndexColumnInfo(Poco::JSON::Object::Ptr json)
: offset()
, length()
{
deserialize(json);
}
Expand Down Expand Up @@ -602,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);
}
Expand Down

0 comments on commit 5b6910f

Please sign in to comment.