本文整理汇总了C++中wuow函数的典型用法代码示例。如果您正苦于以下问题:C++ wuow函数的具体用法?C++ wuow怎么用?C++ wuow使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wuow函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: insertDocument
void insertDocument(Collection* collection, BSONObj obj) {
WriteUnitOfWork wuow(&_txn);
const bool enforceQuota = false;
StatusWith<RecordId> res = collection->insertDocument(&_txn, obj, enforceQuota);
ASSERT(res.isOK());
wuow.commit();
}
示例2: autoDb
mongo::Status mongo::emptyCapped(OperationContext* opCtx, const NamespaceString& collectionName) {
AutoGetDb autoDb(opCtx, collectionName.db(), MODE_X);
bool userInitiatedWritesAndNotPrimary = opCtx->writesAreReplicated() &&
!repl::ReplicationCoordinator::get(opCtx)->canAcceptWritesFor(opCtx, collectionName);
if (userInitiatedWritesAndNotPrimary) {
return Status(ErrorCodes::NotMaster,
str::stream() << "Not primary while truncating collection: "
<< collectionName.ns());
}
Database* db = autoDb.getDb();
uassert(ErrorCodes::NamespaceNotFound, "no such database", db);
Collection* collection = db->getCollection(opCtx, collectionName);
uassert(ErrorCodes::CommandNotSupportedOnView,
str::stream() << "emptycapped not supported on view: " << collectionName.ns(),
collection || !db->getViewCatalog()->lookup(opCtx, collectionName.ns()));
uassert(ErrorCodes::NamespaceNotFound, "no such collection", collection);
if (collectionName.isSystem() && !collectionName.isSystemDotProfile()) {
return Status(ErrorCodes::IllegalOperation,
str::stream() << "Cannot truncate a system collection: "
<< collectionName.ns());
}
if (collectionName.isVirtualized()) {
return Status(ErrorCodes::IllegalOperation,
str::stream() << "Cannot truncate a virtual collection: "
<< collectionName.ns());
}
if ((repl::ReplicationCoordinator::get(opCtx)->getReplicationMode() !=
repl::ReplicationCoordinator::modeNone) &&
collectionName.isOplog()) {
return Status(ErrorCodes::OplogOperationUnsupported,
str::stream() << "Cannot truncate a live oplog while replicating: "
<< collectionName.ns());
}
BackgroundOperation::assertNoBgOpInProgForNs(collectionName.ns());
WriteUnitOfWork wuow(opCtx);
Status status = collection->truncate(opCtx);
if (!status.isOK()) {
return status;
}
getGlobalServiceContext()->getOpObserver()->onEmptyCapped(
opCtx, collection->ns(), collection->uuid());
wuow.commit();
return Status::OK();
}
示例3: run
void run() {
ScopedTransaction transaction(&_txn, MODE_IX);
Lock::DBLock lk(_txn.lockState(), nsToDatabaseSubstring(ns()), MODE_X);
Client::Context ctx(&_txn, ns());
Database* db = ctx.db();
Collection* coll = db->getCollection(&_txn, ns());
if (!coll) {
WriteUnitOfWork wuow(&_txn);
coll = db->createCollection(&_txn, ns());
wuow.commit();
}
WorkingSet ws;
// Add an object to the DB.
insert(BSON("foo" << 5));
set<DiskLoc> locs;
getLocs(&locs, coll);
ASSERT_EQUALS(size_t(1), locs.size());
// Create a mock stage that returns the WSM.
auto_ptr<MockStage> mockStage(new MockStage(&ws));
// Mock data.
{
WorkingSetMember mockMember;
mockMember.state = WorkingSetMember::LOC_AND_IDX;
mockMember.loc = *locs.begin();
// State is loc and index, shouldn't be able to get the foo data inside.
BSONElement elt;
ASSERT_FALSE(mockMember.getFieldDotted("foo", &elt));
mockStage->pushBack(mockMember);
}
// Make the filter.
BSONObj filterObj = BSON("foo" << 6);
StatusWithMatchExpression swme = MatchExpressionParser::parse(filterObj);
verify(swme.isOK());
auto_ptr<MatchExpression> filterExpr(swme.getValue());
// Matcher requires that foo==6 but we only have data with foo==5.
auto_ptr<FetchStage> fetchStage(
new FetchStage(&_txn, &ws, mockStage.release(), filterExpr.get(), coll));
// First call should return a fetch request as it's not in memory.
WorkingSetID id = WorkingSet::INVALID_ID;
PlanStage::StageState state;
// Normally we'd return the object but we have a filter that prevents it.
state = fetchStage->work(&id);
ASSERT_EQUALS(PlanStage::NEED_TIME, state);
// No more data to fetch, so, EOF.
state = fetchStage->work(&id);
ASSERT_EQUALS(PlanStage::IS_EOF, state);
}
示例4: lk
~IndexIteratorTests() {
OperationContextImpl txn;
Lock::DBLock lk(txn.lockState(), nsToDatabaseSubstring(_ns), MODE_X);
Client::Context ctx(&txn, _ns);
WriteUnitOfWork wuow(&txn);
_db->dropCollection(&txn, _ns);
wuow.commit();
}
示例5: insertDocument
void insertDocument(Collection* collection, BSONObj obj) {
WriteUnitOfWork wuow(&_opCtx);
const bool enforceQuota = false;
OpDebug* const nullOpDebug = nullptr;
ASSERT_OK(
collection->insertDocument(&_opCtx, InsertStatement(obj), nullOpDebug, enforceQuota));
wuow.commit();
}
示例6: run
void run() {
Client::WriteContext ctx(&_txn, ns());
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(&_txn, ns());
if (!coll) {
WriteUnitOfWork wuow(&_txn);
coll = db->createCollection(&_txn, ns());
wuow.commit();
}
WorkingSet ws;
// Add 10 objects to the collection.
for (size_t i = 0; i < 10; ++i) {
insert(BSON("x" << 1));
}
// Create 10 objects that are flagged.
for (size_t i = 0; i < 10; ++i) {
WorkingSetID id = ws.allocate();
WorkingSetMember* member = ws.get(id);
member->state = WorkingSetMember::OWNED_OBJ;
member->obj = BSON("x" << 2);
ws.flagForReview(id);
}
// Create a collscan to provide the 10 objects in the collection.
CollectionScanParams params;
params.collection = coll;
params.direction = CollectionScanParams::FORWARD;
params.tailable = false;
params.start = RecordId();
CollectionScan* cs = new CollectionScan(&_txn, params, &ws, NULL);
// Create a KeepMutations stage to merge in the 10 flagged objects.
// Takes ownership of 'cs'
MatchExpression* nullFilter = NULL;
std::auto_ptr<KeepMutationsStage> keep(new KeepMutationsStage(nullFilter, &ws, cs));
for (size_t i = 0; i < 10; ++i) {
WorkingSetID id = getNextResult(keep.get());
WorkingSetMember* member = ws.get(id);
ASSERT_FALSE(ws.isFlagged(id));
ASSERT_EQUALS(member->obj["x"].numberInt(), 1);
}
ASSERT(cs->isEOF());
// Flagged results *must* be at the end.
for (size_t i = 0; i < 10; ++i) {
WorkingSetID id = getNextResult(keep.get());
WorkingSetMember* member = ws.get(id);
ASSERT(ws.isFlagged(id));
ASSERT_EQUALS(member->obj["x"].numberInt(), 2);
}
}
示例7: 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) {
示例8: cc
~IndexIteratorTests() {
const ServiceContext::UniqueOperationContext opCtxPtr = cc().makeOperationContext();
OperationContext& opCtx = *opCtxPtr;
Lock::DBLock lk(&opCtx, _nss.db(), MODE_X);
OldClientContext ctx(&opCtx, _nss.ns());
WriteUnitOfWork wuow(&opCtx);
_db->dropCollection(&opCtx, _nss).transitional_ignore();
wuow.commit();
}
示例9: TEST_F
TEST_F(WiredTigerRecoveryUnitTestFixture, CommitWithoutDurableTimestamp) {
auto opCtx = clientAndCtx1.second.get();
Timestamp ts1(5, 5);
opCtx->recoveryUnit()->setCommitTimestamp(ts1);
{
WriteUnitOfWork wuow(opCtx);
wuow.commit();
}
}
示例10: createOplog
void ReplicationCoordinatorExternalStateImpl::initiateOplog(OperationContext* txn) {
createOplog(txn);
ScopedTransaction scopedXact(txn, MODE_X);
Lock::GlobalWrite globalWrite(txn->lockState());
WriteUnitOfWork wuow(txn);
getGlobalServiceContext()->getOpObserver()->onOpMessage(txn, BSON("msg" << "initiating set"));
wuow.commit();
}
示例11: createOplog
Status ReplicationCoordinatorExternalStateImpl::initializeReplSetStorage(OperationContext* opCtx,
const BSONObj& config) {
try {
createOplog(opCtx);
writeConflictRetry(opCtx,
"initiate oplog entry",
NamespaceString::kRsOplogNamespace.toString(),
[this, &opCtx, &config] {
Lock::GlobalWrite globalWrite(opCtx);
WriteUnitOfWork wuow(opCtx);
Helpers::putSingleton(opCtx, configCollectionName, config);
const auto msgObj = BSON("msg"
<< "initiating set");
_service->getOpObserver()->onOpMessage(opCtx, msgObj);
wuow.commit();
// ReplSetTest assumes that immediately after the replSetInitiate
// command returns, it can allow other nodes to initial sync with no
// retries and they will succeed. Unfortunately, initial sync will
// fail if it finds its sync source has an empty oplog. Thus, we
// need to wait here until the seed document is visible in our oplog.
AutoGetCollection oplog(
opCtx, NamespaceString::kRsOplogNamespace, MODE_IS);
waitForAllEarlierOplogWritesToBeVisible(opCtx);
});
// Set UUIDs for all non-replicated collections. This is necessary for independent replica
// sets and config server replica sets started with no data files because collections in
// local are created prior to the featureCompatibilityVersion being set to 3.6, so the
// collections are not created with UUIDs. We exclude ShardServers when adding UUIDs to
// non-replicated collections on the primary because ShardServers are started up by default
// with featureCompatibilityVersion 3.4, so we don't want to assign UUIDs to them until the
// cluster's featureCompatibilityVersion is explicitly set to 3.6 by the config server. The
// below UUID addition for non-replicated collections only occurs on the primary; UUIDs are
// added to non-replicated collections on secondaries during InitialSync. When the config
// server sets the featureCompatibilityVersion to 3.6, the shard primary will add UUIDs to
// all the collections that need them. One special case here is if a shard is already in
// featureCompatibilityVersion 3.6 and a new node is started up with --shardsvr and added to
// that shard, the new node will still start up with featureCompatibilityVersion 3.4 and
// need to have UUIDs added to each collection. These UUIDs are added during InitialSync,
// because the new node is a secondary.
if (serverGlobalParams.clusterRole != ClusterRole::ShardServer &&
FeatureCompatibilityVersion::isCleanStartUp()) {
auto schemaStatus = updateUUIDSchemaVersionNonReplicated(opCtx, true);
if (!schemaStatus.isOK()) {
return schemaStatus;
}
}
FeatureCompatibilityVersion::setIfCleanStartup(opCtx, _storageInterface);
} catch (const DBException& ex) {
return ex.toStatus();
}
return Status::OK();
}
示例12: IndexIteratorTests
IndexIteratorTests() {
OperationContextImpl txn;
Lock::DBLock lk(txn.lockState(), nsToDatabaseSubstring(_ns), MODE_X);
Client::Context ctx(&txn, _ns);
WriteUnitOfWork wuow(&txn);
_db = ctx.db();
_coll = _db->createCollection(&txn, _ns);
_catalog = _coll->getIndexCatalog();
wuow.commit();
}
示例13: dropCollection
void dropCollection() {
Lock::DBLock dbLock(&_opCtx, nss.db(), MODE_X);
Database* database = DatabaseHolder::getDatabaseHolder().get(&_opCtx, nss.db());
if (!database) {
return;
}
WriteUnitOfWork wuow(&_opCtx);
database->dropCollection(&_opCtx, nss.ns()).transitional_ignore();
wuow.commit();
}
示例14: run
void run() {
Client::WriteContext ctx(&_txn, ns());
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(&_txn, ns());
if (!coll) {
WriteUnitOfWork wuow(&_txn);
coll = db->createCollection(&_txn, ns());
wuow.commit();
}
WorkingSet ws;
// Add an object to the DB.
insert(BSON("foo" << 5));
set<DiskLoc> locs;
getLocs(&locs, coll);
ASSERT_EQUALS(size_t(1), locs.size());
// Create a mock stage that returns the WSM.
auto_ptr<MockStage> mockStage(new MockStage(&ws));
// Mock data.
{
WorkingSetMember mockMember;
mockMember.state = WorkingSetMember::LOC_AND_UNOWNED_OBJ;
mockMember.loc = *locs.begin();
mockMember.obj = coll->docFor(&_txn, mockMember.loc);
// Points into our DB.
mockStage->pushBack(mockMember);
mockMember.state = WorkingSetMember::OWNED_OBJ;
mockMember.loc = DiskLoc();
mockMember.obj = BSON("foo" << 6);
ASSERT_TRUE(mockMember.obj.isOwned());
mockStage->pushBack(mockMember);
}
auto_ptr<FetchStage> fetchStage(new FetchStage(&_txn, &ws, mockStage.release(),
NULL, coll));
WorkingSetID id = WorkingSet::INVALID_ID;
PlanStage::StageState state;
// Don't bother doing any fetching if an obj exists already.
state = fetchStage->work(&id);
ASSERT_EQUALS(PlanStage::ADVANCED, state);
state = fetchStage->work(&id);
ASSERT_EQUALS(PlanStage::ADVANCED, state);
// No more data to fetch, so, EOF.
state = fetchStage->work(&id);
ASSERT_EQUALS(PlanStage::IS_EOF, state);
}
示例15: 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");
}