summaryrefslogtreecommitdiffstats
path: root/ctdb/tests/INTEGRATION/database/vacuum.001.fast.sh
blob: 27a2225f437ba9a7fc22c1ba33ecb29825a14217 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env bash

# Ensure that vacuuming deletes records on all nodes

. "${TEST_SCRIPTS_DIR}/integration.bash"

set -e

ctdb_test_init

vacuum_test ()
{
	local db="$1"
	local num_records="$2"
	local delete_from_lmaster="${3:-false}"

	local t
	if "$delete_from_lmaster" ; then
		t="lmaster"
	else
		t="non-lmaster"
	fi

	echo
	echo '............................................................'
	printf 'Creating %d record(s)\n' "$num_records"
	printf 'Testing vacuuming of 1 record deleted from %s\n' "$t"
	echo '............................................................'

	echo
	echo "Stall vacuuming on all nodes"
	ctdb_onnode -p all "setvar VacuumInterval 99999"

	echo
	echo "Getting list of nodes..."
	local all_pnns
	ctdb_get_all_pnns

	local first
	first=$(echo "$all_pnns" | sed -n -e '1p')

	echo
	echo "Create/wipe test database ${db}"
	ctdb_onnode "$first" "attach ${db}"
	ctdb_onnode "$first" "wipedb ${db}"

	echo
	echo "Write ${num_records} records to ${db}"
	local i
	for i in $(seq 1 "$num_records") ; do
		ctdb_onnode "$first" "writekey ${db} test${i} value${i}"
	done

	echo
	echo "Migrate record(s) to all nodes"
	for i in $(seq 1 "$num_records") ; do
		ctdb_onnode all "readkey ${db} test${i}"
	done

	echo
	echo "Confirm that all nodes have all the records"
	check_cattdb_num_records "$db" "$num_records" "$all_pnns"

	local key="test1"
	echo
	echo "Delete key ${key}"

	echo "  Find lmaster for key \"${key}\""
	testprog_onnode "$first" "ctdb-db-test get-lmaster ${key}"
	# out  is set above
	# shellcheck disable=SC2154
	lmaster="$out"
	echo "  lmaster=${lmaster}"

	if "$delete_from_lmaster" ; then
		echo "  Delete key ${key} on lmaster node ${lmaster}"
		dnode="$lmaster"
	else
		for i in $all_pnns ; do
			if [ "$i" != "$lmaster" ] ; then
				dnode="$i"
				break
			fi
		done
		echo "  Delete key ${key} on non-lmaster node ${dnode}"
	fi
	ctdb_onnode "$dnode" "deletekey ${db} ${key}"

	echo
	vacuum_confirm_key_empty_dmaster "$dnode" "$db" "$key"

	echo
	echo "Confirm all records still exist on all nodes"
	check_cattdb_num_records "$db" "$num_records" "$all_pnns"

	if ! "$delete_from_lmaster" ; then
		# Ask the lmaster to fetch the deleted record
		echo
		echo "Vacuum on non-lmaster node ${dnode}"
		testprog_onnode "$dnode" "ctdb-db-test vacuum ${db}"

		echo
		vacuum_confirm_key_empty_dmaster "$dnode" "$db" "$key"

		# Fetch the record and put it in the delete queue in
		# the main daemon for processing in next vacuuming run
		# on the lmaster
		echo
		echo "Vacuum on lmaster node ${lmaster}"
		testprog_onnode "$lmaster" "ctdb-db-test vacuum ${db}"

		echo
		echo "Confirm all records still exist on all node nodes"
		check_cattdb_num_records "$db" "$num_records" "$all_pnns"

		echo
		vacuum_confirm_key_empty_dmaster "$lmaster" "$db" "$key"
	fi

	echo
	# In the delete-from-lmaster case, the record is already in
	# the lmaster's delete-queue so only a single run is needed
	echo "Vacuum on lmaster node ${lmaster}"
	testprog_onnode "$lmaster" "ctdb-db-test vacuum ${db}"

	echo
	echo "Confirm a record has been deleted on all nodes"
	local n=$((num_records - 1))
	check_cattdb_num_records "$db" "$n" "$all_pnns"

	echo
	echo "Confirm all other records still exist with expected values"
	local i
	for i in $(seq 1 "$num_records") ; do
		local k="test${i}"
		local v="value${i}"

		if [ "$k" = "$key" ] ; then
			continue
		fi

		db_confirm_key_has_value "$first" "$db" "$k" "$v"
	done
	echo "GOOD"
}

testdb="vacuum_test.tdb"

# 1 record, delete from non-lmaster
vacuum_test "$testdb" 1 false

# 10 records, delete from non-lmaster
vacuum_test "$testdb" 10 false

# 1 record, delete from lmaster
vacuum_test "$testdb" 1 true

# 10 records, delete from lmaster
vacuum_test "$testdb" 10 true