I am trying to see how replSet works.
I figured out that if there are 2 nodes i.e one master/primary and one slave/secondry and if master goes down, slave don't vote itself to become master/Primary. It remain secondary.
But when there are 3 nodes, 1 master and 2 slave and if master goes down, one slave get selected as master by voting.
So,
is there any special case for 2 nodes?
or
Am I doing something wrong?
or
Is this is a bug?
I used this link as a reference
http://www.mongodb.org/display/DOCS/Replica+Set+Tutorial#ReplicaSetTutorial-FailingOver
can't see any special note for 2 nodes?
Also, as we discussed in meeting, on my mini mac every example is working!! so it should be something with OS.
so if there are 2 nodes and master goes down how thing works? I mean does node which is up handles write and read independent of master and slave?
----- Original Message -----
From: Kristina Chodorow <kris...@10gen.com>
Date: Sunday, October 24, 2010 7:04 pm
Subject: Re: replSet functioning
To: mongo-node...@googlegroups.com
> A member needs a majority of votes to become primary. If you have 2 members,
> 2 is the only majority you can get. 1 isn't a majority, so if one member
> goes down, the other member can't become primary. That's why the replica
> set tutorial you found has 3 members: 2 out of 3 is a majority, so the
> remaining members *can* elect a new primary.
I have one doubt,
I am making replSetStatus.js which will ensure master,
I am making constructor replSetStatus(new Db("testdb", List<Serveraddress> list, otheroptions..), List<Serveraddress> list);
is Db type parameter fine?I mean I hope its not a bad coding decision.
I am using it because I have to run command DbCommand.createIsMasterCommand(Db);
for every server in list to check for master. And it takes Db as a parameter.
If you have to go through the code to answer it, I will figure it out, no worries.
something like this
ReplSetStatus(List<Server>); // this is constructor
ensureMaster(); it returns latest master from the list (or NULL) every time you call it.
so you have to do something like this
replstat = new ReplSetStatus(List<ServerAddress>);
var latestMaster = replstat.ensureMaster();
and follow on.....................
like new Db("Mongo-DB", latestMaster, ....)
this is what you are looking for? or I am interpreting it wrong.
My code make sure latest master from the list when you call ensureMaster();
and say conn have node1 which is master;
and then new Db("..", conn, ..)
and assume after 10 min node1 gets down!! user again have to call ReplSetConnection() to ensure new master,
so does user will put ReplSetConn() function in forever loop?
thanks,
However when I saw Db.js. I see db.open() try to set master connection.
db.executecommand() always attempt to execute command on masterconnection set by open().
even if that masterconnection is down.
so assume scenario.
repl = new ReplSetConnection(List<ServerAddress>)
db = new Db("....", repl....);
db.open....
db.executecommand(some db_command) // this will try to use masterconnection for execution.
....
....
... //assume now masterconnection goes down
now ReplSetConnection should set masterconnection to new master from list.
so that if we again execute code db.executecommand(some db_command); it wont fail
is that what we need? if yes!! don't you think we just need to add up code in db.js to ensuremaster everytime we execute command instead of adding things into autoreconnect functionality of connection.js?
when I see in connection.js I can't see anything promising(probably my lack of understanding) which can ensure master. However in net.createConnection I see connect and doConnect calling each other. so do you want me to do something in net.js to ensuremaster. ??
I might be missing something, but I am confused here.
I am sorry for keep bugging you. :(
is that what we need?
if yes!! don't you think we just need to add up code in db.js to ensuremaster everytime we execute command
instead of adding things into autoreconnect functionality of connection.js?
I am sorry for keep bugging you. :(
I agree that ensuremaster is expensive but don't you think keeping it in loop forever(to see for fail) is much more costlier than calling it only before executing command ?
Lets see, hoping to commit this stuff before next meet!!
Thanks.
I made up a code which take care of fail over.
my Logic
if(get diconnected) {
call admin db and do ismaster command and
get master/secondry in server list.
}
to call admin db I did something like this within connection.js
new Db("admin", new ReplicaSet<list>, ..)
Db.execute_is_mastercomand for each server in list
and update master connection
I am not sure is that right thing to do?
Is that fine or you think there is better way to use admin db to execute command.
However I am sure that code will take care of fail over :).