Browse Source

Merge pull request #1356 from marko-asplund/master

Toolset: Upgrade cassandra and auto-restart before DB tests
Hamilton Turner 10 years ago
parent
commit
f9d9df177b

+ 172 - 0
config/cassandra/cassandra.init

@@ -0,0 +1,172 @@
+#! /bin/sh
+### BEGIN INIT INFO
+# Provides:          cassandra
+# Required-Start:    $remote_fs $network $named $time
+# Required-Stop:     $remote_fs $network $named $time
+# Should-Start:      ntp mdadm
+# Should-Stop:       ntp mdadm
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: distributed storage system for structured data
+# Description:       Cassandra is a distributed (peer-to-peer) system for
+#                    the management and storage of structured data.
+### END INIT INFO
+
+# Author: Eric Evans <[email protected]>
+
+DESC="Cassandra"
+NAME=cassandra
+PIDFILE=/var/run/$NAME/$NAME.pid
+SCRIPTNAME=/etc/init.d/$NAME
+CASSANDRA_CONF=/etc/cassandra
+WAIT_FOR_START=10
+CASSANDRA_HOME=/usr/share/cassandra
+CASSANDRA_LIB=$CASSANDRA_HOME
+CASSANDRA_PROG=/usr/sbin/cassandra
+FD_LIMIT=100000
+
+# Read configuration variable file if it is present
+[ -r /etc/default/$NAME ] && . /etc/default/$NAME
+
+valid_chome=`find $CASSANDRA_LIB/apache-cassandra*.jar 2> /dev/null`
+[ -n "$valid_chome" ] || exit 0
+[ -e $CASSANDRA_CONF/cassandra.yaml ] || exit 0
+[ -e $CASSANDRA_CONF/cassandra-env.sh ] || exit 0
+
+# Read Cassandra environment file.
+. $CASSANDRA_CONF/cassandra-env.sh
+
+if [ -z "$JVM_OPTS" ]; then
+    echo "Initialization failed; \$JVM_OPTS not set!" >&2
+    exit 3
+fi
+
+export JVM_OPTS
+
+# Export JAVA_HOME, if set.
+[ -n "$JAVA_HOME" ] && export JAVA_HOME
+
+# Load the VERBOSE setting and other rcS variables
+. /lib/init/vars.sh
+
+# Define LSB log_* functions.
+# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
+. /lib/lsb/init-functions
+
+#
+# Function that returns 0 if process is running, or nonzero if not.
+#
+# The nonzero value is 3 if the process is simply not running, and 1 if the
+# process is not running but the pidfile exists (to match the exit codes for
+# the "status" command; see LSB core spec 3.1, section 20.2)
+#
+CMD_PATT="cassandra.+CassandraDaemon"
+is_running()
+{
+    if [ -f $PIDFILE ]; then
+        pid=`cat $PIDFILE`
+        grep -Eq "$CMD_PATT" "/proc/$pid/cmdline" 2>/dev/null && return 0
+        return 1
+    fi
+    return 3
+}
+
+#
+# Function that starts the daemon/service
+#
+do_start()
+{
+    # Return
+    #   0 if daemon has been started
+    #   1 if daemon was already running
+    #   2 if daemon could not be started
+
+    ulimit -l unlimited
+    ulimit -n "$FD_LIMIT"
+
+    cassandra_home=`getent passwd cassandra | awk -F ':' '{ print $6; }'`
+    heap_dump_f="$cassandra_home/java_`date +%s`.hprof"
+    error_log_f="$cassandra_home/hs_err_`date +%s`.log"
+
+    [ -e `dirname "$PIDFILE"` ] || \
+        install -d -ocassandra -gcassandra -m755 `dirname $PIDFILE`
+
+
+
+    start-stop-daemon -S -c cassandra -a $CASSANDRA_PROG -q -p "$PIDFILE" -t >/dev/null || return 1
+
+    start-stop-daemon -S -c cassandra -a $CASSANDRA_PROG -b -p "$PIDFILE" -- \
+        -p "$PIDFILE" -H "$heap_dump_f" -E "$error_log_f" >/dev/null || return 2
+
+}
+
+#
+# Function that stops the daemon/service
+#
+do_stop()
+{
+    # Return
+    #   0 if daemon has been stopped
+    #   1 if daemon was already stopped
+    #   2 if daemon could not be stopped
+    #   other if a failure occurred
+    start-stop-daemon -K -p "$PIDFILE" -R TERM/30/KILL/5 >/dev/null
+    RET=$?
+    rm -f "$PIDFILE"
+    return $RET
+}
+
+case "$1" in
+  start)
+	[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
+	do_start
+	case "$?" in
+		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+	esac
+	;;
+  stop)
+	[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
+	do_stop
+	case "$?" in
+		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+	esac
+	;;
+  restart|force-reload)
+	log_daemon_msg "Restarting $DESC" "$NAME"
+	do_stop
+	case "$?" in
+	  0|1)
+		do_start
+		case "$?" in
+			0) log_end_msg 0 ;;
+			1) log_end_msg 1 ;; # Old process is still running
+			*) log_end_msg 1 ;; # Failed to start
+		esac
+		;;
+	  *)
+	  	# Failed to stop
+		log_end_msg 1
+		;;
+	esac
+	;;
+  status)
+    is_running
+    stat=$?
+    case "$stat" in
+      0) log_success_msg "$DESC is running" ;;
+      1) log_failure_msg "could not access pidfile for $DESC" ;;
+      *) log_success_msg "$DESC is not running" ;;
+    esac
+    exit "$stat"
+    ;;
+  *)
+	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2
+	exit 3
+	;;
+esac
+
+:
+
+# vi:ai sw=4 ts=4 tw=0 et

