本文整理汇总了C++中DiskLoc::obj方法的典型用法代码示例。如果您正苦于以下问题:C++ DiskLoc::obj方法的具体用法?C++ DiskLoc::obj怎么用?C++ DiskLoc::obj使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DiskLoc
的用法示例。
在下文中一共展示了DiskLoc::obj方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: matches
bool CoveredIndexMatcher::matches( const BSONObj& key, const DiskLoc& recLoc,
MatchDetails* details, bool keyUsable ) const {
LOG(5) << "CoveredIndexMatcher::matches() " << key.toString() << ' ' << recLoc.toString() << ' ' << keyUsable << endl;
dassert( key.isValid() );
if ( details )
details->resetOutput();
if ( keyUsable ) {
if ( !_keyMatcher.matches(key, details ) ) {
return false;
}
bool needRecordForDetails = details && details->needRecord();
if ( !_needRecord && !needRecordForDetails ) {
return true;
}
}
if ( details )
details->setLoadedRecord( true );
BSONObj obj = recLoc.obj();
bool res =
_docMatcher->matches( obj, details ) &&
!isOrClauseDup( obj );
LOG(5) << "CoveredIndexMatcher _docMatcher->matches() returns " << res << endl;
return res;
}
示例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: _repairExtent
DiskLoc _repairExtent( Database* db , string ns, bool forward , DiskLoc eLoc ){
LogIndentLevel lil;
if ( eLoc.getOfs() <= 0 ){
error() << "invalid extent ofs: " << eLoc.getOfs() << endl;
return DiskLoc();
}
MongoDataFile * mdf = db->getFile( eLoc.a() );
Extent * e = mdf->debug_getExtent( eLoc );
if ( ! e->isOk() ){
warning() << "Extent not ok magic: " << e->magic << " going to try to continue" << endl;
}
log() << "length:" << e->length << endl;
LogIndentLevel lil2;
DiskLoc loc = forward ? e->firstRecord : e->lastRecord;
while ( ! loc.isNull() ){
if ( loc.getOfs() <= 0 ){
error() << "offset is 0 for record which should be impossible" << endl;
break;
}
log() << loc << endl;
Record* rec = loc.rec();
log() << loc.obj() << endl;
loc = forward ? rec->getNext( loc ) : rec->getPrev( loc );
}
return forward ? e->xnext : e->xprev;
}
示例4: consider
// Consider the point in loc, and keep it if it's within _maxDistance (and we have space for
// it)
void consider(const DiskLoc& loc) {
if (limitReached()) return;
Point p(loc.obj().getFieldDotted(_geoField));
if (distance(_near, p) > _maxDistance)
return;
_locs.push_back(loc);
}
示例5: findOne
/* fetch a single object from collection ns that matches query
set your db SavedContext first
*/
bool Helpers::findOne(Collection* collection, const BSONObj &query, BSONObj& result, bool requireIndex) {
DiskLoc loc = findOne( collection, query, requireIndex );
if ( loc.isNull() )
return false;
result = loc.obj();
return true;
}
示例6: returnResults
PlanStage::StageState TextStage::returnResults(WorkingSetID* out) {
if (_scoreIterator == _scores.end()) {
_internalState = DONE;
return PlanStage::IS_EOF;
}
// Filter for phrases and negative terms, score and truncate.
DiskLoc loc = _scoreIterator->first;
double score = _scoreIterator->second;
_scoreIterator++;
// Ignore non-matched documents.
if (score < 0) {
return PlanStage::NEED_TIME;
}
// Filter for phrases and negated terms
if (_params.query.hasNonTermPieces()) {
if (!_ftsMatcher.matchesNonTerm(loc.obj())) {
return PlanStage::NEED_TIME;
}
}
*out = _ws->allocate();
WorkingSetMember* member = _ws->get(*out);
member->loc = loc;
member->obj = member->loc.obj();
member->state = WorkingSetMember::LOC_AND_UNOWNED_OBJ;
member->addComputed(new TextScoreComputedData(score));
return PlanStage::ADVANCED;
}
示例7: findOne
/* fetch a single object from collection ns that matches query
set your db SavedContext first
*/
bool Helpers::findOne(const StringData& ns, const BSONObj &query, BSONObj& result, bool requireIndex) {
DiskLoc loc = findOne( ns, query, requireIndex );
if ( loc.isNull() )
return false;
result = loc.obj();
return true;
}
示例8: 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;
}
示例9: reset
void IndexSpec::reset( const DiskLoc& loc ){
info = loc.obj();
keyPattern = info["key"].embeddedObjectUserCheck();
if ( keyPattern.objsize() == 0 ) {
out() << info.toString() << endl;
assert(false);
}
_init();
}
示例10: storeOpForSlave
void ClientCursor::storeOpForSlave( DiskLoc last ) {
if ( ! ( _queryOptions & QueryOption_OplogReplay ))
return;
if ( last.isNull() )
return;
BSONElement e = last.obj()["ts"];
if ( e.type() == Date || e.type() == Timestamp )
_slaveReadTill = e._opTime();
}
示例11: processRecord
/**
* analyzeDiskStorage helper which processes a single record.
*/
void processRecord(const DiskLoc& dl, const DiskLoc& prevDl, const Record* r, int extentOfs,
const AnalyzeParams& params, vector<DiskStorageData>& sliceData,
BSONArrayBuilder* recordsArrayBuilder) {
killCurrentOp.checkForInterrupt();
BSONObj obj = dl.obj();
int recBytes = r->lengthWithHeaders();
double characteristicFieldValue = 0;
bool hasCharacteristicField = extractCharacteristicFieldValue(obj, params,
characteristicFieldValue);
bool isLocatedBeforePrevious = dl.a() < prevDl.a();
RecPos pos = RecPos::from(dl.getOfs(), recBytes, extentOfs, params);
bool spansRequestedArea = false;
for (RecPos::SliceIterator it = pos.iterateSlices(); !it.end(); ++it) {
spansRequestedArea = true;
DiskStorageData& slice = sliceData[it->sliceNum];
slice.numEntries += it->ratioHere;
slice.recBytes += it->sizeHere;
slice.bsonBytes += static_cast<long long>(it->ratioHere * obj.objsize());
if (hasCharacteristicField) {
slice.characteristicCount += it->ratioHere;
slice.characteristicSum += it->ratioHere * characteristicFieldValue;
}
if (isLocatedBeforePrevious) {
slice.outOfOrderRecs += it->ratioHere;
}
}
if (recordsArrayBuilder != NULL && spansRequestedArea) {
DEV {
int startsAt = dl.getOfs() - extentOfs;
int endsAt = startsAt + recBytes;
verify((startsAt < params.startOfs && endsAt > params.startOfs) ||
(startsAt < params.endOfs && endsAt >= params.endOfs) ||
(startsAt >= params.startOfs && endsAt < params.endOfs));
}
BSONObjBuilder recordBuilder(recordsArrayBuilder->subobjStart());
recordBuilder.append("ofs", dl.getOfs() - extentOfs);
recordBuilder.append("recBytes", recBytes);
recordBuilder.append("bsonBytes", obj.objsize());
recordBuilder.append("_id", obj["_id"]);
if (hasCharacteristicField) {
recordBuilder.append("characteristic", characteristicFieldValue);
}
recordBuilder.doneFast();
}
示例12: 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;
}
示例13: removeOneKey
bool BtreeBasedAccessMethod::removeOneKey(const BSONObj& key, const DiskLoc& loc) {
bool ret = false;
try {
ret = _newInterface->unindex(key, loc);
} catch (AssertionException& e) {
problem() << "Assertion failure: _unindex failed "
<< _descriptor->indexNamespace() << endl;
out() << "Assertion failure: _unindex failed: " << e.what() << '\n';
out() << " obj:" << loc.obj().toString() << '\n';
out() << " key:" << key.toString() << '\n';
out() << " dl:" << loc.toString() << endl;
logContext();
}
return ret;
}
示例14: insert_makeIndex
/**
* @param loc the location in system.indexes where the index spec is
*/
void NOINLINE_DECL insert_makeIndex(Collection* collectionToIndex,
const DiskLoc& loc,
bool mayInterrupt) {
uassert(13143,
"can't create index on system.indexes",
collectionToIndex->ns().coll() != "system.indexes");
BSONObj info = loc.obj();
std::string idxName = info["name"].valuestr();
// Set curop description before setting indexBuildInProg, so that there's something
// commands can find and kill as soon as indexBuildInProg is set. Only set this if it's a
// killable index, so we don't overwrite commands in currentOp.
if (mayInterrupt) {
cc().curop()->setQuery(info);
}
IndexCatalog::IndexBuildBlock indexBuildBlock( collectionToIndex->getIndexCatalog(), idxName, loc );
verify( indexBuildBlock.indexDetails() );
try {
buildAnIndex( collectionToIndex->ns(), collectionToIndex->details(),
*indexBuildBlock.indexDetails(), mayInterrupt);
indexBuildBlock.success();
}
catch (DBException& e) {
// save our error msg string as an exception or dropIndexes will overwrite our message
LastError *le = lastError.get();
int savecode = 0;
string saveerrmsg;
if ( le ) {
savecode = le->code;
saveerrmsg = le->msg;
}
else {
savecode = e.getCode();
saveerrmsg = e.what();
}
verify(le && !saveerrmsg.empty());
setLastError(savecode,saveerrmsg.c_str());
throw;
}
}
示例15: remove
// Remove the provided doc from the index.
Status BtreeBasedAccessMethod::remove(const BSONObj &obj, const DiskLoc& loc,
const InsertDeleteOptions &options, int64_t* numDeleted) {
BSONObjSet keys;
getKeys(obj, &keys);
*numDeleted = 0;
for (BSONObjSet::const_iterator i = keys.begin(); i != keys.end(); ++i) {
bool thisKeyOK = removeOneKey(*i, loc);
if (thisKeyOK) {
++*numDeleted;
} else if (options.logIfError) {
log() << "unindex failed (key too big?) " << _descriptor->indexNamespace()
<< " key: " << *i << " " << loc.obj()["_id"] << endl;
}
}
return Status::OK();
}