255d58d2156e57d9c2bf1fa15fdb05ba9a4b50c6
[amitay/samba.git] / ctdb / tests / simple / 70_recoverpdbbyseqnum.sh
1 #!/bin/bash
2
3 test_info()
4 {
5     cat <<EOF
6 The persistent databases are recovered using sequence number.
7 The recovery is performed by picking the copy of the database from the
8 node that has the highest sequence number and ignore the content on all
9 other nodes.
10
11
12 Prerequisites:
13
14 * An active CTDB cluster with at least 2 active nodes.
15
16 Steps:
17
18 1. Verify that the status on all of the ctdb nodes is 'OK'.
19 2. create a persistent test database
20 3. test that no seqnum record blends the database during recovery
21 4. test that seqnum record does not blend the database during recovery
22
23 Expected results:
24
25 * that 3,4 will recover the highest seqnum database
26
27 EOF
28 }
29
30 . "${TEST_SCRIPTS_DIR}/integration.bash"
31
32 ctdb_test_init "$@"
33
34 set -e
35
36 cluster_is_healthy
37
38 # Reset configuration
39 ctdb_restart_when_done
40
41 try_command_on_node 0 "$CTDB listnodes"
42 num_nodes=$(echo "$out" | wc -l)
43
44 add_record_per_node ()
45 {
46     _i=0
47     while [ $_i -lt $num_nodes ] ; do
48         _k="KEY${_i}"
49         _d="DATA${_i}"
50         echo "Store key(${_k}) data(${_d}) on node ${_i}"
51         db_ctdb_tstore $_i "$test_db" "$_k" "$_d"
52         _i=$(($_i + 1))
53     done
54 }
55
56 test_db="persistent_test.tdb"
57 echo "Create persistent test database \"$test_db\""
58 try_command_on_node 0 $CTDB attach "$test_db" persistent
59
60 # 3,
61 # If no __db_sequence_number__ recover whole database
62 #
63
64 echo
65 echo "Test that no __db_sequence_number__ does not blend the database during recovery"
66
67 # wipe database
68 echo "Wipe the test database"
69 try_command_on_node 0 $CTDB wipedb "$test_db"
70
71 add_record_per_node
72
73 # force a recovery
74 echo force a recovery
75 try_command_on_node 0 $CTDB recover
76
77 # Check that we now have 1 record on node 0
78 num_records=$(db_ctdb_cattdb_count_records 0 "$test_db")
79 if [ $num_records = "1" ] ; then
80     echo "OK: databases were not blended"
81 else
82     echo "BAD: we did not end up with the expected single record after the recovery"
83     exit 1
84 fi
85
86
87 # 4,
88 # If __db_sequence_number__  recover whole database
89 #
90
91 echo
92 echo test that __db_sequence_number__ does not blend the database during recovery
93
94 # wipe database
95 echo wipe the test database
96 try_command_on_node 0 $CTDB wipedb persistent_test.tdb
97
98 add_record_per_node
99
100 echo "Add __db_sequence_number__==5 record to all nodes"
101 pnn=0
102 while [ $pnn -lt $num_nodes ] ; do
103     db_ctdb_tstore_dbseqnum $pnn "$test_db" 5
104     pnn=$(($pnn + 1))
105 done
106
107 echo "Set __db_sequence_number__ to 7 on node 0"
108 db_ctdb_tstore_dbseqnum 0 "$test_db" 7
109
110 echo "Set __db_sequence_number__ to 8 on node 1"
111 db_ctdb_tstore_dbseqnum 1 "$test_db" 8
112
113
114 # force a recovery
115 echo force a recovery
116 try_command_on_node 0 $CTDB recover
117
118 # check that we now have both records on node 0
119 num_records=$(db_ctdb_cattdb_count_records 0 "$test_db")
120 if [ $num_records = "1" ] ; then
121     echo "OK: databases were not blended"
122 else
123     echo "BAD: we did not end up with the expected single record after the recovery"
124     exit 1
125 fi