Skip to content

Instantly share code, notes, and snippets.

@millerjp
Last active November 17, 2015 13:20
Show Gist options
  • Save millerjp/6e6ac980aa9a842f0841 to your computer and use it in GitHub Desktop.
Save millerjp/6e6ac980aa9a842f0841 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# This script will connect up to each server in the nodes array and perform the necessary steps.
# Uses: https://github.com/BrianGallew/cassandra_range_repair
#
# See: http://www.datastax.com/dev/blog/more-efficient-repairs
# See: http://docs.datastax.com/en/cassandra/2.1/cassandra/operations/ops_repair_nodes_c.html?scroll=concept_ds_ebj_d3q_gk__opsRepairMigrateInc
log(){
echo "`date` - $@ "
}
NOW=$(date +"%Y%m%d")
LOGDIR=/home/cassandra/repairs/$NOW/$$/
mkdir -p $LOGDIR
# Redirect stdout ( > ) into a named pipe ( >() ) running "tee"
exec > >(tee $LOGDIR/repair-run.log)
# Without this, only stdout would be captured - i.e. your
# log file would not contain any error messages.
exec 2>&1
PIDFILE=/home/cassandra/repairs/clustername-repairs.pid
STOPFILE=/home/cassandra/repairs/clustername-repairs-stop
if [ -e $PIDFILE ]; then
pid=`cat $PIDFILE`
if kill -0 &>1 > /dev/null $pid; then
log "$PIDFILE exists - Already running, exiting"
exit 1
else
rm $PIDFILE
fi
fi
echo $$ > $PIDFILE
KEYSPACES=( "keyspace1" "dse_system", "system_auth", "cfs_archive", "cfs", "HiveMetaStore", "OpsCenter")
REPAIR_STEPS=100
declare -A nodes
nodes[node1]=DC1
nodes[node2]=DC1
nodes[node3]=DC1
nodes[node4]=DC2
nodes[node5]=DC2
nodes[node6]=DC2
nodes[node7]=DC3
nodes[node8]=DC3
nodes[node9]=DC3
for i in "${!nodes[@]}"
do
log "Running repairs on node : $i in dc: ${nodes[$i]}"
for x in "${KEYSPACES[@]}"
do
if [[ -f $STOPFILE ]] ; then
log $STOPFILE exists, exiting repair
rm $PIDFILE
exit 1
fi
log "About to do a repair for keyspace $x via `hostname` on node $i"
TIME=$(date +"%Y%m%d%H%M%S")
LOGFILE=$LOGDIR"$TIME-$i-${nodes[$i]}-$x-repair.log"
log "Individual repair log is @ $LOGFILE"
#./range_repair.py -n /usr/bin/nodetool -k $x -H $i -D ${nodes[$i]} -s $REPAIR_STEPS -v --logfile=$LOGFILE
./range_repair.py -n /usr/bin/nodetool -k $x -H $i -D ${nodes[$i]} -s $REPAIR_STEPS -v --logfile=$LOGFILE --dry-run
log "Finished repair for keyspace $x on node $i via `hostname`"
done
done
log "Repair run completed keyspace $x on node $i via `hostname`"
rm $PIDFILE
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment