ctdb-tests: Update integration tests to use ctdb -X
[Samba.git] / ctdb / tests / simple / 75_readonly_records_basic.sh
blobe4d570816092f5f16e3b2e191ca25052178e8a07
1 #!/bin/bash
3 test_info()
5 cat <<EOF
6 Read-only records can be activated at runtime using a ctdb command.
7 If read-only records are not activated, then any attempt to fetch a read-only
8 copy should be automatically upgraded to a read-write fetch_lock().
10 If read-only delegations are present, then any attempt to aquire a read-write
11 fetch_lock will trigger all delegations to be revoked before the fetch lock
12 completes.
15 Prerequisites:
17 * An active CTDB cluster with at least 2 active nodes.
19 Steps:
21 1. Verify that the status on all of the ctdb nodes is 'OK'.
22 2. create a test database and some records
23 3. try to fetch read-only records, this should not result in any delegations
24 4. activate read-only support
25 5. try to fetch read-only records, this should result in delegations
26 6. do a fetchlock and the delegations should be revoked
27 7. try to fetch read-only records, this should result in delegations
28 8. do a recovery and the delegations should be revoked
30 Expected results:
32 Delegations should be created and revoked as above
34 EOF
37 . "${TEST_SCRIPTS_DIR}/integration.bash"
39 ctdb_test_init "$@"
41 set -e
43 cluster_is_healthy
45 # Reset configuration
46 ctdb_restart_when_done
48 ######################################################################
50 # Confirm that no nodes have databases with read-only delegations
51 check_no_readonly ()
53 try_command_on_node all $CTDB cattdb $testdb
54 local ro_flags="RO_HAVE_READONLY|RO_HAVE_DELEGATIONS"
55 local numreadonly=$(grep -c -E "$ro_flags" <<<"$out") || true
56 if [ $numreadonly -eq 0 ] ; then
57 echo "GOOD: no read-only delegations"
58 else
59 echo "BAD: there are read-only delegations"
60 echo "$out"
61 exit 1
65 # Check that the test record has the correct read-only flags on the
66 # given nodes. The first node is the dmaster, which should know there
67 # are delegations but should not be flagged as having a read-only
68 # copy. Subsequent nodes should have a read-only copy but not know
69 # about any (other) delegations.
70 check_readonly ()
72 local dmaster="$1" ; shift
73 local others="$*"
75 local count
77 try_command_on_node $dmaster $CTDB cattdb $testdb
78 count=$(grep -c -E "RO_HAVE_DELEGATIONS" <<<"$out") || true
79 if [ $count -eq 1 ] ; then
80 echo "GOOD: dmaster ${dmaster} has read-only delegations"
81 else
82 echo "BAD: dmaster ${dmaster} has no read-only delegations"
83 echo "$out"
84 exit 1
86 count=$(grep -c -E "RO_HAVE_READONLY" <<<"$out") || true
87 if [ $count -ne 0 ] ; then
88 echo "BAD: dmaster ${dmaster} has a read-only copy"
89 echo "$out"
90 exit 1
93 local o
94 for o in $others ; do
95 try_command_on_node $o $CTDB cattdb $testdb
96 count=$(grep -c -E "RO_HAVE_READONLY" <<<"$out") || true
97 if [ $count -eq 1 ] ; then
98 echo "GOOD: node ${o} has a read-only copy"
99 else
100 echo "BAD: node ${o} has no read-only copy"
101 echo "$out"
102 exit 1
104 count=$(grep -c -E "RO_HAVE_DELEGATIONS" <<<"$out") || true
105 if [ $count -ne 0 ] ; then
106 echo "BAD: other node ${o} has read-only delegations"
107 echo "$out"
108 exit 1
110 done
113 ######################################################################
115 echo "Get list of nodes..."
116 try_command_on_node any $CTDB -X listnodes
117 all_nodes=$(awk -F'|' '{print $2}' <<<"$out")
119 ######################################################################
121 testdb="test.tdb"
122 echo "Create test database \"${testdb}\""
123 try_command_on_node 0 $CTDB attach $testdb
125 echo "Create some records..."
126 try_command_on_node all $CTDB_TEST_WRAPPER ctdb_update_record
128 ######################################################################
130 echo "Try some readonly fetches, these should all be upgraded to full fetchlocks..."
131 try_command_on_node all $CTDB_TEST_WRAPPER "ctdb_fetch_readonly_once </dev/null"
133 check_no_readonly
135 ######################################################################
137 echo "Activate read-only record support for \"$testdb\"..."
138 try_command_on_node all $CTDB setdbreadonly $testdb
140 # Database should be tagged as READONLY
141 try_command_on_node 0 $CTDB getdbmap
142 db_details=$(awk -v db="$testdb" '$2 == foo="name:" db { print }' <<<"$out")
143 if grep -q "READONLY" <<<"$db_details" ; then
144 echo "GOOD: read-only record support is enabled"
145 else
146 echo "BAD: could not activate read-only support"
147 echo "$db_details"
148 exit 1
151 ######################################################################
153 echo "Create 1 read-only delegation ..."
154 # dmaster=1
155 try_command_on_node 1 $CTDB_TEST_WRAPPER ctdb_update_record
157 # Fetch read-only to node 0
158 try_command_on_node 0 $CTDB_TEST_WRAPPER "ctdb_fetch_readonly_once </dev/null"
160 check_readonly 1 0
162 ######################################################################
164 echo "Verify that a fetchlock revokes read-only delegations..."
165 # Node 1 becomes dmaster
166 try_command_on_node 1 $CTDB_TEST_WRAPPER ctdb_update_record
168 check_no_readonly
170 ######################################################################
172 echo "Create more read-only delegations..."
173 dmaster=1
174 try_command_on_node $dmaster $CTDB_TEST_WRAPPER ctdb_update_record
176 others=""
177 for n in $all_nodes ; do
178 if [ "$n" != "$dmaster" ] ; then
179 # Fetch read-only copy to this node
180 try_command_on_node $n \
181 $CTDB_TEST_WRAPPER "ctdb_fetch_readonly_once </dev/null"
182 others="${others} ${n}"
184 done
186 check_readonly $dmaster $others
188 ######################################################################
190 echo "Verify that a recovery will revoke the delegations..."
191 try_command_on_node 0 $CTDB recover
193 check_no_readonly