本文整理汇总了C++中NamespaceDetails::idx方法的典型用法代码示例。如果您正苦于以下问题:C++ NamespaceDetails::idx方法的具体用法?C++ NamespaceDetails::idx怎么用?C++ NamespaceDetails::idx使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NamespaceDetails
的用法示例。
在下文中一共展示了NamespaceDetails::idx方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setHead
void IndexCatalogEntry::setHead( DiskLoc newHead ) {
NamespaceDetails* nsd = _collection->detailsWritable();
int idxNo = _indexNo();
IndexDetails& id = nsd->idx( idxNo );
id.head.writing() = newHead;
_head = newHead;
}
示例2: findById
bool Helpers::findById(Client& c, const char *ns, BSONObj query, BSONObj& result ,
bool * nsFound , bool * indexFound ) {
Lock::assertAtLeastReadLocked(ns);
Database *database = c.database();
verify( database );
NamespaceDetails *d = database->namespaceIndex.details(ns);
if ( ! d )
return false;
if ( nsFound )
*nsFound = 1;
int idxNo = d->findIdIndex();
if ( idxNo < 0 )
return false;
if ( indexFound )
*indexFound = 1;
IndexDetails& i = d->idx( idxNo );
BSONObj key = i.getKeyFromQuery( query );
DiskLoc loc = QueryRunner::fastFindSingle(i, key);
if ( loc.isNull() )
return false;
result = loc.obj();
return true;
}
示例3: newQueryOptimizerCursor
shared_ptr<Cursor> NamespaceDetailsTransient::getCursor( const char *ns, const BSONObj &query, const BSONObj &order ) {
if ( query.isEmpty() && order.isEmpty() ) {
// TODO This will not use a covered index currently.
return theDataFileMgr.findAll( ns );
}
if ( isSimpleIdQuery( query ) ) {
Database *database = cc().database();
assert( database );
NamespaceDetails *d = database->namespaceIndex.details(ns);
if ( d ) {
int idxNo = d->findIdIndex();
if ( idxNo >= 0 ) {
IndexDetails& i = d->idx( idxNo );
BSONObj key = i.getKeyFromQuery( query );
return shared_ptr<Cursor>( BtreeCursor::make( d, idxNo, i, key, key, true, 1 ) );
}
}
}
auto_ptr<MultiPlanScanner> mps( new MultiPlanScanner( ns, query, order ) ); // mayYield == false
shared_ptr<Cursor> single = mps->singleCursor();
if ( single ) {
if ( !query.isEmpty() && !single->matcher() ) {
shared_ptr<CoveredIndexMatcher> matcher( new CoveredIndexMatcher( query, single->indexKeyPattern() ) );
single->setMatcher( matcher );
}
return single;
}
return newQueryOptimizerCursor( mps );
}
示例4: dupCheck
void dupCheck(vector<IndexChanges>& v, NamespaceDetails& d, DiskLoc curObjLoc) {
int z = d.nIndexesBeingBuilt();
for( int i = 0; i < z; i++ ) {
IndexDetails& idx = d.idx(i);
v[i].dupCheck(idx, curObjLoc);
}
}
示例5: 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;
}
示例6: run
bool run(const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
string ns = dbname + "." + cmdObj.firstElement().valuestr();
NamespaceDetails *d = nsdetails(ns);
if (NULL == d) {
errmsg = "can't find ns";
return false;
}
GeoNearArguments commonArgs(cmdObj);
if (commonArgs.numWanted < 0) {
errmsg = "numWanted must be >= 0";
return false;
}
vector<int> idxs;
d->findIndexByType("2d", idxs);
if (idxs.size() > 1) {
errmsg = "more than one 2d index, not sure which to run geoNear on";
return false;
}
if (1 == idxs.size()) {
result.append("ns", ns);
return run2DGeoNear(d->idx(idxs[0]), cmdObj, commonArgs, errmsg, result);
}
d->findIndexByType("2dsphere", idxs);
if (idxs.size() > 1) {
errmsg = "more than one 2dsphere index, not sure which to run geoNear on";
return false;
}
if (1 == idxs.size()) {
result.append("ns", ns);
return run2DSphereGeoNear(d->idx(idxs[0]), cmdObj, commonArgs, errmsg, result);
}
errmsg = "no geo indices for geoNear";
return false;
}
示例7: renameCollection
Status Database::renameCollection( const StringData& fromNS, const StringData& toNS,
bool stayTemp ) {
// move data namespace
Status s = _renameSingleNamespace( fromNS, toNS, stayTemp );
if ( !s.isOK() )
return s;
NamespaceDetails* details = _namespaceIndex.details( toNS );
verify( details );
// move index namespaces
string indexName = _name + ".system.indexes";
BSONObj oldIndexSpec;
while( Helpers::findOne( indexName, BSON( "ns" << fromNS ), oldIndexSpec ) ) {
oldIndexSpec = oldIndexSpec.getOwned();
BSONObj newIndexSpec;
{
BSONObjBuilder b;
BSONObjIterator i( oldIndexSpec );
while( i.more() ) {
BSONElement e = i.next();
if ( strcmp( e.fieldName(), "ns" ) != 0 )
b.append( e );
else
b << "ns" << toNS;
}
newIndexSpec = b.obj();
}
DiskLoc newIndexSpecLoc = theDataFileMgr.insert( indexName.c_str(),
newIndexSpec.objdata(),
newIndexSpec.objsize(),
false,
true,
false );
int indexI = details->findIndexByName( oldIndexSpec.getStringField( "name" ) );
IndexDetails &indexDetails = details->idx(indexI);
string oldIndexNs = indexDetails.indexNamespace();
indexDetails.info = newIndexSpecLoc;
string newIndexNs = indexDetails.indexNamespace();
Status s = _renameSingleNamespace( oldIndexNs, newIndexNs, false );
if ( !s.isOK() )
return s;
deleteObjects( indexName.c_str(), oldIndexSpec, true, false, true );
}
Top::global.collectionDropped( fromNS.toString() );
return Status::OK();
}
示例8: addOtherPlans
void QueryPlanSet::addOtherPlans( bool checkFirst ) {
const char *ns = _frsp->ns();
NamespaceDetails *d = nsdetails( ns );
if ( !d )
return;
// If table scan is optimal or natural order requested or tailable cursor requested
if ( !_frsp->matchPossible() || ( _frsp->noNontrivialRanges() && _order.isEmpty() ) ||
( !_order.isEmpty() && !strcmp( _order.firstElement().fieldName(), "$natural" ) ) ) {
// Table scan plan
addPlan( QueryPlanPtr( new QueryPlan( d, -1, *_frsp, *_originalFrsp, _originalQuery, _order ) ), checkFirst );
return;
}
bool normalQuery = _hint.isEmpty() && _min.isEmpty() && _max.isEmpty();
PlanSet plans;
QueryPlanPtr optimalPlan;
for( int i = 0; i < d->nIndexes; ++i ) {
if ( normalQuery ) {
if ( !_frsp->matchPossibleForIndex( d, i, d->idx( i ).keyPattern() ) ) {
// If no match is possible, only generate a trival plan that won't
// scan any documents.
QueryPlanPtr p( new QueryPlan( d, i, *_frsp, *_originalFrsp, _originalQuery, _order ) );
addPlan( p, checkFirst );
return;
}
if ( !QueryUtilIndexed::indexUseful( *_frsp, d, i, _order ) ) {
continue;
}
}
QueryPlanPtr p( new QueryPlan( d, i, *_frsp, *_originalFrsp, _originalQuery, _order ) );
if ( p->optimal() ) {
if ( !optimalPlan.get() ) {
optimalPlan = p;
}
}
else if ( !p->unhelpful() ) {
plans.push_back( p );
}
}
if ( optimalPlan.get() ) {
addPlan( optimalPlan, checkFirst );
return;
}
for( PlanSet::iterator i = plans.begin(); i != plans.end(); ++i )
addPlan( *i, checkFirst );
// Table scan plan
addPlan( QueryPlanPtr( new QueryPlan( d, -1, *_frsp, *_originalFrsp, _originalQuery, _order ) ), checkFirst );
}
示例9: run
bool run(const string& dbname, BSONObj& cmdObj, int,
string& errmsg, BSONObjBuilder& result, bool fromRepl) {
string ns = dbname + "." + cmdObj.firstElement().valuestr();
NamespaceDetails *nsd = nsdetails(ns);
if (NULL == nsd) {
errmsg = "can't find ns";
return false;
}
vector<int> idxs;
nsd->findIndexByType(GEOSEARCHNAME, idxs);
if (idxs.size() == 0) {
errmsg = "no geoSearch index";
return false;
}
if (idxs.size() > 1) {
errmsg = "more than 1 geosearch index";
return false;
}
BSONElement nearElt = cmdObj["near"];
BSONElement maxDistance = cmdObj["maxDistance"];
BSONElement search = cmdObj["search"];
uassert(13318, "near needs to be an array", nearElt.isABSONObj());
uassert(13319, "maxDistance needs a number", maxDistance.isNumber());
uassert(13320, "search needs to be an object", search.type() == Object);
unsigned limit = 50;
if (cmdObj["limit"].isNumber())
limit = static_cast<unsigned>(cmdObj["limit"].numberInt());
int idxNum = idxs[0];
IndexDetails& id = nsd->idx(idxNum);
if (CatalogHack::testIndexMigration()) {
auto_ptr<IndexDescriptor> desc(CatalogHack::getDescriptor(nsd, idxNum));
auto_ptr<HaystackAccessMethod> ham(new HaystackAccessMethod(desc.get()));
ham->searchCommand(nearElt.Obj(), maxDistance.numberDouble(), search.Obj(),
&result, limit);
} else {
GeoHaystackSearchIndex *si =
static_cast<GeoHaystackSearchIndex*>(id.getSpec().getType());
verify(&id == si->getDetails());
si->searchCommand(nsd, nearElt.Obj(), maxDistance.numberDouble(), search.Obj(),
result, limit);
}
return 1;
}
示例10: 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;
}
示例11: checkDB
void IndexRebuilder::checkDB(const std::string& dbName, bool* firstTime) {
const std::string systemNS = dbName + ".system.namespaces";
DBDirectClient cli;
scoped_ptr<DBClientCursor> cursor(cli.query(systemNS, Query()));
// This depends on system.namespaces not changing while we iterate
while (cursor->more()) {
BSONObj nsDoc = cursor->next();
const char* ns = nsDoc["name"].valuestrsafe();
Client::WriteContext ctx(ns);
NamespaceDetails* nsd = nsdetails(ns);
if (!nsd || !nsd->indexBuildsInProgress) {
continue;
}
log() << "Found interrupted index build on " << ns << endl;
if (*firstTime) {
log() << "Restart the server with --noIndexBuildRetry to skip index rebuilds"
<< endl;
*firstTime = false;
}
// If the indexBuildRetry flag isn't set, just clear the inProg flag
if (!cmdLine.indexBuildRetry) {
// If we crash between unsetting the inProg flag and cleaning up the index, the
// index space will be lost.
int inProg = nsd->indexBuildsInProgress;
getDur().writingInt(nsd->indexBuildsInProgress) = 0;
for (int i = 0; i < inProg; i++) {
nsd->idx(nsd->nIndexes+i).kill_idx();
}
continue;
}
// We go from right to left building these indexes, so that indexBuildInProgress-- has
// the correct effect of "popping" an index off the list.
while (nsd->indexBuildsInProgress > 0) {
retryIndexBuild(dbName, nsd, nsd->nIndexes+nsd->indexBuildsInProgress-1);
}
}
}
示例12: getIndexChanges
void getIndexChanges(vector<IndexChanges>& v, NamespaceDetails& d, BSONObj newObj, BSONObj oldObj, bool &changedId) {
int z = d.nIndexesBeingBuilt();
v.resize(z);
for( int i = 0; i < z; i++ ) {
IndexDetails& idx = d.idx(i);
BSONObj idxKey = idx.info.obj().getObjectField("key"); // eg { ts : 1 }
IndexChanges& ch = v[i];
idx.getKeysFromObject(oldObj, ch.oldkeys);
idx.getKeysFromObject(newObj, ch.newkeys);
if( ch.newkeys.size() > 1 )
d.setIndexIsMultikey(i);
setDifference(ch.oldkeys, ch.newkeys, ch.removed);
setDifference(ch.newkeys, ch.oldkeys, ch.added);
if ( ch.removed.size() > 0 && ch.added.size() > 0 && idx.isIdIndex() ) {
changedId = true;
}
}
}
示例13: run
bool run(const string& dbname , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
string ns = dbname + "." + cmdObj.firstElement().valuestr();
NamespaceDetails * d = nsdetails( ns.c_str() );
if ( ! d ) {
errmsg = "can't find ns";
return false;
}
vector<int> idxs;
d->findIndexByType( GEOSEARCHNAME , idxs );
if ( idxs.size() == 0 ) {
errmsg = "no geoSearch index";
return false;
}
if ( idxs.size() > 1 ) {
errmsg = "more than 1 geosearch index";
return false;
}
int idxNum = idxs[0];
IndexDetails& id = d->idx( idxNum );
GeoHaystackSearchIndex * si = (GeoHaystackSearchIndex*)id.getSpec().getType();
verify( &id == si->getDetails() );
BSONElement n = cmdObj["near"];
BSONElement maxDistance = cmdObj["maxDistance"];
BSONElement search = cmdObj["search"];
uassert( 13318 , "near needs to be an array" , n.isABSONObj() );
uassert( 13319 , "maxDistance needs a number" , maxDistance.isNumber() );
uassert( 13320 , "search needs to be an object" , search.type() == Object );
unsigned limit = 50;
if ( cmdObj["limit"].isNumber() )
limit = (unsigned)cmdObj["limit"].numberInt();
si->searchCommand( d , idxNum , n.Obj() , maxDistance.numberDouble() , search.Obj() , result , limit );
return 1;
}
示例14: setArgumentsHint
void CursorGenerator::setArgumentsHint() {
if ( useHints && _parsedQuery ) {
_argumentsHint = _parsedQuery->getHint();
}
if ( snapshot() ) {
NamespaceDetails *d = nsdetails( _ns );
if ( d ) {
int i = d->findIdIndex();
if( i < 0 ) {
if ( _ns.find( ".system." ) == string::npos )
log() << "warning: no _id index on $snapshot query, ns:" << _ns << endl;
}
else {
/* [dm] the name of an _id index tends to vary, so we build the hint the hard
way here. probably need a better way to specify "use the _id index" as a hint.
if someone is in the query optimizer please fix this then!
*/
_argumentsHint = BSON( "$hint" << d->idx(i).indexName() );
}
}
}
}
示例15: cc
shared_ptr<Cursor> CursorGenerator::shortcutCursor() const {
if ( !mayShortcutQueryOptimizer() ) {
return shared_ptr<Cursor>();
}
if ( _planPolicy.permitOptimalNaturalPlan() && _query.isEmpty() && _order.isEmpty() ) {
return theDataFileMgr.findAll( _ns );
}
if ( _planPolicy.permitOptimalIdPlan() && isSimpleIdQuery( _query ) ) {
Database *database = cc().database();
verify( database );
NamespaceDetails *d = database->namespaceIndex.details( _ns );
if ( d ) {
int idxNo = d->findIdIndex();
if ( idxNo >= 0 ) {
IndexDetails& i = d->idx( idxNo );
BSONObj key = i.getKeyFromQuery( _query );
return shared_ptr<Cursor>( BtreeCursor::make( d, i, key, key, true, 1 ) );
}
}
}
return shared_ptr<Cursor>();
}