本文整理汇总了C++中WorkingSet::getFlagged方法的典型用法代码示例。如果您正苦于以下问题:C++ WorkingSet::getFlagged方法的具体用法?C++ WorkingSet::getFlagged怎么用?C++ WorkingSet::getFlagged使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WorkingSet
的用法示例。
在下文中一共展示了WorkingSet::getFlagged方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
std::set<WorkingSetID> expectedResultIds;
std::set<WorkingSetID> resultIds;
// Create a KeepMutationsStage with an EOF child, and flag 50 objects. We expect these
// objects to be returned by the KeepMutationsStage.
MatchExpression* nullFilter = NULL;
std::auto_ptr<KeepMutationsStage> keep(new KeepMutationsStage(nullFilter, &ws,
new EOFStage()));
for (size_t i = 0; i < 50; ++i) {
WorkingSetID id = ws.allocate();
WorkingSetMember* member = ws.get(id);
member->state = WorkingSetMember::OWNED_OBJ;
member->obj = BSON("x" << 1);
ws.flagForReview(id);
expectedResultIds.insert(id);
}
// Call work() on the KeepMutationsStage. The stage should start streaming the
// already-flagged objects.
WorkingSetID id = getNextResult(keep.get());
resultIds.insert(id);
// Flag more objects, then call work() again on the KeepMutationsStage, and expect none
// of the newly-flagged objects to be returned (the KeepMutationsStage does not
// incorporate objects flagged since the streaming phase started).
//
// This condition triggers SERVER-15580 (the new flagging causes a rehash of the
// unordered_set "WorkingSet::_flagged", which invalidates all iterators, which were
// previously being dereferenced in KeepMutationsStage::work()).
// Note that std::unordered_set<>::insert() triggers a rehash if the new number of
// elements is greater than or equal to max_load_factor()*bucket_count().
size_t rehashSize = static_cast<size_t>(ws.getFlagged().max_load_factor() *
ws.getFlagged().bucket_count());
while (ws.getFlagged().size() <= rehashSize) {
WorkingSetID id = ws.allocate();
WorkingSetMember* member = ws.get(id);
member->state = WorkingSetMember::OWNED_OBJ;
member->obj = BSON("x" << 1);
ws.flagForReview(id);
}
while ((id = getNextResult(keep.get())) != WorkingSet::INVALID_ID) {
resultIds.insert(id);
}
// Assert that only the first 50 objects were returned.
ASSERT(expectedResultIds == resultIds);
}
示例2: run
void run() {
Client::WriteContext ctx(ns());
Database* db = ctx.ctx().db();
Collection* coll = db->getCollection(ns());
if (!coll) {
coll = db->createCollection(ns());
}
for (int i = 0; i < 50; ++i) {
insert(BSON("_id" << i << "foo" << i << "bar" << i << "baz" << i));
}
addIndex(BSON("foo" << 1));
addIndex(BSON("bar" << 1));
addIndex(BSON("baz" << 1));
WorkingSet ws;
scoped_ptr<AndHashStage> ah(new AndHashStage(&ws, NULL));
// Foo <= 20 (descending)
IndexScanParams params;
params.descriptor = getIndex(BSON("foo" << 1), coll);
params.bounds.isSimpleRange = true;
params.bounds.startKey = BSON("" << 20);
params.bounds.endKey = BSONObj();
params.bounds.endKeyInclusive = true;
params.direction = -1;
ah->addChild(new IndexScan(params, &ws, NULL));
// Bar <= 19 (descending)
params.descriptor = getIndex(BSON("bar" << 1), coll);
params.bounds.startKey = BSON("" << 19);
ah->addChild(new IndexScan(params, &ws, NULL));
// First call to work reads the first result from the children.
// The first result is for the first scan over foo is {foo: 20, bar: 20, baz: 20}.
// The first result is for the second scan over bar is {foo: 19, bar: 19, baz: 19}.
WorkingSetID id;
PlanStage::StageState status = ah->work(&id);
ASSERT_EQUALS(PlanStage::NEED_TIME, status);
const unordered_set<WorkingSetID>& flagged = ws.getFlagged();
ASSERT_EQUALS(size_t(0), flagged.size());
// "delete" deletedObj (by invalidating the DiskLoc of the obj that matches it).
BSONObj deletedObj = BSON("_id" << 20 << "foo" << 20 << "bar" << 20 << "baz" << 20);
ah->prepareToYield();
set<DiskLoc> data;
getLocs(&data, coll);
for (set<DiskLoc>::const_iterator it = data.begin(); it != data.end(); ++it) {
if (0 == deletedObj.woCompare(it->obj())) {
ah->invalidate(*it, INVALIDATION_DELETION);
break;
}
}
ah->recoverFromYield();
// The deleted obj should show up in flagged.
ASSERT_EQUALS(size_t(1), flagged.size());
// And not in our results.
int count = 0;
while (!ah->isEOF()) {
WorkingSetID id;
PlanStage::StageState status = ah->work(&id);
if (PlanStage::ADVANCED != status) { continue; }
WorkingSetMember* wsm = ws.get(id);
ASSERT_NOT_EQUALS(0, deletedObj.woCompare(wsm->loc.obj()));
++count;
}
ASSERT_EQUALS(count, 20);
}