-
Notifications
You must be signed in to change notification settings - Fork 21
CNDB-14577: Compact all SSTables of a level shard if their number reaches a limit #1873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Checklist before you submit for review
|
b12b3a2
to
e85cb1d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a couple of comments, and I need to take a fresh look at how the parallelism is controlled on Monday to give you some ideas for that.
src/java/org/apache/cassandra/db/compaction/UnifiedCompactionStrategy.java
Outdated
Show resolved
Hide resolved
src/java/org/apache/cassandra/db/compaction/UnifiedCompactionStrategy.java
Outdated
Show resolved
Hide resolved
AFAICS there are no issues with the parallelism, it should be properly handled by |
ef8f14c
to
d1e5463
Compare
// If that's the case, we perform a major compaction on those shards. | ||
List<Set<CompactionSSTable>> groups = | ||
shardManager.splitSSTablesInShards(sstables, | ||
new ShardingStats(sstables, shardManager, controller).shardCountForDensity, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: This ShardingStats
collection is rather costly. Since we already have a density range for the level, let's use a simpler controller.getNumShards(max)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
(sstableShard, shardRange) -> Sets.newHashSet(sstableShard)); | ||
|
||
List<Set<CompactionSSTable>> oversizeGroups = | ||
groups.stream() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I'm not a fan of the lack of indentation here. Could we move these a few spaces to the right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It comes from the style guide that was set by ant generate-idea-files
:
cassandra/ide/idea/codeStyleSettings.xml
Line 67 in 4182c62
<option name="CONTINUATION_INDENT_SIZE" value="0" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is there and makes a lot of sense for the cases of
x ->
{
...
}
or
functionCall
(
...
)
but
x =
something
is breaking readability. I'm afraid we may have to adjust these manually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These can't be configured separately in IDEA ?
I'll have a look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
|
||
List<Set<CompactionSSTable>> oversizeGroups = | ||
groups.stream() | ||
.filter(group -> group.size() > threshold * controller.getShardMaxSstablesFactor()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes better sense to use the fan factor instead of the threshold (the threshold is always 2 for levelled compaction, and it feels wrong/surprising for e.g. T4 and L4 to have different triggers).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
for (Bucket bucket : buckets) | ||
aggregates.add(bucket.constructAggregate(controller, spaceAvailable, arena)); | ||
} | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add an if (sstables.size() > limit)
to skip quickly if we don't have enough sstables for any shard to be over the limit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
@@ -314,6 +314,10 @@ public abstract class Controller | |||
@Deprecated | |||
static final String STATIC_SCALING_FACTORS_OPTION = "static_scaling_factors"; | |||
|
|||
static final String SHARD_MAX_SSTABLES_FACTOR_OPTION = "shard_max_sstables_factor"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name isn't very readable to me.
Maybe max_sstables_per_shard_factor
or sstables_per_shard_max_factor
?
Or non_overlapping_threshold/trigger
?
Note that we also need to document this in UnifiedCompactionStrategy.md
-- both as a section that describes the behaviour as well as a paragraph in the configuration section. If we can't find a default that works well in almost all situations, also make sure it is eventually added to the product documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
for (Set<CompactionSSTable> group : groups) | ||
{ | ||
if (group.stream().anyMatch( | ||
sstable -> oversizeGroups.stream().anyMatch(oversizeGroup -> oversizeGroup.contains(sstable)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK we can't use streams in OSS C*, where this will also need to be ported. Perhaps turn these into loops already here (IntelliJ can do this for you) so that the code does not immediately diverge?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a performance concern ?
Because the min JDK seems to be 11 even for OSS C*
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Performance. Apparently it is not yet officially forbidden, but it will be: https://lists.apache.org/thread/65glsjzkmpktzmns6j9wvr4nczvskx36
I'm also afraid this can fall under the current "don't use streams on hot paths" recommendation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
d1e5463
to
7a6d9b7
Compare
7a6d9b7
to
bfc79cc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good to me, and we can proceed to make an image from it.
If you think you won't have the time to do the documentation additions, let me know and I will prepare a doc commit.
Collections.emptyList(), | ||
arena, | ||
this)); | ||
oversizeGroups.add(compactionSSTables); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a comment explaining why you prefer to save the groups and check them individually instead of adding all to a single set?
(So that someone reading it doesn't immediately want to do an optimization that may be counterproductive.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, this optimization would be good, wouldn't it ?
I think I should do it...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
how do we disable this feature ? |
Yes that would be the way. We could also implement a magic value like |
|
Oh right, I had fogotten about that. Means that we can also map to |
8295d68
to
52fa379
Compare
|
❌ Build ds-cassandra-pr-gate/PR-1873 rejected by Butler1 new test failure(s) in 4 builds Found 1 new test failures
Found 2 known test failures |
Controller.validateOptions(options); | ||
controller = Controller.fromOptions(cfs, options); | ||
assertEquals(Controller.DEFAULT_MAX_SSTABLES_PER_SHARD_FACTOR * 10, controller.getMaxSstablesPerShardFactor(), epsilon); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I'd also add a test with a value that maps to infinity (e.g. 1e1000) just to make sure we can use that option.
Also consider a copy of the test where we set the factor to infinity and we end up with no compactions selected.
else | ||
{ | ||
// If there are no overlaps, we look if some shards have too many SSTables. | ||
// If that's the case, we perform a major compaction on those shards. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: maybe add a "see CNDB-14577" as a further pointer to the reason we are doing these.
It also makes sense to extract this part in a method (I was surprised sonar isn't complaining about this, but it seems it isn't running).
What is the issue
CNDB-14577: UCS by default does not compact many small non-overlapping sstables with very few rows
What does this PR fix and why was it fixed
This PR limits the number of SSTable for a given compaction level by executing a major compaction of the level instead of the regular compaction of overlapping SSTables.
TODO: