コード例 #1
0
ファイル: btreecursor.cpp プロジェクト: tanfulai/mongo
    /* Since the last noteLocation(), our key may have moved around, and that old cached
       information may thus be stale and wrong (although often it is right).  We check
       that here; if we have moved, we have to search back for where we were at.

       i.e., after operations on the index, the BtreeCursor's cached location info may
       be invalid.  This function ensures validity, so you should call it before using
       the cursor if other writers have used the database since the last noteLocation
       call.
    */
    void BtreeCursor::checkLocation() {
        if ( eof() )
            return;

        if ( keyOfs >= 0 ) {
            BtreeBucket *b = bucket.btree();

            assert( !keyAtKeyOfs.isEmpty() );

            // Note keyAt() returns an empty BSONObj if keyOfs is now out of range,
            // which is possible as keys may have been deleted.
            if ( b->keyAt(keyOfs).woEqual(keyAtKeyOfs) &&
                    b->k(keyOfs).recordLoc == locAtKeyOfs ) {
                if ( !b->k(keyOfs).isUsed() ) {
                    /* we were deleted but still exist as an unused
                       marker key. advance.
                    */
                    skipUnusedKeys();
                }
                return;
            }
        }

        /* normally we don't get to here.  when we do, old position is no longer
            valid and we must refind where we left off (which is expensive)
        */

        bool found;

        /* TODO: Switch to keep indexdetails and do idx.head! */
        bucket = indexDetails.head.btree()->locate(indexDetails, indexDetails.head, keyAtKeyOfs, order, keyOfs, found, locAtKeyOfs, direction);
        RARELY log() << "  key seems to have moved in the index, refinding. found:" << found << endl;
        if ( found )
            skipUnusedKeys();
    }
コード例 #2
0
ファイル: btreecursor.cpp プロジェクト: Bamco/mongo
 void BtreeCursor::skipAndCheck() {
     long long startNscanned = _nscanned;
     skipUnusedKeys();
     while( 1 ) {
         if ( !skipOutOfRangeKeysAndCheckEnd() ) {
             break;
         }
         do {
             // If nscanned is increased by more than 20 before a matching key is found, abort
             // skipping through the btree to find a matching key.  This iteration cutoff
             // prevents unbounded internal iteration within BtreeCursor::init() and
             // BtreeCursor::advance() (the callers of skipAndCheck()).  See SERVER-3448.
             if ( _nscanned > startNscanned + 20 ) {
                 skipUnusedKeys();
                 // If iteration is aborted before a key matching _bounds is identified, the
                 // cursor may be left pointing at a key that is not within bounds
                 // (_bounds->matchesKey( currKey() ) may be false).  Set _boundsMustMatch to
                 // false accordingly.
                 _boundsMustMatch = false;
                 return;
             }
         } while( skipOutOfRangeKeysAndCheckEnd() );
         if ( !skipUnusedKeys() ) {
             break;
         }
     }
 }
コード例 #3
0
ファイル: btreecursor.cpp プロジェクト: FrancescaK/mongo
        /* Since the last noteLocation(), our key may have moved around, and that old cached
           information may thus be stale and wrong (although often it is right).  We check
           that here; if we have moved, we have to search back for where we were at.

           i.e., after operations on the index, the BtreeCursor's cached location info may
           be invalid.  This function ensures validity, so you should call it before using
           the cursor if other writers have used the database since the last noteLocation
           call.
        */
        void checkLocation() {
            if ( eof() )
                return;

            _multikey = d->isMultikey(idxNo);

            if ( keyOfs >= 0 ) {
                assert( !keyAtKeyOfs.isEmpty() );

                try {
                    // Note keyAt() returns an empty BSONObj if keyOfs is now out of range,
                    // which is possible as keys may have been deleted.
                    int x = 0;
                    while( 1 ) {
                        //  if ( b->keyAt(keyOfs).woEqual(keyAtKeyOfs) &&
                        //       b->k(keyOfs).recordLoc == locAtKeyOfs ) {
                        if ( keyAt(keyOfs).binaryEqual(keyAtKeyOfs) ) {
                            const _KeyNode& kn = keyNode(keyOfs);
                            if( kn.recordLoc == locAtKeyOfs ) {
                                if ( !kn.isUsed() ) {
                                    // we were deleted but still exist as an unused
                                    // marker key. advance.
                                    skipUnusedKeys();
                                }
                                return;
                            }
                        }

                        // we check one key earlier too, in case a key was just deleted.  this is
                        // important so that multi updates are reasonably fast.
                        if( keyOfs == 0 || x++ )
                            break;
                        keyOfs--;
                    }
                }
                catch(UserException& e) { 
                    if( e.getCode() != 15850 )
                        throw;
                    // hack: fall through if bucket was just deleted. should only happen under deleteObjects()
                    DEV log() << "debug info: bucket was deleted" << endl;
                }
            }

            /* normally we don't get to here.  when we do, old position is no longer
                valid and we must refind where we left off (which is expensive)
            */

            /* TODO: Switch to keep indexdetails and do idx.head! */
            bucket = _locate(keyAtKeyOfs, locAtKeyOfs);
            RARELY log() << "key seems to have moved in the index, refinding. " << bucket.toString() << endl;
            if ( ! bucket.isNull() )
                skipUnusedKeys();

        }
