Skip to content

Commit 5fde30b

Browse files
authored
DRIVERS-3407 Serialize addShard commands to avoid ConflictingOperationInProgress errors (#340)
1 parent c039564 commit 5fde30b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

mongo_orchestration/sharded_clusters.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import logging
1818
import os
1919
import tempfile
20+
import threading
2021

2122
from uuid import uuid4
2223

@@ -53,6 +54,7 @@ def __init__(self, params):
5354
self._routers = []
5455
self._shards = {}
5556
self.tags = {}
57+
self._lock = threading.Lock()
5658

5759
self.sslParams = params.get('sslParams', {})
5860
self.kwargs = {}
@@ -383,7 +385,9 @@ def router_remove(self, router_id):
383385

384386
def _add(self, shard_uri, name):
385387
"""execute addShard command"""
386-
return self.router_command("addShard", (shard_uri, {"name": name}), is_eval=False)
388+
# MongoDB only allows a single addShard at once, so we need to serialize them.
389+
with self._lock:
390+
return self.router_command("addShard", (shard_uri, {"name": name}), is_eval=False)
387391

388392
def member_add(self, member_id=None, params=None):
389393
"""add new member into existing configuration"""

0 commit comments

Comments
 (0)