Skip to content

Commit 6fa21b4

Browse files
authored
Fix HandleMaxWalSize ScheduleFlush conflict (#140)
1 parent 418645b commit 6fa21b4

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

db/db_impl_write.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ Status DBImpl::HandleMaxWalSize(WriteContext* write_context) {
12411241
}
12421242
}
12431243
}
1244-
if (cfd_picked != nullptr) {
1244+
if (cfd_picked != nullptr && cfd_picked->mem()->SwitchFlushScheduled()) {
12451245
uint64_t alive_log_files_back_size = alive_log_files_.back().size;
12461246
uint64_t max_wal_size = GetMaxWalSize();
12471247
ROCKS_LOG_BUFFER(

db/memtable.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,16 @@ class MemTable {
149149
std::memory_order_relaxed);
150150
}
151151

152+
bool SwitchFlushScheduled() {
153+
auto state = flush_state_.load(std::memory_order_relaxed);
154+
if (state == FLUSH_NOT_REQUESTED) {
155+
flush_state_.compare_exchange_strong(state, FLUSH_REQUESTED,
156+
std::memory_order_relaxed,
157+
std::memory_order_relaxed);
158+
}
159+
return MarkFlushScheduled();
160+
}
161+
152162
// Return an iterator that yields the contents of the memtable.
153163
//
154164
// The caller must ensure that the underlying MemTable remains live

0 commit comments

Comments
 (0)