Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed instructions on how to setup a FalkorDB Cluster #110

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,5 @@ thpool
sds
CRoaring
RSALv

hostnames
108 changes: 41 additions & 67 deletions operations/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,89 +34,57 @@ Next, you need to launch multiple FalkorDB instances that will form the cluster.
### 2.1 Start the nodes

```bash
docker run -d \
--name node1 \
--network falkordb-cluster-network \
-p 6379:6379 \
-e 'FALKORDB_ARGS=--cluster-enabled yes' \
falkordb/falkordb
for i in {1..6}; do
docker run -d \
--name node$i \
--hostname node$i \
--network falkordb-cluster-network \
-p $((6379 + i - 1)):$((6379 + i - 1)) \
-e BROWSER=0 \
-e "FALKORDB_ARGS=--port $((6379 + i - 1)) --cluster-enabled yes --cluster-announce-ip node$i --cluster-announce-port $((6379 + i - 1))" \
falkordb/falkordb
done
Comment on lines +37 to +46
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling and persistence configuration.

The node startup script could be improved in several areas:

  1. Add validation for Docker network existence
  2. Include error handling for container creation
  3. Add volume mounts for data persistence

Consider updating the script:

 for i in {1..6}; do
+  # Validate network exists
+  if ! docker network inspect falkordb-cluster-network >/dev/null 2>&1; then
+    echo "Error: falkordb-cluster-network not found"
+    exit 1
+  fi
+
   docker run -d \
     --name node$i \
     --hostname node$i \
     --network falkordb-cluster-network \
     -p $((6379 + i - 1)):$((6379 + i - 1)) \
     -e BROWSER=0 \
+    -v falkordb-data-$i:/data \
     -e "FALKORDB_ARGS=--port $((6379 + i - 1)) --cluster-enabled yes --cluster-announce-ip node$i --cluster-announce-port $((6379 + i - 1))" \
-    falkordb/falkordb
+    falkordb/falkordb || {
+      echo "Error: Failed to start node$i"
+      exit 1
+    }
 done
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for i in {1..6}; do
docker run -d \
--name node$i \
--hostname node$i \
--network falkordb-cluster-network \
-p $((6379 + i - 1)):$((6379 + i - 1)) \
-e BROWSER=0 \
-e "FALKORDB_ARGS=--port $((6379 + i - 1)) --cluster-enabled yes --cluster-announce-ip node$i --cluster-announce-port $((6379 + i - 1))" \
falkordb/falkordb
done
for i in {1..6}; do
# Validate network exists
if ! docker network inspect falkordb-cluster-network >/dev/null 2>&1; then
echo "Error: falkordb-cluster-network not found"
exit 1
fi
docker run -d \
--name node$i \
--hostname node$i \
--network falkordb-cluster-network \
-p $((6379 + i - 1)):$((6379 + i - 1)) \
-e BROWSER=0 \
-v falkordb-data-$i:/data \
-e "FALKORDB_ARGS=--port $((6379 + i - 1)) --cluster-enabled yes --cluster-announce-ip node$i --cluster-announce-port $((6379 + i - 1))" \
falkordb/falkordb || {
echo "Error: Failed to start node$i"
exit 1
}
done
🧰 Tools
🪛 GitHub Actions: spellcheck

[warning] Spelling error found: 'hostnames'


[warning] Spelling error found: 'testGraph'

```

```bash
docker run -d \
--name node2 \
--network falkordb-cluster-network \
-p 6380:6379 \
-e 'FALKORDB_ARGS=--cluster-enabled yes' \
falkordb/falkordb
```
### 2.2 Edit the /etc/hosts file and add the node container hostnames

```bash
docker run -d \
--name node3 \
--network falkordb-cluster-network \
-p 6381:6379 \
-e 'FALKORDB_ARGS=--cluster-enabled yes' \
falkordb/falkordb
```
For the host to be able to connect to the nodes using the container names, please update your `/etc/hosts` file using the following command.

```bash
docker run -d \
--name node4 \
--network falkordb-cluster-network \
-p 6382:6379 \
-e 'FALKORDB_ARGS=--cluster-enabled yes' \
falkordb/falkordb
for i in {1..6};do
sudo echo "127.0.0.1 node$i" | sudo tee -a /etc/hosts
done
```

```bash
docker run -d \
--name node5 \
--network falkordb-cluster-network \
-p 6383:6379 \
-e 'FALKORDB_ARGS=--cluster-enabled yes' \
falkordb/falkordb
```

```bash
docker run -d \
--name node6 \
--network falkordb-cluster-network \
-p 6384:6379 \
-e 'FALKORDB_ARGS=--cluster-enabled yes' \
falkordb/falkordb
```

In this command, the --network falkordb-cluster-network flag connects the container to the network created in Step 1.

## Step 3: Configuring the Cluster

Once all nodes are up, you need to connect them to form a cluster. Use the redis-cli tool inside one of the nodes to initiate the cluster setup.
Once all nodes are up, you need to connect them to form a cluster. Use the `redis-cli` tool inside one of the nodes to initiate the cluster setup.

### 3.1 Connect to a Node
### 3.1 Initiate the Cluster

This command will join node1-node6 into a cluster.

```bash
docker exec -it node1 /bin/bash
docker exec -it node1 redis-cli --cluster create node1:6379 node2:6380 node3:6381 node4:6382 node5:6383 node6:6384 --cluster-replicas 1 --cluster-yes
```

### 3.2 Initiate the Cluster
### 3.2 Verify Cluster Status

Inside the container, use the following command to form the cluster:
You can verify the status of the cluster with:

```bash
redis-cli --cluster create node1:6379 node2:6379 node3:6379 node4:6379 node5:6379 node6:6379 --cluster-replicas 1
docker exec -it node1 redis-cli --cluster check node1:6379
```
This command will display the status of each node and their roles (master/replica).

This command will join node1, node2, and node3 into a cluster.

### 3.3 Verify Cluster Status
### 3.3 Create a Graph to test deployment

You can verify the status of the cluster with:
The following query will create a graph named "network" within your cluster.

```bash
redis-cli --cluster check node1:6379
redis-cli -c GRAPH.QUERY network "UNWIND range(1, 100) AS id CREATE (n:Person {id: id, name: 'Person ' + toString(id), age: 20 + id % 50})"
```
This command will display the status of each node and their roles (master/replica).

## Step 4: Scaling the Cluster

Expand All @@ -128,22 +96,28 @@ For example, to add a new node:

```bash
docker run -d \
--name node7 \
--network falkordb-cluster-network \
-p 6385:6379 \
-e 'FALKORDB_ARGS=--cluster-enabled yes' \
falkordb/falkordb
--name node7 \
--hostname node7 \
--network falkordb-cluster-network \
-p 6385:6385 \
-e BROWSER=0 \
-e "FALKORDB_ARGS=--port 6385 --cluster-enabled yes --cluster-announce-ip node7 --cluster-announce-port 6385" \
falkordb/falkordb
```

### 4.2 Add the Node to the Cluster

```bash
docker exec -it node1 /bin/bash
redis-cli --cluster add-node node7:6379 node1:6379
docker exec -it node1 redis-cli --cluster add-node node7:6385 node1:6379
```

This will add node7 into the existing cluster.

### 4.3 Add the new node to the /etc/hosts file

```bash
sudo echo "127.0.0.1 node7" | sudo tee -a /etc/hosts
```

## Conclusion

With your FalkorDB cluster set up, you now have a scalable, distributed environment that can handle increased loads and provide higher availability.
Loading