Skip to content

Commit

Permalink
PageStorage: Fix empty page cause TiFlash failed to start (#9283) (#9285
Browse files Browse the repository at this point in the history
)

close #9282

PageStorage: Fix empty page cause TiFlash failed to start

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>

Co-authored-by: JaySon <tshent@qq.com>
Co-authored-by: JaySon-Huang <tshent@qq.com>
  • Loading branch information
ti-chi-bot and JaySon-Huang authored Aug 5, 2024
1 parent 8aec59f commit eb585f7
Show file tree
Hide file tree
Showing 15 changed files with 303 additions and 91 deletions.
1 change: 0 additions & 1 deletion dbms/src/Common/UniThreadPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <memory>
#include <mutex>
#include <optional>
#include <queue>
#include <thread>

namespace DB
Expand Down
9 changes: 7 additions & 2 deletions dbms/src/Storages/Page/V3/Blob/BlobStat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <Common/ProfileEvents.h>
#include <Storages/Page/V3/Blob/BlobFile.h>
#include <Storages/Page/V3/Blob/BlobStat.h>
#include <Storages/Page/V3/PageDefines.h>
#include <Storages/PathPool.h>
#include <boost_wrapper/string_split.h>
#include <common/logger_useful.h>
Expand Down Expand Up @@ -216,8 +217,6 @@ std::pair<BlobStats::BlobStatPtr, BlobFileId> BlobStats::chooseStat(
PageType page_type,
const std::lock_guard<std::mutex> &)
{
BlobStatPtr stat_ptr = nullptr;

// No stats exist
if (stats_map.empty())
{
Expand Down Expand Up @@ -301,6 +300,12 @@ BlobStats::StatsMap BlobStats::getStats() const NO_THREAD_SAFETY_ANALYSIS

BlobFileOffset BlobStats::BlobStat::getPosFromStat(size_t buf_size, const std::unique_lock<std::mutex> &)
{
// A shortcut for empty page. All empty pages will be stored
// at the beginning of the BlobFile. It should not affects the
// sm_max_caps or other fields by adding these empty pages.
if (unlikely(buf_size == 0))
return 0;

BlobFileOffset offset = 0;
UInt64 max_cap = 0;
bool expansion = true;
Expand Down
7 changes: 4 additions & 3 deletions dbms/src/Storages/Page/V3/Blob/GCInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct fmt::formatter<DB::PS::V3::BlobFileGCInfo>
template <typename FormatContext>
auto format(const DB::PS::V3::BlobFileGCInfo & i, FormatContext & ctx) const
{
return fmt::format_to(ctx.out(), "<id:{} rate:{:.2f}>", i.blob_id, i.valid_rate);
return fmt::format_to(ctx.out(), "<blob_id={} rate={:.2f}>", i.blob_id, i.valid_rate);
}
};
template <>
Expand All @@ -53,7 +53,7 @@ struct fmt::formatter<DB::PS::V3::BlobFileTruncateInfo>
{
return fmt::format_to(
ctx.out(),
"<id:{} origin:{} truncate:{} rate:{:.2f}>",
"<blob_id={} origin={} truncate={} rate={:.2f}>",
i.blob_id,
i.origin_size,
i.truncated_size,
Expand Down Expand Up @@ -86,7 +86,7 @@ String BlobStoreGCInfo::toTypeString(const Type type_index) const
if (blob_gc_info[type_index].empty())
return fmt::format("{{{}: [null]}}", magic_enum::enum_name(type_index));

// e.g. {FullGC: [<id:4 rate:0.16>]}}
// e.g. {FullGC: [<blob_id=4 rate=0.16>]}
FmtBuffer fmt_buf;
fmt_buf.fmtAppend("{{{}: [", magic_enum::enum_name(type_index))
.joinStr(
Expand All @@ -103,6 +103,7 @@ String BlobStoreGCInfo::toTypeTruncateString(const Type type_index) const
if (blob_gc_truncate_info.empty())
return fmt::format("{{{}: [null]}}", magic_enum::enum_name(type_index));

// e.g. {Truncated: [<blob_id=221 origin=0 truncate=0 rate=0.00>]}
FmtBuffer fmt_buf;
fmt_buf.fmtAppend("{{{}: [", magic_enum::enum_name(type_index))
.joinStr(
Expand Down
Loading

0 comments on commit eb585f7

Please sign in to comment.