Permalink
Browse files

Merge branch 'cassandra-1.1' into trunk

  • Loading branch information...
2 parents 4c63c86 + 5979bce commit 9263835ba6a81f693d2ceed5ae8f0a495e339ae7 @jbellis jbellis committed May 15, 2012
View
@@ -9,6 +9,7 @@
1.1.1-dev
+ * calculate exact size required for cleanup operations (CASSANDRA-1404)
* avoid blocking additional writes during flush when the commitlog
gets behind temporarily (CASSANDRA-1991)
* enable caching on index CFs based on data CF cache setting (CASSANDRA-4197)
@@ -888,17 +888,35 @@ public void addSSTables(Collection<SSTableReader> sstables)
CompactionManager.instance.submitBackground(this);
}
- /*
- * Add up all the files sizes this is the worst case file
+ /**
+ * Calculate expected file size of SSTable after compaction.
+ *
+ * If operation type is {@code CLEANUP}, then we calculate expected file size
+ * with checking token range to be eliminated.
+ * Other than that, we just add up all the files' size, which is the worst case file
* size for compaction of all the list of files given.
+ *
+ * @param sstables SSTables to calculate expected compacted file size
+ * @param operation Operation type
+ * @return Expected file size of SSTable after compaction
*/
- public long getExpectedCompactedFileSize(Iterable<SSTableReader> sstables)
+ public long getExpectedCompactedFileSize(Iterable<SSTableReader> sstables, OperationType operation)
{
long expectedFileSize = 0;
- for (SSTableReader sstable : sstables)
+ if (operation == OperationType.CLEANUP)
+ {
+ Collection<Range<Token>> ranges = StorageService.instance.getLocalRanges(table.name);
+ for (SSTableReader sstable : sstables)
+ {
+ List<Pair<Long, Long>> positions = sstable.getPositionsForRanges(ranges);
+ for (Pair<Long, Long> position : positions)
+ expectedFileSize += position.right - position.left;
+ }
+ }
+ else
{
- long size = sstable.onDiskLength();
- expectedFileSize = expectedFileSize + size;
+ for (SSTableReader sstable : sstables)
+ expectedFileSize += sstable.onDiskLength();
}
return expectedFileSize;
}
@@ -694,7 +694,7 @@ private void doCleanupCompaction(ColumnFamilyStore cfs, Collection<SSTableReader
logger.info("Cleaning up " + sstable);
// Calculate the expected compacted filesize
- long expectedRangeFileSize = cfs.getExpectedCompactedFileSize(Arrays.asList(sstable)) / 2;
+ long expectedRangeFileSize = cfs.getExpectedCompactedFileSize(Arrays.asList(sstable), OperationType.CLEANUP);
File compactionFileLocation = cfs.directories.getDirectoryForNewSSTables(expectedRangeFileSize);
if (compactionFileLocation == null)
throw new IOException("disk full");
@@ -70,7 +70,7 @@ public int execute(CompactionExecutorStatsCollector collector) throws IOExceptio
if (!isCompactionInteresting(toCompact))
return 0;
- File compactionFileLocation = cfs.directories.getDirectoryForNewSSTables(cfs.getExpectedCompactedFileSize(toCompact));
+ File compactionFileLocation = cfs.directories.getDirectoryForNewSSTables(cfs.getExpectedCompactedFileSize(toCompact, compactionType));
if (compactionFileLocation == null && partialCompactionsAcceptable())
{
// If the compaction file path is null that means we have no space left for this compaction.
@@ -81,7 +81,7 @@ public int execute(CompactionExecutorStatsCollector collector) throws IOExceptio
// Note that we have removed files that are still marked as compacting.
// This suboptimal but ok since the caller will unmark all the sstables at the end.
toCompact.remove(cfs.getMaxSizeFile(toCompact));
- compactionFileLocation = cfs.directories.getDirectoryForNewSSTables(cfs.getExpectedCompactedFileSize(toCompact));
+ compactionFileLocation = cfs.directories.getDirectoryForNewSSTables(cfs.getExpectedCompactedFileSize(toCompact, compactionType));
}
}

0 comments on commit 9263835

Please sign in to comment.