Avoid < 0 value for pending tasks in leveled compaction patch by jbellis; reviewed by slebresne for CASSANDRA-3693
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/10a8f677 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/10a8f677 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/10a8f677 Branch: refs/heads/trunk Commit: 10a8f67783d9987063424212129be29690628bca Parents: 2bb862c Author: Sylvain Lebresne <sylv...@datastax.com> Authored: Wed Jan 11 08:52:42 2012 +0100 Committer: Sylvain Lebresne <sylv...@datastax.com> Committed: Wed Jan 11 08:54:44 2012 +0100 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../cassandra/db/compaction/LeveledManifest.java | 20 +++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/10a8f677/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 09bb85d..b31f3a0 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -19,6 +19,7 @@ * Don't ignore IOException during compaction (CASSANDRA-3655) * Fix assertion error for CF with gc_grace=0 (CASSANDRA-3579) * Shutdown ParallelCompaction reducer executor after use (CASSANDRA-3711) + * Avoid < 0 value for pending tasks in leveled compaction (CASSANDRA-3693) Merged from 0.8: * avoid logging (harmless) exception when GC takes < 1ms (CASSANDRA-3656) * prevent new nodes from thinking down nodes are up forever (CASSANDRA-3626) http://git-wip-us.apache.org/repos/asf/cassandra/blob/10a8f677/src/java/org/apache/cassandra/db/compaction/LeveledManifest.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/db/compaction/LeveledManifest.java b/src/java/org/apache/cassandra/db/compaction/LeveledManifest.java index f61a26a..40a0a17 100644 --- a/src/java/org/apache/cassandra/db/compaction/LeveledManifest.java +++ b/src/java/org/apache/cassandra/db/compaction/LeveledManifest.java @@ -27,6 +27,7 @@ import java.io.IOException; import java.util.*; import com.google.common.collect.Iterables; +import com.google.common.primitives.Ints; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -202,11 +203,14 @@ public class LeveledManifest return builder.toString(); } - private double maxBytesForLevel (int level) + private long maxBytesForLevel(int level) { - return level == 0 - ? 4 * maxSSTableSizeInMB * 1024 * 1024 - : Math.pow(10, level) * maxSSTableSizeInMB * 1024 * 1024; + if (level == 0) + return 4 * maxSSTableSizeInMB * 1024 * 1024; + double bytes = Math.pow(10, level) * maxSSTableSizeInMB * 1024 * 1024; + if (bytes > Long.MAX_VALUE) + throw new RuntimeException("At most " + Long.MAX_VALUE + " bytes may be in a compaction level; your maxSSTableSize must be absurdly high to compute " + bytes); + return (long) bytes; } public synchronized Collection<SSTableReader> getCompactionCandidates() @@ -424,12 +428,14 @@ public class LeveledManifest public int getEstimatedTasks() { - int n = 0; + long tasks = 0; for (int i = generations.length - 1; i >= 0; i--) { List<SSTableReader> sstables = generations[i]; - n += Math.max(0L, SSTableReader.getTotalBytes(sstables) - maxBytesForLevel(i)) / (maxSSTableSizeInMB * 1024 * 1024); + long n = Math.max(0L, SSTableReader.getTotalBytes(sstables) - maxBytesForLevel(i)) / (maxSSTableSizeInMB * 1024 * 1024); + logger.debug("Estimating " + n + " compaction tasks in level " + i); + tasks += n; } - return n; + return Ints.checkedCast(tasks); } }