@@ -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
6263cluster : 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
7999cluster-stop :
0 commit comments