void MockReplicaSet::mockReplSetGetStatusCmd() { // Copied from ReplSetImpl::_summarizeStatus for (ReplNodeMap::iterator nodeIter = _nodeMap.begin(); nodeIter != _nodeMap.end(); ++nodeIter) { MockRemoteDBServer* node = nodeIter->second; vector<BSONObj> hostsField; BSONObjBuilder fullStatBuilder; { BSONObjBuilder selfStatBuilder; selfStatBuilder.append("name", node->getServerAddress()); selfStatBuilder.append("health", 1.0); selfStatBuilder.append("state", getState(node->getServerAddress())); selfStatBuilder.append("self", true); // TODO: _id, stateStr, uptime, optime, optimeDate, maintenanceMode, errmsg hostsField.push_back(selfStatBuilder.obj()); } for (ReplicaSetConfig::MemberIterator member = _replConfig.membersBegin(); member != _replConfig.membersEnd(); ++member) { MockRemoteDBServer* hostNode = getNode(member->getHostAndPort().toString()); if (hostNode == node) { continue; } BSONObjBuilder hostMemberBuilder; // TODO: _id, stateStr, uptime, optime, optimeDate, lastHeartbeat, pingMs // errmsg, authenticated hostMemberBuilder.append("name", hostNode->getServerAddress()); const double health = hostNode->isRunning() ? 1.0 : 0.0; hostMemberBuilder.append("health", health); hostMemberBuilder.append("state", getState(hostNode->getServerAddress())); hostsField.push_back(hostMemberBuilder.obj()); } sort(hostsField.begin(), hostsField.end()); // TODO: syncingTo fullStatBuilder.append("set", _setName); fullStatBuilder.appendTimeT("date", time(0)); fullStatBuilder.append("myState", getState(node->getServerAddress())); fullStatBuilder.append("members", hostsField); fullStatBuilder.append("ok", true); node->setCommandReply("replSetGetStatus", fullStatBuilder.done()); } }
vector<string> MockReplicaSet::getSecondaries() const { vector<string> secondaries; for (ReplicaSetConfig::MemberIterator member = _replConfig.membersBegin(); member != _replConfig.membersEnd(); ++member) { if (member->getHostAndPort() != HostAndPort(_primaryHost)) { secondaries.push_back(member->getHostAndPort().toString()); } } return secondaries; }
void ReplicationCoordinatorImpl::_startHeartbeats() { ReplicaSetConfig::MemberIterator it = _rsConfig.membersBegin(); ReplicaSetConfig::MemberIterator end = _rsConfig.membersBegin(); for(;it != end; it++) { HostAndPort host = it->getHostAndPort(); CBHStatus status = _replExecutor->scheduleWork( stdx::bind( &ReplicationCoordinatorImpl::doMemberHeartbeat, this, stdx::placeholders::_1, host)); if (!status.isOK()) { log() << "replset: cannot start heartbeats for " << host << " due to scheduling error -- "<< status; continue; } _trackHeartbeatHandle(status.getValue()); } }