Skip to content

Commit

Permalink
Fix an invalid default value cause bootstrap failed (#4916) (#5333)
Browse files Browse the repository at this point in the history
close #3157
  • Loading branch information
ti-chi-bot authored Dec 8, 2022
1 parent 97088c2 commit b9544eb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dbms/src/Storages/DeltaMerge/File/DMFilePackFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class DMFilePackFilter
after_filter += u;
ProfileEvents::increment(ProfileEvents::DMFileFilterAftRoughSet, after_filter);

Float64 filter_rate = (Float64)(after_read_packs - after_filter) * 100 / after_read_packs;
Float64 filter_rate = static_cast<Float64>(after_read_packs - after_filter) * 100 / after_read_packs;
LOG_DEBUG(log,
"RSFilter exclude rate: " << ((after_read_packs == 0) ? "nan" : DB::toString(filter_rate, 2))
<< ", after_pk: " << after_pk << ", after_read_packs: " << after_read_packs
Expand Down
21 changes: 19 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 @@ -52,7 +54,22 @@ Field ColumnInfo::defaultValueToField() const
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 @@ -976,4 +993,4 @@ ColumnInfo fieldTypeToColumnInfo(const tipb::FieldType & field_type)
return ret;
}

} // namespace TiDB
} // namespace TiDB

0 comments on commit b9544eb

Please sign in to comment.