27
27
class CmdReplSetFresh : public ReplSetCommand {
29
29
CmdReplSetFresh() : ReplSetCommand("replSetFresh") { }
30
virtual void addRequiredPrivileges(const std::string& dbname,
31
const BSONObj& cmdObj,
32
std::vector<Privilege>* out) {
34
actions.addAction(ActionType::replSetFresh);
35
out->push_back(Privilege(AuthorizationManager::SERVER_RESOURCE_NAME, actions));
32
39
bool shouldVeto(const BSONObj& cmdObj, string& errmsg) {
41
48
const Member* hopeful = theReplSet->findById(id);
42
49
const Member *highestPriority = theReplSet->getMostElectable();
45
52
errmsg = str::stream() << "replSet couldn't find member with id " << id;
48
else if( theReplSet->isPrimary() && theReplSet->lastOpTimeWritten >= hopeful->hbinfo().opTime ) {
56
if (theReplSet->isPrimary() &&
57
theReplSet->lastOpTimeWritten >= hopeful->hbinfo().opTime) {
49
58
// hbinfo is not updated, so we have to check the primary's last optime separately
50
59
errmsg = str::stream() << "I am already primary, " << hopeful->fullName() <<
51
60
" can try again once I've stepped down";
54
else if( primary && primary->hbinfo().opTime >= hopeful->hbinfo().opTime ) {
64
if (primary && primary->hbinfo().opTime >= hopeful->hbinfo().opTime) {
55
65
// other members might be aware of more up-to-date nodes
56
errmsg = str::stream() << hopeful->fullName() << " is trying to elect itself but " <<
57
primary->fullName() << " is already primary and more up-to-date";
60
else if( highestPriority && highestPriority->config().priority > hopeful->config().priority) {
61
errmsg = str::stream() << hopeful->fullName() << " has lower priority than " << highestPriority->fullName();
65
if ( !theReplSet->isElectable(id) ||
66
(highestPriority && highestPriority->config().priority > hopeful->config().priority)) {
66
errmsg = str::stream() << hopeful->fullName() <<
67
" is trying to elect itself but " << primary->fullName() <<
68
" is already primary and more up-to-date";
72
if (highestPriority &&
73
highestPriority->config().priority > hopeful->config().priority) {
74
errmsg = str::stream() << hopeful->fullName() << " has lower priority than " <<
75
highestPriority->fullName();
79
if (!theReplSet->isElectable(id)) {
80
errmsg = str::stream() << "I don't think " << hopeful->fullName() <<
96
111
result.appendDate("opTime", theReplSet->lastOpTimeWritten.asDate());
97
112
result.append("fresher", weAreFresher);
98
result.append("veto", shouldVeto(cmdObj, errmsg));
114
bool veto = shouldVeto(cmdObj, errmsg);
115
result.append("veto", veto);
117
result.append("errmsg", errmsg);
104
124
class CmdReplSetElect : public ReplSetCommand {
106
126
CmdReplSetElect() : ReplSetCommand("replSetElect") { }
127
virtual void addRequiredPrivileges(const std::string& dbname,
128
const BSONObj& cmdObj,
129
std::vector<Privilege>* out) {
131
actions.addAction(ActionType::replSetElect);
132
out->push_back(Privilege(AuthorizationManager::SERVER_RESOURCE_NAME, actions));
108
135
virtual bool run(const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
109
136
if( !check(errmsg, result) )
133
160
bool Consensus::shouldRelinquish() const {
134
161
int vUp = rs._self->config().votes;
135
const long long T = rs.config().ho.heartbeatTimeoutMillis * rs.config().ho.heartbeatConnRetries;
136
162
for( Member *m = rs.head(); m; m=m->next() ) {
137
long long dt = m->hbinfo().timeDown();
163
if (m->hbinfo().up()) {
139
164
vUp += m->config().votes;
142
168
// the manager will handle calling stepdown if another node should be