Pregunta

In my app I am trying to graceful handling case when the master is not available for some reason (for example the connection between DC is broken). In this case write operations should be disabled on the frontend and the cache database should be used for some read operations.

I have tried to use rs.status() command. It works from mongo shell, but it doesn't work from pymongo when the master is not available because replSetGetStatus command is not in list rp.secondary_ok_commands. As result I have got exception:

AutoReconnect: No replica set primary available for query with ReadPreference PRIMARY.

Of cause I can handle this exception, but it is generated after timeout (in my case 10 seconds). But it is too long in my case. I prefer immediate response, and it is ok for me if sometimes it will be incorrect.

¿Fue útil?

Solución

We introduced the alive() method in PyMongo for this purpose.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top