ctdb-tests: Minimise chances of test interfering with itself
[samba.git] / ctdb / tests / simple / 69_recovery_resurrect_deleted.sh
1 #!/bin/bash
2
3 test_info()
4 {
5     cat <<EOF
6 Ensure recovery doesn't resurrect deleted records from recently inactive nodes
7 EOF
8 }
9
10 . "${TEST_SCRIPTS_DIR}/integration.bash"
11
12 ctdb_test_init
13
14 set -e
15
16 cluster_is_healthy
17
18 testdb="rec_test.tdb"
19
20 echo "Getting list of nodes..."
21 try_command_on_node -v any "onnode -pq all ctdb pnn | grep '^[0-9][0-9]*$'"
22
23 first=$(echo "$out" | sed -n -e '1p')
24 second=$(echo "$out" | sed -n -e '2p')
25 notfirst=$(echo "$out" | tail -n +2)
26
27 echo "Create/wipe test database ${testdb}"
28 try_command_on_node $first $CTDB attach "$testdb"
29 try_command_on_node $first $CTDB wipedb "$testdb"
30
31 echo "store key(test1) data(value1)"
32 try_command_on_node $first $CTDB writekey "$testdb" test1 value1
33
34 echo "Migrate key(test1) to all nodes"
35 try_command_on_node all $CTDB readkey "$testdb" test1
36
37 echo "Stop node ${first}"
38 try_command_on_node $first $CTDB stop
39 wait_until_node_has_status $first stopped
40
41 echo "Delete key(test1)"
42 try_command_on_node $second $CTDB deletekey "$testdb" test1
43
44 database_has_zero_records ()
45 {
46         local n
47         for n in $notfirst ; do
48                 try_command_on_node $n $CTDB cattdb "$testdb"
49                 if echo "$out" | grep -q '^key(' ; then
50                         return 1
51                 fi
52         done
53
54         return 0
55 }
56
57 echo "Get vacuum interval"
58 try_command_on_node -v $second $CTDB getvar VacuumInterval
59 vacuum_interval="${out#* = }"
60
61 echo "Wait until vacuuming deletes the record on active nodes"
62 # Why 4?  Steps are:
63 # 1. Original node processes delete queue, asks lmaster to fetch
64 # 2. lmaster recoverd fetches
65 # 3. lmaster processes delete queue
66 # If vacuuming is just missed then need an extra interval
67 t=$((vacuum_interval * 4))
68 wait_until "${t}/10" database_has_zero_records
69
70 echo "Continue node ${first}"
71 try_command_on_node $first $CTDB continue
72 wait_until_node_has_status $first notstopped
73
74 echo "Get database contents"
75 try_command_on_node -v $first $CTDB catdb "$testdb"
76
77 if echo "$out" | grep -q '^key(' ; then
78         echo "BAD: Deleted record has been resurrected"
79         exit 1
80 fi
81
82 echo "GOOD: Deleted record is still gone"