本文整理汇总了C++中MONGO_WRITE_CONFLICT_RETRY_LOOP_END函数的典型用法代码示例。如果您正苦于以下问题:C++ MONGO_WRITE_CONFLICT_RETRY_LOOP_END函数的具体用法?C++ MONGO_WRITE_CONFLICT_RETRY_LOOP_END怎么用?C++ MONGO_WRITE_CONFLICT_RETRY_LOOP_END使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MONGO_WRITE_CONFLICT_RETRY_LOOP_END函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: invariant
OpTime ReplicationCoordinatorExternalStateImpl::onTransitionToPrimary(OperationContext* txn,
bool isV1ElectionProtocol) {
invariant(txn->lockState()->isW());
// Clear the appliedThrough marker so on startup we'll use the top of the oplog. This must be
// done before we add anything to our oplog.
invariant(_storageInterface->getOplogDeleteFromPoint(txn).isNull());
_storageInterface->setAppliedThrough(txn, {});
if (isV1ElectionProtocol) {
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
ScopedTransaction scopedXact(txn, MODE_X);
WriteUnitOfWork wuow(txn);
txn->getClient()->getServiceContext()->getOpObserver()->onOpMessage(
txn,
BSON("msg"
<< "new primary"));
wuow.commit();
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_END(
txn, "logging transition to primary to oplog", "local.oplog.rs");
}
const auto opTimeToReturn = fassertStatusOK(28665, loadLastOpTime(txn));
_shardingOnTransitionToPrimaryHook(txn);
_dropAllTempCollections(txn);
return opTimeToReturn;
}
开发者ID:judahschvimer,项目名称:mongo,代码行数:30,代码来源:replication_coordinator_external_state_impl.cpp
示例2: transaction
long long BackgroundSync::_readLastAppliedHash(OperationContext* txn) {
BSONObj oplogEntry;
try {
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
ScopedTransaction transaction(txn, MODE_IX);
Lock::DBLock lk(txn->lockState(), "local", MODE_X);
bool success = Helpers::getLast(txn, rsOplogName.c_str(), oplogEntry);
if (!success) {
// This can happen when we are to do an initial sync. lastHash will be set
// after the initial sync is complete.
return 0;
}
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "readLastAppliedHash", rsOplogName);
} catch (const DBException& ex) {
severe() << "Problem reading " << rsOplogName << ": " << redact(ex);
fassertFailed(18904);
}
long long hash;
auto status = bsonExtractIntegerField(oplogEntry, kHashFieldName, &hash);
if (!status.isOK()) {
severe() << "Most recent entry in " << rsOplogName << " is missing or has invalid \""
<< kHashFieldName << "\" field. Oplog entry: " << redact(oplogEntry) << ": "
<< redact(status);
fassertFailed(18902);
}
return hash;
}
开发者ID:gormanb,项目名称:mongo,代码行数:28,代码来源:bgsync.cpp
示例3: dropIndexes
Status dropIndexes(OperationContext* txn,
const NamespaceString& ns,
const BSONObj& idxDescriptor,
BSONObjBuilder* result) {
StringData dbName = ns.db();
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
ScopedTransaction transaction(txn, MODE_IX);
AutoGetDb autoDb(txn, dbName, MODE_X);
bool userInitiatedWritesAndNotPrimary = txn->writesAreReplicated() &&
!repl::getGlobalReplicationCoordinator()->canAcceptWritesFor(ns);
if (userInitiatedWritesAndNotPrimary) {
return Status(ErrorCodes::NotMaster,
str::stream() << "Not primary while dropping indexes in "
<< ns.toString());
}
WriteUnitOfWork wunit(txn);
Status status = wrappedRun(txn, dbName, ns, autoDb.getDb(), idxDescriptor, result);
if (!status.isOK()) {
return status;
}
getGlobalServiceContext()->getOpObserver()->onDropIndex(
txn, dbName.toString() + ".$cmd", idxDescriptor);
wunit.commit();
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "dropIndexes", dbName);
return Status::OK();
}
开发者ID:MikuKing,项目名称:mongo,代码行数:30,代码来源:drop_indexes.cpp
示例4: dropAllDatabasesExceptLocal
void dropAllDatabasesExceptLocal(OperationContext* txn) {
ScopedTransaction transaction(txn, MODE_X);
Lock::GlobalWrite lk(txn->lockState());
vector<string> n;
StorageEngine* storageEngine = getGlobalServiceContext()->getGlobalStorageEngine();
storageEngine->listDatabases(&n);
if (n.size() == 0)
return;
log() << "dropAllDatabasesExceptLocal " << n.size();
repl::getGlobalReplicationCoordinator()->dropAllSnapshots();
for (vector<string>::iterator i = n.begin(); i != n.end(); i++) {
if (*i != "local") {
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
Database* db = dbHolder().get(txn, *i);
// This is needed since dropDatabase can't be rolled back.
// This is safe be replaced by "invariant(db);dropDatabase(txn, db);" once fixed
if (db == nullptr) {
log() << "database disappeared after listDatabases but before drop: " << *i;
} else {
Database::dropDatabase(txn, db);
}
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "dropAllDatabasesExceptLocal", *i);
}
}
开发者ID:judahschvimer,项目名称:mongo,代码行数:28,代码来源:database.cpp
示例5: transaction
long long BackgroundSync::_readLastAppliedHash(OperationContext* txn) {
BSONObj oplogEntry;
try {
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
ScopedTransaction transaction(txn, MODE_IX);
Lock::DBLock lk(txn->lockState(), "local", MODE_X);
bool success = Helpers::getLast(txn, rsOplogName.c_str(), oplogEntry);
if (!success) {
// This can happen when we are to do an initial sync. lastHash will be set
// after the initial sync is complete.
return 0;
}
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "readLastAppliedHash", rsOplogName);
} catch (const DBException& ex) {
severe() << "Problem reading " << rsOplogName << ": " << ex.toStatus();
fassertFailed(18904);
}
BSONElement hashElement = oplogEntry[hashFieldName];
if (hashElement.eoo()) {
severe() << "Most recent entry in " << rsOplogName << " missing \"" << hashFieldName
<< "\" field";
fassertFailed(18902);
}
if (hashElement.type() != NumberLong) {
severe() << "Expected type of \"" << hashFieldName << "\" in most recent " << rsOplogName
<< " entry to have type NumberLong, but found " << typeName(hashElement.type());
fassertFailed(18903);
}
return hashElement.safeNumberLong();
}
开发者ID:alabid,项目名称:mongo,代码行数:31,代码来源:bgsync.cpp
示例6: run
bool run(OperationContext* txn, const string& dbname, BSONObj& jsobj, int, string& errmsg,
BSONObjBuilder& result, bool fromRepl) {
const std::string ns = parseNsCollectionRequired(dbname, jsobj);
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
ScopedTransaction transaction(txn, MODE_IX);
AutoGetDb autoDb(txn, dbname, MODE_X);
if (!fromRepl &&
!repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(dbname)) {
return appendCommandStatus(result, Status(ErrorCodes::NotMaster, str::stream()
<< "Not primary while dropping indexes in " << ns));
}
WriteUnitOfWork wunit(txn);
bool ok = wrappedRun(txn, dbname, ns, autoDb.getDb(), jsobj, errmsg, result);
if (!ok) {
return false;
}
if (!fromRepl) {
getGlobalEnvironment()->getOpObserver()->onDropIndex(txn,
dbname + ".$cmd",
jsobj);
}
wunit.commit();
} MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "dropIndexes", dbname);
return true;
}
开发者ID:ambroff,项目名称:mongo,代码行数:27,代码来源:drop_indexes.cpp
示例7: _runTaskReleaseResourcesOnFailure
Status CollectionBulkLoaderImpl::insertDocuments(const std::vector<BSONObj>::const_iterator begin,
const std::vector<BSONObj>::const_iterator end) {
int count = 0;
return _runTaskReleaseResourcesOnFailure(
[begin, end, &count, this](OperationContext* txn) -> Status {
invariant(txn);
for (auto iter = begin; iter != end; ++iter) {
std::vector<MultiIndexBlock*> indexers;
if (_idIndexBlock) {
indexers.push_back(_idIndexBlock.get());
}
if (_secondaryIndexesBlock) {
indexers.push_back(_secondaryIndexesBlock.get());
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
WriteUnitOfWork wunit(txn);
const auto status = _coll->insertDocument(txn, *iter, indexers, false);
if (!status.isOK()) {
return status;
}
wunit.commit();
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_END(
_txn, "CollectionBulkLoaderImpl::insertDocuments", _nss.ns());
++count;
}
return Status::OK();
});
开发者ID:mikety,项目名称:mongo,代码行数:30,代码来源:collection_bulk_loader_impl.cpp
示例8: createOplog
Status ReplicationCoordinatorExternalStateImpl::initializeReplSetStorage(OperationContext* txn,
const BSONObj& config) {
try {
createOplog(txn);
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
ScopedTransaction scopedXact(txn, MODE_X);
Lock::GlobalWrite globalWrite(txn->lockState());
WriteUnitOfWork wuow(txn);
Helpers::putSingleton(txn, configCollectionName, config);
const auto msgObj = BSON("msg"
<< "initiating set");
getGlobalServiceContext()->getOpObserver()->onOpMessage(txn, msgObj);
wuow.commit();
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "initiate oplog entry", "local.oplog.rs");
// This initializes the minvalid document with a null "ts" because older versions (<=3.2)
// get angry if the minValid document is present but doesn't have a "ts" field.
// Consider removing this once we no longer need to support downgrading to 3.2.
_storageInterface->setMinValidToAtLeast(txn, {});
FeatureCompatibilityVersion::setIfCleanStartup(txn, _storageInterface);
} catch (const DBException& ex) {
return ex.toStatus();
}
return Status::OK();
}
开发者ID:judahschvimer,项目名称:mongo,代码行数:29,代码来源:replication_coordinator_external_state_impl.cpp
示例9: uassert
void FeatureCompatibilityVersion::set(OperationContext* txn, StringData version) {
uassert(40284,
"featureCompatibilityVersion must be '3.4' or '3.2'. See "
"http://dochub.mongodb.org/core/3.4-feature-compatibility.",
version == FeatureCompatibilityVersionCommandParser::kVersion34 ||
version == FeatureCompatibilityVersionCommandParser::kVersion32);
DBDirectClient client(txn);
NamespaceString nss(FeatureCompatibilityVersion::kCollection);
if (version == FeatureCompatibilityVersionCommandParser::kVersion34) {
// We build a v=2 index on the "admin.system.version" collection as part of setting the
// featureCompatibilityVersion to 3.4. This is a new index version that isn't supported by
// versions of MongoDB earlier than 3.4 that will cause 3.2 secondaries to crash when it is
// replicated.
std::vector<BSONObj> indexSpecs{k32IncompatibleIndexSpec};
{
ScopedTransaction transaction(txn, MODE_IX);
AutoGetOrCreateDb autoDB(txn, nss.db(), MODE_X);
uassert(ErrorCodes::NotMaster,
str::stream() << "Cannot set featureCompatibilityVersion to '" << version
<< "'. Not primary while attempting to create index on: "
<< nss.ns(),
repl::ReplicationCoordinator::get(txn->getServiceContext())
->canAcceptWritesFor(nss));
IndexBuilder builder(k32IncompatibleIndexSpec, false);
auto status = builder.buildInForeground(txn, autoDB.getDb());
uassertStatusOK(status);
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
WriteUnitOfWork wuow(txn);
getGlobalServiceContext()->getOpObserver()->onCreateIndex(
txn, autoDB.getDb()->getSystemIndexesName(), k32IncompatibleIndexSpec, false);
wuow.commit();
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "FeatureCompatibilityVersion::set", nss.ns());
}
// We then update the featureCompatibilityVersion document stored in the
// "admin.system.version" collection. We do this after creating the v=2 index in order to
// maintain the invariant that if the featureCompatibilityVersion is 3.4, then
// 'k32IncompatibleIndexSpec' index exists on the "admin.system.version" collection.
BSONObj updateResult;
client.runCommand(nss.db().toString(),
makeUpdateCommand(version, WriteConcernOptions::Majority),
updateResult);
uassertStatusOK(getStatusFromCommandResult(updateResult));
uassertStatusOK(getWriteConcernStatusFromCommandResult(updateResult));
// We then update the value of the featureCompatibilityVersion server parameter.
serverGlobalParams.featureCompatibility.version.store(
ServerGlobalParams::FeatureCompatibility::Version::k34);
} else if (version == FeatureCompatibilityVersionCommandParser::kVersion32) {
开发者ID:ksuarz,项目名称:mongo,代码行数:56,代码来源:feature_compatibility_version.cpp
示例10: createOplog
void ReplicationCoordinatorExternalStateImpl::initiateOplog(OperationContext* txn) {
createOplog(txn);
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
ScopedTransaction scopedXact(txn, MODE_X);
Lock::GlobalWrite globalWrite(txn->lockState());
WriteUnitOfWork wuow(txn);
getGlobalServiceContext()->getOpObserver()->onOpMessage(txn, BSON("msg" << "initiating set"));
wuow.commit();
} MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "initiate oplog entry", "local.oplog.rs");
}
开发者ID:Amosvista,项目名称:mongo,代码行数:12,代码来源:replication_coordinator_external_state_impl.cpp
示例11: getInitialSyncFlag
bool getInitialSyncFlag() {
OperationContextImpl txn;
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
ScopedTransaction transaction(&txn, MODE_IX);
Lock::DBLock lk(txn.lockState(), "local", MODE_X);
BSONObj mv;
bool found = Helpers::getSingleton(&txn, minvalidNS, mv);
if (found) {
return mv[initialSyncFlagString].trueValue();
}
return false;
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_END(&txn, "getInitialSyncFlags", minvalidNS);
}
开发者ID:DavidAlphaFox,项目名称:mongodb,代码行数:14,代码来源:minvalid.cpp
示例12: transaction
Status ReplicationCoordinatorExternalStateImpl::storeLocalConfigDocument(OperationContext* txn,
const BSONObj& config) {
try {
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
ScopedTransaction transaction(txn, MODE_IX);
Lock::DBLock dbWriteLock(txn->lockState(), configDatabaseName, MODE_X);
Helpers::putSingleton(txn, configCollectionName, config);
return Status::OK();
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "save replica set config", configCollectionName);
} catch (const DBException& ex) {
return ex.toStatus();
}
}
开发者ID:AndrewHarkusha,项目名称:mongo,代码行数:14,代码来源:replication_coordinator_external_state_impl.cpp
示例13: dropAllDatabasesExceptLocal
void ServiceContextMongoDTest::_dropAllDBs(OperationContext* txn) {
dropAllDatabasesExceptLocal(txn);
ScopedTransaction transaction(txn, MODE_X);
Lock::GlobalWrite lk(txn->lockState());
AutoGetDb autoDBLocal(txn, "local", MODE_X);
const auto localDB = autoDBLocal.getDb();
if (localDB) {
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
// Do not wrap in a WriteUnitOfWork until SERVER-17103 is addressed.
autoDBLocal.getDb()->dropDatabase(txn, localDB);
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "_dropAllDBs", "local");
}
}
开发者ID:AlexOreshkevich,项目名称:mongo,代码行数:15,代码来源:service_context_d_test_fixture.cpp
示例14: MONGO_WRITE_CONFLICT_RETRY_LOOP_END
StatusWith<BSONObj> ReplicationCoordinatorExternalStateImpl::loadLocalConfigDocument(
OperationContext* txn) {
try {
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
BSONObj config;
if (!Helpers::getSingleton(txn, configCollectionName, config)) {
return StatusWith<BSONObj>(
ErrorCodes::NoMatchingDocument,
str::stream() << "Did not find replica set configuration document in "
<< configCollectionName);
}
return StatusWith<BSONObj>(config);
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "load replica set config", configCollectionName);
} catch (const DBException& ex) {
return StatusWith<BSONObj>(ex.toStatus());
}
}
开发者ID:AndrewHarkusha,项目名称:mongo,代码行数:18,代码来源:replication_coordinator_external_state_impl.cpp
示例15: createOplog
Status ReplicationCoordinatorExternalStateImpl::initializeReplSetStorage(OperationContext* txn,
const BSONObj& config,
bool updateReplOpTime) {
try {
createOplog(txn, rsOplogName, true);
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
ScopedTransaction scopedXact(txn, MODE_X);
Lock::GlobalWrite globalWrite(txn->lockState());
WriteUnitOfWork wuow(txn);
Helpers::putSingleton(txn, configCollectionName, config);
const auto msgObj = BSON("msg"
<< "initiating set");
if (updateReplOpTime) {
getGlobalServiceContext()->getOpObserver()->onOpMessage(txn, msgObj);
} else {
// 'updateReplOpTime' is false when called from the replSetInitiate command when the
// server is running with replication disabled. We bypass onOpMessage to invoke
// _logOp directly so that we can override the replication mode and keep _logO from
// updating the replication coordinator's op time (illegal operation when
// replication is not enabled).
repl::oplogCheckCloseDatabase(txn, nullptr);
repl::_logOp(txn,
"n",
"",
msgObj,
nullptr,
false,
rsOplogName,
ReplicationCoordinator::modeReplSet,
updateReplOpTime);
repl::oplogCheckCloseDatabase(txn, nullptr);
}
wuow.commit();
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "initiate oplog entry", "local.oplog.rs");
} catch (const DBException& ex) {
return ex.toStatus();
}
return Status::OK();
}
开发者ID:DCEngines,项目名称:mongo,代码行数:42,代码来源:replication_coordinator_external_state_impl.cpp
示例16: nss
bool SyncTail::shouldRetry(OperationContext* txn, const BSONObj& o) {
const NamespaceString nss(o.getStringField("ns"));
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
// Take an X lock on the database in order to preclude other modifications.
// Also, the database might not exist yet, so create it.
AutoGetOrCreateDb autoDb(txn, nss.db(), MODE_X);
Database* const db = autoDb.getDb();
// we don't have the object yet, which is possible on initial sync. get it.
log() << "adding missing object" << endl; // rare enough we can log
BSONObj missingObj = getMissingDoc(txn, db, o);
if (missingObj.isEmpty()) {
log() << "missing object not found on source."
" presumably deleted later in oplog";
log() << "o2: " << o.getObjectField("o2").toString();
log() << "o firstfield: " << o.getObjectField("o").firstElementFieldName();
return false;
} else {
WriteUnitOfWork wunit(txn);
Collection* const coll = db->getOrCreateCollection(txn, nss.toString());
invariant(coll);
Status status = coll->insertDocument(txn, missingObj, true);
uassert(15917,
str::stream() << "failed to insert missing doc: " << status.toString(),
status.isOK());
LOG(1) << "inserted missing doc: " << missingObj.toString() << endl;
wunit.commit();
return true;
}
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "InsertRetry", nss.ns());
// fixes compile errors on GCC - see SERVER-18219 for details
MONGO_UNREACHABLE;
}
开发者ID:Jaryli,项目名称:mongo,代码行数:42,代码来源:sync_tail.cpp
示例17: handleSERVER23299ForDb
void handleSERVER23299ForDb(OperationContext* txn, Database* db) {
log() << "Scanning " << db->name() << " db for SERVER-23299 eligibility";
const auto dbEntry = db->getDatabaseCatalogEntry();
list<string> collNames;
dbEntry->getCollectionNamespaces(&collNames);
for (const auto& collName : collNames) {
const auto collEntry = dbEntry->getCollectionCatalogEntry(collName);
const auto collOptions = collEntry->getCollectionOptions(txn);
if (!collOptions.temp)
continue;
log() << "Marking collection " << collName << " as permanent per SERVER-23299";
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
WriteUnitOfWork wuow(txn);
collEntry->clearTempFlag(txn);
wuow.commit();
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "repair SERVER-23299", collEntry->ns().ns());
}
log() << "Done scanning " << db->name() << " for SERVER-23299 eligibility";
}
开发者ID:judahschvimer,项目名称:mongo,代码行数:20,代码来源:db.cpp
示例18: dropAllDatabasesExceptLocal
void ServiceContextMongoDTest::_dropAllDBs(OperationContext* txn) {
dropAllDatabasesExceptLocal(txn);
ScopedTransaction transaction(txn, MODE_X);
Lock::GlobalWrite lk(txn->lockState());
AutoGetDb autoDBLocal(txn, "local", MODE_X);
const auto localDB = autoDBLocal.getDb();
if (localDB) {
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
// Do not wrap in a WriteUnitOfWork until SERVER-17103 is addressed.
autoDBLocal.getDb()->dropDatabase(txn, localDB);
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "_dropAllDBs", "local");
}
// dropAllDatabasesExceptLocal() does not close empty databases. However the holder still
// allocates resources to track these empty databases. These resources not released by
// dropAllDatabasesExceptLocal() will be leaked at exit unless we call DatabaseHolder::closeAll.
BSONObjBuilder unused;
invariant(dbHolder().closeAll(txn, unused, false));
}
开发者ID:AshishSanju,项目名称:mongo,代码行数:21,代码来源:service_context_d_test_fixture.cpp
示例19: createOplog
Status ReplicationCoordinatorExternalStateImpl::initializeReplSetStorage(OperationContext* txn,
const BSONObj& config) {
try {
createOplog(txn);
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
ScopedTransaction scopedXact(txn, MODE_X);
Lock::GlobalWrite globalWrite(txn->lockState());
WriteUnitOfWork wuow(txn);
Helpers::putSingleton(txn, configCollectionName, config);
const auto msgObj = BSON("msg"
<< "initiating set");
getGlobalServiceContext()->getOpObserver()->onOpMessage(txn, msgObj);
wuow.commit();
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "initiate oplog entry", "local.oplog.rs");
} catch (const DBException& ex) {
return ex.toStatus();
}
return Status::OK();
}
开发者ID:lovesnow1314,项目名称:mongo,代码行数:22,代码来源:replication_coordinator_external_state_impl.cpp
示例20: waitForLinearizableReadConcern
Status waitForLinearizableReadConcern(OperationContext* txn) {
repl::ReplicationCoordinator* replCoord =
repl::ReplicationCoordinator::get(txn->getClient()->getServiceContext());
{
ScopedTransaction transaction(txn, MODE_IX);
Lock::DBLock lk(txn->lockState(), "local", MODE_IX);
Lock::CollectionLock lock(txn->lockState(), "local.oplog.rs", MODE_IX);
if (!replCoord->canAcceptWritesForDatabase("admin")) {
return {ErrorCodes::NotMaster,
"No longer primary when waiting for linearizable read concern"};
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
WriteUnitOfWork uow(txn);
txn->getClient()->getServiceContext()->getOpObserver()->onOpMessage(
txn,
BSON("msg"
<< "linearizable read"));
uow.commit();
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_END(
txn, "waitForLinearizableReadConcern", "local.rs.oplog");
}
WriteConcernOptions wc = WriteConcernOptions(
WriteConcernOptions::kMajority, WriteConcernOptions::SyncMode::UNSET, 0);
repl::OpTime lastOpApplied = repl::ReplClientInfo::forClient(txn->getClient()).getLastOp();
auto awaitReplResult = replCoord->awaitReplication(txn, lastOpApplied, wc);
if (awaitReplResult.status == ErrorCodes::WriteConcernFailed) {
return Status(ErrorCodes::LinearizableReadConcernError,
"Failed to confirm that read was linearizable.");
}
return awaitReplResult.status;
}
开发者ID:ksuarz,项目名称:mongo,代码行数:38,代码来源:read_concern.cpp
注:本文中的MONGO_WRITE_CONFLICT_RETRY_LOOP_END函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论