コード例 #4
0
ファイル: btreecursor.cpp プロジェクト: kapouer/mongo-debian
 void BtreeCursor::skipAndCheck() {
     skipUnusedKeys( true );
     while( 1 ) {
         if ( !skipOutOfRangeKeysAndCheckEnd() ) {
             break;
         }
         while( skipOutOfRangeKeysAndCheckEnd() );
         if ( !skipUnusedKeys( true ) ) {
             break;
         }
     }
 }
コード例 #5
0
ファイル: btreecursor.cpp プロジェクト: kapouer/mongo-debian
    /* Since the last noteLocation(), our key may have moved around, and that old cached
       information may thus be stale and wrong (although often it is right).  We check
       that here; if we have moved, we have to search back for where we were at.

       i.e., after operations on the index, the BtreeCursor's cached location info may
       be invalid.  This function ensures validity, so you should call it before using
       the cursor if other writers have used the database since the last noteLocation
       call.
    */
    void BtreeCursor::checkLocation() {
        if ( eof() )
            return;

        multikey = d->isMultikey(idxNo);

        if ( keyOfs >= 0 ) {
            BtreeBucket *b = bucket.btree();

            assert( !keyAtKeyOfs.isEmpty() );

            // Note keyAt() returns an empty BSONObj if keyOfs is now out of range,
            // which is possible as keys may have been deleted.
            int x = 0;
            while( 1 ) {
                if ( b->keyAt(keyOfs).woEqual(keyAtKeyOfs) &&
                    b->k(keyOfs).recordLoc == locAtKeyOfs ) {
                        if ( !b->k(keyOfs).isUsed() ) {
                            /* we were deleted but still exist as an unused
                            marker key. advance.
                            */
                            skipUnusedKeys( false );
                        }
                        return;
                }

                /* we check one key earlier too, in case a key was just deleted.  this is 
                   important so that multi updates are reasonably fast.
                   */
                if( keyOfs == 0 || x++ )
                    break;
                keyOfs--;
            }
        }

        /* normally we don't get to here.  when we do, old position is no longer
            valid and we must refind where we left off (which is expensive)
        */

        bool found;

        /* TODO: Switch to keep indexdetails and do idx.head! */
        bucket = indexDetails.head.btree()->locate(indexDetails, indexDetails.head, keyAtKeyOfs, _ordering, keyOfs, found, locAtKeyOfs, direction);
        RARELY log() << "  key seems to have moved in the index, refinding. found:" << found << endl;
        if ( ! bucket.isNull() )
            skipUnusedKeys( false );

    }
コード例 #6
0
    Status BtreeIndexCursor::seek(const vector<const BSONElement*>& position,
                                  const vector<bool>& inclusive) {
        pair<DiskLoc, int> ignored;

        // Bucket is modified by customLocate.  Seeks start @ the root, so we set _bucket to the
        // root here.
        _bucket = _descriptor->getHead();
        _keyOffset = 0;

        _interface->customLocate(
                _bucket,
                _keyOffset,
                _emptyObj,
                0,
                false,
                position,
                inclusive,
                _ordering,
                (int)_direction,
                ignored);

        skipUnusedKeys();

        return Status::OK();
    }
コード例 #7
0
ファイル: btreecursor.cpp プロジェクト: tanfulai/mongo
    BtreeCursor::BtreeCursor( const IndexDetails &_id, const BSONObj &_startKey, const BSONObj &_endKey, int _direction ) :
    startKey( _startKey ),
    endKey( _endKey ),
    indexDetails( _id ),
    order( _id.keyPattern() ),
    direction( _direction ) {
        bool found;
        if ( otherTraceLevel >= 12 ) {
            if ( otherTraceLevel >= 200 ) {
                out() << "::BtreeCursor() qtl>200.  validating entire index." << endl;
                indexDetails.head.btree()->fullValidate(indexDetails.head, order);
            }
            else {
                out() << "BTreeCursor(). dumping head bucket" << endl;
                indexDetails.head.btree()->dump();
            }
        }

        bucket = indexDetails.head.btree()->
        locate(indexDetails, indexDetails.head, startKey, order, keyOfs, found, direction > 0 ? minDiskLoc : maxDiskLoc, direction);
        
        skipUnusedKeys();
        
        checkEnd();         
    }
