문제

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.

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top