本文整理汇总了C++中LastVote::toBSON方法的典型用法代码示例。如果您正苦于以下问题:C++ LastVote::toBSON方法的具体用法?C++ LastVote::toBSON怎么用?C++ LastVote::toBSON使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LastVote
的用法示例。
在下文中一共展示了LastVote::toBSON方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: storeLocalLastVoteDocument
Status ReplicationCoordinatorExternalStateImpl::storeLocalLastVoteDocument(
OperationContext* txn, const LastVote& lastVote) {
BSONObj lastVoteObj = lastVote.toBSON();
try {
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
ScopedTransaction transaction(txn, MODE_IX);
Lock::DBLock dbWriteLock(txn->lockState(), lastVoteDatabaseName, MODE_X);
Helpers::putSingleton(txn, lastVoteCollectionName, lastVoteObj);
return Status::OK();
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_END(
txn, "save replica set lastVote", lastVoteCollectionName);
MONGO_UNREACHABLE;
} catch (const DBException& ex) {
return ex.toStatus();
}
}
示例2: 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();
}
}