alanwang67 commented on code in PR #4476:
URL: https://github.com/apache/cassandra/pull/4476#discussion_r2632818373
##########
src/java/org/apache/cassandra/db/compaction/CompactionStrategyManager.java:
##########
@@ -702,6 +793,85 @@ public boolean isLeveledCompaction()
}
}
+ double[] avgUCSHelper(BiFunction<UnifiedCompactionStrategy, SSTableReader,
Double> fn)
+ {
+ readLock.lock();
+ try
+ {
+ if (repaired.first() instanceof UnifiedCompactionStrategy)
+ {
+ int numberOfLevels = 0;
+
+ double[] sum = new
double[UnifiedCompactionStrategy.MAX_LEVELS];
+ int[] count = new int[UnifiedCompactionStrategy.MAX_LEVELS];
+
+ for (AbstractCompactionStrategy strategy : getAllStrategies())
+ {
+ UnifiedCompactionStrategy ucsStrategy =
(UnifiedCompactionStrategy) strategy;
+ List<Level> levels = ucsStrategy.getLevelsSnapshot();
+ numberOfLevels = Math.max(numberOfLevels, levels.size());
+ for (int i = 0; i < levels.size(); i++)
+ {
+ for (SSTableReader sstable :
levels.get(i).getSSTables())
+ {
+ sum[i] += fn.apply(ucsStrategy, sstable);
+ count[i] += 1;
+ }
+ }
+ }
+
+ double[] res = new double[numberOfLevels];
+ for (int i = 0; i < numberOfLevels; i++)
+ res[i] = count[i] == 0 ? 0 : sum[i] / count[i];
+
+ return res;
+ }
+ return null;
+ }
+ finally
+ {
+ readLock.unlock();
+ }
+ }
+
+ double[] perLevelUCSHelper(TriFunction<Level, SSTableReader, Double,
Double> fn)
+ {
+ readLock.lock();
+ try
+ {
+ if (repaired.first() instanceof UnifiedCompactionStrategy)
+ {
+ int numberOfLevels = 0;
+
+ double[] tmp = new
double[UnifiedCompactionStrategy.MAX_LEVELS];
+
+ for (AbstractCompactionStrategy strategy : getAllStrategies())
+ {
+ UnifiedCompactionStrategy ucsStrategy =
(UnifiedCompactionStrategy) strategy;
+ List<Level> levels = ucsStrategy.getLevelsSnapshot();
+ numberOfLevels = Math.max(numberOfLevels, levels.size());
+ for (int i = 0; i < levels.size(); i++)
+ {
+ for (SSTableReader sstable :
levels.get(i).getSSTables())
+ {
+ tmp[i] = fn.apply(levels.get(i), sstable, tmp[i]);
+ }
+ }
+ }
+
+ double[] res = new double[numberOfLevels];
+ System.arraycopy(tmp, 0, res, 0, numberOfLevels);
+
+ return res;
+ }
+ return null;
+ }
+ finally
+ {
+ readLock.unlock();
+ }
+ }
+
Review Comment:
I'm having a bit of a hard time thinking of a good way to unify the cases
for the accumulator since the different metrics require a mix of the following
parameters `Unified Compaction Strategy`, `Level`, `SSTable`, `Double` to
calculate and I've only seen the maximum lambda of a `TriFunction`. I also am
not sure of the best way to unify doing an average since we need an extra
parameter to store the number of elements we have traversed thus far. The ways
that I have came up with are not super readable and seem quite confusing. An
example would be great!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]