cleanup now deletes the claim file under .cephmig/claims as its last step, if it holds the job's own ID, and removes the claim directories when they are empty. A cleaned-up job is finished: cleanup and finalize do nothing and do not claim the target again, and sync is refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
102 lines
3.9 KiB
Bash
102 lines
3.9 KiB
Bash
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
compose=(docker compose -f dev/compose.yaml)
|
|
fixture() { "${compose[@]}" exec -T client python3 /lab/native-fixture.py "$@"; }
|
|
name=$(fixture setup)
|
|
work="/state/$name"
|
|
state="$work/job.json"
|
|
config="$work/config.json"
|
|
binary=/usr/local/bin/cephmig-native
|
|
completed=false
|
|
busy_pid=
|
|
cleanup() {
|
|
"${compose[@]}" exec -T native touch "$work/stop-busy" || true
|
|
if [[ -n $busy_pid ]]; then wait "$busy_pid" || true; fi
|
|
if [[ $completed = true ]]; then
|
|
fixture cleanup "$name"
|
|
else
|
|
echo "FAIL: retained native fixtures subvolume=$name state=$state" >&2
|
|
fi
|
|
}
|
|
trap cleanup EXIT
|
|
fixture busy "$name" &
|
|
busy_pid=$!
|
|
"${compose[@]}" exec -T native "$binary" inspect --config "$config"
|
|
"${compose[@]}" exec -T native bash -s -- "$binary" "$config" "$state" "$work" <<'SH'
|
|
set -Eeuo pipefail
|
|
binary=$1 config=$2 state=$3 work=$4
|
|
test ! -e /dev/fuse
|
|
! command -v rsync
|
|
! grep -q 'fuse.ceph' /proc/self/mountinfo
|
|
"$binary" sync --config "$config" --state "$state" > "$work/interrupted.json" 2> "$work/interrupted.log" &
|
|
pid=$!
|
|
for ((i=0; i<300; i++)); do
|
|
kill -0 "$pid" || { cat "$work/interrupted.log"; exit 1; }
|
|
if grep -q 'snapshot=history-1: copying' "$work/interrupted.log"; then break; fi
|
|
sleep 0.1
|
|
done
|
|
sleep 1
|
|
kill -TERM "$pid"
|
|
if wait "$pid"; then echo 'expected cancellation' >&2; exit 1; fi
|
|
grep -q 'context canceled' "$work/interrupted.log"
|
|
python3 - "$state" <<'PY'
|
|
import json,sys
|
|
s=json.load(open(sys.argv[1]))
|
|
assert not s.get("live_snapshot") and not s["snapshots"][0]["done"], s
|
|
PY
|
|
SH
|
|
fixture unthrottle "$name"
|
|
# Crash after the target snapshot was persisted, before the journal can mark it done.
|
|
"${compose[@]}" exec -T native bash -s -- "$binary" "$config" "$state" "$work" <<'SH'
|
|
set -Eeuo pipefail
|
|
binary=$1 config=$2 state=$3 work=$4
|
|
mkdir "$work/bin"
|
|
cat > "$work/bin/ceph" <<'WRAPPER'
|
|
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
if [[ -f $CEPHMIG_CRASH_ONCE && " $* " == *'/clusters/target/ceph.conf'* &&
|
|
" $* " == *' fs subvolume snapshot create '* ]]; then
|
|
/usr/bin/ceph "$@"
|
|
rm "$CEPHMIG_CRASH_ONCE"
|
|
kill -KILL "$PPID"
|
|
exit 0
|
|
fi
|
|
exec /usr/bin/ceph "$@"
|
|
WRAPPER
|
|
chmod +x "$work/bin/ceph"
|
|
export CEPHMIG_CRASH_ONCE="$work/crash"
|
|
touch "$CEPHMIG_CRASH_ONCE"
|
|
if PATH="$work/bin:$PATH" "$binary" sync --config "$config" --state "$state" > "$work/crashed.json"; then
|
|
echo 'expected SIGKILL' >&2; exit 1
|
|
fi
|
|
test ! -f "$CEPHMIG_CRASH_ONCE"
|
|
SH
|
|
"${compose[@]}" exec -T native "$binary" sync --config "$config" --state "$state"
|
|
fixture verify "$name"
|
|
fixture mutate "$name"
|
|
"${compose[@]}" exec -T native "$binary" sync --config "$config" --state "$state"
|
|
"${compose[@]}" exec -T native cp "$work/busy-count" "$work/busy-before-final"
|
|
"${compose[@]}" exec -T native "$binary" finalize --config "$config" --state "$state" --writers-stopped
|
|
fixture final "$name"
|
|
"${compose[@]}" exec -T native bash -s -- "$binary" "$config" "$state" "$work" <<'SH'
|
|
set -Eeuo pipefail
|
|
cp "$3" "$4/before.json"
|
|
"$1" finalize --config "$2" --state "$3" --writers-stopped > "$4/idempotent.json"
|
|
python3 - "$4" <<'PY'
|
|
import json,pathlib,sys
|
|
p=pathlib.Path(sys.argv[1])
|
|
assert json.loads((p/"before.json").read_text()) == json.loads((p/"idempotent.json").read_text())
|
|
assert int((p/"busy-count").read_text()) > int((p/"busy-before-final").read_text()) > 20
|
|
PY
|
|
SH
|
|
# Remove all cephmig snapshots; a second run must find nothing left to do.
|
|
"${compose[@]}" exec -T native "$binary" cleanup --config "$config" --state "$state"
|
|
"${compose[@]}" exec -T native "$binary" cleanup --config "$config" --state "$state"
|
|
fixture cleaned "$name"
|
|
# A finished job stays finished and does not claim the target again.
|
|
"${compose[@]}" exec -T native "$binary" finalize --config "$config" --state "$state" --writers-stopped
|
|
fixture cleaned "$name"
|
|
completed=true
|
|
echo 'PASS: native libcephfs without FUSE/rsync, blockdiff, snapshots, links, ACLs, xattrs, quotas, cancellation, SIGKILL resume, unrelated writers, finalization, snapshot cleanup'
|