Skip to content

Instantly share code, notes, and snippets.

@cheecheeo
Created June 8, 2012 18:45
Show Gist options
  • Save cheecheeo/2897537 to your computer and use it in GitHub Desktop.
Save cheecheeo/2897537 to your computer and use it in GitHub Desktop.
Manual Cassandra compaction
#!/bin/bash
# Usage:
# ./cassandra_maintenance.sh
# or
# CASSANDRA_HOME=/path/to/cassandra ./cassandra_maintenance.sh
# Some useful logging commands:
#nodetool -h localhost compactionstats
#while true; do date | perl -pe 's/\n/ /g' >> /tmp/cassandra.log 2>&1 && nodetool -h localhost compactionstats >> /tmp/cassandra.log 2>&1 && sleep 10s; done &
CASSANDRA_HOME=${CASSANDRA_HOME:-/opt/apache-cassandra-1.0.8/bin}
PATH=$CASSANDRA_HOME:$PATH
# Disable compaction for all column families
keyspace=''
echo 'show schema;' | cassandra-cli -h localhost | egrep 'create' | while read line; do
case $line in
"create keyspace"*)
keyspace=$(echo $line | awk '{print $NF}')
;;
"create column family"*)
cf=$(echo $line | awk '{print $NF}')
nodetool -h localhost setcompactionthreshold $keyspace $cf 0 0
;;
*)
echo "impossible" 1>&2;;
esac
done
# No throttling on compaction
nodetool -h localhost setcompactionthroughput 0
# Compact each kesypace
echo 'show schema;' | cassandra-cli -h localhost | egrep 'create keyspace' | while read line; do
keyspace=$(echo $line | awk '{print $NF}')
nodetool -h localhost compact $keyspace
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment