Skip to content

Commit 16811bb

Browse files
feat: parameterized cluster — make cluster NODES=N
- Generates configs from template for N nodes (default 3) - Auto-assigns ports: RESP=8079+N, HTTP=9079+N, Gossip=7945+N - Auto-generates seed list for all nodes - Updated template to match new defaults (TTL=0, single default store) - Usage: make cluster NODES=5
1 parent eb8e911 commit 16811bb

2 files changed

Lines changed: 41 additions & 26 deletions

File tree

Makefile

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,42 @@ clean:
5858
rm -rf bin/ test-results/ logs/ data/
5959
rm -f main hypercache
6060

61-
## cluster: Start a local 3-node cluster
61+
## cluster: Start a local N-node cluster (default: NODES=3)
62+
## Usage: make cluster NODES=5
6263
cluster: build
63-
@mkdir -p logs data/node-1 data/node-2 data/node-3
64-
@echo "Starting node-1..."
65-
./$(BINARY) -protocol resp -config configs/node1-config.yaml > logs/node-1.log 2>&1 &
66-
@sleep 2
67-
@echo "Starting node-2..."
68-
./$(BINARY) -protocol resp -config configs/node2-config.yaml > logs/node-2.log 2>&1 &
69-
@sleep 2
70-
@echo "Starting node-3..."
71-
./$(BINARY) -protocol resp -config configs/node3-config.yaml > logs/node-3.log 2>&1 &
72-
@sleep 3
73-
@echo "Cluster started. Health checks:"
74-
@curl -s http://localhost:9080/health | head -1 || echo "node-1: not ready"
75-
@curl -s http://localhost:9081/health | head -1 || echo "node-2: not ready"
76-
@curl -s http://localhost:9082/health | head -1 || echo "node-3: not ready"
64+
@NODES=$${NODES:-3}; \
65+
mkdir -p logs; \
66+
SEEDS=""; \
67+
for i in $$(seq 1 $$NODES); do \
68+
GOSSIP=$$((7945 + $$i)); \
69+
if [ -n "$$SEEDS" ]; then SEEDS="$$SEEDS,"; fi; \
70+
SEEDS="$${SEEDS}\"127.0.0.1:$$GOSSIP\""; \
71+
done; \
72+
for i in $$(seq 1 $$NODES); do \
73+
NODE_ID="node-$$i"; \
74+
RESP_PORT=$$((8079 + $$i)); \
75+
HTTP_PORT=$$((9079 + $$i)); \
76+
GOSSIP_PORT=$$((7945 + $$i)); \
77+
DATA_DIR="data/$$NODE_ID"; \
78+
mkdir -p "$$DATA_DIR"; \
79+
CFG="/tmp/hypercache-$$NODE_ID.yaml"; \
80+
sed -e "s/\$${NODE_ID}/$$NODE_ID/g" \
81+
-e "s/\$${RESP_PORT}/$$RESP_PORT/g" \
82+
-e "s/\$${HTTP_PORT}/$$HTTP_PORT/g" \
83+
-e "s/\$${GOSSIP_PORT}/$$GOSSIP_PORT/g" \
84+
-e "s|\$${CLUSTER_SEEDS}|$$SEEDS|g" \
85+
-e "s/\$${LOG_LEVEL}/info/g" \
86+
templates/node-config.yaml.template > "$$CFG"; \
87+
echo "Starting $$NODE_ID (RESP=$$RESP_PORT HTTP=$$HTTP_PORT Gossip=$$GOSSIP_PORT)..."; \
88+
./$(BINARY) -protocol resp -config "$$CFG" > "logs/$$NODE_ID.log" 2>&1 & \
89+
sleep 2; \
90+
done; \
91+
sleep 2; \
92+
echo "Cluster health checks:"; \
93+
for i in $$(seq 1 $$NODES); do \
94+
HTTP_PORT=$$((9079 + $$i)); \
95+
curl -s "http://localhost:$$HTTP_PORT/health" | head -1 || echo "node-$$i: not ready"; \
96+
done
7797

7898
## cluster-stop: Stop all local HyperCache processes
7999
cluster-stop:

templates/node-config.yaml.template

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ persistence:
3131

3232
cache:
3333
max_memory: "8GB"
34-
default_ttl: "1h"
34+
default_ttl: "0"
3535
cuckoo_filter_fpp: 0.01
36+
max_stores: 16
3637

3738
storage:
3839
wal_sync_interval: "10ms"
@@ -42,16 +43,10 @@ storage:
4243
stores:
4344
- name: "default"
4445
eviction_policy: "lru"
45-
max_memory: "4GB"
46-
default_ttl: "1h"
47-
- name: "sessions"
48-
eviction_policy: "ttl"
49-
max_memory: "1GB"
50-
default_ttl: "30m"
51-
- name: "analytics"
52-
eviction_policy: "lfu"
53-
max_memory: "2GB"
54-
default_ttl: "24h"
46+
max_memory: "8GB"
47+
default_ttl: "0"
48+
cuckoo_filter: true
49+
persistence: "hybrid"
5550

5651
# Logging Configuration
5752
logging:

0 commit comments

Comments
 (0)