CompactRange() does not fully compact after WriteBatch is written
- Dominant language
- C++
- Stars
- 39.4k
- Forks
- 8.2k
- PR merge metrics
- No merged PRs in 30d
Description
Original [issue 221](https://code.google.com/p/leveldb/issues/detail?id=221) created by jsbell@chromium.org on 2014-01-02T23:03:16.000Z:
After writing data via a WriteBatch then deleting records, a single CompactRange(NULL, NULL) call does not appear to reclaim space as expected. Oddly, a second CompactRange(NULL, NULL) call right after the first does reclaim the space.
Repro:
First, the nominal case:
1. Open db
2. db->Put() 10 records, 1e6 bytes each
3. db->Delete() all 10 records
4. db->CompactRange(NULL, NULL)
Expect: Disk usage < 10kB
Actual: Disk usage < 10kB (i.e. this works as expected)
But now try with a WriteBatch:
1. Open db
2. Create a WriteBatch
3. batch->Put() 10 records, 1e6 bytes each
4. db->Write(WriteBatch)
5. db->Delete() all 10 records
6. Call db->CompactRange(NULL, NULL)
Expect: Disk usage < 10kB
Actual: Disk usage ~ 10MB (i.e. data was not compacted)
Finally, try calling CompactRange() twice:
1. Open db
2. Create a WriteBatch
3. batch->Put() 10 records, 1e6 bytes each
4. db->Write(WriteBatch)
5. db->Delete() all 10 records
6. db->CompactRange(NULL, NULL)
7. db->CompactRange(NULL, NULL)
Expect: Disk usage < 10kB
Actual: Disk usage < 10kB (i.e. data was compacted)
Failing test attached - it uses ftw() to measure disk usage, which may not be ideal.
Contributor guide
Assessment
This issue has not been assessed yet.