Compaction bug
Version: The latest version of RocksDB, 5.17.2
Behavior
We use rocksdb as the local storage in our production environment. Our cluster was upgraded rocksdb from 5.10.4 to 5.17.2 and open the assertion. We meet a coredump with rocksdb when we call manual compaction and our cluster crash and will not recover.
This is the coredump backtrace:

The error message from rocksdb:

Use our tools to decode the key, we found that:
51978.sst
startkey : 74182989 kTypeRangeDeletion
endkey : 74357879 kTypeValue
51976.sst
startkey : 73621839 kTypeDeletion
endkey : 74243730 kTypeRangeDeletion
51978.sst and 51976.sst are overlapping in level 2!
51978.sst and 51976.sst were generated by the same compaction job:

We put or delete some kvs to rocksdb, and we call DeleteRange() and then we call ManualCompaction(). The compaction job generates two files with overlap. This situation will cause the coredump when log apply.

@ajkr
(Note: I will only be able to respond sporadically, as I am no longer at Facebook.)
So this looks to me as though the problem lies in CompactionJob::FinishCompactionOutputFile. This function tries to truncate tombstone start keys to not overlap with previous files in the level, but it looks like that somehow failed here. Typically, a compaction is single-threaded and creates output files in user key order. However, it looks like 51978.sst was created before 51976.sst even though the former has bigger keys. This only happens when using subcompactions, which are a feature that has not seen much use in production at Facebook and likely has some bugs. So if you're using that in production, I would recommend against it (though I understand why it's tempting since from what I understand, you call CompactRange frequently).
(I actually fixed a somewhat similar bug in https://github.com/facebook/rocksdb/pull/4723, where the seqnum of a range tombstone file boundary was improperly set to 0 in some cases. This wasn't backported to 5.17 since we didn't think people were using both subcompactions and range deletions, and I see that this actually happened here, but I don't think that's not the cause of the overlap; I just thought I should mention it.)
If possible, can you provide the range tombstone that split across these two files? You should be able to see it by using sst_dump on either of the two files, since the tombstone is not truncated to file boundaries on disk (only when it's loaded in memory). Thanks!
If you have some test code that can reproduce the issue, that'd be helpful. Also does it only happen when run on a DB that was upgraded from RocksDB 5.10?
It is possible to see a situation like the following when using subcompaction
- Two subcompactions (sub1, sub2) boundary is set to [1, 100) [100, 200)
- A delete range is [80, 120)
- When the compaction iterator meet the key
79, and the next valid key is131, and the output file is determined to be closed (big enough or too much overlap). - Then we call FinishCompactionOutputFile(), the next key is set to 131, and we get a output file with range [xxx,
120) (the upper bound is truncated by the tombstone) - The upper bound of the output file is bigger than the end of sub1, and was overlapping with the first output file of sub2
To fix this, the FinishCompactionOutputFile should check if the upper bound of output file bigger than the end of subcompaction.
Thanks for your reply @abhimadan, learn a lot from you.
Closing this issue as it is fixed in #4898 . Thanks for reporting and fixing it, @yangzhijia .
I still meet the bugs in rocksdb 5.18.0,is that fixed in this version?