Optimize usage of Status in CompactionJob
Summary: Based on @ljin feedback Test Plan: compiles Reviewers: ljin, yhchiang, sdong Reviewed By: sdong Subscribers: ljin, dhruba, leveldb Differential Revision: https://reviews.facebook.net/D28515
This commit is contained in:
parent
bcdb9671c0
commit
4a3bd2bad2
@ -455,14 +455,14 @@ Status CompactionJob::Run() {
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status CompactionJob::Install(Status status, port::Mutex* db_mutex) {
|
void CompactionJob::Install(Status* status, port::Mutex* db_mutex) {
|
||||||
db_mutex->AssertHeld();
|
db_mutex->AssertHeld();
|
||||||
ColumnFamilyData* cfd = compact_->compaction->column_family_data();
|
ColumnFamilyData* cfd = compact_->compaction->column_family_data();
|
||||||
cfd->internal_stats()->AddCompactionStats(
|
cfd->internal_stats()->AddCompactionStats(
|
||||||
compact_->compaction->output_level(), compaction_stats_);
|
compact_->compaction->output_level(), compaction_stats_);
|
||||||
|
|
||||||
if (status.ok()) {
|
if (status->ok()) {
|
||||||
status = InstallCompactionResults(db_mutex);
|
*status = InstallCompactionResults(db_mutex);
|
||||||
}
|
}
|
||||||
VersionStorageInfo::LevelSummaryStorage tmp;
|
VersionStorageInfo::LevelSummaryStorage tmp;
|
||||||
const auto& stats = compaction_stats_;
|
const auto& stats = compaction_stats_;
|
||||||
@ -483,11 +483,10 @@ Status CompactionJob::Install(Status status, port::Mutex* db_mutex) {
|
|||||||
(stats.bytes_written + stats.bytes_readnp1 + stats.bytes_readn) /
|
(stats.bytes_written + stats.bytes_readnp1 + stats.bytes_readn) /
|
||||||
static_cast<double>(stats.bytes_readn),
|
static_cast<double>(stats.bytes_readn),
|
||||||
stats.bytes_written / static_cast<double>(stats.bytes_readn),
|
stats.bytes_written / static_cast<double>(stats.bytes_readn),
|
||||||
status.ToString().c_str(), stats.num_input_records,
|
status->ToString().c_str(), stats.num_input_records,
|
||||||
stats.num_dropped_records);
|
stats.num_dropped_records);
|
||||||
|
|
||||||
CleanupCompaction(status);
|
CleanupCompaction(*status);
|
||||||
return status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Status CompactionJob::ProcessKeyValueCompaction(int64_t* imm_micros,
|
Status CompactionJob::ProcessKeyValueCompaction(int64_t* imm_micros,
|
||||||
@ -1054,7 +1053,7 @@ Status CompactionJob::OpenCompactionOutputFile() {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompactionJob::CleanupCompaction(Status status) {
|
void CompactionJob::CleanupCompaction(const Status& status) {
|
||||||
if (compact_->builder != nullptr) {
|
if (compact_->builder != nullptr) {
|
||||||
// May happen if we get a shutdown call in the middle of compaction
|
// May happen if we get a shutdown call in the middle of compaction
|
||||||
compact_->builder->Abandon();
|
compact_->builder->Abandon();
|
||||||
|
@ -75,7 +75,7 @@ class CompactionJob {
|
|||||||
Status Run();
|
Status Run();
|
||||||
// REQUIRED: mutex held
|
// REQUIRED: mutex held
|
||||||
// status is the return of Run()
|
// status is the return of Run()
|
||||||
Status Install(Status status, port::Mutex* db_mutex);
|
void Install(Status* status, port::Mutex* db_mutex);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void AllocateCompactionOutputFileNumbers();
|
void AllocateCompactionOutputFileNumbers();
|
||||||
@ -92,7 +92,7 @@ class CompactionJob {
|
|||||||
SequenceNumber* prev_snapshot);
|
SequenceNumber* prev_snapshot);
|
||||||
void RecordCompactionIOStats();
|
void RecordCompactionIOStats();
|
||||||
Status OpenCompactionOutputFile();
|
Status OpenCompactionOutputFile();
|
||||||
void CleanupCompaction(Status status);
|
void CleanupCompaction(const Status& status);
|
||||||
|
|
||||||
// CompactionJob state
|
// CompactionJob state
|
||||||
struct CompactionState;
|
struct CompactionState;
|
||||||
|
@ -1295,12 +1295,10 @@ Status DBImpl::CompactFilesImpl(
|
|||||||
mutex_.Unlock();
|
mutex_.Unlock();
|
||||||
Status status = compaction_job.Run();
|
Status status = compaction_job.Run();
|
||||||
mutex_.Lock();
|
mutex_.Lock();
|
||||||
|
compaction_job.Install(&status, &mutex_);
|
||||||
if (status.ok()) {
|
if (status.ok()) {
|
||||||
status = compaction_job.Install(status, &mutex_);
|
InstallSuperVersionBackground(c->column_family_data(), &job_context,
|
||||||
if (status.ok()) {
|
*c->mutable_cf_options());
|
||||||
InstallSuperVersionBackground(c->column_family_data(), &job_context,
|
|
||||||
*c->mutable_cf_options());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
c->ReleaseCompactionFiles(s);
|
c->ReleaseCompactionFiles(s);
|
||||||
c->ReleaseInputs();
|
c->ReleaseInputs();
|
||||||
@ -2070,7 +2068,7 @@ Status DBImpl::BackgroundCompaction(bool* madeProgress, JobContext* job_context,
|
|||||||
mutex_.Unlock();
|
mutex_.Unlock();
|
||||||
status = compaction_job.Run();
|
status = compaction_job.Run();
|
||||||
mutex_.Lock();
|
mutex_.Lock();
|
||||||
status = compaction_job.Install(status, &mutex_);
|
compaction_job.Install(&status, &mutex_);
|
||||||
if (status.ok()) {
|
if (status.ok()) {
|
||||||
InstallSuperVersionBackground(c->column_family_data(), job_context,
|
InstallSuperVersionBackground(c->column_family_data(), job_context,
|
||||||
*c->mutable_cf_options());
|
*c->mutable_cf_options());
|
||||||
|
Loading…
Reference in New Issue
Block a user