Skip to content

Check internal key range when compacting from last level to penultimate level - #12063

Closed
cbi42 wants to merge 6 commits into
meta:mainfrom
cbi42:penultimate-output-bound
Closed

cbi42 wants to merge 6 commits into
meta:mainfrom
cbi42:penultimate-output-bound

Conversation

@cbi42

@cbi42 cbi42 commented Nov 12, 2023 •

Copy link
Copy Markdown
Contributor

Summary: The test failure in #11909 shows that we may compact keys outside of internal key range of penultimate level input files from last level to penultimate level, which can potentially cause overlapping files in the penultimate level. This PR updates the Compaction::WithinPenultimateLevelOutputRange() to check internal key range instead of user key.

Other fixes:

  • skip range del sentinels when deciding output level for tiered compaction

Test plan:

@cbi42
cbi42 marked this pull request as draft November 12, 2023 01:46
@cbi42
cbi42 force-pushed the penultimate-output-bound branch from 41dfc28 to d3f98b7 Compare November 13, 2023 22:30
facebook-github-bot pushed a commit that referenced this pull request Nov 13, 2023
…Overlap` (#12064)

Summary:
Fixes #11909. The test passes after the change in #11917 to start mock clock from a non-zero time.

The reason for test failing is a bit complicated:
- The Put here https://github.com/pdillinger/rocksdb/blob/e4ad4a0ef1b852dc203311fb885c673c891f08e0/db/compaction/tiered_compaction_test.cc#L2045 happens before mock clock advances beyond 0.
- This causes oldest_key_time_ to be 0 for memtable.
- oldest_ancester_time of the first L0 file becomes 0
- L0 -> L5/6 compaction output files sets `oldest_ancestoer_time` to the current time due to these lines: https://github.com/facebook/rocksdb/blob/509947ce2c970d296fd0d868455d560c7f778a57/db/compaction/compaction_job.cc#L1898C34-L1904.
- This causes some small sequence number to be mapped to current time: https://github.com/facebook/rocksdb/blob/509947ce2c970d296fd0d868455d560c7f778a57/db/compaction/compaction_job.cc#L301
- Keys in L6 is being moved up to L5 due to the unexpected seqno_to_time mapping
- When compacting keys from last level to the penultimate level, we only check keys to be within user key range of penultimate level input files. If we compact the following file 3 with file 1 and output keys to L5, we can get the reported inconsistency bug.
```
L5: file 1 [K5@20, K10@kMaxSeqno], file 2 [K10@30, K14@34)
L6: file 3 [K6@5, K10@20]
```

#12063 will add fixes to check internal key range when compacting keys from last level up to the penultimate level.

Pull Request resolved: #12064

Test Plan: the unit test passes

Reviewed By: ajkr

Differential Revision: D51281149

Pulled By: cbi42

fbshipit-source-id: 00b7f026c453454d9f3af5b2de441383a96f0c62
@cbi42
cbi42 force-pushed the penultimate-output-bound branch from d3f98b7 to cfb7cfb Compare November 14, 2023 01:07
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@cbi42 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@cbi42 has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@cbi42 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@cbi42
cbi42 marked this pull request as ready for review November 14, 2023 02:49
@cbi42
cbi42 requested a review from ajkr November 14, 2023 02:49

@ajkr ajkr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can a test like TieredCompactionTest.RangeBasedTieredStorageLevel be modified to cover this case? The previous way it was caught seemed like a surprising coincidence

Comment thread db/compaction/compaction.cc Resolved
@cbi42
cbi42 force-pushed the penultimate-output-bound branch from 697d3ae to a9543c5 Compare November 17, 2023 16:20
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@cbi42 has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@cbi42 has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@cbi42 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@cbi42

cbi42 commented Nov 17, 2023

Copy link
Copy Markdown
Contributor Author

Can a test like TieredCompactionTest.RangeBasedTieredStorageLevel be modified to cover this case? The previous way it was caught seemed like a surprising coincidence

Yes, I added a repro in TieredCompactionTest.CheckInternalKeyRange and updated TieredCompactionTest.RangeBasedTieredStorageLevel to include a related test case. I was not sure how to write a unit test for this, the set up in TieredCompactionTest.CheckInternalKeyRange helps 👍

Thanks for the review!

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@cbi42 merged this pull request in 4e58cc6.

facebook-github-bot pushed a commit that referenced this pull request Nov 21, 2023
Summary:
`WithinPenultimateLevelOutputRange()` is updated in #12063 to check internal key range. However, op_type of a key can change during compaction, e.g. MERGE -> PUT, which makes a key larger and becomes out of penultimate output range. This has caused stress test failures with error message "Unsafe to store Seq later than snapshot in the last level if per_key_placement is enabled". So update `WithinPenultimateLevelOutputRange()` to only check user key and sequence number.

Pull Request resolved: #12081

Test Plan:
* This repro can produce the corruption within a few runs. Ran it a few times after the fix and did not see Corruption failure.
```
python3 ./tools/db_crashtest.py whitebox --test_tiered_storage --random_kill_odd=888887 --use_merge=1 --writepercent=100 --readpercent=0 --prefixpercent=0 --delpercent=0 --delrangepercent=0 --iterpercent=0 --write_buffer_size=419430 --column_families=1 --read_fault_one_in=0 --write_fault_one_in=0
```

Reviewed By: ajkr

Differential Revision: D51481202

Pulled By: cbi42

fbshipit-source-id: cad6b65099733e03071b496e752bbdb09cf4db82
Tim-Reed pushed a commit to Tim-Reed/rocksdb that referenced this pull request Oct 1, 2026
…Overlap` (meta#12064)

Summary:
Fixes meta#11909. The test passes after the change in meta#11917 to start mock clock from a non-zero time.

The reason for test failing is a bit complicated:
- The Put here https://github.com/pdillinger/rocksdb/blob/e4ad4a0ef1b852dc203311fb885c673c891f08e0/db/compaction/tiered_compaction_test.cc#L2045 happens before mock clock advances beyond 0.
- This causes oldest_key_time_ to be 0 for memtable.
- oldest_ancester_time of the first L0 file becomes 0
- L0 -> L5/6 compaction output files sets `oldest_ancestoer_time` to the current time due to these lines: https://github.com/facebook/rocksdb/blob/e9c5eb70d180fe0a1b80f91998c084e40714c23b/db/compaction/compaction_job.cc#L1898C34-L1904.
- This causes some small sequence number to be mapped to current time: https://github.com/facebook/rocksdb/blob/e9c5eb70d180fe0a1b80f91998c084e40714c23b/db/compaction/compaction_job.cc#L301
- Keys in L6 is being moved up to L5 due to the unexpected seqno_to_time mapping
- When compacting keys from last level to the penultimate level, we only check keys to be within user key range of penultimate level input files. If we compact the following file 3 with file 1 and output keys to L5, we can get the reported inconsistency bug.
```
L5: file 1 [K5@20, K10@kMaxSeqno], file 2 [K10@30, K14@34)
L6: file 3 [K6@5, K10@20]
```

meta#12063 will add fixes to check internal key range when compacting keys from last level up to the penultimate level.

Pull Request resolved: meta#12064

Test Plan: the unit test passes

Reviewed By: ajkr

Differential Revision: D51281149

Pulled By: cbi42

fbshipit-source-id: 00b7f026c453454d9f3af5b2de441383a96f0c62
Tim-Reed pushed a commit to Tim-Reed/rocksdb that referenced this pull request Oct 1, 2026
…te level (meta#12063)

Summary:
The test failure in meta#11909 shows that we may compact keys outside of internal key range of penultimate level input files from last level to penultimate level, which can potentially cause overlapping files in the penultimate level. This PR updates the  `Compaction::WithinPenultimateLevelOutputRange()` to check internal key range instead of user key.

Other fixes:
* skip range del sentinels when deciding output level for tiered compaction

Pull Request resolved: meta#12063

Test Plan:
- existing unit tests
- apply the fix to meta#11905 and run `./tiered_compaction_test --gtest_filter="*RangeDelsCauseFileEndpointsToOverlap*"`

Reviewed By: ajkr

Differential Revision: D51288985

Pulled By: cbi42

fbshipit-source-id: 70085db5f5c3b15300bcbc39057d57b83fd9902a
Tim-Reed pushed a commit to Tim-Reed/rocksdb that referenced this pull request Oct 1, 2026
…#12081)

Summary:
`WithinPenultimateLevelOutputRange()` is updated in meta#12063 to check internal key range. However, op_type of a key can change during compaction, e.g. MERGE -> PUT, which makes a key larger and becomes out of penultimate output range. This has caused stress test failures with error message "Unsafe to store Seq later than snapshot in the last level if per_key_placement is enabled". So update `WithinPenultimateLevelOutputRange()` to only check user key and sequence number.

Pull Request resolved: meta#12081

Test Plan:
* This repro can produce the corruption within a few runs. Ran it a few times after the fix and did not see Corruption failure.
```
python3 ./tools/db_crashtest.py whitebox --test_tiered_storage --random_kill_odd=888887 --use_merge=1 --writepercent=100 --readpercent=0 --prefixpercent=0 --delpercent=0 --delrangepercent=0 --iterpercent=0 --write_buffer_size=419430 --column_families=1 --read_fault_one_in=0 --write_fault_one_in=0
```

Reviewed By: ajkr

Differential Revision: D51481202

Pulled By: cbi42

fbshipit-source-id: cad6b65099733e03071b496e752bbdb09cf4db82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants