-
Notifications
You must be signed in to change notification settings - Fork 411
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
PageStorage: Fix the WAL snapshot dumped into file may contains invalid "being_ref_count" #4987
Merged
ti-chi-bot
merged 19 commits into
pingcap:master
from
JaySon-Huang:fix_concurrent_dump_snapshot
May 24, 2022
Merged
Changes from 10 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
17a1640
Create another directory instance for dumping log files snapshot
JaySon-Huang 0dd6845
Remove encryption info for WAL log file
JaySon-Huang 09c067c
cleanup useless code
JaySon-Huang 796e861
Check the recover mode
JaySon-Huang 1e3bea5
Update comment
JaySon-Huang 74ccd9a
Use provider->deleteRegularFile
JaySon-Huang 9d99567
Merge branch 'master' into fix_concurrent_dump_snapshot
JaySon-Huang 8e51c2b
PageDirectory: need do gc twice in restore.
jiaqizho 40f83ad
Remove useless code
JaySon-Huang 3ec076a
Address comment
JaySon-Huang 114054b
change the relative order of deleting file and deleting encryption info
lidezhu e3980a6
Fix FileProvider::deleteRegularFile
JaySon-Huang e02a724
Merge branch 'master' into fix_concurrent_dump_snapshot
JaySon-Huang ff79bcf
fix
JaySon-Huang 158403c
pick the fix on GlobalStoragePool::gc
JaySon-Huang 6bc27c0
fix ut regression
JaySon-Huang d2db443
Merge branch 'master' into fix_concurrent_dump_snapshot
ti-chi-bot c689dfe
Merge branch 'master' into fix_concurrent_dump_snapshot
ti-chi-bot 377d31c
address comment
JaySon-Huang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
// limitations under the License. | ||
|
||
#include <Common/Exception.h> | ||
#include <Common/Logger.h> | ||
#include <Encryption/FileProvider.h> | ||
#include <Poco/File.h> | ||
#include <Poco/Logger.h> | ||
|
@@ -46,25 +47,31 @@ std::pair<WALStorePtr, WALStoreReaderPtr> WALStore::create( | |
auto reader = WALStoreReader::create(storage_name, | ||
provider, | ||
delegator, | ||
static_cast<WALRecoveryMode>(config.wal_recover_mode.get())); | ||
config.getRecoverMode()); | ||
// Create a new LogFile for writing new logs | ||
auto last_log_num = reader->lastLogNum() + 1; // TODO reuse old file | ||
return { | ||
std::unique_ptr<WALStore>(new WALStore(std::move(storage_name), delegator, provider, last_log_num, std::move(config))), | ||
reader}; | ||
} | ||
|
||
WALStoreReaderPtr WALStore::createReaderForFiles(const String & identifier, const LogFilenameSet & log_filenames, const ReadLimiterPtr & read_limiter) | ||
{ | ||
return WALStoreReader::create(identifier, provider, log_filenames, config.getRecoverMode(), read_limiter); | ||
} | ||
|
||
WALStore::WALStore( | ||
String storage_name, | ||
String storage_name_, | ||
const PSDiskDelegatorPtr & delegator_, | ||
const FileProviderPtr & provider_, | ||
Format::LogNumberType last_log_num_, | ||
WALStore::Config config_) | ||
: delegator(delegator_) | ||
: storage_name(std::move(storage_name_)) | ||
, delegator(delegator_) | ||
, provider(provider_) | ||
, last_log_num(last_log_num_) | ||
, wal_paths_index(0) | ||
, logger(Logger::get("WALStore", std::move(storage_name))) | ||
, logger(Logger::get("WALStore", storage_name)) | ||
, config(config_) | ||
{ | ||
} | ||
|
@@ -186,7 +193,7 @@ bool WALStore::saveSnapshot(FilesSnapshot && files_snap, PageEntriesEdit && dire | |
|
||
LOG_FMT_INFO(logger, "Saving directory snapshot"); | ||
|
||
// Use {largest_log_num + 1, 1} to save the `edit` | ||
// Use {largest_log_num, 1} to save the `edit` | ||
const auto log_num = files_snap.persisted_log_files.rbegin()->log_num; | ||
// Create a temporary file for saving directory snapshot | ||
auto [compact_log, log_filename] = createLogWriter({log_num, 1}, /*manual_flush*/ true); | ||
|
@@ -212,25 +219,11 @@ bool WALStore::saveSnapshot(FilesSnapshot && files_snap, PageEntriesEdit && dire | |
true); | ||
LOG_FMT_INFO(logger, "Rename log file to normal done [fullname={}]", normal_fullname); | ||
|
||
// #define ARCHIVE_COMPACTED_LOGS // keep for debug | ||
|
||
// Remove compacted log files. | ||
for (const auto & filename : files_snap.persisted_log_files) | ||
{ | ||
if (auto f = Poco::File(filename.fullname(LogFileStage::Normal)); f.exists()) | ||
{ | ||
#ifndef ARCHIVE_COMPACTED_LOGS | ||
f.remove(); | ||
#else | ||
const Poco::Path archive_path(delegator->defaultPath(), "archive"); | ||
Poco::File archive_dir(archive_path); | ||
if (!archive_dir.exists()) | ||
archive_dir.createDirectory(); | ||
auto dest = archive_path.toString() + "/" + filename.filename(LogFileStage::Normal); | ||
f.moveTo(dest); | ||
LOG_FMT_INFO(logger, "archive {} to {}", filename.fullname(LogFileStage::Normal), dest); | ||
#endif | ||
} | ||
const auto log_fullname = filename.fullname(LogFileStage::Normal); | ||
provider->deleteRegularFile(log_fullname, EncryptionPath(log_fullname, "")); | ||
Comment on lines
+225
to
+226
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix #4986
jiaqizho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
FmtBuffer fmt_buf; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not simply