コード例 #8
0
ファイル: btreecursor.cpp プロジェクト: fes/mongo
 void BtreeCursor::init() {
     bool found;
     bucket = indexDetails.head.btree()->
     locate(indexDetails, indexDetails.head, startKey, order, keyOfs, found, direction > 0 ? minDiskLoc : maxDiskLoc, direction);
     
     skipUnusedKeys();
     
     checkEnd();         
 }
コード例 #9
0
ファイル: btreecursor.cpp プロジェクト: FrancescaK/mongo
 void BtreeCursor::skipAndCheck() {
     long long startNscanned = _nscanned;
     skipUnusedKeys();
     while( 1 ) {
         if ( !skipOutOfRangeKeysAndCheckEnd() ) {
             break;
         }
         do {
             if ( _nscanned > startNscanned + 20 ) {
                 skipUnusedKeys();
                 return;
             }
         } while( skipOutOfRangeKeysAndCheckEnd() );
         if ( !skipUnusedKeys() ) {
             break;
         }
     }
 }
コード例 #10
0
ファイル: btreecursor.cpp プロジェクト: tanfulai/mongo
 bool BtreeCursor::advance() {
     checkForInterrupt();
     if ( bucket.isNull() )
         return false;
     bucket = bucket.btree()->advance(bucket, keyOfs, direction, "BtreeCursor::advance");
     skipUnusedKeys();
     checkEnd();
     return !bucket.isNull();
 }
コード例 #11
0
ファイル: btreecursor.cpp プロジェクト: kapouer/mongo-debian
 void BtreeCursor::init() {
     if ( _spec.getType() ){
         startKey = _spec.getType()->fixKey( startKey );
         endKey = _spec.getType()->fixKey( endKey );
     }
     bool found;
     bucket = indexDetails.head.btree()->
         locate(indexDetails, indexDetails.head, startKey, _ordering, keyOfs, found, direction > 0 ? minDiskLoc : maxDiskLoc, direction);
     skipUnusedKeys( false );
     checkEnd();
 }
コード例 #12
0
ファイル: btreecursor.cpp プロジェクト: Ry4an/mongo
 void BtreeCursor::init() {
     if ( _spec.getType() ) {
         startKey = _spec.getType()->fixKey( startKey );
         endKey = _spec.getType()->fixKey( endKey );
     }
     bucket = _locate(startKey, _direction > 0 ? minDiskLoc : maxDiskLoc);
     if ( ok() ) {
         _nscanned = 1;
     }
     skipUnusedKeys();
     checkEnd();
 }
コード例 #13
0
ファイル: btree_index_cursor.cpp プロジェクト: Ecako/mongo
Status BtreeIndexCursor::restorePosition() {
    // _keyOffset could be -1 if the bucket was deleted.  When buckets are deleted, the
    // Btree calls a clientcursor function that calls down to all BTree buckets.  Really,
    // this deletion thing should be kept BTree-internal.
    if (_keyOffset >= 0) {
        verify(!_savedKey.isEmpty());

        try {
            if (isSavedPositionValid()) {
                return Status::OK();
            }
            if (_keyOffset > 0) {
                --_keyOffset;
                // "we check one key earlier too, in case a key was just deleted.  this is
                // important so that multi updates are reasonably fast." -- btreecursor.cpp
                if (isSavedPositionValid()) {
                    return Status::OK();
                }
            }
            // Object isn't at the saved position.  Fall through to calling seek.
        } catch (UserException& e) {
            // deletedBucketCode is what keyAt throws if the bucket was deleted.  Not a
            // problem...
            if (BtreeInterface::deletedBucketCode != e.getCode()) {
                return e.toStatus();
            }
            // Our bucket was deleted, so we look for the saved key.
            DEV log() << "debug info: bucket was deleted" << endl;
        }
    }

    // Our old position was invalidated (keyOfs was set to -1) or our saved position
    // is no longer valid, so we must re-find.
    RARELY log() << "key seems to have moved in the index, refinding. "
                 << _bucket.toString() << endl;

    bool found;

    // Why don't we just call seek?  Because we want to pass _savedLoc.
    _bucket = _interface->locate(
                  _descriptor->getOnDisk(),
                  _descriptor->getHead(),
                  _savedKey,
                  _ordering,
                  _keyOffset,
                  found,
                  _savedLoc,
                  _direction);

    skipUnusedKeys();

    return Status::OK();
}
コード例 #14
0
ファイル: btreecursor.cpp プロジェクト: FrancescaK/mongo
 void BtreeCursor::initWithoutIndependentFieldRanges() {
     if ( indexDetails.getSpec().getType() ) {
         startKey = indexDetails.getSpec().getType()->fixKey( startKey );
         endKey = indexDetails.getSpec().getType()->fixKey( endKey );
     }
     bucket = _locate(startKey, _direction > 0 ? minDiskLoc : maxDiskLoc);
     if ( ok() ) {
         _nscanned = 1;
     }
     skipUnusedKeys();
     checkEnd();
 }
