~ubuntu-branches/ubuntu/utopic/mongodb/utopic

« back to all changes in this revision

Viewing changes to src/mongo/db/btreeposition.cpp

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-07-03 09:23:46 UTC
  • mfrom: (1.3.10) (44.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20140703092346-c5bvt46wnzougyly
Tags: 1:2.6.3-0ubuntu1
* New upstream stable release:
  - Dropped patches, included upstream:
    + 0003-All-platforms-but-Windows-find-hash-in-std-tr1.patch
    + 0008-Use-system-libstemmer.patch
    + 0011-Use-a-signed-char-to-store-BSONType-enumerations.patch
    + 0001-SERVER-12064-Atomic-operations-for-gcc-non-Intel-arc.patch
    + 0002-SERVER-12065-Support-ARM-and-AArch64-builds.patch
  - d/p/*: Refreshed/rebased remaining patches.
  - Use system provided libyaml-cpp:
    + d/control: Add libyaml-cpp-dev to BD's.
    + d/rules: Enable --with-system-yaml option.
    + d/p/fix-yaml-detection.patch: Fix detection of libyaml-cpp library.
  - d/mongodb-server.mongodb.upstart: Sync changes from upstream.
  - d/control,mongodb-dev.*: Drop mongodb-dev package; it has no reverse
    dependencies and upstream no longer install header files.
  - d/NEWS: Point users to upstream upgrade documentation for upgrades
    from 2.4 to 2.6.
* Merge from Debian unstable.
* d/control: BD on libv8-3.14-dev to ensure that transitioning to new v8
  versions is a explicit action due to changes in behaviour in >= 3.25
  (LP: #1295723).
* d/mongodb-server.prerm: Dropped debug echo call from maintainer script
  (LP: #1294455).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 *    Copyright (C) 2012 10gen Inc.
3
 
 *
4
 
 *    This program is free software: you can redistribute it and/or  modify
5
 
 *    it under the terms of the GNU Affero General Public License, version 3,
6
 
 *    as published by the Free Software Foundation.
7
 
 *
8
 
 *    This program is distributed in the hope that it will be useful,
9
 
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
 *    GNU Affero General Public License for more details.
12
 
 *
13
 
 *    You should have received a copy of the GNU Affero General Public License
14
 
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
 */
16
 
 
17
 
#include "mongo/db/btreeposition.h"
18
 
 
19
 
#include "mongo/db/btree.h"
20
 
#include "mongo/db/index.h"
21
 
#include "mongo/db/pdfile.h"
22
 
 
23
 
namespace mongo {
24
 
 
25
 
    std::ostream& operator<<( std::ostream& stream, const BtreeKeyLocation& loc ) {
26
 
        return stream << BSON( "bucket" << loc.bucket.toString() <<
27
 
                               "index" << loc.pos ).jsonString();
28
 
    }
29
 
 
30
 
    LogicalBtreePosition::LogicalBtreePosition( const IndexDetails& indexDetails,
31
 
                                                Ordering ordering,
32
 
                                                const BtreeKeyLocation& initialLocation ) :
33
 
        _indexDetails( &indexDetails ),
34
 
        _ordering( ordering ),
35
 
        _initialLocation( initialLocation ),
36
 
        _initialLocationValid() {
37
 
        fassert( 16494, _indexDetails->version() == 1 );
38
 
    }
39
 
 
40
 
    void LogicalBtreePosition::init() {
41
 
        if ( _initialLocation.bucket.isNull() ) {
42
 
            // Abort if the initial location is not a valid bucket.
43
 
            return;
44
 
        }
45
 
 
46
 
        // Store the key and record referenced at the supplied initial location.
47
 
        BucketBasics<V1>::KeyNode keyNode =
48
 
                _initialLocation.bucket.btree<V1>()->keyNode( _initialLocation.pos );
49
 
        _key = keyNode.key.toBson().getOwned();
50
 
        _record = keyNode.recordLoc;
51
 
        _initialLocationValid = true;
52
 
    }
53
 
 
54
 
    BtreeKeyLocation LogicalBtreePosition::currentLocation() const {
55
 
        if ( _initialLocation.bucket.isNull() ) {
56
 
            // Abort if the initial location is not a valid bucket.
57
 
            return BtreeKeyLocation();
58
 
        }
59
 
 
60
 
        // If the initial location has not been invalidated ...
61
 
        if ( _initialLocationValid ) {
62
 
 
63
 
            const BtreeBucket<V1>* bucket = _initialLocation.bucket.btree<V1>();
64
 
            if ( // ... and the bucket was not marked as invalid ...
65
 
                 bucket->getN() != bucket->INVALID_N_SENTINEL &&
66
 
                 // ... and the initial location index is valid for the bucket ...
67
 
                 _initialLocation.pos < bucket->getN() ) {
68
 
 
69
 
                BucketBasics<V1>::KeyNode keyNode = bucket->keyNode( _initialLocation.pos );
70
 
                if ( // ... and the record location equals the initial record location ...
71
 
                     keyNode.recordLoc == _record &&
72
 
                     // ... and the key equals the initial key ...
73
 
                     keyNode.key.toBson().binaryEqual( _key ) ) {
74
 
                    // ... then the initial location is the current location, so return it.
75
 
                    return _initialLocation;
76
 
                }
77
 
            }
78
 
        }
79
 
 
80
 
        // Relocate the key and record location retrieved from _initialLocation.
81
 
        BtreeKeyLocation ret;
82
 
        bool found;
83
 
        ret.bucket = _indexDetails->head.btree<V1>()->locate( *_indexDetails,
84
 
                                                              _indexDetails->head,
85
 
                                                              _key,
86
 
                                                              _ordering,
87
 
                                                              ret.pos,
88
 
                                                              found,
89
 
                                                              _record,
90
 
                                                              1 // Forward direction means the next
91
 
                                                                // ordered key will be returned if
92
 
                                                                // the requested key is missing.
93
 
                                                             );
94
 
        return ret;
95
 
    }
96
 
 
97
 
} // namespace mongo