+ 6 - 0
config/cassandra/cassandra.init.env

@@ -0,0 +1,6 @@
+
+CASSANDRA_HOME=/opt/cassandra
+CASSANDRA_LIB=$CASSANDRA_HOME/lib
+CASSANDRA_CONF=$CASSANDRA_HOME/conf
+CASSANDRA_PROG=$CASSANDRA_HOME/bin/cassandra
+

+ 35 - 12
config/cassandra/cassandra.yaml

@@ -7,7 +7,7 @@
 
 # The name of the cluster. This is mainly used to prevent machines in
 # one logical cluster from joining another.
-cluster_name: 'Benchmark Cluster'
+cluster_name: 'TFB Cluster'
 
 # This defines the number of tokens randomly assigned to this node on the ring
 # The more tokens, relative to other nodes, the larger the proportion of data
@@ -17,7 +17,8 @@ cluster_name: 'Benchmark Cluster'
 # If you leave this unspecified, Cassandra will use the default of 1 token for legacy compatibility,
 # and will use the initial_token as described below.
 #
-# Specifying initial_token will override this setting.
+# Specifying initial_token will override this setting on the node's initial start,
+# on subsequent starts, this setting will apply even if initial token is set.
 #
 # If you already have a cluster with 1 token per node, and wish to migrate to 
 # multiple tokens per node, see http://wiki.apache.org/cassandra/Operations
@@ -78,6 +79,14 @@ authorizer: AllowAllAuthorizer
 # Will be disabled automatically for AllowAllAuthorizer.
 permissions_validity_in_ms: 2000
 
+# Refresh interval for permissions cache (if enabled).
+# After this interval, cache entries become eligible for refresh. Upon next
+# access, an async reload is scheduled and the old value returned until it
+# completes. If permissions_validity_in_ms is non-zero, then this must be
+# also.
+# Defaults to the same value as permissions_validity_in_ms.
+# permissions_update_interval_in_ms: 1000
+
 # The partitioner is responsible for distributing groups of rows (by
 # partition key) across nodes in the cluster.  You should leave this
 # alone for new clusters.  The partitioner can NOT be changed without
@@ -332,11 +341,11 @@ start_rpc: true
 # Note that unlike ListenAddress above, it is allowed to specify 0.0.0.0
 # here if you want to listen on all interfaces, but that will break clients 
 # that rely on node auto-discovery.
-rpc_address: 0.0.0.0
+rpc_address: 127.0.0.1
 # port for Thrift to listen for clients on
 rpc_port: 9160
 
-# enable or disable keepalive on rpc connections
+# enable or disable keepalive on rpc/native connections
 rpc_keepalive: true
 
 # Cassandra provides two out-of-the-box options for the RPC Server:
@@ -349,7 +358,8 @@ rpc_keepalive: true
 # hsha  -> Stands for "half synchronous, half asynchronous." All thrift clients are handled
 #          asynchronously using a small number of threads that does not vary with the amount
 #          of thrift clients (and thus scales well to many clients). The rpc requests are still
-#          synchronous (one thread per active request).
+#          synchronous (one thread per active request). If hsha is selected then it is essential
+#          that rpc_max_threads is changed from the default value of unlimited.
 #
 # The default is sync because on Windows hsha is about 30% slower.  On Linux,
 # sync/hsha performance is about the same, with hsha of course using less memory.
@@ -420,15 +430,22 @@ auto_snapshot: true
 tombstone_warn_threshold: 1000
 tombstone_failure_threshold: 100000
 
