Whamcloud - gitweb
b=21265
[fs/lustre-release.git] / lustre / tests / recovery-random-scale.sh
1 #!/bin/bash
2
3 # client failure does not affect other clients
4
5 # Start load on clients (each client works on it's own directory).
6 # At defined (5-10 minutes) interval fail one random client and then fail mds.
7 # Reintegrate failed client after recovery completed,
8 # application errors are allowed for that client but not on other clients.
9 # 10 minute intervals and verify that no application errors occur.
10
11 # Test runs one of CLIENT_LOAD progs on remote clients.
12
13 LUSTRE=${LUSTRE:-`dirname $0`/..}
14 SETUP=${SETUP:-""}
15 CLEANUP=${CLEANUP:-""}
16 . $LUSTRE/tests/test-framework.sh
17
18 init_test_env $@
19
20 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
21
22 TESTSUITELOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh)}
23 DEBUGLOG=$TESTSUITELOG.debug
24
25 cleanup_logs
26
27 exec 2>$DEBUGLOG
28 echo "--- env ---" >&2
29 env >&2
30 echo "--- env ---" >&2
31 set -x
32
33 [ "$SHARED_DIRECTORY" ] || \
34     { skip "$0: Empty SHARED_DIRECTORY" && exit 0; }
35
36 [ -n "$CLIENTS" ] || { skip "$0 Need two or more remote clients" && exit 0; }
37 [ $CLIENTCOUNT -ge 3 ] || \
38     { skip "$0 Need two or more clients, have $CLIENTCOUNT" && exit 0; }
39
40 END_RUN_FILE=${END_RUN_FILE:-$SHARED_DIRECTORY/end_run_file}
41 LOAD_PID_FILE=${LOAD_PID_FILE:-$TMP/client-load.pid}
42
43 remote_mds_nodsh && skip "remote MDS with nodsh" && exit 0
44
45 build_test_filter
46
47 check_and_setup_lustre
48 rm -rf $DIR/[df][0-9]*
49
50 # the test node needs to be insulated from a lustre failure as much as possible,
51 # so not even loading the lustre modules is ideal.
52 # -- umount lustre
53 # -- remove hostname from clients list
54 zconf_umount $(hostname) $MOUNT
55 NODES_TO_USE=${NODES_TO_USE:-$CLIENTS}
56 NODES_TO_USE=$(exclude_items_from_list $NODES_TO_USE $(hostname))
57
58 check_progs_installed $NODES_TO_USE ${CLIENT_LOADS[@]}
59
60 MDTS=$(get_facets MDS)
61
62 if [ "$SLOW" = "no" ]; then
63     DURATION=${DURATION:-$((60 * 30))}
64     SERVER_FAILOVER_PERIOD=${SERVER_FAILOVER_PERIOD:-$((60 * 5))}
65 else
66     DURATION=${DURATION:-$((60 * 60 * 24))}
67     SERVER_FAILOVER_PERIOD=${SERVER_FAILOVER_PERIOD:-$((60 * 10))} # 10 minutes
68 fi
69
70 rm -f $END_RUN_FILE
71
72 vmstatLOG=${TESTSUITELOG}_$(basename $0 .sh).vmstat
73
74 numfailovers () {
75     local facet
76     local var
77
78     for facet in $MDTS ${failed_clients//,/ }; do
79         var=${facet}_nums
80         val=${!var}
81         if [ "$val" ] ; then
82             echo "$facet failed  over  $val times"
83         fi
84     done
85 }
86
87 # list is comma separated
88 print_logs () {
89     local list=$1
90
91     do_nodes $list "node=\\\$(hostname)
92 var=\\\${node}_load
93 log=${TESTSUITELOG}_run_${!var}.sh-\\\$node.debug
94 if [ -e \\\$log ] ; then
95 echo Node \\\$node debug log:
96 cat \\\$log
97 fi"
98 }
99
100 summary_and_cleanup () {
101
102     local rc=$?
103     local var
104     trap 0
105
106     # Having not empty END_RUN_FILE means the failed loads only
107     if [ -s $END_RUN_FILE ]; then
108         echo "Found the END_RUN_FILE file: $END_RUN_FILE"
109         cat $END_RUN_FILE
110         local END_RUN_NODE=
111         read END_RUN_NODE < $END_RUN_FILE
112
113     # a client load will end (i.e. fail) if it finds
114     # the end run file.  that does not mean that that client load
115     # actually failed though.  the first node in the END_RUN_NODE is
116     # the one we are really interested in.
117         if [ -n "$END_RUN_NODE" ]; then
118             var=$(client_var_name $END_RUN_NODE)_load
119             echo "Client load failed on node $END_RUN_NODE" 
120             echo
121             echo "client $END_RUN_NODE load stdout and debug files :
122               ${TESTSUITELOG}_run_${!var}.sh-${END_RUN_NODE}
123               ${TESTSUITELOG}_run_${!var}.sh-${END_RUN_NODE}.debug"
124         fi
125         rc=1
126     fi
127
128
129     echo $(date +'%F %H:%M:%S') Terminating clients loads ...
130     echo "$0" >> $END_RUN_FILE
131     local result=PASS
132     [ $rc -eq 0 ] || result=FAIL
133
134     log "Duraion:                $DURATION
135 Server failover period: $SERVER_FAILOVER_PERIOD seconds
136 Exited after:           $ELAPSED seconds
137 Number of failovers before exit:
138 $(numfailovers)
139 Status: $result: rc=$rc"
140
141     # stop the vmstats on the OSTs
142     if [ "$VMSTAT" ]; then
143         do_nodes $(comma_list $(osts_nodes)) "test -f /tmp/vmstat.pid && \
144             { kill -s TERM \$(cat /tmp/vmstat.pid); rm -f /tmp/vmstat.pid; \
145             gzip -f9 $vmstatLOG-\$(hostname); }"
146     fi
147
148     # make sure the client loads die
149     do_nodes $NODES_TO_USE "set -x; test -f $LOAD_PID_FILE && \
150         { kill -s TERM \$(cat $LOAD_PID_FILE) || true; }"
151
152     # and free up the pdshes that started them, if any are still around
153     if [ -n "$CLIENT_LOAD_PIDS" ]; then
154         kill $CLIENT_LOAD_PIDS || true
155         sleep 5
156         kill -9 $CLIENT_LOAD_PIDS || true
157     fi
158
159     if [ $rc -ne 0 ]; then
160         print_logs $NODES_TO_USE
161         # we are interested in only on failed clients and servers
162         local failedclients=$(cat $END_RUN_FILE | grep -v $0)
163         # FIXME: need ostfailover-s nodes also for FLAVOR=OST
164         local product=$(gather_logs $(comma_list $(osts_nodes) \
165                                  $mds_HOST $mdsfailover_HOST $failedclients))
166         echo logs files $product
167     fi
168
169     [ $rc -eq 0 ] && zconf_mount $(hostname) $MOUNT
170
171     exit $rc
172 }
173
174 #
175 # MAIN 
176 #
177 log "-----============= $0 starting =============-----"
178
179 trap summary_and_cleanup EXIT # INT
180
181 ELAPSED=0
182
183 # vmstat the osts
184 if [ "$VMSTAT" ]; then
185     do_nodes $(comma_list $(osts_nodes)) "vmstat 1 > $vmstatLOG-\$(hostname) 2>/dev/null </dev/null & echo \$! > /tmp/vmstat.pid"
186 fi
187
188 # Start client loads.
189 start_client_loads $NODES_TO_USE
190
191 echo clients load pids:
192 if ! do_nodes $NODES_TO_USE "set -x; echo \$(hostname): && cat $LOAD_PID_FILE"; then
193     if [ -e $DEBUGLOG ]; then
194         exec 2<&-
195         cat $DEBUGLOG
196         exit 3
197     fi
198 fi
199
200 START_TS=$(date +%s)
201 CURRENT_TS=$START_TS
202
203 MINSLEEP=${MINSLEEP:-120}
204 REQFAIL_PERCENT=${REQFAIL_PERCENT:-3}   # bug17839 comment 62
205 REQFAIL=${REQFAIL:-$(( DURATION / SERVER_FAILOVER_PERIOD * REQFAIL_PERCENT / 100))}
206 reqfail=0
207 sleep=0
208
209 # This is used for FAIL_CLIENT only
210 ERRORS_OK="yes"
211 while [ $ELAPSED -lt $DURATION -a ! -e $END_RUN_FILE ]; do
212
213     # In order to perform the 
214     # expected number of failovers, we need to account the following :
215     # 1) the time that has elapsed during the client load checking
216     # 2) time takes for failover
217
218     it_time_start=$(date +%s)
219     
220     FAIL_CLIENT=$(get_random_entry $NODES_TO_USE)
221     client_var=$(client_var_name $FAIL_CLIENT)_nums
222
223     # store the list of failed clients
224     # lists are comma separated
225     failed_clients=$(expand_list $failed_clients $FAIL_CLIENT)
226
227     SERVERFACET=$(get_random_entry $MDTS)
228     var=${SERVERFACET}_nums
229
230     # Check that our client loads are still running. If any have died, 
231     # that means they have died outside of recovery, which is unacceptable.    
232
233     log "==== Checking the clients loads BEFORE failover -- failure NOT OK \
234     ELAPSED=$ELAPSED DURATION=$DURATION PERIOD=$SERVER_FAILOVER_PERIOD" 
235
236     if ! check_client_loads $NODES_TO_USE; then
237         exit 4
238     fi
239
240     log "FAIL CLIENT $FAIL_CLIENT ... "
241     shutdown_client $FAIL_CLIENT
242
243     log "Starting failover on $SERVERFACET"
244
245     facet_failover "$SERVERFACET" || exit 1
246     if ! wait_recovery_complete $SERVERFACET $((TIMEOUT * 10)); then 
247         echo "$SERVERFACET recovery is not completed!"
248         exit 7
249     fi
250  
251     boot_node $FAIL_CLIENT
252     echo "Reintegrating $FAIL_CLIENT"
253     zconf_mount $FAIL_CLIENT $MOUNT || exit $?
254
255     # Increment the number of failovers
256     val=$((${!var} + 1))
257     eval $var=$val
258     val=$((${!client_var} + 1))
259     eval $client_var=$val
260
261     # load script on failed clients could create END_RUN_FILE
262     # We shuold remove it and ignore the failure if this
263     # file contains the failed client only.
264     # We can not use ERRORS_OK when start all loads at the start of this script
265     # because the application errors allowed for random failed client only, but
266     # not for all clients.
267     if [ -e $END_RUN_FILE ]; then
268         read END_RUN_NODE < $END_RUN_FILE
269         [[ $END_RUN_NODE = $FAIL_CLIENT ]] && 
270             rm -f $END_RUN_FILE || exit 13
271     fi
272    
273     restart_client_loads $FAIL_CLIENT $ERRORS_OK || exit $?
274
275     # Check that not failed clients loads are still running.
276     # No application failures should occur on clients that was not failed.
277
278     log "==== Checking the clients loads AFTER failed client reintegrated -- failure NOT OK"
279     if ! ERRORS_OK= check_client_loads $(exclude_items_from_list $NODES_TO_USE $FAIL_CLIENT); then
280         log "Client load failed. Exiting"
281         exit 5
282     fi
283
284     CURRENT_TS=$(date +%s)
285     ELAPSED=$((CURRENT_TS - START_TS))
286  
287     sleep=$((SERVER_FAILOVER_PERIOD-(CURRENT_TS - it_time_start)))
288
289     # keep count the number of itterations when
290     # time spend to failover and two client loads check exceeded 
291     # the value ( SERVER_FAILOVER_PERIOD - MINSLEEP )
292     if [ $sleep -lt $MINSLEEP ]; then
293         reqfail=$((reqfail +1))
294         log "WARNING: failover, client reintegration and check_client_loads time
295 exceeded SERVER_FAILOVER_PERIOD - MINSLEEP !
296 Failed to meet interval $reqfail times ( REQFAIL=$REQFAIL ); have sleep=$sleep"
297         [ $reqfail -gt $REQFAIL ] && exit 6 
298     fi  
299
300     log " Number of failovers:
301 $(numfailovers)                and counting..."
302
303     if [ $((ELAPSED + sleep)) -gt $DURATION ]; then
304          break
305     fi
306
307     if [ $sleep -gt 0 ]; then 
308         echo "sleeping $sleep seconds ... "
309         sleep $sleep
310     fi
311 done
312
313 exit 0