From b782d6f187257e852c30a9eff76a9cbbfd6bfce8 Mon Sep 17 00:00:00 2001 From: Keith Rarick Date: Wed, 30 Sep 2009 17:24:40 -0700 Subject: [PATCH] Add a disk full test; fix the bug it exposed. --- binlog.c | 5 +- sh-tests/binlog-diskfull.sh | 140 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+), 1 deletion(-) create mode 100755 sh-tests/binlog-diskfull.sh diff --git a/binlog.c b/binlog.c index 8d8e2db..a3941de 100644 --- a/binlog.c +++ b/binlog.c @@ -583,6 +583,8 @@ maintain_invariant(size_t n) static size_t binlog_reserve_space(size_t n) { + size_t r; + /* This return value must be nonzero but is otherwise ignored. */ if (!current_binlog) return 1; @@ -592,7 +594,8 @@ binlog_reserve_space(size_t n) return maintain_invariant(n); } - ensure_free_space(n); + r = ensure_free_space(n); + if (r != n) return twarnx("ensure_free_space"), 0; newest_binlog->free -= n; newest_binlog->reserved += n; diff --git a/sh-tests/binlog-diskfull.sh b/sh-tests/binlog-diskfull.sh new file mode 100755 index 0000000..93e24f5 --- /dev/null +++ b/sh-tests/binlog-diskfull.sh @@ -0,0 +1,140 @@ +#!/usr/bin/env bash + +ENOSPC=28 +server=localhost +port=11400 +tmpdir="$TMPDIR" +size=1000 +test -z "$tmpdir" && tmpdir=/tmp +out1="${tmpdir}/bnch$$.1" +out2="${tmpdir}/bnch$$.2" +logdir="${tmpdir}/bnch$$.d" +nc='nc -q 1' +nc -q 1 2>&1 | grep -q option && nc='nc -w 1' # workaround for older netcat + +if test `type -t fiu-run` = unfound +then + echo ...skipped. '(requires fiu tools from http://blitiri.com.ar/p/libfiu/)' + exit 0 +fi + +killbeanstalkd() { + { + test -z "$bpid" || kill -9 $bpid + /bin/true # Somehow this gets rid of an unnessary shell message. + } >/dev/null 2>&1 + bpid= +} + +cleanup() { + killbeanstalkd + rm -rf "$logdir" "$out1" "$out2" +} + +catch() { + echo '' Interrupted + exit 3 +} + +trap cleanup EXIT +trap catch HUP INT QUIT TERM + +if [ ! -x ./beanstalkd ]; then + echo "Executable ./beanstalkd not found; do you need to compile first?" + exit 2 +fi + +mkdir -p $logdir + +fiu-run -x ./beanstalkd -p $port -b "$logdir" -s $size >/dev/null 2>/dev/null & +bpid=$! + +sleep .1 +if ! ps -p $bpid >/dev/null; then + echo "Could not start beanstalkd for testing (possibly port $port is taken)" + exit 2 +fi + +# Make beanstalkd think the disk is full now. +fiu-ctrl -e posix/io/oc/open -i $ENOSPC $bpid + +# Insert enough jobs to create another binlog file +$nc $server $port < "$out1" +put 0 0 100 50 +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +put 0 0 100 50 +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +put 0 0 100 50 +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +put 0 0 100 50 +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +put 0 0 100 50 +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +EOF + +diff - "$out1" < "$out1" +put 0 0 100 50 +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +put 0 0 100 50 +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +put 0 0 100 50 +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +put 0 0 100 50 +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +EOF + +diff - "$out1" </dev/null 2>/dev/null & +bpid=$! + +sleep .1 +if ! ps -p $bpid >/dev/null; then + echo "Could not start beanstalkd for testing (possibly port $port is taken)" + exit 2 +fi + +$nc $server $port < "$out2" +delete 1 +delete 2 +delete 3 +delete 6 +delete 7 +delete 8 +delete 9 +EOF + +diff - "$out2" <