Skip to content

Commit

Permalink
Code Review Updates #5
Browse files Browse the repository at this point in the history
  • Loading branch information
udi-speedb committed Sep 5, 2022
1 parent e20340e commit 6cc4a50
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
10 changes: 7 additions & 3 deletions db/memtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,12 @@ class MemTable {
uint64_t GetID() const { return id_; }

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_in_progress_ && (completed == false)) {
if (flush_completed_ && (completed == false)) {
mem_tracker_.FreeMemAborted();
}
flush_completed_ = completed;
Expand Down Expand Up @@ -542,8 +546,8 @@ class MemTable {
std::atomic<size_t> write_buffer_size_;

// These are used to manage memtable flushes to storage
bool flush_in_progress_; // started the flush
bool flush_completed_; // finished the flush
bool flush_in_progress_; // started the flush
bool flush_completed_; // finished the flush
uint64_t file_number_; // filled up after flush is complete

// The updates to be applied to the transaction log when this
Expand Down
4 changes: 2 additions & 2 deletions db/memtable_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,8 @@ void MemTableList::RemoveMemTablesOrRestoreFlags(
m->edit_.GetBlobFileAdditions().size(), mem_id);
}

m->SetFlushInProgress(false);
m->SetFlushCompleted(false);
m->SetFlushInProgress(false);

m->edit_.Clear();
num_flush_not_started_++;
Expand Down Expand Up @@ -894,8 +894,8 @@ Status InstallMemtableAtomicFlushResults(
edit->GetBlobFileAdditions().size(), mem_id);
}

m->SetFlushInProgress(false);
m->SetFlushCompleted(false);
m->SetFlushInProgress(false);
m->GetEdits()->Clear();
m->SetFileNumber(0);
imm->num_flush_not_started_++;
Expand Down
2 changes: 1 addition & 1 deletion include/rocksdb/write_buffer_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class WriteBufferManager final {
// The process may complete successfully and FreeMem() will be called to
// notifiy successfull completion, or, aborted, and FreeMemCancelled() will be
// called to notify that.
void FreeMemStarted(size_t mem);
void FreeMemBegin(size_t mem);

// Freeing 'mem' bytes was aborted and that memory is no longer in the process
// of being freed
Expand Down
6 changes: 4 additions & 2 deletions memtable/alloc_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void AllocTracker::FreeMemStarted() {

if (state_ == State::kDoneAllocating) {
if (ShouldUpdateWriteBufferManager()) {
write_buffer_manager_->FreeMemStarted(
write_buffer_manager_->FreeMemBegin(
bytes_allocated_.load(std::memory_order_relaxed));
}
state_ = State::kFreeMemStarted;
Expand All @@ -61,7 +61,9 @@ void AllocTracker::FreeMemStarted() {

void AllocTracker::FreeMemAborted() {
assert(write_buffer_manager_ != nullptr);
assert(state_ == State::kFreeMemStarted);
// May be called without actually starting to free memory
assert((state_ == State::kDoneAllocating) ||
(state_ == State::kFreeMemStarted));

if (state_ == State::kFreeMemStarted) {
if (ShouldUpdateWriteBufferManager()) {
Expand Down
2 changes: 1 addition & 1 deletion memtable/write_buffer_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void WriteBufferManager::ScheduleFreeMem(size_t mem) {
}
}

void WriteBufferManager::FreeMemStarted(size_t mem) {
void WriteBufferManager::FreeMemBegin(size_t mem) {
if (enabled()) {
memory_being_freed_.fetch_add(mem, std::memory_order_relaxed);
}
Expand Down
2 changes: 1 addition & 1 deletion memtable/write_buffer_manager_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const size_t kSizeDummyEntry = 256 * 1024;

namespace {
void BeginAndFree(WriteBufferManager& wbf, size_t size) {
wbf.FreeMemStarted(size);
wbf.FreeMemBegin(size);
wbf.FreeMem(size);
}

Expand Down

0 comments on commit 6cc4a50

Please sign in to comment.