Skip to content

Commit f4e8ec9

Browse files
committed
Simplify port assignment using explicit arrays
1 parent 880c46e commit f4e8ec9

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

hack/sh/run.sh

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,14 @@ export compose=$SDIR/compose.yml
2828
SRC_SHARDS="${SRC_SHARDS:-2}"
2929
TGT_SHARDS="${TGT_SHARDS:-2}"
3030

31-
# Validate shard counts against available init scripts and compose services
32-
MAX_SRC_SHARDS=3 # src/rs0.js, src/rs1.js, src/rs2.js
33-
MAX_TGT_SHARDS=3 # tgt/rs0.js, tgt/rs1.js, tgt/rs2.js
31+
# Port mappings for each shard (must match compose.yml)
32+
# Source shards: rs0=30000, rs1=30100, rs2=30200
33+
# Target shards: rs0=40000, rs1=40100, rs2=40200
34+
SRC_SHARD_PORTS=(30000 30100 30200)
35+
TGT_SHARD_PORTS=(40000 40100 40200)
36+
37+
MAX_SRC_SHARDS=${#SRC_SHARD_PORTS[@]}
38+
MAX_TGT_SHARDS=${#TGT_SHARD_PORTS[@]}
3439

3540
if [ "$SRC_SHARDS" -gt "$MAX_SRC_SHARDS" ]; then
3641
echo "ERROR: SRC_SHARDS=$SRC_SHARDS exceeds maximum $MAX_SRC_SHARDS"
@@ -61,7 +66,7 @@ mwait "src-cfg0:27000" && rsinit "src/cfg" "src-cfg0:27000"
6166

6267
# Initialize source shards
6368
for i in $(seq 0 $((SRC_SHARDS - 1))); do
64-
PORT=$((30000 + i * 100))
69+
PORT=${SRC_SHARD_PORTS[$i]}
6570
mwait "src-rs${i}0:${PORT}" && rsinit "src/rs${i}" "src-rs${i}0:${PORT}"
6671
done
6772

@@ -71,7 +76,7 @@ dcf up -d src-mongos && mwait "src-mongos:27017"
7176
# Add source shards to cluster
7277
ADD_SHARDS_CMD=""
7378
for i in $(seq 0 $((SRC_SHARDS - 1))); do
74-
PORT=$((30000 + i * 100))
79+
PORT=${SRC_SHARD_PORTS[$i]}
7580
ADD_SHARDS_CMD="${ADD_SHARDS_CMD}sh.addShard('rs${i}/src-rs${i}0:${PORT}'); "
7681
done
7782
msh "src-mongos:27017" --eval "$ADD_SHARDS_CMD"
@@ -90,7 +95,7 @@ mwait "tgt-cfg0:28000" && rsinit "tgt/cfg" "tgt-cfg0:28000"
9095

9196
# Initialize target shards
9297
for i in $(seq 0 $((TGT_SHARDS - 1))); do
93-
PORT=$((40000 + i * 100))
98+
PORT=${TGT_SHARD_PORTS[$i]}
9499
mwait "tgt-rs${i}0:${PORT}" && rsinit "tgt/rs${i}" "tgt-rs${i}0:${PORT}"
95100
done
96101

@@ -100,7 +105,7 @@ dcf up -d tgt-mongos && mwait "tgt-mongos:27017"
100105
# Add target shards to cluster
101106
ADD_SHARDS_CMD=""
102107
for i in $(seq 0 $((TGT_SHARDS - 1))); do
103-
PORT=$((40000 + i * 100))
108+
PORT=${TGT_SHARD_PORTS[$i]}
104109
ADD_SHARDS_CMD="${ADD_SHARDS_CMD}sh.addShard('rs${i}/tgt-rs${i}0:${PORT}'); "
105110
done
106111
msh "tgt-mongos:27017" --eval "$ADD_SHARDS_CMD"

0 commit comments

Comments
 (0)