Storage Engine API
index_create_impl.h
Go to the documentation of this file.
1 
29 #pragma once
30 
32 
33 #include <memory>
34 #include <set>
35 #include <string>
36 #include <vector>
37 
38 #include "mongo/base/disallow_copying.h"
39 #include "mongo/base/status.h"
42 #include "mongo/db/index/index_access_method.h"
43 #include "mongo/db/record_id.h"
44 
45 namespace mongo {
46 
47 class BackgroundOperation;
48 class BSONObj;
49 class Collection;
50 class OperationContext;
51 
65 
66 public:
70  MultiIndexBlockImpl(OperationContext* opCtx, Collection* collection);
71  ~MultiIndexBlockImpl() override;
72 
81  void allowBackgroundBuilding() override {
82  _buildInBackground = true;
83  }
84 
89  void allowInterruption() override {
90  _allowInterruption = true;
91  }
92 
100  void ignoreUniqueConstraint() override {
101  _ignoreUnique = true;
102  }
103 
108  void removeExistingIndexes(std::vector<BSONObj>* specs) const override;
109 
118  StatusWith<std::vector<BSONObj>> init(const std::vector<BSONObj>& specs) override;
119  StatusWith<std::vector<BSONObj>> init(const BSONObj& spec) override;
120 
135  Status insertAllDocumentsInCollection(std::set<RecordId>* dupsOut = nullptr) override;
136 
144  Status insert(const BSONObj& wholeDocument, const RecordId& loc) override;
145 
158  Status doneInserting(std::set<RecordId>* dupsOut = nullptr) override;
159 
169  void commit(stdx::function<void(const BSONObj& spec)> onCreateFn) override;
170 
185  void abortWithoutCleanup() override;
186 
187  bool getBuildInBackground() const override {
188  return _buildInBackground;
189  }
190 
191 private:
194 
195  struct IndexToBuild {
196  std::unique_ptr<IndexCatalogImpl::IndexBuildBlock> block;
197 
198  IndexAccessMethod* real = NULL; // owned elsewhere
199  const MatchExpression* filterExpression; // might be NULL, owned elsewhere
200  std::unique_ptr<IndexAccessMethod::BulkBuilder> bulk;
201 
202  InsertDeleteOptions options;
203  };
204 
205  virtual bool initBackgroundIndexFromSpec(const BSONObj& spec) const = 0;
206 
207  std::vector<IndexToBuild> _indexes;
208 
209  std::unique_ptr<BackgroundOperation> _backgroundOperation;
210 
211  // Pointers not owned here and must outlive 'this'
213  OperationContext* _opCtx;
214 
218 
220 };
221 
222 } // namespace mongo
const MatchExpression * filterExpression
Definition: index_create_impl.h:199
void allowBackgroundBuilding() override
By default we ignore the &#39;background&#39; flag in specs when building an index.
Definition: index_create_impl.h:81
void commit(stdx::function< void(const BSONObj &spec)> onCreateFn) override
Marks the index ready for use.
Definition: index_create_impl.cpp:509
Status doneInserting(std::set< RecordId > *dupsOut=nullptr) override
Call this after the last insert().
Definition: index_create_impl.cpp:484
bool getBuildInBackground() const override
Definition: index_create_impl.h:187
~MultiIndexBlockImpl() override
Definition: index_create_impl.cpp:140
InsertDeleteOptions options
Definition: index_create_impl.h:202
void abortWithoutCleanup() override
May be called at any time after construction but before a successful commit().
Definition: index_create_impl.cpp:504
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
OperationContext * _opCtx
Definition: index_create_impl.h:213
bool _buildInBackground
Definition: index_create_impl.h:215
Collection *const collection
Definition: collection_info_cache_impl.cpp:53
OperationContext Database StringData BSONObj CollectionOptions::ParseKind bool const BSONObj &idIndex Status
Definition: database_impl.cpp:956
std::vector< IndexToBuild > _indexes
Definition: index_create_impl.h:207
StatusWith< std::vector< BSONObj > > init(const std::vector< BSONObj > &specs) override
Prepares the index(es) for building and returns the canonicalized form of the requested index specifi...
Definition: index_create_impl.cpp:207
void allowInterruption() override
Call this before init() to allow the index build to be interrupted.
Definition: index_create_impl.h:89
this is NOT safe through a yield right now.
Definition: collection.h:160
void ignoreUniqueConstraint() override
By default we enforce the &#39;unique&#39; flag in specs when building an index by failing.
Definition: index_create_impl.h:100
Definition: index_create.h:63
Status insert(const BSONObj &wholeDocument, const RecordId &loc) override
Call this after init() for each document in the collection.
Definition: index_create_impl.cpp:464
Definition: index_key_validate.h:40
Builds one or more indexes.
Definition: index_create_impl.h:63
IndexAccessMethod * real
Definition: index_create_impl.h:198
bool _allowInterruption
Definition: index_create_impl.h:216
MultiIndexBlockImpl(OperationContext *opCtx, Collection *collection)
Neither pointer is owned.
Definition: index_create_impl.cpp:132
std::unique_ptr< IndexAccessMethod::BulkBuilder > bulk
Definition: index_create_impl.h:200
Collection * _collection
Definition: index_create_impl.h:212
std::unique_ptr< BackgroundOperation > _backgroundOperation
Definition: index_create_impl.h:209
On rollback sets MultiIndexBlockImpl::_needToCleanup to true.
Definition: index_create_impl.cpp:101
MONGO_DISALLOW_COPYING(MultiIndexBlockImpl)
void removeExistingIndexes(std::vector< BSONObj > *specs) const override
Removes pre-existing indexes from &#39;specs&#39;.
Definition: index_create_impl.cpp:190
virtual bool initBackgroundIndexFromSpec(const BSONObj &spec) const =0
Definition: index_create_impl.h:195
std::unique_ptr< IndexCatalogImpl::IndexBuildBlock > block
Definition: index_create_impl.h:196
On rollback in init(), cleans up _indexes so that ~MultiIndexBlock doesn&#39;t try to clean up _indexes m...
Definition: index_create_impl.cpp:119
Collection *const OperationContext *const opCtx
Definition: collection_impl.cpp:80
bool _ignoreUnique
Definition: index_create_impl.h:217
Status insertAllDocumentsInCollection(std::set< RecordId > *dupsOut=nullptr) override
Inserts all documents in the Collection into the indexes and logs with timing info.
Definition: index_create_impl.cpp:322
bool _needToCleanup
Definition: index_create_impl.h:219