do a bit less work in the normal case (#5695)

Summary:
i.e. if alive logfile is not being moved to archive while we are in GetSortedWalsOfType()
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5695

Differential Revision: D17279489

Pulled By: vjnadimpalli

fbshipit-source-id: 02bcf920a75b812edba8b87c6079b4e6fd5e683c
This commit is contained in:
jsteemann 2019-09-10 09:40:21 -07:00 committed by Facebook Github Bot
parent 699e1b5ede
commit 4d945c57ac

View File

@ -312,14 +312,15 @@ Status WalManager::GetSortedWalsOfType(const std::string& path,
uint64_t size_bytes; uint64_t size_bytes;
s = env_->GetFileSize(LogFileName(path, number), &size_bytes); s = env_->GetFileSize(LogFileName(path, number), &size_bytes);
// re-try in case the alive log file has been moved to archive. // re-try in case the alive log file has been moved to archive.
std::string archived_file = ArchivedLogFileName(path, number); if (!s.ok() && log_type == kAliveLogFile) {
if (!s.ok() && log_type == kAliveLogFile && std::string archived_file = ArchivedLogFileName(path, number);
env_->FileExists(archived_file).ok()) { if (env_->FileExists(archived_file).ok()) {
s = env_->GetFileSize(archived_file, &size_bytes); s = env_->GetFileSize(archived_file, &size_bytes);
if (!s.ok() && env_->FileExists(archived_file).IsNotFound()) { if (!s.ok() && env_->FileExists(archived_file).IsNotFound()) {
// oops, the file just got deleted from archived dir! move on // oops, the file just got deleted from archived dir! move on
s = Status::OK(); s = Status::OK();
continue; continue;
}
} }
} }
if (!s.ok()) { if (!s.ok()) {
@ -388,7 +389,7 @@ Status WalManager::ReadFirstRecord(const WalFileType type,
if (type == kAliveLogFile) { if (type == kAliveLogFile) {
std::string fname = LogFileName(db_options_.wal_dir, number); std::string fname = LogFileName(db_options_.wal_dir, number);
s = ReadFirstLine(fname, number, sequence); s = ReadFirstLine(fname, number, sequence);
if (env_->FileExists(fname).ok() && !s.ok()) { if (!s.ok() && env_->FileExists(fname).ok()) {
// return any error that is not caused by non-existing file // return any error that is not caused by non-existing file
return s; return s;
} }