-# Add column indexes to a row after its contents reach this size.
-# Increase if your column values are large, or if you have a very large
-# number of columns.  The competing causes are, Cassandra has to
-# deserialize this much of the row to read a single column, so you want
-# it to be small - at least if you do many partial-row reads - but all
-# the index data is read for each access, so you don't want to generate
-# that wastefully either.
+# Granularity of the collation index of rows within a partition.
+# Increase if your rows are large, or if you have a very large
+# number of rows per partition.  The competing goals are these:
+#   1) a smaller granularity means more index entries are generated
+#      and looking up rows withing the partition by collation column
+#      is faster
+#   2) but, Cassandra will keep the collation index in memory for hot
+#      rows (as part of the key cache), so a larger granularity means
+#      you can cache more hot rows
 column_index_size_in_kb: 64
 
+
+# Log WARN on any batch size exceeding this value. 5kb per batch by default.
+# Caution should be taken on increasing the size of this threshold as it can lead to node instability.
+batch_size_warn_threshold_in_kb: 5
+
 # Size limit for rows being compacted in memory.  Larger rows will spill
 # over to disk and use a slower two-pass compaction process.  A message
 # will be logged specifying the row key.
@@ -474,6 +491,12 @@ compaction_preheat_key_cache: true
 # When unset, the default is 200 Mbps or 25 MB/s.
 # stream_throughput_outbound_megabits_per_sec: 200
 
+# Throttles all streaming file transfer between the datacenters,
+# this setting allows users to throttle inter dc stream throughput in addition
+# to throttling all network stream traffic as configured with
+# stream_throughput_outbound_megabits_per_sec
+# inter_dc_stream_throughput_outbound_megabits_per_sec:
+
 # How long the coordinator should wait for read operations to complete
 read_request_timeout_in_ms: 5000
 # How long the coordinator should wait for seq or index scans to complete

+ 1 - 0
toolset/benchmark/benchmarker.py

@@ -535,6 +535,7 @@ class Benchmarker:
             sudo restart mongod
             sudo service redis-server restart
             sudo service postgresql restart
+            sudo service cassandra restart
           """)
           time.sleep(10)
 

+ 17 - 9
toolset/setup/linux/database.sh

@@ -159,15 +159,24 @@ fi
 ##############################
 echo "Setting up Apache Cassandra database"
 sudo apt-get install -qqy openjdk-7-jdk
-export CASS_V=2.0.7
+
+sudo addgroup --system cassandra
+sudo adduser --system --home /ssd/cassandra --no-create-home --ingroup cassandra cassandra
+
+export CASS_V=2.0.12
 wget -nv http://archive.apache.org/dist/cassandra/$CASS_V/apache-cassandra-$CASS_V-bin.tar.gz
-tar xzf apache-cassandra-$CASS_V-bin.tar.gz
+sudo tar xzf apache-cassandra-$CASS_V-bin.tar.gz -C /opt
+sudo ln -s /opt/apache-cassandra-$CASS_V /opt/cassandra
 
 rm -rf /ssd/cassandra /ssd/log/cassandra
 mkdir -p /ssd/cassandra /ssd/log/cassandra
-mv cassandra/cassandra.yaml apache-cassandra-$CASS_V/conf
-mv cassandra/log4j-server.properties apache-cassandra-$CASS_V/conf
-nohup apache-cassandra-$CASS_V/bin/cassandra -p c.pid > cassandra.log
+sudo chown -R cassandra:cassandra /ssd/cassandra
+sudo cp -f cassandra/cassandra.init /etc/init.d/cassandra
+sudo cp -f cassandra/cassandra.init.env /etc/default/cassandra
+sudo cp -f cassandra/cassandra.yaml /opt/apache-cassandra-$CASS_V/conf
+sudo cp -f cassandra/log4j-server.properties /opt/apache-cassandra-$CASS_V/conf
+sudo update-rc.d cassandra defaults
+sudo service cassandra start
 
 for i in {1..45}; do
   nc -z localhost 9160 && break || sleep 1;
@@ -175,11 +184,10 @@ for i in {1..45}; do
 done
 nc -z localhost 9160
 if [ $? -eq 0 ]; then
-  cat cassandra/cleanup-keyspace.cql | apache-cassandra-$CASS_V/bin/cqlsh 127.0.0.1
+  cat cassandra/cleanup-keyspace.cql | /opt/apache-cassandra-$CASS_V/bin/cqlsh 127.0.0.1
   python cassandra/db-data-gen.py > cassandra/tfb-data.cql
-  apache-cassandra-$CASS_V/bin/cqlsh -f cassandra/create-keyspace.cql 127.0.0.1
-  apache-cassandra-$CASS_V/bin/cqlsh -f cassandra/tfb-data.cql 127.0.0.1
-  rm -rf apache-cassandra-*-bin.tar.gz cassandra
+  /opt/apache-cassandra-$CASS_V/bin/cqlsh -f cassandra/create-keyspace.cql 127.0.0.1
+  /opt/apache-cassandra-$CASS_V/bin/cqlsh -f cassandra/tfb-data.cql 127.0.0.1
 else
   >&2 echo "Cassandra did not start, skipping"
 fi