|
6 | 6 | # SRC_SHARDS=1 ./run.sh # Custom source shards, default target |
7 | 7 | # TGT_SHARDS=3 ./run.sh # Default source, custom target shards |
8 | 8 | # SRC_SHARDS=3 TGT_SHARDS=1 ./run.sh # Custom both |
| 9 | +# SRC_SHARDS=0 TGT_SHARDS=2 ./run.sh # Target only |
| 10 | +# SRC_SHARDS=2 TGT_SHARDS=0 ./run.sh # Source only |
9 | 11 | # |
10 | | -# Limits: Max 3 shards each for source and target |
| 12 | +# Limits: Max 3 shards each for source and target (0 = skip source/target cluster) |
11 | 13 | # Services are named: src-rs{N}0 and tgt-rs{N}0 where N is the shard index (0-based) |
12 | 14 | # Ports: source shards start at 30000 (increment by 100), target shards at 40000 |
13 | 15 |
|
@@ -49,63 +51,76 @@ if [ "$TGT_SHARDS" -gt "$MAX_TGT_SHARDS" ]; then |
49 | 51 | exit 1 |
50 | 52 | fi |
51 | 53 |
|
52 | | -echo "Starting source cluster with $SRC_SHARDS shards (max: $MAX_SRC_SHARDS)" |
53 | | -echo "Starting target cluster with $TGT_SHARDS shards (max: $MAX_TGT_SHARDS)" |
54 | | - |
55 | | -# Build list of source shard services to start |
56 | | -SRC_SERVICES="src-cfg0" |
57 | | -for i in $(seq 0 $((SRC_SHARDS - 1))); do |
58 | | - SRC_SERVICES="$SRC_SERVICES src-rs${i}0" |
59 | | -done |
60 | | - |
61 | | -# Start source config server and shards |
62 | | -dcf up -d $SRC_SERVICES |
63 | | - |
64 | | -# Initialize source config server |
65 | | -mwait "src-cfg0:27000" && rsinit "src/cfg" "src-cfg0:27000" |
66 | | - |
67 | | -# Initialize source shards |
68 | | -for i in $(seq 0 $((SRC_SHARDS - 1))); do |
69 | | - PORT=${SRC_SHARD_PORTS[$i]} |
70 | | - mwait "src-rs${i}0:${PORT}" && rsinit "src/rs${i}" "src-rs${i}0:${PORT}" |
71 | | -done |
72 | | - |
73 | | -# Start source mongos |
74 | | -dcf up -d src-mongos && mwait "src-mongos:27017" |
75 | | - |
76 | | -# Add source shards to cluster |
77 | | -ADD_SHARDS_CMD="" |
78 | | -for i in $(seq 0 $((SRC_SHARDS - 1))); do |
79 | | - PORT=${SRC_SHARD_PORTS[$i]} |
80 | | - ADD_SHARDS_CMD="${ADD_SHARDS_CMD}sh.addShard('rs${i}/src-rs${i}0:${PORT}'); " |
81 | | -done |
82 | | -msh "src-mongos:27017" --eval "$ADD_SHARDS_CMD" |
83 | | - |
84 | | -# Build list of target shard services to start |
85 | | -TGT_SERVICES="tgt-cfg0" |
86 | | -for i in $(seq 0 $((TGT_SHARDS - 1))); do |
87 | | - TGT_SERVICES="$TGT_SERVICES tgt-rs${i}0" |
88 | | -done |
89 | | - |
90 | | -# Start target config server and shards |
91 | | -dcf up -d $TGT_SERVICES |
92 | | - |
93 | | -# Initialize target config server |
94 | | -mwait "tgt-cfg0:28000" && rsinit "tgt/cfg" "tgt-cfg0:28000" |
95 | | - |
96 | | -# Initialize target shards |
97 | | -for i in $(seq 0 $((TGT_SHARDS - 1))); do |
98 | | - PORT=${TGT_SHARD_PORTS[$i]} |
99 | | - mwait "tgt-rs${i}0:${PORT}" && rsinit "tgt/rs${i}" "tgt-rs${i}0:${PORT}" |
100 | | -done |
101 | | - |
102 | | -# Start target mongos |
103 | | -dcf up -d tgt-mongos && mwait "tgt-mongos:27017" |
104 | | - |
105 | | -# Add target shards to cluster |
106 | | -ADD_SHARDS_CMD="" |
107 | | -for i in $(seq 0 $((TGT_SHARDS - 1))); do |
108 | | - PORT=${TGT_SHARD_PORTS[$i]} |
109 | | - ADD_SHARDS_CMD="${ADD_SHARDS_CMD}sh.addShard('rs${i}/tgt-rs${i}0:${PORT}'); " |
110 | | -done |
111 | | -msh "tgt-mongos:27017" --eval "$ADD_SHARDS_CMD" |
| 54 | + |
| 55 | + |
| 56 | +# Start source sharded cluster only if SRC_SHARDS > 0 |
| 57 | +if [ "$SRC_SHARDS" -gt 0 ]; then |
| 58 | + echo "Starting source cluster with $SRC_SHARDS shards (max: $MAX_SRC_SHARDS)" |
| 59 | + |
| 60 | + # Build list of source shard services to start |
| 61 | + SRC_SERVICES="src-cfg0" |
| 62 | + for i in $(seq 0 $((SRC_SHARDS - 1))); do |
| 63 | + SRC_SERVICES="$SRC_SERVICES src-rs${i}0" |
| 64 | + done |
| 65 | + |
| 66 | + # Start source config server and shards |
| 67 | + dcf up -d $SRC_SERVICES |
| 68 | + |
| 69 | + # Initialize source config server |
| 70 | + mwait "src-cfg0:27000" && rsinit "src/cfg" "src-cfg0:27000" |
| 71 | + |
| 72 | + # Initialize source shards |
| 73 | + for i in $(seq 0 $((SRC_SHARDS - 1))); do |
| 74 | + PORT=${SRC_SHARD_PORTS[$i]} |
| 75 | + mwait "src-rs${i}0:${PORT}" && rsinit "src/rs${i}" "src-rs${i}0:${PORT}" |
| 76 | + done |
| 77 | + |
| 78 | + # Start source mongos |
| 79 | + dcf up -d src-mongos && mwait "src-mongos:27017" |
| 80 | + |
| 81 | + # Add source shards to cluster |
| 82 | + ADD_SHARDS_CMD="" |
| 83 | + for i in $(seq 0 $((SRC_SHARDS - 1))); do |
| 84 | + PORT=${SRC_SHARD_PORTS[$i]} |
| 85 | + ADD_SHARDS_CMD="${ADD_SHARDS_CMD}sh.addShard('rs${i}/src-rs${i}0:${PORT}'); " |
| 86 | + done |
| 87 | + msh "src-mongos:27017" --eval "$ADD_SHARDS_CMD" |
| 88 | +else |
| 89 | + echo "Skipping source cluster (SRC_SHARDS=0)" |
| 90 | +fi |
| 91 | + |
| 92 | +# Start target sharded cluster only if TGT_SHARDS > 0 |
| 93 | +if [ "$TGT_SHARDS" -gt 0 ]; then |
| 94 | + echo "Starting target cluster with $TGT_SHARDS shards (max: $MAX_TGT_SHARDS)" |
| 95 | + |
| 96 | + # Build list of target shard services to start |
| 97 | + TGT_SERVICES="tgt-cfg0" |
| 98 | + for i in $(seq 0 $((TGT_SHARDS - 1))); do |
| 99 | + TGT_SERVICES="$TGT_SERVICES tgt-rs${i}0" |
| 100 | + done |
| 101 | + |
| 102 | + # Start target config server and shards |
| 103 | + dcf up -d $TGT_SERVICES |
| 104 | + |
| 105 | + # Initialize target config server |
| 106 | + mwait "tgt-cfg0:28000" && rsinit "tgt/cfg" "tgt-cfg0:28000" |
| 107 | + |
| 108 | + # Initialize target shards |
| 109 | + for i in $(seq 0 $((TGT_SHARDS - 1))); do |
| 110 | + PORT=${TGT_SHARD_PORTS[$i]} |
| 111 | + mwait "tgt-rs${i}0:${PORT}" && rsinit "tgt/rs${i}" "tgt-rs${i}0:${PORT}" |
| 112 | + done |
| 113 | + |
| 114 | + # Start target mongos |
| 115 | + dcf up -d tgt-mongos && mwait "tgt-mongos:27017" |
| 116 | + |
| 117 | + # Add target shards to cluster |
| 118 | + ADD_SHARDS_CMD="" |
| 119 | + for i in $(seq 0 $((TGT_SHARDS - 1))); do |
| 120 | + PORT=${TGT_SHARD_PORTS[$i]} |
| 121 | + ADD_SHARDS_CMD="${ADD_SHARDS_CMD}sh.addShard('rs${i}/tgt-rs${i}0:${PORT}'); " |
| 122 | + done |
| 123 | + msh "tgt-mongos:27017" --eval "$ADD_SHARDS_CMD" |
| 124 | +else |
| 125 | + echo "Skipping target cluster (TGT_SHARDS=0)" |
| 126 | +fi |
0 commit comments