Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 check!

like image 964
Rich Avatar asked Feb 08 '11 10:02

Rich


People also ask

What is the role of arbiter in MongoDB?

Arbiters are mongod instances that are part of a replica set but do not hold data (i.e. do not provide data redundancy). They can, however, participate in elections. Arbiters have minimal resource requirements and do not require dedicated hardware.

Which can be used to check the replica set configuration?

You can access the configuration of a replica set using the rs. conf() method or the replSetGetConfig command.

What is a MongoDB connection string?

MongoDB connection string is defined as connection format to join the MongoDB database server, we have using username, hostname, password, and port parameter to connect the database server. Without a connection string, we cannot connect to the database server, we need a connection string to connect the database server.


2 Answers

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.

like image 88
AdaTheDev Avatar answered Nov 15 '22 22:11

AdaTheDev


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).

like image 32
raylu Avatar answered Nov 15 '22 22:11

raylu