diff options
author | Dianna Hohensee <dianna.hohensee@mongodb.com> | 2022-12-30 20:53:16 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-12-30 21:49:31 +0000 |
commit | 113d60cdb95149af07820a57127216d34a1c3c0f (patch) | |
tree | 2b921e08f956ec11dcd86dc2627e4e64164091f3 | |
parent | 040c77af8b2a867207d4973a1ede67b52ddfd4ef (diff) | |
download | mongo-113d60cdb95149af07820a57127216d34a1c3c0f.tar.gz |
SERVER-72419 Refactor IndexAccessMethod to have a single side-writes function for both sorted & columnar indexes
-rw-r--r-- | src/mongo/db/index/columns_access_method.cpp | 14 | ||||
-rw-r--r-- | src/mongo/db/index/columns_access_method.h | 12 | ||||
-rw-r--r-- | src/mongo/db/index/index_access_method.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/index/index_access_method.h | 18 | ||||
-rw-r--r-- | src/mongo/db/index/index_build_interceptor.cpp | 29 |
5 files changed, 31 insertions, 44 deletions
diff --git a/src/mongo/db/index/columns_access_method.cpp b/src/mongo/db/index/columns_access_method.cpp index 2dd98afa286..3aa913a0f19 100644 --- a/src/mongo/db/index/columns_access_method.cpp +++ b/src/mongo/db/index/columns_access_method.cpp @@ -495,11 +495,13 @@ void ColumnStoreAccessMethod::setIdent(std::shared_ptr<Ident> ident) { _store->setIdent(std::move(ident)); } -void ColumnStoreAccessMethod::applyColumnDataSideWrite(OperationContext* opCtx, - const CollectionPtr& coll, - const BSONObj& operation, - int64_t* keysInserted, - int64_t* keysDeleted) { +Status ColumnStoreAccessMethod::applyIndexBuildSideWrite(OperationContext* opCtx, + const CollectionPtr& coll, + const BSONObj& operation, + const InsertDeleteOptions& unusedOptions, + KeyHandlerFn&& unusedFn, + int64_t* keysInserted, + int64_t* keysDeleted) { const IndexBuildInterceptor::Op opType = operation.getStringField("op") == "i"_sd ? IndexBuildInterceptor::Op::kInsert : operation.getStringField("op") == "d"_sd ? IndexBuildInterceptor::Op::kDelete @@ -530,6 +532,8 @@ void ColumnStoreAccessMethod::applyColumnDataSideWrite(OperationContext* opCtx, opCtx->recoveryUnit()->onRollback([keysInserted] { dec(keysInserted); }); break; } + + return Status::OK(); } // static diff --git a/src/mongo/db/index/columns_access_method.h b/src/mongo/db/index/columns_access_method.h index 99d0a07d7f6..8d67306fdd7 100644 --- a/src/mongo/db/index/columns_access_method.h +++ b/src/mongo/db/index/columns_access_method.h @@ -86,11 +86,13 @@ public: int64_t* keysInsertedOut, int64_t* keysDeletedOut) final; - void applyColumnDataSideWrite(OperationContext* opCtx, - const CollectionPtr& coll, - const BSONObj& operation, - int64_t* keysInserted, - int64_t* keysDeleted) final; + Status applyIndexBuildSideWrite(OperationContext* opCtx, + const CollectionPtr& coll, + const BSONObj& operation, + const InsertDeleteOptions& unusedOptions, + KeyHandlerFn&& unusedFn, + int64_t* keysInserted, + int64_t* keysDeleted) final; Status initializeAsEmpty(OperationContext* opCtx) final; diff --git a/src/mongo/db/index/index_access_method.cpp b/src/mongo/db/index/index_access_method.cpp index 84c2c6e0201..3d5a1d0c8ad 100644 --- a/src/mongo/db/index/index_access_method.cpp +++ b/src/mongo/db/index/index_access_method.cpp @@ -632,7 +632,7 @@ void SortedDataIndexAccessMethod::setIdent(std::shared_ptr<Ident> newIdent) { this->_newInterface->setIdent(std::move(newIdent)); } -Status SortedDataIndexAccessMethod::applySortedDataSideWrite(OperationContext* opCtx, +Status SortedDataIndexAccessMethod::applyIndexBuildSideWrite(OperationContext* opCtx, const CollectionPtr& coll, const BSONObj& operation, const InsertDeleteOptions& options, diff --git a/src/mongo/db/index/index_access_method.h b/src/mongo/db/index/index_access_method.h index 7e7391aa02b..29c472a63d6 100644 --- a/src/mongo/db/index/index_access_method.h +++ b/src/mongo/db/index/index_access_method.h @@ -174,23 +174,13 @@ public: */ virtual void setIdent(std::shared_ptr<Ident> newIdent) = 0; - virtual Status applySortedDataSideWrite(OperationContext* opCtx, + virtual Status applyIndexBuildSideWrite(OperationContext* opCtx, const CollectionPtr& coll, const BSONObj& operation, const InsertDeleteOptions& options, KeyHandlerFn&& onDuplicateKey, - int64_t* const keysInserted, - int64_t* const keysDeleted) { - MONGO_UNREACHABLE; - }; - - virtual void applyColumnDataSideWrite(OperationContext* opCtx, - const CollectionPtr& coll, - const BSONObj& operation, - int64_t* keysInserted, - int64_t* keysDeleted) { - MONGO_UNREACHABLE; - }; + int64_t* keysInserted, + int64_t* keysDeleted) = 0; // // Bulk operations support @@ -582,7 +572,7 @@ public: void setIdent(std::shared_ptr<Ident> newIdent) final; - Status applySortedDataSideWrite(OperationContext* opCtx, + Status applyIndexBuildSideWrite(OperationContext* opCtx, const CollectionPtr& coll, const BSONObj& operation, const InsertDeleteOptions& options, diff --git a/src/mongo/db/index/index_build_interceptor.cpp b/src/mongo/db/index/index_build_interceptor.cpp index fb5d964b075..dd282cb0bf5 100644 --- a/src/mongo/db/index/index_build_interceptor.cpp +++ b/src/mongo/db/index/index_build_interceptor.cpp @@ -305,25 +305,16 @@ Status IndexBuildInterceptor::_applyWrite(OperationContext* opCtx, TrackDuplicates trackDups, int64_t* const keysInserted, int64_t* const keysDeleted) { - // Check field for "key" to determine if collection is sorted data or column store. - if (operation.hasField("key")) { - return _indexCatalogEntry->accessMethod()->applySortedDataSideWrite( - opCtx, - coll, - operation, - options, - [=](const KeyString::Value& duplicateKey) { - return trackDups == TrackDuplicates::kTrack - ? recordDuplicateKey(opCtx, duplicateKey) - : Status::OK(); - }, - keysInserted, - keysDeleted); - } else { - _indexCatalogEntry->accessMethod()->applyColumnDataSideWrite( - opCtx, coll, operation, keysInserted, keysDeleted); - return Status::OK(); - } + // Sorted index types may choose to disallow duplicates (enforcing an unique index). Columnar + // indexes are not sorted and therefore cannot enforce uniqueness constraints. Only sorted + // indexes will use this lambda passed through the IndexAccessMethod interface. + IndexAccessMethod::KeyHandlerFn onDuplicateKeyFn = [=](const KeyString::Value& duplicateKey) { + return trackDups == TrackDuplicates::kTrack ? recordDuplicateKey(opCtx, duplicateKey) + : Status::OK(); + }; + + return _indexCatalogEntry->accessMethod()->applyIndexBuildSideWrite( + opCtx, coll, operation, options, std::move(onDuplicateKeyFn), keysInserted, keysDeleted); } void IndexBuildInterceptor::_yield(OperationContext* opCtx, const Yieldable* yieldable) { |