File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -191,6 +191,48 @@ functions:
191
191
echo "{ \"releases\": { \"default\": \"$MONGODB_BINARIES\" }}" > $MONGO_ORCHESTRATION_HOME/orchestration.config
192
192
./.evergreen/run-orchestration.sh
193
193
194
+ # Ensure server on port 27017 is the primary server.
195
+ if [[ "$TOPOLOGY" == replica_set ]]; then
196
+ # Replset members should be on the following ports.
197
+ declare hosts="localhost:27017,localhost:27018,localhost:27019"
198
+
199
+ # Authentication may be required.
200
+ declare creds
201
+ if [[ -n "$AUTH" ]]; then
202
+ creds="bob:pwd123@"
203
+ else
204
+ creds=""
205
+ fi
206
+
207
+ declare uri
208
+ printf -v uri "mongodb://%s%s" "$creds" "$hosts"
209
+
210
+ # Raise the priority of the member on port 27017. Others should have priority 1.
211
+ declare script
212
+ printf -v script "%s\n%s\n%s\n" \
213
+ "let c = rs.conf()" \
214
+ "c.members.find((m) => m.host.includes('27017')).priority = 10" \
215
+ "rs.reconfig(c)"
216
+
217
+ mongosh --quiet "$uri" --eval "$script"
218
+
219
+ # Wait up to a minute for member on port 27017 to become primary.
220
+ wait_for_primary() {
221
+ for _ in $(seq 60); do
222
+ if mongosh --quiet "$uri" --eval "quit(rs.hello().primary.includes('27017') ? 0 : 1)"; then
223
+ return 0
224
+ else
225
+ sleep 1
226
+ fi
227
+ done
228
+ echo "Could not set replset member on port 27017 as primary"
229
+ return 1
230
+ }
231
+ echo "Waiting for replset member 27017 to become primary..."
232
+ wait_for_primary
233
+ echo "Waiting for replset member 27017 to become primary... done."
234
+ fi
235
+
194
236
# Copy mongocryptd up so other functions can find it later, since we can't share PATHs
195
237
if [ -f $MONGODB_BINARIES/mongocryptd ]; then
196
238
cp $MONGODB_BINARIES/mongocryptd ../mongocryptd
You can’t perform that action at this time.
0 commit comments