Skip to content

Commit

Permalink
Add script to generate docker-compose.yaml for Qdrant cluster (qdra…
Browse files Browse the repository at this point in the history
…nt#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>
  • Loading branch information
3 people authored and generall committed Jun 19, 2023
1 parent df88289 commit 09940cb
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/collection/src/operations/types.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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)
}
}
}
}
Expand Down
57 changes: 57 additions & 0 deletions tools/generate_docker_compose_cluster.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 09940cb

Please sign in to comment.