Skip to content

Instantly share code, notes, and snippets.

@jeromatron
Last active April 12, 2018 13:12
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jeromatron/e238e5795b3e79866b83 to your computer and use it in GitHub Desktop.
Save jeromatron/e238e5795b3e79866b83 to your computer and use it in GitHub Desktop.
Using jmxsh to compact specfic sstables

Sometimes you'll want to compact specific sstables and you won't want to major compact. You may not have the ability to run jconsole and want to use a command-line tool. There's a ticket (CASSANDRA-10660) to be able to do this with nodetool, but in the meantime, you can use something like jmxsh (or my mirror for when google pulls the plug on google code).

The jmx mbean to do user defined compaction is in the org.apache.cassandra.db package in the CompactionExecutor and the method is called forceUserDefinedCompaction. You'll need to get a list of sstables that you want to compact.

Start jmxsh with java -jar jmxsh-R5.jar -h localhost -p 7199:

jeremy$ java -jar jmxsh-R5.jar -h localhost -p 7199
jmxsh v1.0, Tue Jan 22 10:23:12 CST 2008

Type 'help' for help.  Give the option '-?' to any command
for usage help.

Starting up in shell mode.
%

Now that you're at the prompt, you can either press enter to navigate through the different mbeans or you can use jmx_invoke to call the one you want. Here is an example of using jmx_invoke with forceUserDefinedCompaction on a couple of sstables:

% jmx_invoke -m org.apache.cassandra.db:type=CompactionManager forceUserDefinedCompaction system-schema_columns-jb-3-Data.db,system-schema_columns-jb-4-Data.db   
% 

There's no completion message. You can just go to nodetool compactionstats output or the data directory to see whether it's working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment