File: recover.sh

package info (click to toggle)
golang-github-canonical-go-dqlite 2.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 712 kB
  • sloc: sh: 380; makefile: 5
file content (97 lines) | stat: -rwxr-xr-x 2,344 bytes parent folder | download | duplicates (2)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/sh -eu
#
# Test the dqlite cluster recovery.

ASAN=${ASAN:-}

BASEDIR=$(dirname "$0")
. "$BASEDIR"/dqlite-demo-util.sh

$GO build -tags libsqlite3 $ASAN ./cmd/dqlite/

trap tear_down EXIT
trap sig_handler HUP INT TERM

set_up

echo "=> Start test"

echo "=> Put key to node 1"
if [ "$(curl -s -X PUT -d my-value http://127.0.0.1:8001/my-key)" != "done" ]; then
    echo "Error: put key to node 1"
fi

echo "=> Get key from node 1"
if [ "$(curl -s http://127.0.0.1:8001/my-key)" != "my-value" ]; then
    echo "Error: get key from node 1"
fi

echo "=> Stopping the cluster"
tear_down_node 3
tear_down_node 2
tear_down_node 1

echo "=> Running recovery on node 1"
node1_dir=$DIR/127.0.0.1:9001
node2_dir=$DIR/127.0.0.1:9002
node1_id=$(grep ID "$node1_dir"/info.yaml | cut -d" " -f2)
node2_id=$(grep ID "$node2_dir"/info.yaml | cut -d" " -f2)
target_yaml=${DIR}/cluster.yaml
cat <<EOF > "$target_yaml"
- Address: 127.0.0.1:9001
  ID: ${node1_id}
  Role: 0
- Address: 127.0.0.1:9002
  ID: ${node2_id}
  Role: 1
EOF

if ! ./dqlite -s 127.0.0.1:9001 test ".reconfigure ${node1_dir} ${target_yaml}"; then
    echo "Error: Reconfigure failed"
    exit 1
fi

echo "=> Starting nodes 1 & 2"
start_node 1 ""
start_node 2 ""

echo "=> Confirming new config"
if [ "$(./dqlite -s 127.0.0.1:9001 test .leader)" != 127.0.0.1:9001 ]; then
    echo "Error: Expected node 1 to be leader"
    exit 1
fi

if [ "$(./dqlite -s 127.0.0.1:9001 test .cluster | wc -l)" != 2 ]; then
    echo "Error: Expected 2 servers in the cluster"
    exit 1
fi

if ! ./dqlite -s 127.0.0.1:9001 test .cluster | grep -q "127.0.0.1:9001|voter"; then
    echo "Error: server 1 not voter"
    exit 1
fi

if ! ./dqlite -s 127.0.0.1:9001 test .cluster | grep -q "127.0.0.1:9002|stand-by"; then
    echo "Error: server 2 not stand-by"
    exit 1
fi

echo "=> Get original key from node 1"
if [ "$(curl -s http://127.0.0.1:8001/my-key)" != "my-value" ]; then
    echo "Error: get key from node 1"
    exit 1
fi

echo "=> Put new key to node 1"
if [ "$(curl -s -X PUT -d my-value-new http://127.0.0.1:8001/my-key-new)" != "done" ]; then
    echo "Error: put new key to node 1"
    exit 1
fi

echo "=> Get new key from node 1"
if [ "$(curl -s http://127.0.0.1:8001/my-key-new)" != "my-value-new" ]; then
    echo "Error: get new key from node 1"
    exit 1
fi

echo "=> Test successful"