add a command line flag to ctdbd to start a recovery daemon.
[sahlberg/ctdb.git] / tests / recover.sh
1 #!/bin/sh
2
3 killall -q ctdbd
4 killall -q ctdb_recoverd
5
6 echo "Starting 4 ctdb daemons"
7 bin/ctdbd --recovery-daemon --nlist direct/4nodes.txt
8 bin/ctdbd --recovery-daemon --nlist direct/4nodes.txt --listen=127.0.0.2:9001 --socket=/tmp/ctdb.socket.127.0.0.2
9 bin/ctdbd --recovery-daemon --nlist direct/4nodes.txt --listen=127.0.0.3:9001 --socket=/tmp/ctdb.socket.127.0.0.3
10 bin/ctdbd --recovery-daemon --nlist direct/4nodes.txt --listen=127.0.0.4:9001 --socket=/tmp/ctdb.socket.127.0.0.4
11
12 echo
13 echo "Attaching to some databases"
14 bin/ctdb_control attach test1.tdb || exit 1
15 bin/ctdb_control attach test2.tdb || exit 1
16 bin/ctdb_control attach test3.tdb || exit 1
17 bin/ctdb_control attach test4.tdb || exit 1
18
19 echo "Clearing all databases to make sure they are all empty"
20 bin/ctdb_control getdbmap 0 | egrep "^dbid:" | sed -e "s/^dbid://" -e "s/ .*$//" | while read DB; do
21         seq 0 3 | while read NODE; do
22                 bin/ctdb_control cleardb $NODE $DB
23         done
24 done
25
26
27 echo
28 echo
29 echo "Printing all databases on all nodes. they should all be empty"
30 echo "============================================================="
31 bin/ctdb_control getdbmap 0 | egrep "^dbid:" | sed -e "s/^.*name://" -e "s/ .*$//" | while read DBNAME; do
32         seq 0 3 | while read NODE; do
33                 echo "Content of DBNAME:$DBNAME NODE:$NODE :"
34                 bin/ctdb_control catdb $DBNAME $NODE
35         done
36 done
37
38 echo
39 echo
40 echo "Populating the databases"
41 ./bin/ctdb_control writerecord 0 0x220c2a7b testkey1 testdata1
42 ./bin/ctdb_control setdmaster 0 0x220c2a7b 1
43
44 ./bin/ctdb_control writerecord 1 0x220c2a7b testkey1 testdata1
45 ./bin/ctdb_control writerecord 1 0x220c2a7b testkey1 testdata1
46 ./bin/ctdb_control setdmaster 1 0x220c2a7b 2
47
48 ./bin/ctdb_control writerecord 2 0x220c2a7b testkey1 testdata1
49 ./bin/ctdb_control writerecord 2 0x220c2a7b testkey1 testdata1
50 ./bin/ctdb_control writerecord 2 0x220c2a7b testkey1 testdata1
51 ./bin/ctdb_control setdmaster 2 0x220c2a7b 3
52
53 ./bin/ctdb_control writerecord 3 0x220c2a7b testkey1 testdata1
54 ./bin/ctdb_control writerecord 3 0x220c2a7b testkey1 testdata1
55 ./bin/ctdb_control writerecord 3 0x220c2a7b testkey1 testdata1
56 ./bin/ctdb_control writerecord 3 0x220c2a7b testkey1 testdata1
57 ./bin/ctdb_control setdmaster 3 0x220c2a7b 3
58
59
60 echo
61 echo
62 echo "Printing all databases on all nodes. there should be a record there"
63 echo "============================================================="
64 bin/ctdb_control getdbmap 0 | egrep "^dbid:" | sed -e "s/^.*name://" -e "s/ .*$//" | while read DBNAME; do
65         seq 0 3 | while read NODE; do
66                 echo "Content of DBNAME:$DBNAME NODE:$NODE :"
67                 bin/ctdb_control catdb $DBNAME $NODE
68         done
69 done
70
71 echo
72 echo
73 echo "killing off node #2"
74 echo "==================="
75 CTDBPID=`./bin/ctdb_control getpid 2 | sed -e "s/Pid://"`
76 kill $CTDBPID
77 sleep 1
78
79
80 echo
81 echo
82 echo "wait 3 seconds to let the recovery daemon do its job"
83 echo "===================================================="
84 sleep 3
85
86 echo
87 echo
88 echo "Printing all databases on all nodes."
89 echo "The databases should be the same now on all nodes"
90 echo "and the record will have been migrated to node 0"
91 echo "================================================="
92 echo "Node 0:"
93 bin/ctdb_control catdb test4.tdb 0
94 echo "Node 1:"
95 bin/ctdb_control catdb test4.tdb 1
96 echo "Node 3:"
97 bin/ctdb_control catdb test4.tdb 3
98 echo "nodemap:"
99 bin/ctdb_control getnodemap 0
100
101 echo
102 echo
103 echo "Traverse the cluster and dump the database"
104 bin/ctdb_control catdb test4.tdb
105
106
107 #leave the ctdb daemons running   so one can look at the box in more detail
108 #killall -q ctdbd