summaryrefslogtreecommitdiff
path: root/src/mongo/db/catalog/index_create.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/catalog/index_create.h
parent01965cf52bce6976637ecb8f4a622aeb05ab256a (diff)
downloadmongo-9c2ed42daa8fbbef4a919c21ec564e2db55e8d60.tar.gz
SERVER-18579: Clang-Format - reformat code, no comment reflow
Diffstat (limited to 'src/mongo/db/catalog/index_create.h')
-rw-r--r--src/mongo/db/catalog/index_create.h348
1 files changed, 178 insertions, 170 deletions
diff --git a/src/mongo/db/catalog/index_create.h b/src/mongo/db/catalog/index_create.h
index f4be38710cd..d3dccb20b46 100644
--- a/src/mongo/db/catalog/index_create.h
+++ b/src/mongo/db/catalog/index_create.h
@@ -42,189 +42,197 @@
namespace mongo {
- class BackgroundOperation;
- class BSONObj;
- class Collection;
- class OperationContext;
+class BackgroundOperation;
+class BSONObj;
+class Collection;
+class OperationContext;
+
+/**
+ * Builds one or more indexes.
+ *
+ * If any method other than insert() returns a not-ok Status, this MultiIndexBlock should be
+ * considered failed and must be destroyed.
+ *
+ * If a MultiIndexBlock is destroyed before commit() or if commit() is rolled back, it will
+ * clean up all traces of the indexes being constructed. MultiIndexBlocks should not be
+ * destructed from inside of a WriteUnitOfWork as any cleanup needed should never be rolled back
+ * (as it is itself essentially a form of rollback, you don't want to "rollback the rollback").
+ */
+class MultiIndexBlock {
+ MONGO_DISALLOW_COPYING(MultiIndexBlock);
+
+public:
+ /**
+ * Neither pointer is owned.
+ */
+ MultiIndexBlock(OperationContext* txn, Collection* collection);
+ ~MultiIndexBlock();
+
+ /**
+ * By default we ignore the 'background' flag in specs when building an index. If this is
+ * called before init(), we will build the indexes in the background as long as *all* specs
+ * call for background indexing. If any spec calls for foreground indexing all indexes will
+ * be built in the foreground, as there is no concurrency benefit to building a subset of
+ * indexes in the background, but there is a performance benefit to building all in the
+ * foreground.
+ */
+ void allowBackgroundBuilding() {
+ _buildInBackground = true;
+ }
/**
- * Builds one or more indexes.
+ * Call this before init() to allow the index build to be interrupted.
+ * This only affects builds using the insertAllDocumentsInCollection helper.
+ */
+ void allowInterruption() {
+ _allowInterruption = true;
+ }
+
+ /**
+ * By default we enforce the 'unique' flag in specs when building an index by failing.
+ * If this is called before init(), we will ignore unique violations. This has no effect if
+ * no specs are unique.
*
- * If any method other than insert() returns a not-ok Status, this MultiIndexBlock should be
- * considered failed and must be destroyed.
+ * If this is called, any dupsOut sets passed in will never be filled.
+ */
+ void ignoreUniqueConstraint() {
+ _ignoreUnique = true;
+ }
+
+ /**
+ * Removes pre-existing indexes from 'specs'. If this isn't done, init() may fail with
+ * IndexAlreadyExists.
+ */
+ void removeExistingIndexes(std::vector<BSONObj>* specs) const;
+
+ /**
+ * Prepares the index(es) for building.
*
- * If a MultiIndexBlock is destroyed before commit() or if commit() is rolled back, it will
- * clean up all traces of the indexes being constructed. MultiIndexBlocks should not be
- * destructed from inside of a WriteUnitOfWork as any cleanup needed should never be rolled back
- * (as it is itself essentially a form of rollback, you don't want to "rollback the rollback").
+ * Does not need to be called inside of a WriteUnitOfWork (but can be due to nesting).
+ *
+ * Requires holding an exclusive database lock.
*/
- class MultiIndexBlock {
- MONGO_DISALLOW_COPYING( MultiIndexBlock );
- public:
- /**
- * Neither pointer is owned.
- */
- MultiIndexBlock(OperationContext* txn, Collection* collection);
- ~MultiIndexBlock();
-
- /**
- * By default we ignore the 'background' flag in specs when building an index. If this is
- * called before init(), we will build the indexes in the background as long as *all* specs
- * call for background indexing. If any spec calls for foreground indexing all indexes will
- * be built in the foreground, as there is no concurrency benefit to building a subset of
- * indexes in the background, but there is a performance benefit to building all in the
- * foreground.
- */
- void allowBackgroundBuilding() { _buildInBackground = true; }
-
- /**
- * Call this before init() to allow the index build to be interrupted.
- * This only affects builds using the insertAllDocumentsInCollection helper.
- */
- void allowInterruption() { _allowInterruption = true; }
-
- /**
- * By default we enforce the 'unique' flag in specs when building an index by failing.
- * If this is called before init(), we will ignore unique violations. This has no effect if
- * no specs are unique.
- *
- * If this is called, any dupsOut sets passed in will never be filled.
- */
- void ignoreUniqueConstraint() { _ignoreUnique = true; }
-
- /**
- * Removes pre-existing indexes from 'specs'. If this isn't done, init() may fail with
- * IndexAlreadyExists.
- */
- void removeExistingIndexes(std::vector<BSONObj>* specs) const;
-
- /**
- * Prepares the index(es) for building.
- *
- * Does not need to be called inside of a WriteUnitOfWork (but can be due to nesting).
- *
- * Requires holding an exclusive database lock.
- */
- Status init(const std::vector<BSONObj>& specs);
- Status init(const BSONObj& spec) {
- return init(std::vector<BSONObj>(1, spec));
- }
+ Status init(const std::vector<BSONObj>& specs);
+ Status init(const BSONObj& spec) {
+ return init(std::vector<BSONObj>(1, spec));
+ }
+
+ /**
+ * Inserts all documents in the Collection into the indexes and logs with timing info.
+ *
+ * This is a simplified replacement for insert and doneInserting. Do not call this if you
+ * are calling either of them.
+ *
+ * If dupsOut is passed as non-NULL, violators of uniqueness constraints will be added to
+ * the set rather than failing the build. Documents added to this set are not indexed, so
+ * callers MUST either fail this index build or delete the documents from the collection.
+ *
+ * Can throw an exception if interrupted.
+ *
+ * Should not be called inside of a WriteUnitOfWork.
+ */
+ Status insertAllDocumentsInCollection(std::set<RecordId>* dupsOut = NULL);
- /**
- * Inserts all documents in the Collection into the indexes and logs with timing info.
- *
- * This is a simplified replacement for insert and doneInserting. Do not call this if you
- * are calling either of them.
- *
- * If dupsOut is passed as non-NULL, violators of uniqueness constraints will be added to
- * the set rather than failing the build. Documents added to this set are not indexed, so
- * callers MUST either fail this index build or delete the documents from the collection.
- *
- * Can throw an exception if interrupted.
- *
- * Should not be called inside of a WriteUnitOfWork.
- */
- Status insertAllDocumentsInCollection(std::set<RecordId>* dupsOut = NULL);
-
- /**
- * Call this after init() for each document in the collection.
- *
- * Do not call if you called insertAllDocumentsInCollection();
- *
- * Should be called inside of a WriteUnitOfWork.
- */
- Status insert(const BSONObj& wholeDocument, const RecordId& loc);
-
- /**
- * Call this after the last insert(). This gives the index builder a chance to do any
- * long-running operations in separate units of work from commit().
- *
- * Do not call if you called insertAllDocumentsInCollection();
- *
- * If dupsOut is passed as non-NULL, violators of uniqueness constraints will be added to
- * the set. Documents added to this set are not indexed, so callers MUST either fail this
- * index build or delete the documents from the collection.
- *
- * Should not be called inside of a WriteUnitOfWork.
- */
- Status doneInserting(std::set<RecordId>* dupsOut = NULL);
-
- /**
- * Marks the index ready for use. Should only be called as the last method after
- * doneInserting() or insertAllDocumentsInCollection() return success.
- *
- * Should be called inside of a WriteUnitOfWork. If the index building is to be logOp'd,
- * logOp() should be called from the same unit of work as commit().
- *
- * Requires holding an exclusive database lock.
- */
- void commit();
-
- /**
- * May be called at any time after construction but before a successful commit(). Suppresses
- * the default behavior on destruction of removing all traces of uncommitted index builds.
- *
- * The most common use of this is if the indexes were already dropped via some other
- * mechanism such as the whole collection being dropped. In that case, it would be invalid
- * to try to remove the indexes again. Also, replication uses this to ensure that indexes
- * that are being built on shutdown are resumed on startup.
- *
- * Do not use this unless you are really sure you need to.
- *
- * Does not matter whether it is called inside of a WriteUnitOfWork. Will not be rolled
- * back.
- */
- void abortWithoutCleanup();
-
- bool getBuildInBackground() const { return _buildInBackground; }
-
- private:
- class SetNeedToCleanupOnRollback;
- class CleanupIndexesVectorOnRollback;
-
- struct IndexToBuild {
-#if defined(_MSC_VER) && _MSC_VER < 1900 // MVSC++ <= 2013 can't generate default move operations
- IndexToBuild() = default;
- IndexToBuild(IndexToBuild&& other)
- : block(std::move(other.block))
- , real(std::move(other.real))
- , bulk(std::move(other.bulk))
- , options(std::move(other.options))
- , filterExpression(std::move(other.filterExpression))
- {}
-
- IndexToBuild& operator= (IndexToBuild&& other) {
- block = std::move(other.block);
- real = std::move(other.real);
- filterExpression = std::move(other.filterExpression);
- bulk = std::move(other.bulk);
- options = std::move(other.options);
- return *this;
- }
+ /**
+ * Call this after init() for each document in the collection.
+ *
+ * Do not call if you called insertAllDocumentsInCollection();
+ *
+ * Should be called inside of a WriteUnitOfWork.
+ */
+ Status insert(const BSONObj& wholeDocument, const RecordId& loc);
+
+ /**
+ * Call this after the last insert(). This gives the index builder a chance to do any
+ * long-running operations in separate units of work from commit().
+ *
+ * Do not call if you called insertAllDocumentsInCollection();
+ *
+ * If dupsOut is passed as non-NULL, violators of uniqueness constraints will be added to
+ * the set. Documents added to this set are not indexed, so callers MUST either fail this
+ * index build or delete the documents from the collection.
+ *
+ * Should not be called inside of a WriteUnitOfWork.
+ */
+ Status doneInserting(std::set<RecordId>* dupsOut = NULL);
+
+ /**
+ * Marks the index ready for use. Should only be called as the last method after
+ * doneInserting() or insertAllDocumentsInCollection() return success.
+ *
+ * Should be called inside of a WriteUnitOfWork. If the index building is to be logOp'd,
+ * logOp() should be called from the same unit of work as commit().
+ *
+ * Requires holding an exclusive database lock.
+ */
+ void commit();
+
+ /**
+ * May be called at any time after construction but before a successful commit(). Suppresses
+ * the default behavior on destruction of removing all traces of uncommitted index builds.
+ *
+ * The most common use of this is if the indexes were already dropped via some other
+ * mechanism such as the whole collection being dropped. In that case, it would be invalid
+ * to try to remove the indexes again. Also, replication uses this to ensure that indexes
+ * that are being built on shutdown are resumed on startup.
+ *
+ * Do not use this unless you are really sure you need to.
+ *
+ * Does not matter whether it is called inside of a WriteUnitOfWork. Will not be rolled
+ * back.
+ */
+ void abortWithoutCleanup();
+
+ bool getBuildInBackground() const {
+ return _buildInBackground;
+ }
+
+private:
+ class SetNeedToCleanupOnRollback;
+ class CleanupIndexesVectorOnRollback;
+
+ struct IndexToBuild {
+#if defined(_MSC_VER) && _MSC_VER < 1900 // MVSC++ <= 2013 can't generate default move operations
+ IndexToBuild() = default;
+ IndexToBuild(IndexToBuild&& other)
+ : block(std::move(other.block)),
+ real(std::move(other.real)),
+ bulk(std::move(other.bulk)),
+ options(std::move(other.options)),
+ filterExpression(std::move(other.filterExpression)) {}
+
+ IndexToBuild& operator=(IndexToBuild&& other) {
+ block = std::move(other.block);
+ real = std::move(other.real);
+ filterExpression = std::move(other.filterExpression);
+ bulk = std::move(other.bulk);
+ options = std::move(other.options);
+ return *this;
+ }
#endif
- std::unique_ptr<IndexCatalog::IndexBuildBlock> block;
+ std::unique_ptr<IndexCatalog::IndexBuildBlock> block;
- IndexAccessMethod* real = NULL; // owned elsewhere
- const MatchExpression* filterExpression; // might be NULL, owned elsewhere
- std::unique_ptr<IndexAccessMethod::BulkBuilder> bulk;
+ IndexAccessMethod* real = NULL; // owned elsewhere
+ const MatchExpression* filterExpression; // might be NULL, owned elsewhere
+ std::unique_ptr<IndexAccessMethod::BulkBuilder> bulk;
- InsertDeleteOptions options;
- };
+ InsertDeleteOptions options;
+ };
- std::vector<IndexToBuild> _indexes;
+ std::vector<IndexToBuild> _indexes;
- std::unique_ptr<BackgroundOperation> _backgroundOperation;
+ std::unique_ptr<BackgroundOperation> _backgroundOperation;
- // Pointers not owned here and must outlive 'this'
- Collection* _collection;
- OperationContext* _txn;
+ // Pointers not owned here and must outlive 'this'
+ Collection* _collection;
+ OperationContext* _txn;
- bool _buildInBackground;
- bool _allowInterruption;
- bool _ignoreUnique;
+ bool _buildInBackground;
+ bool _allowInterruption;
+ bool _ignoreUnique;
- bool _needToCleanup;
- };
+ bool _needToCleanup;
+};
-} // namespace mongo
+} // namespace mongo