Skip to content

Commit

Permalink
FIX exception: GC removed normal file which just created (#3216) (#3228)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Oct 19, 2021
1 parent d68a8cc commit 8242cf2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion dbms/src/Storages/Page/PageFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,7 @@ PageFile::recover(const String & parent_path, const FileProviderPtr & file_provi
LOG_INFO(log, "Broken page without data file, ignored: " + pf.dataPath());
return {{}, Type::Invalid};
}

return {pf, Type::Formal};
}
else if (ss[0] == folder_prefix_checkpoint)
Expand All @@ -870,7 +871,6 @@ PageFile::recover(const String & parent_path, const FileProviderPtr & file_provi
LOG_INFO(log, "Broken page without meta file, ignored: " + pf.metaPath());
return {{}, Type::Invalid};
}
pf.type = Type::Checkpoint;

return {pf, Type::Checkpoint};
}
Expand Down
31 changes: 18 additions & 13 deletions dbms/src/Storages/Page/PageStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,22 @@ PageFileSet PageStorage::listAllPageFiles(const FileProviderPtr & file_provi
if (!option.ignore_checkpoint)
page_files.insert(page_file);
}
else
else if (page_file_type == PageFile::Type::Temp)
{
// For Temp and Invalid
if (option.remove_tmp_files)
{
if (page_file_type == PageFile::Type::Temp)
{
page_file.deleteEncryptionInfo();
}
// Remove temp and invalid file.
page_file.deleteEncryptionInfo();
// Remove temp files.
if (Poco::File file(directory + "/" + name); file.exists())
file.remove(true);
}
}
else
{
// Remove invalid files.
if (Poco::File file(directory + "/" + name); option.remove_invalid_files && file.exists())
file.remove(true);
}
}
}

Expand Down Expand Up @@ -250,8 +252,9 @@ void PageStorage::restore()
#ifdef PAGE_STORAGE_UTIL_DEBUGGGING
opt.remove_tmp_files = false;
#endif
opt.ignore_legacy = false;
opt.ignore_checkpoint = false;
opt.ignore_legacy = false;
opt.ignore_checkpoint = false;
opt.remove_invalid_files = true;
PageFileSet page_files = PageStorage::listAllPageFiles(file_provider, delegator, page_file_log, opt);

/// Restore current version from both formal and legacy page files
Expand Down Expand Up @@ -834,9 +837,10 @@ void PageStorage::drop()

ListPageFilesOption opt;
opt.ignore_checkpoint = false;
opt.ignore_legacy = false;
opt.remove_tmp_files = false;
auto page_files = PageStorage::listAllPageFiles(file_provider, delegator, page_file_log, opt);
opt.ignore_legacy = false;
opt.remove_tmp_files = false;
opt.remove_invalid_files = false;
auto page_files = PageStorage::listAllPageFiles(file_provider, delegator, page_file_log, opt);

for (const auto & page_file : page_files)
{
Expand Down Expand Up @@ -972,7 +976,8 @@ bool PageStorage::gc(bool not_skip, const WriteLimiterPtr & write_limiter, const
}
ListPageFilesOption opt;
opt.remove_tmp_files = true;
auto page_files = PageStorage::listAllPageFiles(file_provider, delegator, page_file_log, opt);
opt.remove_invalid_files = false;
auto page_files = PageStorage::listAllPageFiles(file_provider, delegator, page_file_log, opt);
if (unlikely(page_files.empty()))
{
// In case the directory are removed by accident
Expand Down
1 change: 1 addition & 0 deletions dbms/src/Storages/Page/PageStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class PageStorage : private boost::noncopyable
bool remove_tmp_files = false;
bool ignore_legacy = false;
bool ignore_checkpoint = false;
bool remove_invalid_files = false;
};

using VersionedPageEntries = PageEntriesVersionSetWithDelta;
Expand Down

0 comments on commit 8242cf2

Please sign in to comment.