mongoDB replica set

断了今生、忘了曾经 提交于 2019-12-24 07:07:34

问题


I am trying to understand the concept of replica sets in MongoDB.

Taking a simple example of 2 mongoDB instances A (primary) and B (secondary).

If my client is happily querying A I understand that writes get replicated to B but what happens if server A becomes inaccessible?

Whilst in terms of mongo replication I can see that B gets elected as the new primary, how does the client know to now channel its queries to B and not A? Is this all done internally to mongo?

I ask because my client's configuration has a uri pointing to A yet nothing for B. Is that correct?


回答1:


Taking a simple example of 2 mongoDB instances A (primary) and B (secondary).

You should not use two instance as part of your replica set. You should either have an arbiter or another secondary so that elections can take place.

Please see here for gotchas, here for replication fundamentals and here for information on elections.

If my client is happily querying A I understand that writes get replicated to B but what happens if server A becomes inaccessible?

The service should failover with server B becoming primary. However, with two instances, server B will not be able to elect itself as primary because there is no majority.

Whilst in terms of mongo replication I can see that B gets elected as the new primary, how does the client know to now channel its queries to B and not A? Is this all done internally to mongo?

This is typically performed through the driver as the driver is aware of the replica set configuration. Please see here for the relevant driver documentation (depending on what driver you are using).



来源:https://stackoverflow.com/questions/13395430/mongodb-replica-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!