void startReplication() {
/* if we are going to be a replica set, we aren't doing other forms of replication. */
if( !cmdLine._replSet.empty() ) { //看看参数里面有没有--replSet
if( replSettings.slave || replSettings.master ) { //这个参数不能与—slave与—master共存
log() box.getPrimary(); //当前的主服务器
const Member* hopeful = theReplSet->findById(id); //希望成为主机的服务器(从上面的代码看是发送请求方服务器)
const Member *highestPriority = theReplSet->getMostElectable(); //当前节点心目中的主机
//以下判断发现不符合条件的就否决投票
if( !hopeful ) { //没有目标服务器
errmsg = str::stream() lastOpTimeWritten >= hopeful->hbinfo().opTime ) {
// hbinfo is not updated, so we have to check the primary's last optime separately
errmsg = str::stream() = hopeful->hbinfo().opTime ) {
// other members might be aware of more up-to-date nodes
errmsg = str::stream() fullName() hopeful->config().priority) {
errmsg = str::stream() fullName() isElectable(id) ||
(highestPriority && highestPriority->config().priority > hopeful->config().priority)) {
return true;
}
return false;
}
//得到投票数据以后解析
bool Consensus::weAreFreshest(bool& allUp, int& nTies) {
//省略发送请求的部分
//请求返回后存储在list中
int nok = 0;
allUp = true;
for( list::iterator i = L.begin(); i != L.end(); i++ ) {
//i存储这其他节点返回的结果
if( i->ok ) {
nok++;
if( i->result["fresher"].trueValue() ) { //当前服务器不是最新的
log() result["errmsg"];
if (!msg.eoo()) {
log()