コード例 #15
0
ファイル: btreecursor.cpp プロジェクト: fes/mongo
 bool BtreeCursor::advance() {
     checkForInterrupt();
     if ( bucket.isNull() )
         return false;
     bucket = bucket.btree()->advance(bucket, keyOfs, direction, "BtreeCursor::advance");
     skipUnusedKeys();
     checkEnd();
     while( !ok() && ++boundIndex_ < bounds_.size() ) {
         startKey = bounds_[ boundIndex_ ].first;
         endKey = bounds_[ boundIndex_ ].second;
         init();
     }
     return !bucket.isNull();
 }
コード例 #16
0
ファイル: btreecursor.cpp プロジェクト: kapouer/mongo-debian
    bool BtreeCursor::advance() {
        killCurrentOp.checkForInterrupt();
        if ( bucket.isNull() )
            return false;

        bucket = bucket.btree()->advance(bucket, keyOfs, direction, "BtreeCursor::advance");

        if ( !_independentFieldRanges ) {
            skipUnusedKeys( false );
            checkEnd();
            return ok();
        }
        
        skipAndCheck();
        return ok();
    }
コード例 #17
0
    Status BtreeIndexCursor::skip(const vector<const BSONElement*>& position,
            const vector<bool>& inclusive) {
        _interface->advanceTo(
                _bucket,
                _keyOffset,
                _emptyObj,
                0,
                false,
                position,
                inclusive,
                _ordering,
                (int)_direction);

        skipUnusedKeys();

        return Status::OK();
    }
コード例 #18
0
    bool BtreeIndexCursor::isSavedPositionValid() {
        // We saved the key.  If it's in the same position we saved it from...
        if (_interface->keyAt(_bucket, _keyOffset).binaryEqual(_savedKey)) {
            // And the record it points to is the same record...
            if (_interface->recordAt(_bucket, _keyOffset) == _savedLoc) {
                // Success!  We found it.  However!
                if (!_interface->keyIsUsed(_bucket, _keyOffset)) {
                    // We could have been deleted but still exist as a "vacant" key, so skip
                    // over any unused keys.
                    skipUnusedKeys();
                }
                return true;
            }
        }

        return false;
    }
コード例 #19
0
ファイル: btree_index_cursor.cpp プロジェクト: Ecako/mongo
Status BtreeIndexCursor::seek(const BSONObj& position) {
    // Unused out parameter.
    bool found;

    _bucket = _interface->locate(
                  _descriptor->getOnDisk(),
                  _descriptor->getHead(),
                  position,
                  _ordering,
                  _keyOffset,
                  found,
                  1 == _direction ? minDiskLoc : maxDiskLoc,
                  _direction);

    skipUnusedKeys();

    return Status::OK();
}
コード例 #20
0
ファイル: btreecursor.cpp プロジェクト: FrancescaK/mongo
    bool BtreeCursor::advance() {
        killCurrentOp.checkForInterrupt();
        if ( bucket.isNull() )
            return false;

        bucket = _advance(bucket, keyOfs, _direction, "BtreeCursor::advance");

        if ( !_independentFieldRanges ) {
            skipUnusedKeys();
            checkEnd();
            if ( ok() ) {
                ++_nscanned;
            }
        }
        else {
            skipAndCheck();
        }
        return ok();
    }
コード例 #21
0
ファイル: btreecursor.cpp プロジェクト: Bamco/mongo
    bool BtreeCursor::advance() {
        // Reset this flag at the start of a new iteration.
        _boundsMustMatch = true;

        killCurrentOp.checkForInterrupt();
        if ( bucket.isNull() )
            return false;
        
        bucket = _advance(bucket, keyOfs, _direction, "BtreeCursor::advance");
        
        if ( !_independentFieldRanges ) {
            skipUnusedKeys();
            checkEnd();
            if ( ok() ) {
                ++_nscanned;
            }
        }
        else {
            skipAndCheck();
        }
        return ok();
    }
コード例 #22
0
 void BtreeIndexCursor::next() { advance("BtreeIndexCursor::next"); skipUnusedKeys(); }