Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
236 views
in Technique[技术] by (71.8m points)

mongodb - AutoReconnect exception "master has changed"

Having some trouble understanding the right approach here.

I have a connection to a mongodb replica set with three members (standard master-slave-slave). Everything is working fine with the connection when the master remains consistent.

pymongo.Connection(['host1:27017','host2:27018','host3:27019']).database_test

For some reason, when the replica set primary steps down, this starts to throw an autoreconnect exception that doesn't go away even after a new primary is elected.

Now I am aware that this exception needs to be caught and handled, most likely by waiting for the new primary to be elected. The problem I am having seems to be that it doesn't care at all once the new primary has been chosen. This "master has changed" exception just keeps coming up.

Printing the connection with __dict__ shows all three hosts.

I've tried passing the replicaset kwarg to the connection, but this comes up as an unexpected argument.

Is there a reason why this kind of connection wouldn't just start querying against the new primary?

EDIT:

This same problem is apparently now manifesting on the deployment server. The autoreconnect exception is thrown if the master changes at all and never goes away even after a new primary is elected.

Pymongo is version 2.2 and mongodb version 2.0.2. Changing the manner in which the connection is defined in the pymongo code (mongouri vs. list of hosts) has no effect. The only way to revive the service is to rs.stepDown() the other hosts until the original master is primary once more.

question from:https://stackoverflow.com/questions/8506753/autoreconnect-exception-master-has-changed

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The behavior you describe is a bug. The best possible course of action is to make sure there is a bug logged for it and link to it from your question. Since the question is almost a year old, I am expecting the bug to be closed (check jira.mongodb.org/browse/SERVER-4405 to see if it applies).

If you upgrade to MongoDB 2.2 or later, the problem should go away.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...