Skip to content

Instantly share code, notes, and snippets.

@phact
Last active June 21, 2019 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phact/b0d7b73c0ffc2f5697d7a68014b8f4ce to your computer and use it in GitHub Desktop.
Save phact/b0d7b73c0ffc2f5697d7a68014b8f4ce to your computer and use it in GitHub Desktop.
surgical script that kicks off user defined compactions to purge tombstones in c*
#!/bin/bash
#set -x
DATA_DIRECTORY="/var/lib/cassandra/data"
CASS_TOOLS_BIN_DIRECTORY="/DSE_DIR_HERE/resources/cassandra/tools/bin/"
KEYSPACE_NAME="assethub"
TABLE_NAME="clusters"
SSTABLE_DIR="$DATA_DIRECTORY/$KEYSPACE_NAME/$TABLE_NAME"
MIN_FILE_SIZE_KB=100
TOMBSTONE_THRESHOLD=.05
#DEBUG=true
cd /tmp || exit
if [ ! -e jmxsh-R5.jar ]; then
wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/jmxsh/jmxsh-R5.jar
fi
# Names must not have spaces or globable chars
SSTABLE_ARRAY=($(find "$SSTABLE_DIR"* -maxdepth 1 -size +"$MIN_FILE_SIZE_KB"k -name '*Data.db'))
TOMBSTONE_ARRAY=($(find "$SSTABLE_DIR"* -maxdepth 1 -size +"$MIN_FILE_SIZE_KB"k -name '*Data.db' | xargs "$CASS_TOOLS_BIN_DIRECTORY"sstablemetadata 2> /dev/null | grep tombstones: | awk -F':' '{print $2}'))
#DEBUG
if [ -n "$DEBUG" ]; then
echo "SSTable array ${SSTABLE_ARRAY[*]}"
echo "Tombstone array ${TOMBSTONE_ARRAY[*]}"
fi
for i in "${!TOMBSTONE_ARRAY[@]}"
do
if [ -n "$DEBUG" ]; then
echo "Tombstone count, Threshold: ${TOMBSTONE_ARRAY[$i]}, $TOMBSTONE_THRESHOLD"
fi
if (( $(echo "${TOMBSTONE_ARRAY[$i]} $TOMBSTONE_THRESHOLD" | awk '{print ($1 > $2)}') )); then
echo "jmx_invoke -m org.apache.cassandra.db:type=CompactionManager forceUserDefinedCompaction " "${SSTABLE_ARRAY[$i]}" > UDC.sh
fi
done
java -jar jmxsh-R5.jar -h localhost -p 7199 -q UDC.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment