Skip to content

IntraL0Compaction cause consitency corruption #5913

Closed

Description

@Little-Wallace

Note: Please use Issues only for bug reports. For questions, discussions, feature requests, etc. post to dev group: https://www.facebook.com/groups/rocksdb.dev

Expected behavior

Actual behavior

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.

This is our RocksDB Branch and RocksDB Version

Steps to reproduce the behavior

We have reproduce this problem.
And there is my code: https://github.com/Little-Wallace/rocksdb/blob/l0-check/db/db_compaction_test.cc#L4759

This problem is caused by IntraL0Compaction.

  • 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.

Activity

  1. yiwu-arbug commented on Oct 22, 2019

    @yiwu-arbug
    Contributor

    @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.

  2. changed the title [-]CheckConsistency failed[/-] [+]IntraL0Compaction cause consitency corruption[/+] on Oct 23, 2019
  3. Little-Wallace commented on Oct 23, 2019

    @Little-Wallace
    ContributorAuthor

    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.

      • s6.smallest_seqno < s5.smallest_seqno < s5.largest_seqno < s6.largest_seqno

    Here is my code to reproduce this problem: https://github.com/Little-Wallace/rocksdb/blob/l0-check/db/db_compaction_test.cc#L4831

  4. yiwu-arbug commented on Oct 23, 2019

    @yiwu-arbug
    Contributor

    @siying @maysamyabandeh @ajkr mind take a look? Turns out this is a data corruption issue involving intra-L0 compaction and file ingestion. Thanks!

  5. ajkr commented on Oct 23, 2019

    @ajkr
    Contributor

    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.

  6. siying commented on Oct 23, 2019

    @siying
    Contributor

    @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?

  7. riversand963 commented on Oct 23, 2019

    @riversand963
    Contributor

    A few thoughts.

    1. 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.
    2. Based on 1, relaxing consistency check for L0 seems reasonable. Original consistency check does not take this case into account and is overly strict.
  8. siying commented on Oct 23, 2019

    @siying
    Contributor

    @riversand963 I was mostly referring to the bug @Little-Wallace mentioned. I think the non-overlapping scenario is discussed in #5958

  9. maysamyabandeh commented on Jan 31, 2020

    @maysamyabandeh
    Contributor

    Fixed in #5958

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions