ctdb-tests: Update preamble for INTEGRATION tests
[vlendec/samba-autobuild/.git] / ctdb / tests / INTEGRATION / database / vacuum.033.locked.sh
1 #!/usr/bin/env bash
2
3 # Confirm that a record is not vacuumed if it is locked on the
4 # deleting node when the 3rd fast vacuuming run occurs, but is dropped
5 # from the lmaster delete list
6
7 . "${TEST_SCRIPTS_DIR}/integration.bash"
8
9 set -e
10
11 ctdb_test_init
12
13 db="vacuum_test.tdb"
14 key="key"
15
16 echo "Stall vacuuming on all nodes"
17 ctdb_onnode -p all "setvar VacuumInterval 99999"
18
19 echo
20 echo "Getting list of nodes..."
21 ctdb_get_all_pnns
22
23 # all_pnns is set above by ctdb_get_all_pnns()
24 # shellcheck disable=SC2154
25 first=$(echo "$all_pnns" | sed -n -e '1p')
26
27 echo
28 echo "Determine lmaster node for key"
29 testprog_onnode "$first" "ctdb-db-test get-lmaster key"
30 # $out is set above by testprog_onnode()
31 # shellcheck disable=SC2154
32 lmaster="$out"
33 echo "lmaster=${lmaster}"
34
35 non_lmaster=""
36 # Find a non-lmaster node
37 for i in $all_pnns ; do
38         if [ "$i" != "$lmaster" ] ; then
39                 non_lmaster="$i"
40                 break
41         fi
42 done
43 if [ -z "$non_lmaster" ] ; then
44         ctdb_test_fail "Could not find non-lmaster node for key"
45 fi
46
47 echo "............................................................"
48 echo "Delete key ${key} on node ${non_lmaster}"
49 echo "Lock on non-lmaster node ${non_lmaster} during 3rd vacuuming run"
50 echo "............................................................"
51
52 echo
53
54 echo "Create/wipe test database ${db}"
55 ctdb_onnode "$first" "attach ${db}"
56 ctdb_onnode "$first" "wipedb ${db}"
57
58 echo "Create a record in ${db}"
59 ctdb_onnode "$first" "writekey ${db} ${key} value1"
60
61 echo "Migrate record to all nodes"
62 ctdb_onnode all "readkey ${db} ${key}"
63
64 echo "Confirm that all nodes have the record"
65 check_cattdb_num_records "$db" 1 "$all_pnns"
66
67 echo
68
69 echo "Delete key \"${key}\" from node ${non_lmaster}"
70 ctdb_onnode "$non_lmaster" "deletekey $db ${key}"
71
72 echo
73 echo "Do a fast vacuuming run on node ${non_lmaster}"
74 testprog_onnode "$non_lmaster" "ctdb-db-test vacuum ${db}"
75
76 echo
77 echo "Confirm that all nodes still have the record"
78 check_cattdb_num_records "$db" 1 "$all_pnns"
79
80 echo
81 echo "Do a fast vacuuming run on lmaster node ${lmaster}"
82 testprog_onnode "$lmaster" "ctdb-db-test vacuum ${db}"
83
84 echo
85 echo "Confirm that all nodes still have the record"
86 check_cattdb_num_records "$db" 1 "$all_pnns"
87
88 echo
89 echo "Lock record on non-lmaster node ${non_lmaster}"
90 testprog_onnode "$non_lmaster" "ctdb-db-test local-lock ${db} ${key}"
91 pid="${out#OK }"
92 ctdb_test_cleanup_pid_set "$non_lmaster" "$pid"
93
94 echo "Do a fast vacuuming run on node ${lmaster}"
95 testprog_onnode "$lmaster" "ctdb-db-test vacuum ${db}"
96
97 echo "Kill lock process ${pid} on node ${non_lmaster}"
98 try_command_on_node "$non_lmaster" "kill ${pid}"
99 ctdb_test_cleanup_pid_clear
100
101 echo
102 echo "Confirm that nodes ${lmaster} and ${non_lmaster} still have the record"
103 check_cattdb_num_records "$db" 1 "${lmaster} ${non_lmaster}"
104
105 vacuum_confirm_key_empty_dmaster "$lmaster" "$db" "$key"
106
107 echo
108
109 # Record has been dropped from the delete list so this will not pick it up
110 echo "Do a fast vacuuming run on lmaster node ${lmaster}"
111 testprog_onnode "$lmaster" "ctdb-db-test vacuum ${db}"
112
113 echo
114 echo "Confirm that nodes ${lmaster} and ${non_lmaster} still have the record"
115 check_cattdb_num_records "$db" 1 "${lmaster} ${non_lmaster}"
116
117 vacuum_confirm_key_empty_dmaster "$lmaster" "$db" "$key"