CASSANDRA-21605: Improve algorithmic complexity for finding intersecting SSTables in LCS - #5135
Open
cheeeee wants to merge 1 commit into
Open
CASSANDRA-21605: Improve algorithmic complexity for finding intersecting SSTables in LCS#5135cheeeee wants to merge 1 commit into
cheeeee wants to merge 1 commit into
Conversation
…CS (CASSANDRA-21605) In LeveledCompactionStrategy, SSTables in levels L1 through L8 are stored in a TreeSet and are strictly disjoint and sorted by first key. However, LeveledManifest.getCandidatesFor(level) previously performed an O(N) linear scan over all sstables in the next level (generating an intermediate HashMap of bounds for the entire level via genBounds on every candidate iteration). This patch replaces the O(N) scan with an O(log N + K) binary search: 1. LeveledGenerations: add getOverlapping(level, sstable) which queries the level's TreeSet using sortedLevel.floor(sstable), checking if the predecessor extends into the target bounds, and then scanning forward with an early break as soon as candidate.first.token > sstable.last.token. 2. LeveledManifest: eliminate intermediate genBounds HashMap creation and invoke generations.getOverlapping(level + 1, sstable). 3. Unit tests: comprehensive testGetOverlapping in LeveledGenerationsTest covering exact matches, multi-table spans, gaps, floor-only, successor-only, empty levels, and Level 0. Fixes: CASSANDRA-21605
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Jira Issue
Motivation
In$O(N)$ linear scan over all SSTables in the next level, constructing an intermediate $O(N \times M)$ comparisons and heavy garbage generation.
LeveledCompactionStrategy, SSTables in levels L1 through L8 are stored in aTreeSetand are strictly disjoint and sorted by first key. However,LeveledManifest.getCandidatesFor(level)previously performed anHashMapof bounds for the entire level (genBounds) on every candidate iteration. On large tables with thousands of SSTables per level, this resulted inChanges
LeveledGenerations): AddedgetOverlapping(level, sstable). For levelsTreeSetusingsortedLevel.floor(sstable)to locate the sole predecessor that could potentially overlap, then iterates forward viatailSet, breaking immediately oncecandidate.first.token > sstable.last.token.LeveledManifest): Eliminated the intermediategenBoundsHashMapcreation and invokedgenerations.getOverlapping(level + 1, sstable).Testing
LeveledGenerationsTest: 5/5 tests pass (addedtestGetOverlappingcovering exact boundaries, multi-table spans, gaps between tables, floor-only, successor-only, and empty levels).LeveledCompactionStrategyTest: full test suite passes cleanly (18/18 tests).