-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Major - P3
-
None
-
Affects Version/s: 3.7.2, 3.10.1
-
Component/s: API
-
None
-
Environment:CentOS
3.10.0-327
Python 2.7.5
Hi, mongodb developers,
I want to convert the sharded cluster in our production environment to a replica set, but i don't want to change the connection uri in the application configuration.
Currently, i have two mongoses in the sharded cluster, so after migrate the data from sharded cluster to the new replica set, i would stop the mongoses and reuse the ip&ports of the original mongoses and set them to the primary and secondary member in the new replica set.
I hope the application would automatically connect to the replica set and work fine, but i'm not sure if this will work, so i made the a test to simulate the above situation.
—
Following is the sharded cluster deployed in a test environment,
- two mongoses: 100.81.164.181:9510, 100.81.164.181:9511
- two shards:
- 100.81.164.181:9791
- 100.81.164.181:9891
- config server: 100.81.164.181:9666
and the replica set,
- 100.81.164.181:9510, 100.81.164.181:9511, 100.81.164.181:9512 (note: 100.81.164.181:9510 and 100.81.164.181:9511 is reused from mongoses)
and the test application code,
#!/usr/bin/python import thread import time import logging from pymongo import MongoClient import sys LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s" logging.basicConfig(level=logging.INFO, format=LOG_FORMAT) client = MongoClient('mongodb://100.81.164.181:9510,100.81.164.181:9511/admin') # Define a function for the thread def write_read(threadName, delay): k = 0 db = threadName + "-db" collection = threadName + "-collection" coll_handle = client[db][collection] while 1: try: time.sleep(delay) res = coll_handle.insert_one({'k': k, 'payload': 'xxxxxx'}) logging.info("**%s** read after write: %s" % \ (threadName, str(coll_handle.find_one({'k': k})))) k = k + 1 except Exception as e: logging.error("-- %s -- write_read mongo error: %s" % \ (threadName, str(e))) # Create two threads as follows thread_num = int(sys.argv[1]) try: for _ in xrange(0, thread_num): thread.start_new_thread(write_read, ("Thread-%d" % _, 1, ) ) except Exception as e: logging.error("Error: unable to start thread, %s.", str(e)) while 1: time.sleep(2) pass
start with: python test.py 20
Use 20 threads to continually write to and read from mongodb.
—
After stop the mongoses and start the replica set, the test code failed to connect to the replica set until i restarted it. The error message from the driver is,
No mongoses available
—
So, after changing the deployment behind the connection uri from sharded cluster to replica set, is there any way to let the mongo driver automatically identity this situation without a restart?
Please offer some help, thanks.
- is related to
-
DRIVERS-910 Allow MongoClient to automatically transition from replica set to sharded endpoint without restarts
- Ready for Work