本文整理汇总了C++中NamespaceDetails::findIndexByKeyPattern方法的典型用法代码示例。如果您正苦于以下问题:C++ NamespaceDetails::findIndexByKeyPattern方法的具体用法?C++ NamespaceDetails::findIndexByKeyPattern怎么用?C++ NamespaceDetails::findIndexByKeyPattern使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NamespaceDetails
的用法示例。
在下文中一共展示了NamespaceDetails::findIndexByKeyPattern方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handle_system_collection_insert
static int handle_system_collection_insert(const char *ns, const BSONObj &obj, bool logop) {
// Trying to insert into a system collection. Fancy side-effects go here:
// TODO: see insert_checkSys
if (mongoutils::str::endsWith(ns, ".system.indexes")) {
// obj is something like this:
// { _id: ObjectId('511d34f6d3080c48017a14d0'), ns: "test.leif", key: { a: -1.0 }, name: "a_-1", unique: true }
const string &coll = obj["ns"].String();
NamespaceDetails *details = getAndMaybeCreateNS(coll.c_str(), logop);
BSONObj key = obj["key"].Obj();
int i = details->findIndexByKeyPattern(key);
if (i >= 0) {
return ASSERT_ID_DUPKEY;
} else {
details->createIndex(obj);
}
} else if (legalClientSystemNS(ns, true)) {
if (mongoutils::str::endsWith(ns, ".system.users")) {
uassert( 14051 , "system.users entry needs 'user' field to be a string", obj["user"].type() == String );
uassert( 14052 , "system.users entry needs 'pwd' field to be a string", obj["pwd"].type() == String );
uassert( 14053 , "system.users entry needs 'user' field to be non-empty", obj["user"].String().size() );
uassert( 14054 , "system.users entry needs 'pwd' field to be non-empty", obj["pwd"].String().size() );
}
} else {
uasserted(16459, str::stream() << "attempt to insert in system namespace '" << ns << "'");
}
return 0;
}
示例2: getIndex
IndexDescriptor* getIndex(const BSONObj& obj) {
Client::ReadContext ctx(ns());
Collection* collection = ctx.ctx().db()->getCollection( ns() );
NamespaceDetails* nsd = collection->details();
int idxNo = nsd->findIndexByKeyPattern(obj);
return collection->getIndexCatalog()->getDescriptor( idxNo );
}
示例3: removeRange
long long Helpers::removeRange( const string& ns , const BSONObj& min , const BSONObj& max , bool yield , bool maxInclusive , RemoveCallback * callback, bool fromMigrate ) {
BSONObj keya , keyb;
BSONObj minClean = toKeyFormat( min , keya );
BSONObj maxClean = toKeyFormat( max , keyb );
verify( keya == keyb );
Client::Context ctx(ns);
shared_ptr<Cursor> c;
auto_ptr<ClientCursor> cc;
{
NamespaceDetails* nsd = nsdetails( ns.c_str() );
if ( ! nsd )
return 0;
int ii = nsd->findIndexByKeyPattern( keya );
verify( ii >= 0 );
IndexDetails& i = nsd->idx( ii );
c.reset( BtreeCursor::make( nsd , ii , i , minClean , maxClean , maxInclusive, 1 ) );
cc.reset( new ClientCursor( QueryOption_NoCursorTimeout , c , ns ) );
cc->setDoingDeletes( true );
}
long long num = 0;
while ( cc->ok() ) {
if ( yield && ! cc->yieldSometimes( ClientCursor::WillNeed) ) {
// cursor got finished by someone else, so we're done
cc.release(); // if the collection/db is dropped, cc may be deleted
break;
}
if ( ! cc->ok() )
break;
DiskLoc rloc = cc->currLoc();
if ( callback )
callback->goingToDelete( cc->current() );
cc->advance();
c->prepareToTouchEarlierIterate();
logOp( "d" , ns.c_str() , rloc.obj()["_id"].wrap() , 0 , 0 , fromMigrate );
theDataFileMgr.deleteRecord(ns.c_str() , rloc.rec(), rloc);
num++;
c->recoverFromTouchingEarlierIterate();
getDur().commitIfNeeded();
}
return num;
}
示例4: removeRange
long long Helpers::removeRange( const string& ns , const BSONObj& min , const BSONObj& max , bool yield , bool maxInclusive , RemoveCallback * callback ) {
BSONObj keya , keyb;
BSONObj minClean = toKeyFormat( min , keya );
BSONObj maxClean = toKeyFormat( max , keyb );
assert( keya == keyb );
Client::Context ctx(ns);
NamespaceDetails* nsd = nsdetails( ns.c_str() );
if ( ! nsd )
return 0;
int ii = nsd->findIndexByKeyPattern( keya );
assert( ii >= 0 );
long long num = 0;
IndexDetails& i = nsd->idx( ii );
shared_ptr<Cursor> c( new BtreeCursor( nsd , ii , i , minClean , maxClean , maxInclusive, 1 ) );
auto_ptr<ClientCursor> cc( new ClientCursor( QueryOption_NoCursorTimeout , c , ns ) );
cc->setDoingDeletes( true );
while ( c->ok() ) {
DiskLoc rloc = c->currLoc();
BSONObj key = c->currKey();
if ( callback )
callback->goingToDelete( c->current() );
c->advance();
c->noteLocation();
logOp( "d" , ns.c_str() , rloc.obj()["_id"].wrap() );
theDataFileMgr.deleteRecord(ns.c_str() , rloc.rec(), rloc);
num++;
c->checkLocation();
if ( yield && ! cc->yieldSometimes() ) {
// cursor got finished by someone else, so we're done
cc.release(); // if the collection/db is dropped, cc may be deleted
break;
}
}
return num;
}
示例5: getIndex
IndexDescriptor* getIndex(const BSONObj& obj, Collection* coll) {
NamespaceDetails* nsd = coll->details();
int idxNo = nsd->findIndexByKeyPattern(obj);
return coll->getIndexCatalog()->getDescriptor( idxNo );
}
示例6: buildStages
PlanStage* buildStages(const QuerySolution& qsol, const QuerySolutionNode* root, WorkingSet* ws, bool use_chronos = false) {
if (STAGE_COLLSCAN == root->getType()) {
const CollectionScanNode* csn = static_cast<const CollectionScanNode*>(root);
CollectionScanParams params;
params.ns = csn->name;
params.tailable = csn->tailable;
params.direction = (csn->direction == 1) ? CollectionScanParams::FORWARD
: CollectionScanParams::BACKWARD;
params.maxScan = csn->maxScan;
return new CollectionScan(params, ws, csn->filter.get(), use_chronos);
}
else if (STAGE_IXSCAN == root->getType()) {
const IndexScanNode* ixn = static_cast<const IndexScanNode*>(root);
//
// XXX XXX
// Given that this grabs data from the catalog, we must do this inside of a lock.
// We should change this to take a (ns, index key pattern) pair so that the params
// don't involve any on-disk data, just descriptions thereof.
// XXX XXX
//
Database* db = cc().database();
Collection* collection = db ? db->getCollection(qsol.ns) : NULL;
if (NULL == collection) {
warning() << "Can't ixscan null ns " << qsol.ns << endl;
return NULL;
}
NamespaceDetails* nsd = collection->details();
int idxNo = nsd->findIndexByKeyPattern(ixn->indexKeyPattern);
if (-1 == idxNo) {
warning() << "Can't find idx " << ixn->indexKeyPattern.toString()
<< "in ns " << qsol.ns << endl;
return NULL;
}
IndexScanParams params;
params.descriptor = collection->getIndexCatalog()->getDescriptor( idxNo );
params.bounds = ixn->bounds;
params.direction = ixn->direction;
params.limit = ixn->limit;
params.maxScan = ixn->maxScan;
params.addKeyMetadata = ixn->addKeyMetadata;
params.ns = qsol.ns;
return new IndexScan(params, ws, ixn->filter.get(), use_chronos);
}
else if (STAGE_FETCH == root->getType()) {
const FetchNode* fn = static_cast<const FetchNode*>(root);
PlanStage* childStage = buildStages(qsol, fn->children[0], ws);
if (NULL == childStage) { return NULL; }
return new FetchStage(ws, childStage, fn->filter.get());
}
else if (STAGE_SORT == root->getType()) {
const SortNode* sn = static_cast<const SortNode*>(root);
PlanStage* childStage = buildStages(qsol, sn->children[0], ws);
if (NULL == childStage) { return NULL; }
SortStageParams params;
params.pattern = sn->pattern;
params.query = sn->query;
params.limit = sn->limit;
return new SortStage(params, ws, childStage);
}
else if (STAGE_PROJECTION == root->getType()) {
const ProjectionNode* pn = static_cast<const ProjectionNode*>(root);
PlanStage* childStage = buildStages(qsol, pn->children[0], ws);
if (NULL == childStage) { return NULL; }
return new ProjectionStage(pn->projection, pn->fullExpression, ws, childStage);
}
else if (STAGE_LIMIT == root->getType()) {
const LimitNode* ln = static_cast<const LimitNode*>(root);
PlanStage* childStage = buildStages(qsol, ln->children[0], ws);
if (NULL == childStage) { return NULL; }
return new LimitStage(ln->limit, ws, childStage);
}
else if (STAGE_SKIP == root->getType()) {
const SkipNode* sn = static_cast<const SkipNode*>(root);
PlanStage* childStage = buildStages(qsol, sn->children[0], ws);
if (NULL == childStage) { return NULL; }
return new SkipStage(sn->skip, ws, childStage);
}
else if (STAGE_AND_HASH == root->getType()) {
const AndHashNode* ahn = static_cast<const AndHashNode*>(root);
auto_ptr<AndHashStage> ret(new AndHashStage(ws, ahn->filter.get()));
for (size_t i = 0; i < ahn->children.size(); ++i) {
PlanStage* childStage = buildStages(qsol, ahn->children[i], ws);
if (NULL == childStage) { return NULL; }
ret->addChild(childStage);
}
return ret.release();
}
else if (STAGE_OR == root->getType()) {
const OrNode * orn = static_cast<const OrNode*>(root);
auto_ptr<OrStage> ret(new OrStage(ws, orn->dedup, orn->filter.get()));
for (size_t i = 0; i < orn->children.size(); ++i) {
PlanStage* childStage = buildStages(qsol, orn->children[i], ws);
if (NULL == childStage) { return NULL; }
ret->addChild(childStage);
}
return ret.release();
}
else if (STAGE_AND_SORTED == root->getType()) {
const AndSortedNode* asn = static_cast<const AndSortedNode*>(root);
auto_ptr<AndSortedStage> ret(new AndSortedStage(ws, asn->filter.get()));
//.........这里部分代码省略.........
示例7: getIndex
IndexDescriptor* getIndex(const BSONObj& obj) {
Client::ReadContext ctx(ns());
NamespaceDetails* nsd = nsdetails(ns());
int idxNo = nsd->findIndexByKeyPattern(obj);
return CatalogHack::getDescriptor(nsd, idxNo);
}
示例8: parseQuery
PlanStage* parseQuery(const string& dbname, BSONObj obj, WorkingSet* workingSet,
OwnedPointerVector<MatchExpression>* exprs) {
BSONElement firstElt = obj.firstElement();
if (!firstElt.isABSONObj()) { return NULL; }
BSONObj paramObj = firstElt.Obj();
MatchExpression* matcher = NULL;
BSONObj nodeArgs;
// Every node has these two fields.
const string filterTag = "filter";
const string argsTag = "args";
BSONObjIterator it(paramObj);
while (it.more()) {
BSONElement e = it.next();
if (!e.isABSONObj()) { return NULL; }
BSONObj argObj = e.Obj();
if (filterTag == e.fieldName()) {
StatusWithMatchExpression swme = MatchExpressionParser::parse(argObj);
if (!swme.isOK()) { return NULL; }
// exprs is what will wind up deleting this.
matcher = swme.getValue();
verify(NULL != matcher);
exprs->mutableVector().push_back(matcher);
}
else if (argsTag == e.fieldName()) {
nodeArgs = argObj;
}
else {
uasserted(16910, "Unknown fieldname " + string(e.fieldName())
+ " in query node " + obj.toString());
return NULL;
}
}
string nodeName = firstElt.fieldName();
if ("ixscan" == nodeName) {
NamespaceDetails* nsd = nsdetails(dbname + "." + nodeArgs["name"].String());
uassert(16913, "Can't find collection " + nodeArgs["name"].String(), nsd);
int idxNo = nsd->findIndexByKeyPattern(nodeArgs["keyPattern"].Obj());
uassert(16890, "Can't find index: " + nodeArgs["keyPattern"].Obj().toString(),
idxNo != -1);
IndexScanParams params;
params.descriptor = CatalogHack::getDescriptor(nsd, idxNo);
params.startKey = nodeArgs["startKey"].Obj();
params.endKey = nodeArgs["endKey"].Obj();
params.endKeyInclusive = nodeArgs["endKeyInclusive"].Bool();
params.direction = nodeArgs["direction"].numberInt();
params.limit = nodeArgs["limit"].numberInt();
params.forceBtreeAccessMethod = false;
return new IndexScan(params, workingSet, matcher);
}
else if ("andHash" == nodeName) {
uassert(16921, "Nodes argument must be provided to AND",
nodeArgs["nodes"].isABSONObj());
auto_ptr<AndHashStage> andStage(new AndHashStage(workingSet, matcher));
int nodesAdded = 0;
BSONObjIterator it(nodeArgs["nodes"].Obj());
while (it.more()) {
BSONElement e = it.next();
uassert(16922, "node of AND isn't an obj?: " + e.toString(),
e.isABSONObj());
PlanStage* subNode = parseQuery(dbname, e.Obj(), workingSet, exprs);
uassert(16923, "Can't parse sub-node of AND: " + e.Obj().toString(),
NULL != subNode);
// takes ownership
andStage->addChild(subNode);
++nodesAdded;
}
uassert(16927, "AND requires more than one child", nodesAdded >= 2);
return andStage.release();
}
else if ("andSorted" == nodeName) {
uassert(16924, "Nodes argument must be provided to AND",
nodeArgs["nodes"].isABSONObj());
auto_ptr<AndSortedStage> andStage(new AndSortedStage(workingSet,
matcher));
int nodesAdded = 0;
BSONObjIterator it(nodeArgs["nodes"].Obj());
while (it.more()) {
BSONElement e = it.next();
uassert(16925, "node of AND isn't an obj?: " + e.toString(),
e.isABSONObj());
PlanStage* subNode = parseQuery(dbname, e.Obj(), workingSet, exprs);
uassert(16926, "Can't parse sub-node of AND: " + e.Obj().toString(),
NULL != subNode);
// takes ownership
//.........这里部分代码省略.........
示例9: buildStages
PlanStage* buildStages(const string& ns, const QuerySolutionNode* root, WorkingSet* ws) {
if (STAGE_COLLSCAN == root->getType()) {
const CollectionScanNode* csn = static_cast<const CollectionScanNode*>(root);
CollectionScanParams params;
params.ns = csn->name;
params.tailable = csn->tailable;
params.direction = (csn->direction == 1) ? CollectionScanParams::FORWARD
: CollectionScanParams::BACKWARD;
return new CollectionScan(params, ws, csn->filter.get());
}
else if (STAGE_IXSCAN == root->getType()) {
const IndexScanNode* ixn = static_cast<const IndexScanNode*>(root);
//
// XXX XXX
// Given that this grabs data from the catalog, we must do this inside of a lock.
// We should change this to take a (ns, index key pattern) pair so that the params
// don't involve any on-disk data, just descriptions thereof.
// XXX XXX
//
IndexScanParams params;
NamespaceDetails* nsd = nsdetails(ns.c_str());
if (NULL == nsd) {
warning() << "Can't ixscan null ns " << ns << endl;
return NULL;
}
int idxNo = nsd->findIndexByKeyPattern(ixn->indexKeyPattern);
if (-1 == idxNo) {
warning() << "Can't find idx " << ixn->indexKeyPattern.toString()
<< "in ns " << ns << endl;
return NULL;
}
params.descriptor = CatalogHack::getDescriptor(nsd, idxNo);
params.bounds = ixn->bounds;
params.direction = ixn->direction;
params.limit = ixn->limit;
return new IndexScan(params, ws, ixn->filter.get());
}
else if (STAGE_FETCH == root->getType()) {
const FetchNode* fn = static_cast<const FetchNode*>(root);
PlanStage* childStage = buildStages(ns, fn->child.get(), ws);
if (NULL == childStage) { return NULL; }
return new FetchStage(ws, childStage, fn->filter.get());
}
else if (STAGE_SORT == root->getType()) {
const SortNode* sn = static_cast<const SortNode*>(root);
PlanStage* childStage = buildStages(ns, sn->child.get(), ws);
if (NULL == childStage) { return NULL; }
SortStageParams params;
params.pattern = sn->pattern;
return new SortStage(params, ws, childStage);
}
else if (STAGE_PROJECTION == root->getType()) {
const ProjectionNode* pn = static_cast<const ProjectionNode*>(root);
PlanStage* childStage = buildStages(ns, pn->child.get(), ws);
if (NULL == childStage) { return NULL; }
return new ProjectionStage(pn->projection, ws, childStage, NULL);
}
else if (STAGE_LIMIT == root->getType()) {
const LimitNode* ln = static_cast<const LimitNode*>(root);
PlanStage* childStage = buildStages(ns, ln->child.get(), ws);
if (NULL == childStage) { return NULL; }
return new LimitStage(ln->limit, ws, childStage);
}
else if (STAGE_SKIP == root->getType()) {
const SkipNode* sn = static_cast<const SkipNode*>(root);
PlanStage* childStage = buildStages(ns, sn->child.get(), ws);
if (NULL == childStage) { return NULL; }
return new SkipStage(sn->skip, ws, childStage);
}
else if (STAGE_AND_HASH == root->getType()) {
const AndHashNode* ahn = static_cast<const AndHashNode*>(root);
auto_ptr<AndHashStage> ret(new AndHashStage(ws, ahn->filter.get()));
for (size_t i = 0; i < ahn->children.size(); ++i) {
PlanStage* childStage = buildStages(ns, ahn->children[i], ws);
if (NULL == childStage) { return NULL; }
ret->addChild(childStage);
}
return ret.release();
}
else if (STAGE_OR == root->getType()) {
const OrNode * orn = static_cast<const OrNode*>(root);
auto_ptr<OrStage> ret(new OrStage(ws, orn->dedup, orn->filter.get()));
for (size_t i = 0; i < orn->children.size(); ++i) {
PlanStage* childStage = buildStages(ns, orn->children[i], ws);
if (NULL == childStage) { return NULL; }
ret->addChild(childStage);
}
return ret.release();
}
else if (STAGE_AND_SORTED == root->getType()) {
const AndSortedNode* asn = static_cast<const AndSortedNode*>(root);
auto_ptr<AndSortedStage> ret(new AndSortedStage(ws, asn->filter.get()));
for (size_t i = 0; i < asn->children.size(); ++i) {
PlanStage* childStage = buildStages(ns, asn->children[i], ws);
if (NULL == childStage) { return NULL; }
ret->addChild(childStage);
}
return ret.release();
}
else if (STAGE_SORT_MERGE == root->getType()) {
//.........这里部分代码省略.........
示例10: removeRange
long long Helpers::removeRange( const string& ns ,
const BSONObj& min ,
const BSONObj& max ,
const BSONObj& keyPattern ,
bool maxInclusive ,
bool secondaryThrottle ,
RemoveCallback * callback,
bool fromMigrate ) {
Client& c = cc();
long long numDeleted = 0;
PageFaultRetryableSection pgrs;
long long millisWaitingForReplication = 0;
while ( 1 ) {
try {
Client::WriteContext ctx(ns);
scoped_ptr<Cursor> c;
{
NamespaceDetails* nsd = nsdetails( ns.c_str() );
if ( ! nsd )
break;
int ii = nsd->findIndexByKeyPattern( keyPattern );
verify( ii >= 0 );
IndexDetails& i = nsd->idx( ii );
// Extend min to get (min, MinKey, MinKey, ....)
BSONObj newMin = Helpers::modifiedRangeBound( min , keyPattern , -1 );
// If upper bound is included, extend max to get (max, MaxKey, MaxKey, ...)
// If not included, extend max to get (max, MinKey, MinKey, ....)
int minOrMax = maxInclusive ? 1 : -1;
BSONObj newMax = Helpers::modifiedRangeBound( max , keyPattern , minOrMax );
c.reset( BtreeCursor::make( nsd , ii , i , newMin , newMax , maxInclusive , 1 ) );
}
if ( ! c->ok() ) {
// we're done
break;
}
DiskLoc rloc = c->currLoc();
BSONObj obj = c->current();
// this is so that we don't have to handle this cursor in the delete code
c.reset(0);
if ( callback )
callback->goingToDelete( obj );
logOp( "d" , ns.c_str() , rloc.obj()["_id"].wrap() , 0 , 0 , fromMigrate );
theDataFileMgr.deleteRecord(ns.c_str() , rloc.rec(), rloc);
numDeleted++;
}
catch( PageFaultException& e ) {
e.touch();
continue;
}
Timer secondaryThrottleTime;
if ( secondaryThrottle ) {
if ( ! waitForReplication( c.getLastOp(), 2, 60 /* seconds to wait */ ) ) {
warning() << "replication to secondaries for removeRange at least 60 seconds behind" << endl;
}
millisWaitingForReplication += secondaryThrottleTime.millis();
}
if ( ! Lock::isLocked() ) {
int micros = ( 2 * Client::recommendedYieldMicros() ) - secondaryThrottleTime.micros();
if ( micros > 0 ) {
LOG(1) << "Helpers::removeRangeUnlocked going to sleep for " << micros << " micros" << endl;
sleepmicros( micros );
}
}
}
if ( secondaryThrottle )
log() << "Helpers::removeRangeUnlocked time spent waiting for replication: "
<< millisWaitingForReplication << "ms" << endl;
return numDeleted;
}