-
Notifications
You must be signed in to change notification settings - Fork 5
/
import_while_crashing.sh
executable file
·75 lines (59 loc) · 1.67 KB
/
import_while_crashing.sh
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
#!/bin/bash
set -e
source common.sh
SIZE=600000
echo "Building all required containers"
( cd apps/importer/ && docker build -t importer . )
( cd apps/chaotic-killer/ && docker build -t killer . )
export COMPOSE="apps/weaviate/docker-compose.yml"
echo "Starting Weaviate..."
docker compose -f $COMPOSE up -d
wait_weaviate
echo "Starting the chaos script to kill Weaviate periodically (in the background)"
docker run \
--network host \
--rm -t -d \
-v "$PWD:$PWD" \
-w "$PWD" \
-v /var/run/docker.sock:/var/run/docker.sock \
--name killer \
killer
echo "Run import script in foreground..."
if ! docker run \
-e 'DIMENSIONS=48' \
-e 'SHARDS=1' \
-e "SIZE=$SIZE" \
-e 'BATCH_SIZE=128' \
-e 'ORIGIN=http://localhost:8080' \
--network host \
-t importer; then
echo "Importer failed, printing latest Weaviate logs..."
exit 1
fi
echo "Import completed successfully, stop killer"
docker rm -f killer
echo "Wait for Weaviate to be ready again in case there was a kill recently"
wait_weaviate
echo "Validate the count is correct"
attempt=1
retries=3
while [ $attempt -le $retries ]; do
object_count=$(curl -s 'localhost:8080/v1/graphql' -X POST \
-H 'content-type: application/json' \
-d '{"query":"{Aggregate{DemoClass{meta{count}}}}"}' | \
jq '.data.Aggregate.DemoClass[0].meta.count')
if [ "$object_count" -ge "$SIZE" ]; then
echo "Object count is correct"
break
fi
echo "Not enough objects present, wanted $SIZE, got $object_count"
echo "Retrying in 5 seconds..."
sleep 5
attempt=$((attempt + 1))
done
if [ $attempt -gt $retries ]; then
echo "Failed to validate object count after $retries attempts"
exit 1
fi
echo "Passed!"
shutdown