From e8e4e455ca3ed38a0b066d8ea532e00ffc350a56 Mon Sep 17 00:00:00 2001 From: Branimir Lambov Date: Thu, 5 Dec 2024 13:22:26 +0200 Subject: [PATCH] Adjust number of shards printed per level --- .../compaction/UnifiedCompactionStrategy.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/java/org/apache/cassandra/db/compaction/UnifiedCompactionStrategy.java b/src/java/org/apache/cassandra/db/compaction/UnifiedCompactionStrategy.java index 76bd104ff5e4..c1fd1a6b0f57 100644 --- a/src/java/org/apache/cassandra/db/compaction/UnifiedCompactionStrategy.java +++ b/src/java/org/apache/cassandra/db/compaction/UnifiedCompactionStrategy.java @@ -940,33 +940,35 @@ public Map getMaxOverlapsMap() Map> arenas = getLevels(liveSSTables, (i1, i2) -> true); // take all sstables - // find the sstable with the biggest density to define the global shard count ShardManager shardManager = getShardManager(); - double maxDensity = 0; - for (CompactionSSTable liveSSTable : liveSSTables) - maxDensity = Math.max(maxDensity, shardManager.density(liveSSTable)); - int shardCount = controller.getNumShards(maxDensity); - Map map = new LinkedHashMap<>(); + // max general overlap (max # of sstables per query) - map.put("all", getMaxOverlapsPerShardString(liveSSTables, shardManager, shardCount)); + map.put("all", getMaxOverlapsPerShardString(liveSSTables, shardManager)); for (var arena : arenas.entrySet()) { final String arenaName = arena.getKey().name(); for (var level : arena.getValue()) - map.put(arenaName + ":" + level.getIndex(), getMaxOverlapsPerShardString(level.getSSTables(), shardManager, controller.getNumShards(level.max))); + map.put(arenaName + "-L" + level.getIndex(), getMaxOverlapsPerShardString(level.getSSTables(), shardManager)); } return map; } - private static String getMaxOverlapsPerShardString(Collection sstables, ShardManager shardManager, int shardCount) + private String getMaxOverlapsPerShardString(Collection sstables, ShardManager shardManager) { + // Find the sstable with the biggest density to define the shard count. + // This is better than using a level's max bound as that will show more shards than there actually are. + double maxDensity = 0; + for (CompactionSSTable liveSSTable : sstables) + maxDensity = Math.max(maxDensity, shardManager.density(liveSSTable)); + int shardCount = controller.getNumShards(maxDensity); + int[] overlapsMap = getMaxOverlapsPerShard(sstables, shardManager, shardCount); int max = 0; for (int i : overlapsMap) max = Math.max(max, i); - return max + ", per shard: " + Arrays.toString(overlapsMap); + return max + " (per shard: " + Arrays.toString(overlapsMap) + ")"; } public static int[] getMaxOverlapsPerShard(Collection sstables, ShardManager shardManager, int shardCount)