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
17 * An active CTDB cluster with at least 2 active nodes.
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
32 Delegations should be created and revoked as above
37 . "${TEST_SCRIPTS_DIR}/integration.bash"
45 ######################################################################
47 # Confirm that no nodes have databases with read-only delegations
50 try_command_on_node all $CTDB cattdb $testdb
51 local ro_flags="RO_HAVE_READONLY|RO_HAVE_DELEGATIONS"
52 local numreadonly=$(grep -c -E "$ro_flags" <<<"$out") || true
53 if [ $numreadonly -eq 0 ] ; then
54 echo "GOOD: no read-only delegations"
56 echo "BAD: there are read-only delegations"
62 # Check that the test record has the correct read-only flags on the
63 # given nodes. The first node is the dmaster, which should know there
64 # are delegations but should not be flagged as having a read-only
65 # copy. Subsequent nodes should have a read-only copy but not know
66 # about any (other) delegations.
69 local dmaster="$1" ; shift
74 try_command_on_node $dmaster $CTDB cattdb $testdb
75 count=$(grep -c -E "RO_HAVE_DELEGATIONS" <<<"$out") || true
76 if [ $count -eq 1 ] ; then
77 echo "GOOD: dmaster ${dmaster} has read-only delegations"
79 echo "BAD: dmaster ${dmaster} has no read-only delegations"
83 count=$(grep -c -E "RO_HAVE_READONLY" <<<"$out") || true
84 if [ $count -ne 0 ] ; then
85 echo "BAD: dmaster ${dmaster} has a read-only copy"
92 try_command_on_node $o $CTDB cattdb $testdb
93 count=$(grep -c -E "RO_HAVE_READONLY" <<<"$out") || true
94 if [ $count -eq 1 ] ; then
95 echo "GOOD: node ${o} has a read-only copy"
97 echo "BAD: node ${o} has no read-only copy"
101 count=$(grep -c -E "RO_HAVE_DELEGATIONS" <<<"$out") || true
102 if [ $count -ne 0 ] ; then
103 echo "BAD: other node ${o} has read-only delegations"
110 ######################################################################
112 echo "Get list of nodes..."
113 try_command_on_node any $CTDB -X listnodes
114 all_nodes=$(awk -F'|' '{print $2}' <<<"$out")
116 ######################################################################
119 echo "Create test database \"${testdb}\""
120 try_command_on_node 0 $CTDB attach $testdb
122 echo "Create some records..."
123 try_command_on_node all $CTDB_TEST_WRAPPER $VALGRIND update_record \
124 -D ${testdb} -k testkey
126 ######################################################################
128 echo "Try some readonly fetches, these should all be upgraded to full fetchlocks..."
129 try_command_on_node all $CTDB_TEST_WRAPPER $VALGRIND fetch_readonly \
130 -D ${testdb} -k testkey
134 ######################################################################
136 echo "Activate read-only record support for \"$testdb\"..."
137 try_command_on_node all $CTDB setdbreadonly $testdb
139 # Database should be tagged as READONLY
140 try_command_on_node 0 $CTDB getdbmap
141 db_details=$(awk -v db="$testdb" '$2 == foo="name:" db { print }' <<<"$out")
142 if grep -q "READONLY" <<<"$db_details" ; then
143 echo "GOOD: read-only record support is enabled"
145 echo "BAD: could not activate read-only support"
150 ######################################################################
152 echo "Create 1 read-only delegation ..."
154 try_command_on_node 1 $CTDB_TEST_WRAPPER $VALGRIND update_record \
155 -D ${testdb} -k testkey
157 # Fetch read-only to node 0
158 try_command_on_node 0 $CTDB_TEST_WRAPPER $VALGRIND fetch_readonly \
159 -D ${testdb} -k testkey
163 ######################################################################
165 echo "Verify that a fetchlock revokes read-only delegations..."
166 # Node 1 becomes dmaster
167 try_command_on_node 1 $CTDB_TEST_WRAPPER $VALGRIND update_record \
168 -D ${testdb} -k testkey
172 ######################################################################
174 echo "Create more read-only delegations..."
176 try_command_on_node $dmaster $CTDB_TEST_WRAPPER $VALGRIND update_record \
177 -D ${testdb} -k testkey
180 for n in $all_nodes ; do
181 if [ "$n" != "$dmaster" ] ; then
182 # Fetch read-only copy to this node
183 try_command_on_node $n $CTDB_TEST_WRAPPER $VALGRIND fetch_readonly \
184 -D ${testdb} -k testkey
185 others="${others} ${n}"
189 check_readonly $dmaster $others
191 ######################################################################
193 echo "Verify that a recovery will revoke the delegations..."
194 try_command_on_node 0 $CTDB recover