Skip to content

Commit

Permalink
calculate exact size required for cleanup operations
Browse files Browse the repository at this point in the history
patch by yukim; reviewed by jbellis for CASSANDRA-1404
  • Loading branch information
jbellis committed May 15, 2012
1 parent 783e5d4 commit 5979bce
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
@@ -1,4 +1,5 @@
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)
Expand Down
30 changes: 24 additions & 6 deletions src/java/org/apache/cassandra/db/ColumnFamilyStore.java
Expand Up @@ -889,17 +889,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;
}
Expand Down
Expand Up @@ -693,7 +693,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");
Expand Down
Expand Up @@ -74,7 +74,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.
Expand All @@ -85,7 +85,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));
}
}

Expand Down

0 comments on commit 5979bce

Please sign in to comment.