开发者

Should a MongoDB arbiter be included in the client connection configuration?

开发者 https://www.devze.com 2023-02-09 09:38 出处:网络
If a replica set is set up in Mongo with only two nodes, an arbiter needs to be added to ensure that there is always a majority in a vote for a new master. The arbiter never becomes the master itself,

If a replica set is set up in Mongo with only two nodes, an arbiter needs to be added to ensure that there is always a majority in a vote for a new master. The arbiter never becomes the master itself, it is purely there to provide the casting vote in an otherwise neck-and-neck election.

When connecting a client (in my case Java) to a MongoDB cluster, we are supposed to specify all the nodes of the cluster in the connection configuration:

List addrs = new ArrayList();
addrs.add( new ServerAddress( "localhost" , 27017 ) );
addrs.add( new ServerAddress( "localhost" , 27018 ) );

Mongo mongo = new Mongo(addrs);

Should the arbiter be included in the connection configuration? I would guess not as they:

don't have a copy of the data and will never become the primary node (or even a readable secondary)

(Taken from here)

...but I just wanted to double che开发者_运维百科ck!


No, you shouldn't need to include arbiters in the connection.

After all, as you suspected, there would be little point in your code trying to connect to one of those as there is no data there. They just do their stuff behind the scenses to help auto-failover.

You don't even have to specify all the servers in your connection configuration (not even the master) - as long as one of the servers you do mention returns a response, it can find the master from there. Though IMHO, the more you name the better, just incase a number of them go down.


The list is just a seed list. The actual members of the replica set are determined after connecting to one. You could just specify the one at 27017 (but it would be bad if that one were down).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号