mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
[misc] add scripts for testing redis cluster
This commit is contained in:
parent
7b69cc42c9
commit
830d6275b3
3 changed files with 102 additions and 0 deletions
4
libraries/redis-wrapper/test/scripts/cluster/clear-dbs.sh
Executable file
4
libraries/redis-wrapper/test/scripts/cluster/clear-dbs.sh
Executable file
|
@ -0,0 +1,4 @@
|
|||
while true; do
|
||||
seq 0 8 \
|
||||
| xargs -I% redis-cli -p 700% FLUSHALL > /dev/null
|
||||
done
|
25
libraries/redis-wrapper/test/scripts/cluster/cluster.js
Normal file
25
libraries/redis-wrapper/test/scripts/cluster/cluster.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
execute this script with a redis cluster running to test the health check.
|
||||
starting and stopping shards with this script running is a good test.
|
||||
|
||||
to create a new cluster, use $ ./create-redis-cluster.sh
|
||||
to run a chaos monkey, use $ ./clear-dbs.sh
|
||||
*/
|
||||
|
||||
const redis = require('../../../')
|
||||
|
||||
const rclient = redis.createClient({
|
||||
cluster: Array.from({ length: 9 }).map((value, index) => {
|
||||
return { host: '127.0.0.1', port: 7000 + index }
|
||||
}),
|
||||
})
|
||||
|
||||
setInterval(() => {
|
||||
rclient.healthCheck((err) => {
|
||||
if (err) {
|
||||
console.log('HEALTH CHECK FAILED', err)
|
||||
} else {
|
||||
console.log('HEALTH CHECK OK')
|
||||
}
|
||||
})
|
||||
}, 1000)
|
73
libraries/redis-wrapper/test/scripts/cluster/create-cluster.sh
Executable file
73
libraries/redis-wrapper/test/scripts/cluster/create-cluster.sh
Executable file
|
@ -0,0 +1,73 @@
|
|||
#!/bin/bash
|
||||
|
||||
# USAGE: $0 [NUMBER_OF_NODES, default: 9] [DATA_DIR, default: a new temp dir]
|
||||
#
|
||||
# ports are assigned from 7000 on
|
||||
#
|
||||
# NOTE: the cluster setup requires redis 5+
|
||||
|
||||
set -ex
|
||||
|
||||
COUNT=${1:-9}
|
||||
DATA=$2
|
||||
|
||||
if [[ -z "$DATA" ]]; then
|
||||
IS_TEMP=1
|
||||
TEMP=`mktemp -d`
|
||||
DATA="$TEMP"
|
||||
fi
|
||||
|
||||
HAS_DATA=
|
||||
if [[ -e "$DATA/7000/node.conf" ]]; then
|
||||
HAS_DATA=1
|
||||
fi
|
||||
|
||||
PIDs=""
|
||||
|
||||
cleanup() {
|
||||
# ensure that we delete the temp dir, no matter how the kill cmd exists
|
||||
set +e
|
||||
# invoke kill with at least one PID
|
||||
echo "$PIDs" | xargs -r kill
|
||||
if [[ ! -z "$IS_TEMP" ]]; then
|
||||
rm -rf "$TEMP"
|
||||
fi
|
||||
}
|
||||
trap cleanup exit
|
||||
|
||||
for NUM in `seq "$COUNT"`; do
|
||||
PORT=`expr 6999 + "$NUM"`
|
||||
CWD="$DATA/$PORT"
|
||||
mkdir -p "$CWD"
|
||||
pushd "$CWD"
|
||||
redis-server \
|
||||
--appendonly no \
|
||||
--cluster-enabled yes \
|
||||
--cluster-config-file node.conf \
|
||||
--port "$PORT" \
|
||||
--save "" \
|
||||
> /dev/null \
|
||||
&
|
||||
PIDs="$PIDs $!"
|
||||
popd
|
||||
done
|
||||
|
||||
# initial nodes
|
||||
if [[ -z "$HAS_DATA" ]]; then
|
||||
# confirm the setup
|
||||
echo yes \
|
||||
| redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002
|
||||
fi
|
||||
|
||||
# scale up as requested
|
||||
for NUM in `seq 4 "$COUNT"`; do
|
||||
PORT=`expr 6999 + "$NUM"`
|
||||
GUARD="$DATA/$PORT/.joined"
|
||||
if [[ ! -e "$GUARD" ]]; then
|
||||
redis-cli --cluster add-node "127.0.0.1:$PORT" 127.0.0.1:7000 --cluster-slave
|
||||
touch "$GUARD"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "CLUSTER IS READY" >&2
|
||||
wait
|
Loading…
Reference in a new issue