facebook / facebook/rocksdb

Assertion `!ShouldScheduleFlush()' failed when constructing a memtable.

Open
#10,713 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
32.1k
Forks
6.9k
Avg merge
32m
Merged PRs (30d)
1

Description

Recently I used YCSB to do some database benchmarking. I tried to change some default options, when I changed write_buffer_size to 2M, the database always made an error when construct Memtable.
### Expected behavior
Execute the constructor of Memtable correctly.
### Actual behavior
**Error:**/rocksdb/db/memtable.cc:117: rocksdb::MemTable::MemTable(const rocksdb::InternalKeyComparator&, const rocksdb::ImmutableOptions&, const rocksdb::MutableCFOptions&, rocksdb::WriteBufferManager*, rocksdb::SequenceNumber, uint32_t): Assertion `!ShouldScheduleFlush()' failed.

When a Memtable is constructed, the state of flush_state_ will be checked first, which cannot be FLUSH_REQUESTED.
![image](https://user-images.githubusercontent.com/43242755/191453650-90c2c16d-3ff0-4eda-a684-7d61e2fdcf21.png)
However, in the previous UpdateFlushState(), since ShouldFlushNow() returned true, flush_state_ was set to FLUSH_REQUESTED, which caused it to fail in the asset below.
![image](https://user-images.githubusercontent.com/43242755/191453788-cffc73ab-b67d-48f3-b928-6695c19c1e3f.png)
I read the source code of ShouleFlushNow() carefully, when I debug to this function, the kArenaBlockSize is 16M and the write_buffer_size is 2M. ShouldFlushNow() will not return through the following two logics.
![image](https://user-images.githubusercontent.com/43242755/191454149-81cdd105-729b-477d-841f-b17f038812f5.png)
Instead return the result with this line of code at the end. I noticed the comment, which states that this means Arena has already allocated his "last block". At this time, my arena_.AllocatedAndUnused() is 1384, which is much smaller than 0.25*kArenaBlockSize.
![image](https://user-images.githubusercontent.com/43242755/191454898-d84421f7-6791-4ace-b78a-5c8960e079bf.png)
### Steps to reproduce the behavior
Simply, just set write_buffer_size to 2M or less, or a slightly larger number.(:

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the failure with write_buffer_size set to 2M or less. Read db/memtable.cc around the MemTable constructor, UpdateFlushState(), and ShouldFlushNow(), then trace why FLUSH_REQUESTED persists into construction. Done means the constructor completes without the assertion for the reported configuration and the behavior is covered by an appropriate regression check.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.