当前位置: 首页>>代码示例>>C++>>正文


C++ LastVote::getTerm方法代码示例

本文整理汇总了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();
}
开发者ID:jiangjian-zh,项目名称:mongo,代码行数:29,代码来源:replication_coordinator_impl_elect_v1.cpp

示例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();
}
开发者ID:i80and,项目名称:mongo,代码行数:37,代码来源:replication_coordinator_impl_elect_v1.cpp

示例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();
}
开发者ID:CaffeineForCode,项目名称:mongo,代码行数:21,代码来源:replication_coordinator_impl_elect_v1.cpp

示例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();
    }
}
开发者ID:i80and,项目名称:mongo,代码行数:40,代码来源:replication_coordinator_external_state_impl.cpp


注:本文中的LastVote::getTerm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。