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"
46 ctdb_restart_when_done
48 ######################################################################
50 # Confirm that no nodes have databases with read-only delegations
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"
59 echo "BAD: there are read-only delegations"
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.
72 local dmaster
="$1" ; shift
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"
82 echo "BAD: dmaster ${dmaster} has no read-only delegations"
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"
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"
100 echo "BAD: node ${o} has no read-only copy"
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"
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 ######################################################################
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"
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"
146 echo "BAD: could not activate read-only support"
151 ######################################################################
153 echo "Create 1 read-only delegation ..."
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"
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
170 ######################################################################
172 echo "Create more read-only delegations..."
174 try_command_on_node
$dmaster $CTDB_TEST_WRAPPER ctdb_update_record
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}"
186 check_readonly
$dmaster $others
188 ######################################################################
190 echo "Verify that a recovery will revoke the delegations..."
191 try_command_on_node
0 $CTDB recover