Add script to generate docker-compose.yaml for Qdrant cluster (#1489)

* Add a simple script to generate `docker-compose.yaml` for a cluster of specified number of nodes

* Improve service error from `RequestError` conversion

* fixup! Improve service error from `RequestError` conversion [skip ci]

* fixup! Add a simple script to generate `docker-compose.yaml` for a cluster of specified number of nodes [skip ci]

* Add CPU limit to the `docker-compose-gen.sh` [skip ci]

* fixup! Add CPU limit to the `docker-compose-gen.sh` [skip ci]

* Move docker-compose generator script into tools directory, add docs

* Apply suggestions from code review

Co-authored-by: Roman Titov <ffuugoo@users.noreply.github.com>

* Simplify error message constructing

---------

Co-authored-by: timvisee <tim@visee.me>
Co-authored-by: Tim Visée <tim+github@visee.me>
This commit is contained in:
Roman Titov
2023-05-25 16:49:12 +02:00
committed by Andrey Vasnetsov
parent df88289f4c
commit 09940cb49b
2 changed files with 67 additions and 1 deletions

View File

@@ -1,5 +1,8 @@
use std::backtrace::Backtrace;
use std::collections::{BTreeMap, HashMap};
use std::error::Error as _;
use std::fmt::Write as _;
use std::iter;
use std::num::NonZeroU64;
use std::time::SystemTimeError;
@@ -674,7 +677,13 @@ impl From<RequestError<tonic::Status>> for CollectionError {
fn from(err: RequestError<tonic::Status>) -> Self {
match err {
RequestError::FromClosure(status) => status.into(),
RequestError::Tonic(err) => CollectionError::service_error(format!("{err}")),
RequestError::Tonic(err) => {
let mut msg = err.to_string();
for src in iter::successors(err.source(), |&src| src.source()) {
write!(&mut msg, ": {src}").unwrap();
}
CollectionError::service_error(msg)
}
}
}
}

View File

@@ -0,0 +1,57 @@
#!/usr/bin/env bash
# Generate a docker-compose configuration for a cluster.
#
# Parameters:
# - $1: number of nodes (default: 5)
# - $2: base port (default: 6330)
#
# Example usage:
# ./generate_docker_compose_cluster.sh 5 > docker-compose.yaml
set -euo pipefail
declare NODES="${1:-5}"
declare BASE_PORT="${2:-6330}"
cat <<-EOF
version: "3.7"
services:
EOF
for ((node=0; node<NODES; node++))
do
declare SERVICE_NAME=qdrant_node_$node
declare HTTP_PORT=$((BASE_PORT + node * 10 + 3))
declare GRPC_PORT=$((BASE_PORT + node * 10 + 4))
if ((node == 0))
then
declare COMMAND="./qdrant --uri 'http://$SERVICE_NAME:6335'"
else
declare COMMAND="bash -c \"sleep $((10 + node / 10 + RANDOM % 10)) && ./qdrant --bootstrap 'http://qdrant_node_0:6335' --uri 'http://$SERVICE_NAME:6335'\""
fi
cat <<-EOF
$SERVICE_NAME:
image: qdrant/qdrant:latest
command: $COMMAND
restart: always
environment:
- QDRANT__SERVICE__GRPC_PORT=6334
- QDRANT__CLUSTER__ENABLED=true
- QDRANT__CLUSTER__P2P__PORT=6335
- QDRANT__CLUSTER__CONSENSUS__MAX_MESSAGE_QUEUE_SIZE=5000
- QDRANT__LOG_LEVEL=debug,raft=info
ports:
- "$HTTP_PORT:6333"
- "$GRPC_PORT:6334"
deploy:
resources:
limits:
cpus: "0.3"
EOF
done