]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: test: Add script to test LOST state
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Fri, 15 Oct 2010 01:14:27 +0000 (18:14 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Fri, 22 Oct 2010 00:31:58 +0000 (17:31 -0700)
Signed-off-by: Colin McCabe <colinm@hq.newdream.net>
src/test/test_lost.sh [new file with mode: 0755]

diff --git a/src/test/test_lost.sh b/src/test/test_lost.sh
new file mode 100755 (executable)
index 0000000..08e94fa
--- /dev/null
@@ -0,0 +1,94 @@
+#!/bin/bash -x
+
+#
+# Simple test of recovery logic
+#
+
+# Constants
+MAX_OBJS=100
+OBJ_SIZE=1000000
+TEMPDIR=`mktemp -d`
+SDIR=`dirname $0`/..
+
+# Initialization
+cd $SDIR
+[ -e "/dev/urandom" ] || die "need /dev/urandom"
+trap cleanup INT TERM EXIT
+rm -rf $TEMPDIR
+mkdir -p $TEMPDIR || die "failed to make tempdir"
+
+# Functions
+cleanup() {
+        rm -rf "${TEMPDIR}"
+}
+
+die() {
+        echo $@
+        exit 1
+}
+
+stop_osd() {
+        osd_index=$1
+        pidfile="out/osd.$osd_index.pid"
+        if [ -e $pidfile ]; then
+                kill `cat $pidfile` && return 0
+        else
+                echo "cosd process $osd_index is not running" 
+        fi
+        return 1
+}
+
+restart_osd() {
+        osd_index=$1
+        ./cosd -i $osd_index -c ceph.conf &
+}
+
+write_objects() {
+        start_ver=$1
+        stop_ver=$2
+        for v in `seq $start_ver $stop_ver`; do
+                head -c $OBJ_SIZE /dev/zero  | tr '\0' '$v' > $TEMPDIR/ver$v
+                for i in `seq -w 1 $MAX_OBJS`; do
+                        ./rados -p data put obj$i $TEMPDIR/ver$v || die "radostool failed"
+                done
+        done
+}
+
+setup() {
+        # Start ceph
+        ./stop.sh
+
+        # TODO: somehow constrain the number of PGs created by vstart.sh so that
+        # situations are more reproducible
+        CEPH_NUM_OSD=2 ./vstart.sh -d -n || die "vstart failed"
+}
+
+do_test() {
+        # Write lots and lots of objects
+        write_objects 1 3
+
+        # Take down osd1
+        stop_osd 1
+
+        # Continue writing a lot of objects
+        write_objects 4 6
+
+        # Bring up osd1
+        restart_osd 1
+
+        # Give recovery some time to start
+        sleep 30
+
+        # Stop osd0 before recovery can complete
+        stop_osd 0
+
+        # Now we should be in LOST_REVERT
+}
+
+run() {
+        setup
+
+        do_test
+}
+
+$@