summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2018-10-25 15:29:05 -0400
committerBenety Goh <benety@mongodb.com>2018-10-25 15:29:31 -0400
commit3fa49ade000f010f5e7b68c81c02c67fc0db4060 (patch)
treec9742ce54ff363eceb9bfbe6be8000f9bcc86985 /src
parentb6147f664cc22c360611b05f79c0d8febf3c7692 (diff)
downloadmongo-3fa49ade000f010f5e7b68c81c02c67fc0db4060.tar.gz
SERVER-37589 split IndexAccessMethod::BulkBuilder into interface and implementation
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/index/index_access_method.cpp74
-rw-r--r--src/mongo/db/index/index_access_method.h48
2 files changed, 79 insertions, 43 deletions
diff --git a/src/mongo/db/index/index_access_method.cpp b/src/mongo/db/index/index_access_method.cpp
index 3aec791354e..4641d6c865d 100644
--- a/src/mongo/db/index/index_access_method.cpp
+++ b/src/mongo/db/index/index_access_method.cpp
@@ -482,14 +482,55 @@ Status AbstractIndexAccessMethod::compact(OperationContext* opCtx) {
return this->_newInterface->compact(opCtx);
}
+class AbstractIndexAccessMethod::BulkBuilderImpl : public IndexAccessMethod::BulkBuilder {
+public:
+ BulkBuilderImpl(const IndexAccessMethod* index,
+ const IndexDescriptor* descriptor,
+ size_t maxMemoryUsageBytes);
+
+ Status insert(OperationContext* opCtx,
+ const BSONObj& obj,
+ const RecordId& loc,
+ const InsertDeleteOptions& options) final;
+
+ const MultikeyPaths& getMultikeyPaths() const final;
+
+ bool isMultikey() const final;
+
+ /**
+ * Inserts all multikey metadata keys cached during the BulkBuilder's lifetime into the
+ * underlying Sorter, finalizes it, and returns an iterator over the sorted dataset.
+ */
+ Sorter::Iterator* done() final;
+
+ int64_t getKeysInserted() const final;
+
+private:
+ std::unique_ptr<Sorter> _sorter;
+ const IndexAccessMethod* _real;
+ int64_t _keysInserted = 0;
+
+ // Set to true if any document added to the BulkBuilder causes the index to become multikey.
+ bool _isMultiKey = false;
+
+ // Holds the path components that cause this index to be multikey. The '_indexMultikeyPaths'
+ // vector remains empty if this index doesn't support path-level multikey tracking.
+ MultikeyPaths _indexMultikeyPaths;
+
+ // Caches the set of all multikey metadata keys generated during the bulk build process.
+ // These are inserted into the sorter after all normal data keys have been added, just
+ // before the bulk build is committed.
+ BSONObjSet _multikeyMetadataKeys{SimpleBSONObjComparator::kInstance.makeBSONObjSet()};
+};
+
std::unique_ptr<IndexAccessMethod::BulkBuilder> AbstractIndexAccessMethod::initiateBulk(
size_t maxMemoryUsageBytes) {
- return std::unique_ptr<BulkBuilder>(new BulkBuilder(this, _descriptor, maxMemoryUsageBytes));
+ return std::make_unique<BulkBuilderImpl>(this, _descriptor, maxMemoryUsageBytes);
}
-IndexAccessMethod::BulkBuilder::BulkBuilder(const IndexAccessMethod* index,
- const IndexDescriptor* descriptor,
- size_t maxMemoryUsageBytes)
+AbstractIndexAccessMethod::BulkBuilderImpl::BulkBuilderImpl(const IndexAccessMethod* index,
+ const IndexDescriptor* descriptor,
+ size_t maxMemoryUsageBytes)
: _sorter(Sorter::make(
SortOptions()
.TempDir(storageGlobalParams.dbpath + "/_tmp")
@@ -498,10 +539,10 @@ IndexAccessMethod::BulkBuilder::BulkBuilder(const IndexAccessMethod* index,
BtreeExternalSortComparison(descriptor->keyPattern(), descriptor->version()))),
_real(index) {}
-Status IndexAccessMethod::BulkBuilder::insert(OperationContext* opCtx,
- const BSONObj& obj,
- const RecordId& loc,
- const InsertDeleteOptions& options) {
+Status AbstractIndexAccessMethod::BulkBuilderImpl::insert(OperationContext* opCtx,
+ const BSONObj& obj,
+ const RecordId& loc,
+ const InsertDeleteOptions& options) {
BSONObjSet keys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths multikeyPaths;
@@ -529,7 +570,16 @@ Status IndexAccessMethod::BulkBuilder::insert(OperationContext* opCtx,
return Status::OK();
}
-IndexAccessMethod::BulkBuilder::Sorter::Iterator* IndexAccessMethod::BulkBuilder::done() {
+const MultikeyPaths& AbstractIndexAccessMethod::BulkBuilderImpl::getMultikeyPaths() const {
+ return _indexMultikeyPaths;
+}
+
+bool AbstractIndexAccessMethod::BulkBuilderImpl::isMultikey() const {
+ return _isMultiKey;
+}
+
+IndexAccessMethod::BulkBuilder::Sorter::Iterator*
+AbstractIndexAccessMethod::BulkBuilderImpl::done() {
for (const auto& key : _multikeyMetadataKeys) {
_sorter->add(key, kMultikeyMetadataKeyId);
++_keysInserted;
@@ -537,6 +587,10 @@ IndexAccessMethod::BulkBuilder::Sorter::Iterator* IndexAccessMethod::BulkBuilder
return _sorter->done();
}
+int64_t AbstractIndexAccessMethod::BulkBuilderImpl::getKeysInserted() const {
+ return _keysInserted;
+}
+
Status AbstractIndexAccessMethod::commitBulk(OperationContext* opCtx,
BulkBuilder* bulk,
bool mayInterrupt,
@@ -550,7 +604,7 @@ Status AbstractIndexAccessMethod::commitBulk(OperationContext* opCtx,
ProgressMeterHolder pm(
CurOp::get(opCtx)->setMessage_inlock("Index Bulk Build: (2/3) btree bottom up",
"Index: (2/3) BTree Bottom Up Progress",
- bulk->_keysInserted,
+ bulk->getKeysInserted(),
10));
lk.unlock();
diff --git a/src/mongo/db/index/index_access_method.h b/src/mongo/db/index/index_access_method.h
index 8bbc755e420..51fe0439608 100644
--- a/src/mongo/db/index/index_access_method.h
+++ b/src/mongo/db/index/index_access_method.h
@@ -209,50 +209,30 @@ public:
public:
using Sorter = mongo::Sorter<BSONObj, RecordId>;
+ virtual ~BulkBuilder() = default;
+
/**
* Insert into the BulkBuilder as-if inserting into an IndexAccessMethod.
*/
- Status insert(OperationContext* opCtx,
- const BSONObj& obj,
- const RecordId& loc,
- const InsertDeleteOptions& options);
+ virtual Status insert(OperationContext* opCtx,
+ const BSONObj& obj,
+ const RecordId& loc,
+ const InsertDeleteOptions& options) = 0;
- const MultikeyPaths& getMultikeyPaths() const {
- return _indexMultikeyPaths;
- }
+ virtual const MultikeyPaths& getMultikeyPaths() const = 0;
- bool isMultikey() const {
- return _isMultiKey;
- }
+ virtual bool isMultikey() const = 0;
/**
* Inserts all multikey metadata keys cached during the BulkBuilder's lifetime into the
* underlying Sorter, finalizes it, and returns an iterator over the sorted dataset.
*/
- Sorter::Iterator* done();
-
- private:
- friend class AbstractIndexAccessMethod;
-
- BulkBuilder(const IndexAccessMethod* index,
- const IndexDescriptor* descriptor,
- size_t maxMemoryUsageBytes);
-
- std::unique_ptr<Sorter> _sorter;
- const IndexAccessMethod* _real;
- int64_t _keysInserted = 0;
+ virtual Sorter::Iterator* done() = 0;
- // Set to true if any document added to the BulkBuilder causes the index to become multikey.
- bool _isMultiKey = false;
-
- // Holds the path components that cause this index to be multikey. The '_indexMultikeyPaths'
- // vector remains empty if this index doesn't support path-level multikey tracking.
- MultikeyPaths _indexMultikeyPaths;
-
- // Caches the set of all multikey metadata keys generated during the bulk build process.
- // These are inserted into the sorter after all normal data keys have been added, just
- // before the bulk build is committed.
- BSONObjSet _multikeyMetadataKeys{SimpleBSONObjComparator::kInstance.makeBSONObjSet()};
+ /**
+ * Returns number of keys inserted using this BulkBuilder.
+ */
+ virtual int64_t getKeysInserted() const = 0;
};
/**
@@ -508,6 +488,8 @@ protected:
const IndexDescriptor* const _descriptor;
private:
+ class BulkBuilderImpl;
+
/**
* Determine whether the given Status represents an exception that should cause the indexing
* process to abort. The 'key' argument is passed in to allow the offending entry to be logged