You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
IntraL0Compaction cause consitency corruption #5913
We use RocksDB as storage library of TiKV, and we set force_consistency_checks be true in product environment. It crash because of CheckConsistency failed. The error is "L0 files seqno 3001491972 3004797440 vs. 3002875611 3004524421". The message appeared many times in stderr.
By the way, we set WriteOptions.sync be false. I'm not sure whether it was related to this problem.
First we ingest five external sst into Rocksdb, and they happened to be ingested in L0. and there had been some data in memtable, which make the smallest sequence number of memtable is less than which of sst that we ingest.
If there had been one compaction job which compacted sst from L0 to L1, LevelCompactionPicker would trigger a IntraL0Compaction which would compact this five sst from L0 to L0. We call this sst A, which was merged from five ingested sst.
Then some data was put into memtable, and memtable was flushed to L0. We called this sst B.
RocksDB check consistency , and find the smallest_seqno of A is less than that of B and crash. Because B was merged from five sst, the smallest sequence number of it was less than the biggest sequece number of it. So RocksDB could not tell if B was produce by ingested.
@siying This is a false-positive reported by force_consistency_checks=true if there's a intra-L0 compaction compacts an ingested file. It prevent the force_consistency_checks flag to be useful. Do you mind suggesting how we should fix it? We are thinking adding a flag in FileMetaData to note if the file comes intra-L0 compaction of ingested file, and skip those files in CheckConsistency. Thanks.
And we find another problem which is also caused by IntraL0Compaction.
First we have flushed many sst in L0, we call them [s1, s2, s3].
There is an immutable memtable request to be flushed, but because flush thread is busy, so it has not been picked. we call it m1. And at the moment, one sst is ingested into L0. We call it s4. Because s4 is ingested after m1 became immutable memtable, so it has a larger log sequence number than m1.
m1 is flushed in L0. because it is small, this flush job finish quickly. we call it s5.
[s1, s2, s3, s4] are compacted into one sst to L0, by IntraL0Compaction. We call it s6.
compacted 4@0 files to L0
When s6 is added into manifest, the corruption happened. because the largest sequence number of s6 is equal to s4, and they are both larger than that of s5. But because s1 is older than m1, so the smallest sequence number of s6 is smaller than that of s5.
We ran into this too, see cockroachdb#67. Sorry I did not upstream it as my solution was simply to weaken L0 consistency checks, which felt a bit heavy handed. But I will submit it upstream now as it seems to affect more than just us.
edit: never mind, will not submit it as you have a PR open already.
@Little-Wallace hmm... That is a good point. I don't know the best way to solve this bug. Should we avoid picking those two memtables together? CC @riversand963 any thoughts on it?
Ingestion of external SST file does not necessarily trigger a flush of existing memtables. If the keys do not overlap, we proceed to ingestion without flushing first. Therefore, the sequence of events described in this issue is what we expect.
Based on 1, relaxing consistency check for L0 seems reasonable. Original consistency check does not take this case into account and is overly strict.
Activity
yiwu-arbug commentedon Oct 22, 2019
@siying This is a false-positive reported by
force_consistency_checks=trueif there's a intra-L0 compaction compacts an ingested file. It prevent theforce_consistency_checksflag to be useful. Do you mind suggesting how we should fix it? We are thinking adding a flag inFileMetaDatato note if the file comes intra-L0 compaction of ingested file, and skip those files inCheckConsistency. Thanks.[-]CheckConsistency failed[/-][+]IntraL0Compaction cause consitency corruption[/+]Little-Wallace commentedon Oct 23, 2019
And we find another problem which is also caused by IntraL0Compaction.
First we have flushed many sst in L0, we call them [s1, s2, s3].
There is an immutable memtable request to be flushed, but because flush thread is busy, so it has not been picked. we call it m1. And at the moment, one sst is ingested into L0. We call it s4. Because s4 is ingested after m1 became immutable memtable, so it has a larger log sequence number than m1.
m1 is flushed in L0. because it is small, this flush job finish quickly. we call it s5.
[s1, s2, s3, s4] are compacted into one sst to L0, by IntraL0Compaction. We call it s6.
When s6 is added into manifest, the corruption happened. because the largest sequence number of s6 is equal to s4, and they are both larger than that of s5. But because s1 is older than m1, so the smallest sequence number of s6 is smaller than that of s5.
Here is my code to reproduce this problem: https://github.com/Little-Wallace/rocksdb/blob/l0-check/db/db_compaction_test.cc#L4831
yiwu-arbug commentedon Oct 23, 2019
@siying @maysamyabandeh @ajkr mind take a look? Turns out this is a data corruption issue involving intra-L0 compaction and file ingestion. Thanks!
ajkr commentedon Oct 23, 2019
We ran into this too, see cockroachdb#67. Sorry I did not upstream it as my solution was simply to weaken L0 consistency checks, which felt a bit heavy handed. But I will submit it upstream now as it seems to affect more than just us.
edit: never mind, will not submit it as you have a PR open already.
siying commentedon Oct 23, 2019
@Little-Wallace hmm... That is a good point. I don't know the best way to solve this bug. Should we avoid picking those two memtables together? CC @riversand963 any thoughts on it?
riversand963 commentedon Oct 23, 2019
A few thoughts.
siying commentedon Oct 23, 2019
@riversand963 I was mostly referring to the bug @Little-Wallace mentioned. I think the non-overlapping scenario is discussed in #5958
Fix corruption with intra-L0 on ingested files (#5958)
Fix corruption with intra-L0 on ingested files (meta#5958)
Fix corruption with intra-L0 on ingested files (meta#5958)
Fix corruption with intra-L0 on ingested files (meta#5958)
Fix corruption with intra-L0 on ingested files (meta#5958)
maysamyabandeh commentedon Jan 31, 2020
Fixed in #5958
Fix corruption with intra-L0 on ingested files (meta#5958)