本文整理汇总了C++中LastVote::getTerm方法的典型用法代码示例。如果您正苦于以下问题:C++ LastVote::getTerm方法的具体用法?C++ LastVote::getTerm怎么用?C++ LastVote::getTerm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LastVote
的用法示例。
在下文中一共展示了LastVote::getTerm方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _writeLastVoteForMyElection
void ReplicationCoordinatorImpl::_writeLastVoteForMyElection(
LastVote lastVote, const ReplicationExecutor::CallbackArgs& cbData) {
invariant(_voteRequester);
invariant(!_electionWinnerDeclarer);
LoseElectionDryRunGuardV1 lossGuard(this);
if (cbData.status == ErrorCodes::CallbackCanceled) {
return;
}
invariant(cbData.txn);
Status status = _externalState->storeLocalLastVoteDocument(cbData.txn, lastVote);
if (!status.isOK()) {
error() << "failed to store LastVote document when voting for myself: " << status;
return;
}
auto cbStatus = _replExecutor.scheduleWork(
[this, lastVote](const ReplicationExecutor::CallbackArgs& cbData) {
_startVoteRequester(lastVote.getTerm());
});
if (cbStatus.getStatus() == ErrorCodes::ShutdownInProgress) {
return;
}
fassert(28768, cbStatus.getStatus());
_replExecutor.signalEvent(_electionDryRunFinishedEvent);
lossGuard.dismiss();
}
示例2: _writeLastVoteForMyElection
void ReplicationCoordinatorImpl::_writeLastVoteForMyElection(
LastVote lastVote, const executor::TaskExecutor::CallbackArgs& cbData) {
// storeLocalLastVoteDocument can call back in to the replication coordinator,
// so _mutex must be unlocked here. However, we cannot return until we
// lock it because we want to lose the election on cancel or error and
// doing so requires _mutex.
auto status = [&] {
if (!cbData.status.isOK()) {
return cbData.status;
}
auto opCtx = cc().makeOperationContext();
return _externalState->storeLocalLastVoteDocument(opCtx.get(), lastVote);
}();
stdx::lock_guard<stdx::mutex> lk(_mutex);
invariant(_voteRequester);
LoseElectionDryRunGuardV1 lossGuard(this);
if (status == ErrorCodes::CallbackCanceled) {
return;
}
if (!status.isOK()) {
log() << "failed to store LastVote document when voting for myself: " << status;
return;
}
if (_topCoord->getTerm() != lastVote.getTerm()) {
log() << "not running for primary, we have been superseded already while writing our last "
"vote. election term: "
<< lastVote.getTerm() << ", current term: " << _topCoord->getTerm();
return;
}
_startVoteRequester_inlock(lastVote.getTerm());
_replExecutor->signalEvent(_electionDryRunFinishedEvent);
lossGuard.dismiss();
}
示例3: _writeLastVoteForMyElection
void ReplicationCoordinatorImpl::_writeLastVoteForMyElection(
LastVote lastVote, const ReplicationExecutor::CallbackArgs& cbData) {
invariant(_voteRequester);
LoseElectionDryRunGuardV1 lossGuard(this);
if (cbData.status == ErrorCodes::CallbackCanceled) {
return;
}
invariant(cbData.txn);
Status status = _externalState->storeLocalLastVoteDocument(cbData.txn, lastVote);
if (!status.isOK()) {
error() << "failed to store LastVote document when voting for myself: " << status;
return;
}
_startVoteRequester(lastVote.getTerm());
_replExecutor.signalEvent(_electionDryRunFinishedEvent);
lossGuard.dismiss();
}
示例4: storeLocalLastVoteDocument
Status ReplicationCoordinatorExternalStateImpl::storeLocalLastVoteDocument(
OperationContext* opCtx, const LastVote& lastVote) {
BSONObj lastVoteObj = lastVote.toBSON();
try {
Status status =
writeConflictRetry(opCtx, "save replica set lastVote", lastVoteCollectionName, [&] {
Lock::DBLock dbWriteLock(opCtx, lastVoteDatabaseName, MODE_X);
// If there is no last vote document, we want to store one. Otherwise, we only want
// to replace it if the new last vote document would have a higher term. We both
// check the term of the current last vote document and insert the new document
// under the DBLock to synchronize the two operations.
BSONObj result;
bool exists = Helpers::getSingleton(opCtx, lastVoteCollectionName, result);
if (!exists) {
Helpers::putSingleton(opCtx, lastVoteCollectionName, lastVoteObj);
} else {
StatusWith<LastVote> oldLastVoteDoc = LastVote::readFromLastVote(result);
if (!oldLastVoteDoc.isOK()) {
return oldLastVoteDoc.getStatus();
}
if (lastVote.getTerm() > oldLastVoteDoc.getValue().getTerm()) {
Helpers::putSingleton(opCtx, lastVoteCollectionName, lastVoteObj);
}
}
return Status::OK();
});
if (!status.isOK()) {
return status;
}
opCtx->recoveryUnit()->waitUntilDurable();
return Status::OK();
} catch (const DBException& ex) {
return ex.toStatus();
}
}