forked from bloomberg/comdb2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunit
More file actions
executable file
·56 lines (43 loc) · 2.1 KB
/
runit
File metadata and controls
executable file
·56 lines (43 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env bash
bash -n "$0" | exit 1
dbnm=$1
if [ "x$dbnm" == "x" ] ; then
failexit "need a DB name"
fi
source ${TESTSROOTDIR}/tools/runit_common.sh
source ${TESTSROOTDIR}/tools/waitmach.sh
function wait_for_coherent_state() {
local host=$1
local desired_state=$2
local master=$3
local state=""
while :; do
state=$(cdb2sql --tabs --host ${master} ${CDB2_OPTIONS} ${DBNAME} default "select coherent_state from comdb2_cluster where host='$host'")
if [[ "$state" == "$desired_state" ]]; then
break
fi
echo "Waiting for $host to become $desired_state (currently $state)"
sleep 1
done
}
$CDB2SQL_EXE ${CDB2_OPTIONS} ${DBNAME} default "create table if not exists t(a int, b blob)"
$CDB2SQL_EXE ${CDB2_OPTIONS} ${DBNAME} default "truncate t"
echo "Populating"
for i in $(seq 1 3000); do
$CDB2SQL_EXE ${CDB2_OPTIONS} ${DBNAME} default "insert into t values($i, randomblob(700000))"
done
host=$($CDB2SQL_EXE --tabs ${CDB2_OPTIONS} ${DBNAME} default "select host from comdb2_cluster where is_master='N' and coherent_state='coherent' limit 1")
delhost=$($CDB2SQL_EXE --tabs ${CDB2_OPTIONS} ${DBNAME} default "select host from comdb2_cluster where is_master='N' and coherent_state='coherent' and host != '$host' limit 1")
master=$($CDB2SQL_EXE --tabs ${CDB2_OPTIONS} ${DBNAME} default "select host from comdb2_cluster where is_master='Y'")
echo "Using node $host"
ssh $host "${CDB2SQL_EXE} -admin ${CDB2_OPTIONS} ${DBNAME} @localhost 'put tunable rep_debug_delay 10'"
$CDB2SQL_EXE --host $delhost ${CDB2_OPTIONS} ${DBNAME} default "delete from t limit 3000" &
sleep 10
ssh $host "${CDB2SQL_EXE} -admin ${CDB2_OPTIONS} ${DBNAME} @localhost 'put tunable rep_debug_delay 0'"
# we expect the node we artificially delayed to become incoherent first, then coherent
wait_for_coherent_state $host "INCOHERENT" $master
wait_for_coherent_state $host "coherent" $master
# wait for the node to actually become available (which may happen after it becomes coherent)
# if we don't do this, then the test will fail with 'db unavailable at finish'.
waitmach $host
echo "Success"