DataStax Help Center

Change CompactionStrategy and sub-properties via JMX


Changing compaction strategy could be CPU and I/O intensive because all sstables will be rewritten during the process. To change the compaction strategy by ALTER TABLE, all nodes will recompact data at the same time. People might hear about using JMX to change compaction strategy and sub-properties on single node. There are some caveats for using JMX to update the compaction options. This article is to discuss when to use JMX to make the change, the caveats, and the steps to make the JMX call.  

When to use JMX to set CompactionStrategy:

1. To change the compaction strategy on single node temporarily for certain operation task, for example, modifying the compaction class and/or sub-properties on a single node to clean up tombstones or sstables locally.  After the task is done, restarting cassandra will revert the change back to the schema version.

CAVEAT: DO NOT issue any ALTER TABLE command on the same table. Altering anything else about the table through cqlsh will cause the JMX settings change being sent to all nodes.


2. To switch the compaction strategy and sub-properties for a table, but would like to avoid re-compacting the sstables at the same time on all nodes.  Once you have completed this process on each node, you will then want to issue the ALTER TABLE command to make the changes permanent.    

CAVEAT: Finish compaction on a couple of nodes before starting the next. DO NOT trigger schema update on the node before compaction around all nodes finishes.

Mbean attribute to be set:

org.apache.cassandra.db:type=ColumnFamilies,keyspace=<your keyspace>,columnfamily=<your table> CompactionParametersJson

You can use jconsole to make the change, or a command line jmx client such as jmxsh.

Using the JMX client, you would issue the following commands:

1. Connect to Cassandra:

$ java -jar jmxsh-R5.jar -h localhost -p 7199

2. Check the current value:

% jmx_get -m org.apache.cassandra.db:type=ColumnFamilies,keyspace=demodb,columnfamily=test CompactionParametersJson

3. To change the compaction strategy and/or sub-properties:

% jmx_set -m org.apache.cassandra.db:type=ColumnFamilies,keyspace=demodb,columnfamily=test CompactionParametersJson \{"class":"LeveledCompactionStrategy","sstable_size_in_mb":"200"\}

4. Recheck the value:

% jmx_get -m org.apache.cassandra.db:type=ColumnFamilies,keyspace=demodb,columnfamily=test CompactionParametersJson

What could be set in CompactionParametersJson are the parameters after compaction={} in a CREATE TABLE command. 


Related: CASSANDRA-9965




Was this article helpful?
1 out of 1 found this helpful
Have more questions? Submit a request


Powered by Zendesk