Configuring compaction

Steps for configuring compaction.

In addition to consolidating SSTables, the compaction process merges keys, combines columns, evicts tombstones, and creates a new index in the merged SSTable.

There are two different compaction strategies that you can configure on a table:

  • Size-tiered compaction
  • Leveled compaction

In Cassandra 1.2 and later, you can configure when compaction (eviction) occurs for tombstones for TTL-configured and deleted columns with the tombstone parameters. Setting these parameters helps you avoid having to manually performing compaction to recover disk space.

You can set subproperties for the chosen compaction strategy:

Parameter SizeTieredCompactionStrategy LeveledCompactionStrategy
bucket_high Yes No
bucket_low Yes No
max_threshold Yes Yes
min_threshold Yes Yes
min_sstable_size Yes No
sstable_size_in_mb No Yes
tombstone_compaction_interval Yes Yes
tombstone_threshold Yes Yes

You can specify a number of compaction parameters in the cassandra.yaml file:

To configure compaction, construct a property map in the CQL collection format:

name = { 'name' : value, 'name', value : 'name', value
      ... }

In this string, italics indicates optional.


  1. Create or update a table to set the compaction strategy using the ALTER or CREATE TABLE statements.
      compaction = { 'class' :  'LeveledCompactionStrategy'  }
  2. Control the frequency and scope of a minor compaction of a table that uses the default size-tiered compaction strategy by setting the CQL 3 min_threshold attribute.
    ALTER TABLE users
      WITH compaction =
      {'class' : 'SizeTieredCompactionStrategy', 'min_threshold' : 6 }

    For the list of options and more information, see CQL keyspace and table properties.