-
Type: Improvement
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.0
-
Component/s: None
-
None
-
Environment:python2.6, up to pymongo2.0
-
Fully Compatible
Give more simple way to configure MasterSlaveConnection just like Connection object.
1. Developer can simply provide replica set nodes to MasterSlaveConnection, MasterSlaveConnection itself determine which one is master, and which ones are slaves.
2. When Master is down, MasterSlaveConnection raise AutoReconnect upon next write request, and find new master in slave nodes and use it as slave.
3. If all slaves are down, MasterSlaveConnection will route all read operations to master, until one of them recovered.
e.g: Server A is master, B, C is slave, D is hidden.
conn = MasterSlaveConnection(nodes="A:27017,B:27017,C:27017")
conn.master # --> A
conn.slaves # --> [B, C]
- A is down, B become master
conn.test.foo.insert( {'bar':1}) # --> AutoReconnect
{'bar':1}
conn.test.foo.insert() # --> find new master in slaves, find that B is master, so route write operation to B, and success.
conn.master # --> B
conn.slaves # --> [A, C]
conn.test.foo.find() # --> Route to C
- A recovered
conn.test.foo.find() # --> Route to A or C
- A, C are down
conn.test.foo.find() # --> Route to B
- A, C recovers again.
conn.test.foo.find() # --> Route to A or C
- duplicates
-
PYTHON-196 there should be a decent way to route reads to slaves using pymongo and replica set
- Closed