Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix blobstore truncate unexpected normal files #3984

Merged
merged 11 commits into from
Feb 10, 2022
8 changes: 4 additions & 4 deletions dbms/src/Storages/Page/V3/BlobFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ extern const char exception_before_page_file_write_sync[];
namespace PS::V3
{
BlobFile::BlobFile(String path_,
FileProviderPtr file_provider_,
bool truncate_if_exists)
FileProviderPtr file_provider_)
: file_provider{file_provider_}
, path(path_)
{
// TODO: support encryption file
wrfile = file_provider->newWriteReadableFile(
getPath(),
getEncryptionPath(),
truncate_if_exists,
/*create_new_encryption_info_*/ truncate_if_exists);
false,
/*create_new_encryption_info_*/ false);
}

void BlobFile::read(char * buffer, size_t offset, size_t size, const ReadLimiterPtr & read_limiter)
Expand Down
3 changes: 1 addition & 2 deletions dbms/src/Storages/Page/V3/BlobFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ class BlobFile
{
public:
BlobFile(String path_,
FileProviderPtr file_provider_,
bool truncate_if_exists = true);
FileProviderPtr file_provider_);

~BlobFile();

Expand Down
11 changes: 9 additions & 2 deletions dbms/src/Storages/Page/V3/BlobStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include <ext/scope_guard.h>
#include <mutex>

namespace ProfileEvents
{
extern const Event PSMWritePages;
Expand Down Expand Up @@ -475,7 +474,15 @@ std::vector<BlobFileId> BlobStore::getGCStats()
auto lock = stat->lock();
auto right_margin = stat->smap->getRightMargin();

// Avoid divide by zero
if (right_margin == 0)
jiaqizho marked this conversation as resolved.
Show resolved Hide resolved
{
LOG_FMT_TRACE(log, "Current blob is empty [blob_id={}, total size(all invalid)={}].", stat->id, stat->sm_total_size);
continue;
}

stat->sm_valid_rate = stat->sm_valid_size * 1.0 / right_margin;

if (stat->sm_valid_rate > 1.0)
{
LOG_FMT_ERROR(
jiaqizho marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -493,7 +500,6 @@ std::vector<BlobFileId> BlobStore::getGCStats()
if (stat->sm_valid_rate <= config.heavy_gc_valid_rate)
{
LOG_FMT_TRACE(log, "Current [blob_id={}] valid rate is {:.2f}, Need do compact GC", stat->id, stat->sm_valid_rate);
stat->sm_total_size = stat->sm_valid_size;
blob_need_gc.emplace_back(stat->id);

// Change current stat to read only
Expand All @@ -507,6 +513,7 @@ std::vector<BlobFileId> BlobStore::getGCStats()
if (right_margin != stat->sm_total_size)
{
auto blobfile = getBlobFile(stat->id);
LOG_FMT_TRACE(log, "Truncate blob file [blob_id={}] [origin size={}] [truncated size={}]", stat->id, stat->sm_total_size, right_margin);
blobfile->truncate(right_margin);
stat->sm_total_size = right_margin;
}
Expand Down