summaryrefslogtreecommitdiff
path: root/src/mongo/db/index/index_descriptor.h
diff options
context:
space:
mode:
authorMark Benvenuto <mark.benvenuto@mongodb.com>2015-06-20 00:22:50 -0400
committerMark Benvenuto <mark.benvenuto@mongodb.com>2015-06-20 10:56:02 -0400
commit9c2ed42daa8fbbef4a919c21ec564e2db55e8d60 (patch)
tree3814f79c10d7b490948d8cb7b112ac1dd41ceff1 /src/mongo/db/index/index_descriptor.h
parent01965cf52bce6976637ecb8f4a622aeb05ab256a (diff)
downloadmongo-9c2ed42daa8fbbef4a919c21ec564e2db55e8d60.tar.gz
SERVER-18579: Clang-Format - reformat code, no comment reflow
Diffstat (limited to 'src/mongo/db/index/index_descriptor.h')
-rw-r--r--src/mongo/db/index/index_descriptor.h372
1 files changed, 203 insertions, 169 deletions
diff --git a/src/mongo/db/index/index_descriptor.h b/src/mongo/db/index/index_descriptor.h
index 742e5a3ea16..2bceb9aeb0a 100644
--- a/src/mongo/db/index/index_descriptor.h
+++ b/src/mongo/db/index/index_descriptor.h
@@ -39,181 +39,215 @@
namespace mongo {
- class IndexCatalog;
- class IndexCatalogEntry;
- class IndexCatalogEntryContainer;
+class IndexCatalog;
+class IndexCatalogEntry;
+class IndexCatalogEntryContainer;
+/**
+ * A cache of information computed from the memory-mapped per-index data (OnDiskIndexData).
+ * Contains accessors for the various immutable index parameters, and an accessor for the
+ * mutable "head" pointer which is index-specific.
+ *
+ * All synchronization is the responsibility of the caller.
+ */
+class IndexDescriptor {
+public:
/**
- * A cache of information computed from the memory-mapped per-index data (OnDiskIndexData).
- * Contains accessors for the various immutable index parameters, and an accessor for the
- * mutable "head" pointer which is index-specific.
- *
- * All synchronization is the responsibility of the caller.
+ * OnDiskIndexData is a pointer to the memory mapped per-index data.
+ * infoObj is a copy of the index-describing BSONObj contained in the OnDiskIndexData.
*/
- class IndexDescriptor {
- public:
- /**
- * OnDiskIndexData is a pointer to the memory mapped per-index data.
- * infoObj is a copy of the index-describing BSONObj contained in the OnDiskIndexData.
- */
- IndexDescriptor(Collection* collection, const std::string& accessMethodName, BSONObj infoObj)
- : _magic(123987),
- _collection(collection),
- _accessMethodName(accessMethodName),
- _infoObj(infoObj.getOwned()),
- _numFields(infoObj.getObjectField("key").nFields()),
- _keyPattern(infoObj.getObjectField("key").getOwned()),
- _indexName(infoObj.getStringField("name")),
- _parentNS(infoObj.getStringField("ns")),
- _isIdIndex(isIdIndexPattern( _keyPattern )),
- _sparse(infoObj["sparse"].trueValue()),
- _unique( _isIdIndex || infoObj["unique"].trueValue() ),
- _partial(!infoObj["partialFilterExpression"].eoo()),
- _cachedEntry( NULL )
- {
- _indexNamespace = makeIndexNamespace( _parentNS, _indexName );
-
- _version = 0;
- BSONElement e = _infoObj["v"];
- if ( e.isNumber() ) {
- _version = e.numberInt();
- }
- }
-
- ~IndexDescriptor() {
- _magic = 555;
- }
-
- //
- // Information about the key pattern.
- //
-
- /**
- * Return the user-provided index key pattern.
- * Example: {geo: "2dsphere", nonGeo: 1}
- * Example: {foo: 1, bar: -1}
- */
- const BSONObj& keyPattern() const { _checkOk(); return _keyPattern; }
-
- // How many fields do we index / are in the key pattern?
- int getNumFields() const { _checkOk(); return _numFields; }
-
- //
- // Information about the index's namespace / collection.
- //
-
- // Return the name of the index.
- const std::string& indexName() const { _checkOk(); return _indexName; }
-
- // Return the name of the indexed collection.
- const std::string& parentNS() const { return _parentNS; }
-
- // Return the name of this index's storage area (database.table.$index)
- const std::string& indexNamespace() const { return _indexNamespace; }
-
- // Return the name of the access method we must use to access this index's data.
- const std::string& getAccessMethodName() const { return _accessMethodName; }
-
- //
- // Properties every index has
- //
-
- // Return what version of index this is.
- int version() const { return _version; }
-
- // May each key only occur once?
- bool unique() const { return _unique; }
-
- // Is this index sparse?
- bool isSparse() const { return _sparse; }
-
- // Is this a partial index?
- bool isPartial() const { return _partial; }
-
- // Is this index multikey?
- bool isMultikey( OperationContext* txn ) const {
- _checkOk();
- return _collection->getIndexCatalog()->isMultikey( txn, this );
+ IndexDescriptor(Collection* collection, const std::string& accessMethodName, BSONObj infoObj)
+ : _magic(123987),
+ _collection(collection),
+ _accessMethodName(accessMethodName),
+ _infoObj(infoObj.getOwned()),
+ _numFields(infoObj.getObjectField("key").nFields()),
+ _keyPattern(infoObj.getObjectField("key").getOwned()),
+ _indexName(infoObj.getStringField("name")),
+ _parentNS(infoObj.getStringField("ns")),
+ _isIdIndex(isIdIndexPattern(_keyPattern)),
+ _sparse(infoObj["sparse"].trueValue()),
+ _unique(_isIdIndex || infoObj["unique"].trueValue()),
+ _partial(!infoObj["partialFilterExpression"].eoo()),
+ _cachedEntry(NULL) {
+ _indexNamespace = makeIndexNamespace(_parentNS, _indexName);
+
+ _version = 0;
+ BSONElement e = _infoObj["v"];
+ if (e.isNumber()) {
+ _version = e.numberInt();
}
+ }
- bool isIdIndex() const { _checkOk(); return _isIdIndex; }
-
- //
- // Properties that are Index-specific.
- //
-
- // Allow access to arbitrary fields in the per-index info object. Some indices stash
- // index-specific data there.
- BSONElement getInfoElement(const std::string& name) const { return _infoObj[name]; }
+ ~IndexDescriptor() {
+ _magic = 555;
+ }
- //
- // "Internals" of accessing the index, used by IndexAccessMethod(s).
- //
+ //
+ // Information about the key pattern.
+ //
- // Return a (rather compact) std::string representation.
- std::string toString() const { _checkOk(); return _infoObj.toString(); }
-
- // Return the info object.
- const BSONObj& infoObj() const { _checkOk(); return _infoObj; }
-
- // Both the collection and the catalog must outlive the IndexDescriptor
- const Collection* getCollection() const { return _collection; }
- const IndexCatalog* getIndexCatalog() const { return _collection->getIndexCatalog(); }
-
- bool areIndexOptionsEquivalent( const IndexDescriptor* other ) const;
-
- static bool isIdIndexPattern( const BSONObj &pattern ) {
- BSONObjIterator i(pattern);
- BSONElement e = i.next();
- //_id index must have form exactly {_id : 1} or {_id : -1}.
- //Allows an index of form {_id : "hashed"} to exist but
- //do not consider it to be the primary _id index
- if(! ( strcmp(e.fieldName(), "_id") == 0
- && (e.numberInt() == 1 || e.numberInt() == -1)))
- return false;
- return i.next().eoo();
- }
-
- static std::string makeIndexNamespace( StringData ns,
- StringData name ) {
- return ns.toString() + ".$" + name.toString();
- }
-
- private:
-
- void _checkOk() const;
-
- int _magic;
-
- // Related catalog information of the parent collection
- Collection* _collection;
-
- // What access method should we use for this index?
- std::string _accessMethodName;
-
- // The BSONObj describing the index. Accessed through the various members above.
- const BSONObj _infoObj;
-
- // --- cached data from _infoObj
-
- int64_t _numFields; // How many fields are indexed?
- BSONObj _keyPattern;
- std::string _indexName;
- std::string _parentNS;
- std::string _indexNamespace;
- bool _isIdIndex;
- bool _sparse;
- bool _unique;
- bool _partial;
- int _version;
-
- // only used by IndexCatalogEntryContainer to do caching for perf
- // users not allowed to touch, and not part of API
- IndexCatalogEntry* _cachedEntry;
-
- friend class IndexCatalog;
- friend class IndexCatalogEntry;
- friend class IndexCatalogEntryContainer;
- };
+ /**
+ * Return the user-provided index key pattern.
+ * Example: {geo: "2dsphere", nonGeo: 1}
+ * Example: {foo: 1, bar: -1}
+ */
+ const BSONObj& keyPattern() const {
+ _checkOk();
+ return _keyPattern;
+ }
+
+ // How many fields do we index / are in the key pattern?
+ int getNumFields() const {
+ _checkOk();
+ return _numFields;
+ }
+
+ //
+ // Information about the index's namespace / collection.
+ //
+
+ // Return the name of the index.
+ const std::string& indexName() const {
+ _checkOk();
+ return _indexName;
+ }
+
+ // Return the name of the indexed collection.
+ const std::string& parentNS() const {
+ return _parentNS;
+ }
+
+ // Return the name of this index's storage area (database.table.$index)
+ const std::string& indexNamespace() const {
+ return _indexNamespace;
+ }
+
+ // Return the name of the access method we must use to access this index's data.
+ const std::string& getAccessMethodName() const {
+ return _accessMethodName;
+ }
+
+ //
+ // Properties every index has
+ //
+
+ // Return what version of index this is.
+ int version() const {
+ return _version;
+ }
+
+ // May each key only occur once?
+ bool unique() const {
+ return _unique;
+ }
+
+ // Is this index sparse?
+ bool isSparse() const {
+ return _sparse;
+ }
+
+ // Is this a partial index?
+ bool isPartial() const {
+ return _partial;
+ }
+
+ // Is this index multikey?
+ bool isMultikey(OperationContext* txn) const {
+ _checkOk();
+ return _collection->getIndexCatalog()->isMultikey(txn, this);
+ }
+
+ bool isIdIndex() const {
+ _checkOk();
+ return _isIdIndex;
+ }
+
+ //
+ // Properties that are Index-specific.
+ //
+
+ // Allow access to arbitrary fields in the per-index info object. Some indices stash
+ // index-specific data there.
+ BSONElement getInfoElement(const std::string& name) const {
+ return _infoObj[name];
+ }
+
+ //
+ // "Internals" of accessing the index, used by IndexAccessMethod(s).
+ //
+
+ // Return a (rather compact) std::string representation.
+ std::string toString() const {
+ _checkOk();
+ return _infoObj.toString();
+ }
+
+ // Return the info object.
+ const BSONObj& infoObj() const {
+ _checkOk();
+ return _infoObj;
+ }
+
+ // Both the collection and the catalog must outlive the IndexDescriptor
+ const Collection* getCollection() const {
+ return _collection;
+ }
+ const IndexCatalog* getIndexCatalog() const {
+ return _collection->getIndexCatalog();
+ }
+
+ bool areIndexOptionsEquivalent(const IndexDescriptor* other) const;
+
+ static bool isIdIndexPattern(const BSONObj& pattern) {
+ BSONObjIterator i(pattern);
+ BSONElement e = i.next();
+ //_id index must have form exactly {_id : 1} or {_id : -1}.
+ // Allows an index of form {_id : "hashed"} to exist but
+ // do not consider it to be the primary _id index
+ if (!(strcmp(e.fieldName(), "_id") == 0 && (e.numberInt() == 1 || e.numberInt() == -1)))
+ return false;
+ return i.next().eoo();
+ }
+
+ static std::string makeIndexNamespace(StringData ns, StringData name) {
+ return ns.toString() + ".$" + name.toString();
+ }
+
+private:
+ void _checkOk() const;
+
+ int _magic;
+
+ // Related catalog information of the parent collection
+ Collection* _collection;
+
+ // What access method should we use for this index?
+ std::string _accessMethodName;
+
+ // The BSONObj describing the index. Accessed through the various members above.
+ const BSONObj _infoObj;
+
+ // --- cached data from _infoObj
+
+ int64_t _numFields; // How many fields are indexed?
+ BSONObj _keyPattern;
+ std::string _indexName;
+ std::string _parentNS;
+ std::string _indexNamespace;
+ bool _isIdIndex;
+ bool _sparse;
+ bool _unique;
+ bool _partial;
+ int _version;
+
+ // only used by IndexCatalogEntryContainer to do caching for perf
+ // users not allowed to touch, and not part of API
+ IndexCatalogEntry* _cachedEntry;
+
+ friend class IndexCatalog;
+ friend class IndexCatalogEntry;
+ friend class IndexCatalogEntryContainer;
+};
} // namespace mongo