summaryrefslogtreecommitdiff
path: root/src/mongo/db/index/index_access_method.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_access_method.h
parent01965cf52bce6976637ecb8f4a622aeb05ab256a (diff)
downloadmongo-9c2ed42daa8fbbef4a919c21ec564e2db55e8d60.tar.gz
SERVER-18579: Clang-Format - reformat code, no comment reflow
Diffstat (limited to 'src/mongo/db/index/index_access_method.h')
-rw-r--r--src/mongo/db/index/index_access_method.h410
1 files changed, 205 insertions, 205 deletions
diff --git a/src/mongo/db/index/index_access_method.h b/src/mongo/db/index/index_access_method.h
index 3f311128a2e..5dc88d30d80 100644
--- a/src/mongo/db/index/index_access_method.h
+++ b/src/mongo/db/index/index_access_method.h
@@ -40,250 +40,250 @@
namespace mongo {
- class BSONObjBuilder;
- class MatchExpression;
- class UpdateTicket;
- struct InsertDeleteOptions;
+class BSONObjBuilder;
+class MatchExpression;
+class UpdateTicket;
+struct InsertDeleteOptions;
+
+/**
+ * An IndexAccessMethod is the interface through which all the mutation, lookup, and
+ * traversal of index entries is done. The class is designed so that the underlying index
+ * data structure is opaque to the caller.
+ *
+ * IndexAccessMethods for existing indices are obtained through the system catalog.
+ *
+ * We assume the caller has whatever locks required. This interface is not thread safe.
+ *
+ */
+class IndexAccessMethod {
+ MONGO_DISALLOW_COPYING(IndexAccessMethod);
+
+public:
+ IndexAccessMethod(IndexCatalogEntry* btreeState, SortedDataInterface* btree);
+ virtual ~IndexAccessMethod() {}
+
+ //
+ // Lookup, traversal, and mutation support
+ //
/**
- * An IndexAccessMethod is the interface through which all the mutation, lookup, and
- * traversal of index entries is done. The class is designed so that the underlying index
- * data structure is opaque to the caller.
- *
- * IndexAccessMethods for existing indices are obtained through the system catalog.
- *
- * We assume the caller has whatever locks required. This interface is not thread safe.
+ * Internally generate the keys {k1, ..., kn} for 'obj'. For each key k, insert (k ->
+ * 'loc') into the index. 'obj' is the object at the location 'loc'. If not NULL,
+ * 'numInserted' will be set to the number of keys added to the index for the document. If
+ * there is more than one key for 'obj', either all keys will be inserted or none will.
*
+ * The behavior of the insertion can be specified through 'options'.
*/
- class IndexAccessMethod {
- MONGO_DISALLOW_COPYING(IndexAccessMethod);
- public:
+ Status insert(OperationContext* txn,
+ const BSONObj& obj,
+ const RecordId& loc,
+ const InsertDeleteOptions& options,
+ int64_t* numInserted);
- IndexAccessMethod(IndexCatalogEntry* btreeState, SortedDataInterface* btree);
- virtual ~IndexAccessMethod() { }
+ /**
+ * Analogous to above, but remove the records instead of inserting them. If not NULL,
+ * numDeleted will be set to the number of keys removed from the index for the document.
+ */
+ Status remove(OperationContext* txn,
+ const BSONObj& obj,
+ const RecordId& loc,
+ const InsertDeleteOptions& options,
+ int64_t* numDeleted);
- //
- // Lookup, traversal, and mutation support
- //
+ /**
+ * Checks whether the index entries for the document 'from', which is placed at location
+ * 'loc' on disk, can be changed to the index entries for the doc 'to'. Provides a ticket
+ * for actually performing the update.
+ *
+ * Returns an error if the update is invalid. The ticket will also be marked as invalid.
+ * Returns OK if the update should proceed without error. The ticket is marked as valid.
+ *
+ * There is no obligation to perform the update after performing validation.
+ */
+ Status validateUpdate(OperationContext* txn,
+ const BSONObj& from,
+ const BSONObj& to,
+ const RecordId& loc,
+ const InsertDeleteOptions& options,
+ UpdateTicket* ticket,
+ const MatchExpression* indexFilter);
- /**
- * Internally generate the keys {k1, ..., kn} for 'obj'. For each key k, insert (k ->
- * 'loc') into the index. 'obj' is the object at the location 'loc'. If not NULL,
- * 'numInserted' will be set to the number of keys added to the index for the document. If
- * there is more than one key for 'obj', either all keys will be inserted or none will.
- *
- * The behavior of the insertion can be specified through 'options'.
- */
- Status insert(OperationContext* txn,
- const BSONObj& obj,
- const RecordId& loc,
- const InsertDeleteOptions& options,
- int64_t* numInserted);
+ /**
+ * Perform a validated update. The keys for the 'from' object will be removed, and the keys
+ * for the object 'to' will be added. Returns OK if the update succeeded, failure if it did
+ * not. If an update does not succeed, the index will be unmodified, and the keys for
+ * 'from' will remain. Assumes that the index has not changed since validateUpdate was
+ * called. If the index was changed, we may return an error, as our ticket may have been
+ * invalidated.
+ */
+ Status update(OperationContext* txn, const UpdateTicket& ticket, int64_t* numUpdated);
- /**
- * Analogous to above, but remove the records instead of inserting them. If not NULL,
- * numDeleted will be set to the number of keys removed from the index for the document.
- */
- Status remove(OperationContext* txn,
- const BSONObj& obj,
- const RecordId& loc,
- const InsertDeleteOptions& options,
- int64_t* numDeleted);
+ /**
+ * Returns an unpositioned cursor over 'this' index.
+ */
+ std::unique_ptr<SortedDataInterface::Cursor> newCursor(OperationContext* txn,
+ bool isForward = true) const;
- /**
- * Checks whether the index entries for the document 'from', which is placed at location
- * 'loc' on disk, can be changed to the index entries for the doc 'to'. Provides a ticket
- * for actually performing the update.
- *
- * Returns an error if the update is invalid. The ticket will also be marked as invalid.
- * Returns OK if the update should proceed without error. The ticket is marked as valid.
- *
- * There is no obligation to perform the update after performing validation.
- */
- Status validateUpdate(OperationContext* txn,
- const BSONObj& from,
- const BSONObj& to,
- const RecordId& loc,
- const InsertDeleteOptions& options,
- UpdateTicket* ticket,
- const MatchExpression* indexFilter);
+ // ------ index level operations ------
- /**
- * Perform a validated update. The keys for the 'from' object will be removed, and the keys
- * for the object 'to' will be added. Returns OK if the update succeeded, failure if it did
- * not. If an update does not succeed, the index will be unmodified, and the keys for
- * 'from' will remain. Assumes that the index has not changed since validateUpdate was
- * called. If the index was changed, we may return an error, as our ticket may have been
- * invalidated.
- */
- Status update(OperationContext* txn, const UpdateTicket& ticket, int64_t* numUpdated);
- /**
- * Returns an unpositioned cursor over 'this' index.
- */
- std::unique_ptr<SortedDataInterface::Cursor> newCursor(OperationContext* txn,
- bool isForward = true) const;
+ /**
+ * initializes this index
+ * only called once for the lifetime of the index
+ * if called multiple times, is an error
+ */
+ Status initializeAsEmpty(OperationContext* txn);
- // ------ index level operations ------
+ /**
+ * Try to page-in the pages that contain the keys generated from 'obj'.
+ * This can be used to speed up future accesses to an index by trying to ensure the
+ * appropriate pages are not swapped out.
+ * See prefetch.cpp.
+ */
+ Status touch(OperationContext* txn, const BSONObj& obj);
+ /**
+ * this pages in the entire index
+ */
+ Status touch(OperationContext* txn) const;
- /**
- * initializes this index
- * only called once for the lifetime of the index
- * if called multiple times, is an error
- */
- Status initializeAsEmpty(OperationContext* txn);
+ /**
+ * Walk the entire index, checking the internal structure for consistency.
+ * Set numKeys to the number of keys in the index.
+ *
+ * 'output' is used to store results of validate when 'full' is true.
+ * If 'full' is false, 'output' may be NULL.
+ *
+ * Return OK if the index is valid.
+ *
+ * Currently wasserts that the index is invalid. This could/should be changed in
+ * the future to return a Status.
+ */
+ Status validate(OperationContext* txn, bool full, int64_t* numKeys, BSONObjBuilder* output);
- /**
- * Try to page-in the pages that contain the keys generated from 'obj'.
- * This can be used to speed up future accesses to an index by trying to ensure the
- * appropriate pages are not swapped out.
- * See prefetch.cpp.
- */
- Status touch(OperationContext* txn, const BSONObj& obj);
+ /**
+ * Add custom statistics about this index to BSON object builder, for display.
+ *
+ * 'scale' is a scaling factor to apply to all byte statistics.
+ *
+ * Returns true if stats were appended.
+ */
+ bool appendCustomStats(OperationContext* txn, BSONObjBuilder* result, double scale) const;
- /**
- * this pages in the entire index
- */
- Status touch(OperationContext* txn) const;
+ /**
+ * @return The number of bytes consumed by this index.
+ * Exactly what is counted is not defined based on padding, re-use, etc...
+ */
+ long long getSpaceUsedBytes(OperationContext* txn) const;
- /**
- * Walk the entire index, checking the internal structure for consistency.
- * Set numKeys to the number of keys in the index.
- *
- * 'output' is used to store results of validate when 'full' is true.
- * If 'full' is false, 'output' may be NULL.
- *
- * Return OK if the index is valid.
- *
- * Currently wasserts that the index is invalid. This could/should be changed in
- * the future to return a Status.
- */
- Status validate(OperationContext* txn, bool full, int64_t* numKeys, BSONObjBuilder* output);
+ RecordId findSingle(OperationContext* txn, const BSONObj& key) const;
- /**
- * Add custom statistics about this index to BSON object builder, for display.
- *
- * 'scale' is a scaling factor to apply to all byte statistics.
- *
- * Returns true if stats were appended.
- */
- bool appendCustomStats(OperationContext* txn, BSONObjBuilder* result, double scale) const;
+ //
+ // Bulk operations support
+ //
+ class BulkBuilder {
+ public:
/**
- * @return The number of bytes consumed by this index.
- * Exactly what is counted is not defined based on padding, re-use, etc...
+ * Insert into the BulkBuilder as-if inserting into an IndexAccessMethod.
*/
- long long getSpaceUsedBytes( OperationContext* txn ) const;
-
- RecordId findSingle( OperationContext* txn, const BSONObj& key ) const;
-
- //
- // Bulk operations support
- //
-
- class BulkBuilder {
- public:
- /**
- * Insert into the BulkBuilder as-if inserting into an IndexAccessMethod.
- */
- Status insert(OperationContext* txn,
- const BSONObj& obj,
- const RecordId& loc,
- const InsertDeleteOptions& options,
- int64_t* numInserted);
+ Status insert(OperationContext* txn,
+ const BSONObj& obj,
+ const RecordId& loc,
+ const InsertDeleteOptions& options,
+ int64_t* numInserted);
- private:
- friend class IndexAccessMethod;
+ private:
+ friend class IndexAccessMethod;
- using Sorter = mongo::Sorter<BSONObj, RecordId>;
+ using Sorter = mongo::Sorter<BSONObj, RecordId>;
- BulkBuilder(const IndexAccessMethod* index, const IndexDescriptor* descriptor);
+ BulkBuilder(const IndexAccessMethod* index, const IndexDescriptor* descriptor);
- std::unique_ptr<Sorter> _sorter;
- const IndexAccessMethod* _real;
- int64_t _keysInserted = 0;
- bool _isMultiKey = false;
- };
+ std::unique_ptr<Sorter> _sorter;
+ const IndexAccessMethod* _real;
+ int64_t _keysInserted = 0;
+ bool _isMultiKey = false;
+ };
- /**
- * Starts a bulk operation.
- * You work on the returned BulkBuilder and then call commitBulk.
- * This can return NULL, meaning bulk mode is not available.
- *
- * It is only legal to initiate bulk when the index is new and empty.
- */
- std::unique_ptr<BulkBuilder> initiateBulk();
+ /**
+ * Starts a bulk operation.
+ * You work on the returned BulkBuilder and then call commitBulk.
+ * This can return NULL, meaning bulk mode is not available.
+ *
+ * It is only legal to initiate bulk when the index is new and empty.
+ */
+ std::unique_ptr<BulkBuilder> initiateBulk();
- /**
- * Call this when you are ready to finish your bulk work.
- * Pass in the BulkBuilder returned from initiateBulk.
- * @param bulk - something created from initiateBulk
- * @param mayInterrupt - is this commit interruptable (will cancel)
- * @param dupsAllowed - if false, error or fill 'dups' if any duplicate values are found
- * @param dups - if NULL, error out on dups if not allowed
- * if not NULL, put the bad RecordIds there
- */
- Status commitBulk(OperationContext* txn,
- std::unique_ptr<BulkBuilder> bulk,
- bool mayInterrupt,
- bool dupsAllowed,
- std::set<RecordId>* dups);
+ /**
+ * Call this when you are ready to finish your bulk work.
+ * Pass in the BulkBuilder returned from initiateBulk.
+ * @param bulk - something created from initiateBulk
+ * @param mayInterrupt - is this commit interruptable (will cancel)
+ * @param dupsAllowed - if false, error or fill 'dups' if any duplicate values are found
+ * @param dups - if NULL, error out on dups if not allowed
+ * if not NULL, put the bad RecordIds there
+ */
+ Status commitBulk(OperationContext* txn,
+ std::unique_ptr<BulkBuilder> bulk,
+ bool mayInterrupt,
+ bool dupsAllowed,
+ std::set<RecordId>* dups);
- /**
- * Fills 'keys' with the keys that should be generated for 'obj' on this index.
- */
- virtual void getKeys(const BSONObj &obj, BSONObjSet *keys) const = 0;
+ /**
+ * Fills 'keys' with the keys that should be generated for 'obj' on this index.
+ */
+ virtual void getKeys(const BSONObj& obj, BSONObjSet* keys) const = 0;
- protected:
- // Determines whether it's OK to ignore ErrorCodes::KeyTooLong for this OperationContext
- bool ignoreKeyTooLong(OperationContext* txn);
+protected:
+ // Determines whether it's OK to ignore ErrorCodes::KeyTooLong for this OperationContext
+ bool ignoreKeyTooLong(OperationContext* txn);
- IndexCatalogEntry* _btreeState; // owned by IndexCatalogEntry
- const IndexDescriptor* _descriptor;
+ IndexCatalogEntry* _btreeState; // owned by IndexCatalogEntry
+ const IndexDescriptor* _descriptor;
- private:
- void removeOneKey(OperationContext* txn,
- const BSONObj& key,
- const RecordId& loc,
- bool dupsAllowed);
+private:
+ void removeOneKey(OperationContext* txn,
+ const BSONObj& key,
+ const RecordId& loc,
+ bool dupsAllowed);
- const std::unique_ptr<SortedDataInterface> _newInterface;
- };
+ const std::unique_ptr<SortedDataInterface> _newInterface;
+};
- /**
- * Updates are two steps: verify that it's a valid update, and perform it.
- * validateUpdate fills out the UpdateStatus and update actually applies it.
- */
- class UpdateTicket {
- // No public interface
- private:
- friend class IndexAccessMethod;
+/**
+ * Updates are two steps: verify that it's a valid update, and perform it.
+ * validateUpdate fills out the UpdateStatus and update actually applies it.
+ */
+class UpdateTicket {
+ // No public interface
+private:
+ friend class IndexAccessMethod;
- bool _isValid;
+ bool _isValid;
- BSONObjSet oldKeys;
- BSONObjSet newKeys;
+ BSONObjSet oldKeys;
+ BSONObjSet newKeys;
- // These point into the sets oldKeys and newKeys.
- std::vector<BSONObj*> removed;
- std::vector<BSONObj*> added;
+ // These point into the sets oldKeys and newKeys.
+ std::vector<BSONObj*> removed;
+ std::vector<BSONObj*> added;
- RecordId loc;
- bool dupsAllowed;
- };
+ RecordId loc;
+ bool dupsAllowed;
+};
- /**
- * Flags we can set for inserts and deletes (and updates, which are kind of both).
- */
- struct InsertDeleteOptions {
- InsertDeleteOptions() : logIfError(false), dupsAllowed(false) { }
+/**
+ * Flags we can set for inserts and deletes (and updates, which are kind of both).
+ */
+struct InsertDeleteOptions {
+ InsertDeleteOptions() : logIfError(false), dupsAllowed(false) {}
- // If there's an error, log() it.
- bool logIfError;
+ // If there's an error, log() it.
+ bool logIfError;
- // Are duplicate keys allowed in the index?
- bool dupsAllowed;
- };
+ // Are duplicate keys allowed in the index?
+ bool dupsAllowed;
+};
} // namespace mongo