Skip to content

Commit

Permalink
Accurate memory tracking of immutable memory (#132) - adapted
Browse files Browse the repository at this point in the history
  • Loading branch information
udi-speedb committed Oct 31, 2023
1 parent b3ee8ef commit e7fbdef
Show file tree
Hide file tree
Showing 9 changed files with 776 additions and 464 deletions.
20 changes: 19 additions & 1 deletion db/memtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -505,13 +505,31 @@ class MemTable {

uint64_t GetID() const { return id_; }

void SetFlushCompleted(bool completed) { flush_completed_ = completed; }
void SetFlushCompleted(bool completed) {
// Flush Can't complete twice
if (completed) {
assert(!flush_completed_);
}
// In case flush is aborted, notify the memory tracker
if (flush_completed_ && (completed == false)) {
mem_tracker_.FreeMemAborted();
}
flush_completed_ = completed;
}

uint64_t GetFileNumber() const { return file_number_; }

void SetFileNumber(uint64_t file_num) { file_number_ = file_num; }

void SetFlushInProgress(bool in_progress) {
if (in_progress && (flush_in_progress_ == false)) {
assert(!flush_completed_);
mem_tracker_.FreeMemStarted();
} else if ((in_progress == false) && flush_in_progress_) {
// In case flush is aborted, notify the memory tracker
mem_tracker_.FreeMemAborted();
}

flush_in_progress_ = in_progress;
}

Expand Down
13 changes: 7 additions & 6 deletions db/memtable_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ void MemTableList::PickMemtablesToFlush(uint64_t max_memtable_id,
if (num_flush_not_started_ == 0) {
imm_flush_needed.store(false, std::memory_order_release);
}
m->flush_in_progress_ = true; // flushing will start very soon
m->SetFlushInProgress(true); // flushing will start very soon
if (max_next_log_number) {
*max_next_log_number =
std::max(m->GetNextLogNumber(), *max_next_log_number);
Expand Down Expand Up @@ -476,8 +476,8 @@ void MemTableList::RollbackMemtableFlush(const autovector<MemTable*>& mems,
if (m->flush_in_progress_) {
assert(m->file_number_ == 0);
m->file_number_ = 0;
m->flush_in_progress_ = false;
m->flush_completed_ = false;
m->SetFlushInProgress(false);
m->SetFlushCompleted(false);
m->edit_.Clear();
num_flush_not_started_++;
}
Expand Down Expand Up @@ -510,7 +510,7 @@ Status MemTableList::TryInstallMemtableFlushResults(
// All the edits are associated with the first memtable of this batch.
assert(i == 0 || mems[i]->GetEdits()->NumEntries() == 0);

mems[i]->flush_completed_ = true;
mems[i]->SetFlushCompleted(true);
mems[i]->file_number_ = file_number;
}

Expand Down Expand Up @@ -788,8 +788,9 @@ void MemTableList::RemoveMemTablesOrRestoreFlags(
m->edit_.GetBlobFileAdditions().size(), mem_id);
}

m->flush_completed_ = false;
m->flush_in_progress_ = false;
m->SetFlushCompleted(false);
m->SetFlushInProgress(false);

m->edit_.Clear();
num_flush_not_started_++;
m->file_number_ = 0;
Expand Down
Loading

0 comments on commit e7fbdef

Please sign in to comment.