[ https://issues.apache.org/jira/browse/CASSANDRA-12961?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15933580#comment-15933580 ]
Carlos Alonso commented on CASSANDRA-12961: ------------------------------------------- Hi guys, I'm planning to do this improvement. It's gonna be my first one ever so please, bear with me :) After going through the code I think it makes sense to get the L0 check outside the loop as [~jjirsa] suggests as a first approach. Pretty much like we do on the first few lines of that method when we check if we're bootstrapping. On a separate issue we can tackle the improvement [~carlyeks] suggests as it will be a different check. The way I see it is that this function will end up being split into several checks. Something along this lines: # If bootstrapping, check for L0 STCS # else if L0 is falling behind #* if there's space in L1. Normal L0 -> L1 #* else compact L0 # else iterate levels descendingly and compact if enough score This will make for a pretty big function, so splitting in smaller functions will also help I think. > LCS needlessly checks for L0 STCS candidates multiple times > ----------------------------------------------------------- > > Key: CASSANDRA-12961 > URL: https://issues.apache.org/jira/browse/CASSANDRA-12961 > Project: Cassandra > Issue Type: Improvement > Components: Compaction > Reporter: Jeff Jirsa > Priority: Trivial > Labels: lhf > > It's very likely that the check for L0 STCS candidates (if L0 is falling > behind) can be moved outside of the loop, or at very least made so that it's > not called on each loop iteration: > {code} > for (int i = generations.length - 1; i > 0; i--) > { > List<SSTableReader> sstables = getLevel(i); > if (sstables.isEmpty()) > continue; // mostly this just avoids polluting the debug log > with zero scores > // we want to calculate score excluding compacting ones > Set<SSTableReader> sstablesInLevel = Sets.newHashSet(sstables); > Set<SSTableReader> remaining = Sets.difference(sstablesInLevel, > cfs.getTracker().getCompacting()); > double score = (double) SSTableReader.getTotalBytes(remaining) / > (double)maxBytesForLevel(i, maxSSTableSizeInBytes); > logger.trace("Compaction score for level {} is {}", i, score); > if (score > 1.001) > { > // before proceeding with a higher level, let's see if L0 is > far enough behind to warrant STCS > CompactionCandidate l0Compaction = > getSTCSInL0CompactionCandidate(); > if (l0Compaction != null) > return l0Compaction; > ...... > {code} -- This message was sent by Atlassian JIRA (v6.3.15#6346)