diff options
Diffstat (limited to 'src/mongo/db/index')
-rw-r--r-- | src/mongo/db/index/haystack_access_method.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/index/haystack_access_method.h | 2 | ||||
-rw-r--r-- | src/mongo/db/index/haystack_access_method_internal.h | 10 | ||||
-rw-r--r-- | src/mongo/db/index/index_access_method.cpp | 115 | ||||
-rw-r--r-- | src/mongo/db/index/index_access_method.h | 36 |
5 files changed, 85 insertions, 84 deletions
diff --git a/src/mongo/db/index/haystack_access_method.cpp b/src/mongo/db/index/haystack_access_method.cpp index 877e94c0c7d..213c9f05baa 100644 --- a/src/mongo/db/index/haystack_access_method.cpp +++ b/src/mongo/db/index/haystack_access_method.cpp @@ -68,7 +68,7 @@ void HaystackAccessMethod::doGetKeys(const BSONObj& obj, ExpressionKeysPrivate::getHaystackKeys(obj, _geoField, _otherFields, _bucketSize, keys); } -void HaystackAccessMethod::searchCommand(OperationContext* txn, +void HaystackAccessMethod::searchCommand(OperationContext* opCtx, Collection* collection, const BSONObj& nearObj, double maxDistance, @@ -87,7 +87,7 @@ void HaystackAccessMethod::searchCommand(OperationContext* txn, } int scale = static_cast<int>(ceil(maxDistance / _bucketSize)); - GeoHaystackSearchHopper hopper(txn, nearObj, maxDistance, limit, _geoField, collection); + GeoHaystackSearchHopper hopper(opCtx, nearObj, maxDistance, limit, _geoField, collection); long long btreeMatches = 0; @@ -111,7 +111,7 @@ void HaystackAccessMethod::searchCommand(OperationContext* txn, unique_ptr<PlanExecutor> exec( - InternalPlanner::indexScan(txn, + InternalPlanner::indexScan(opCtx, collection, _descriptor, key, diff --git a/src/mongo/db/index/haystack_access_method.h b/src/mongo/db/index/haystack_access_method.h index a6ff68bdd9f..4bf8fc41839 100644 --- a/src/mongo/db/index/haystack_access_method.h +++ b/src/mongo/db/index/haystack_access_method.h @@ -60,7 +60,7 @@ public: protected: friend class GeoHaystackSearchCommand; - void searchCommand(OperationContext* txn, + void searchCommand(OperationContext* opCtx, Collection* collection, const BSONObj& nearObj, double maxDistance, diff --git a/src/mongo/db/index/haystack_access_method_internal.h b/src/mongo/db/index/haystack_access_method_internal.h index 4bc2e7430ad..b1d26b716ee 100644 --- a/src/mongo/db/index/haystack_access_method_internal.h +++ b/src/mongo/db/index/haystack_access_method_internal.h @@ -48,13 +48,13 @@ public: * @param limit The maximum number of results to return * @param geoField Which field in the provided RecordId has the point to test. */ - GeoHaystackSearchHopper(OperationContext* txn, + GeoHaystackSearchHopper(OperationContext* opCtx, const BSONObj& nearObj, double maxDistance, unsigned limit, const std::string& geoField, const Collection* collection) - : _txn(txn), + : _opCtx(opCtx), _collection(collection), _near(nearObj), _maxDistance(maxDistance), @@ -66,7 +66,7 @@ public: void consider(const RecordId& loc) { if (limitReached()) return; - Point p(dps::extractElementAtPath(_collection->docFor(_txn, loc).value(), _geoField)); + Point p(dps::extractElementAtPath(_collection->docFor(_opCtx, loc).value(), _geoField)); if (distance(_near, p) > _maxDistance) return; _locs.push_back(loc); @@ -74,7 +74,7 @@ public: int appendResultsTo(BSONArrayBuilder* b) { for (unsigned i = 0; i < _locs.size(); i++) - b->append(_collection->docFor(_txn, _locs[i]).value()); + b->append(_collection->docFor(_opCtx, _locs[i]).value()); return _locs.size(); } @@ -84,7 +84,7 @@ public: } private: - OperationContext* _txn; + OperationContext* _opCtx; const Collection* _collection; Point _near; diff --git a/src/mongo/db/index/index_access_method.cpp b/src/mongo/db/index/index_access_method.cpp index c787d1429dc..0a087140600 100644 --- a/src/mongo/db/index/index_access_method.cpp +++ b/src/mongo/db/index/index_access_method.cpp @@ -112,16 +112,16 @@ IndexAccessMethod::IndexAccessMethod(IndexCatalogEntry* btreeState, SortedDataIn verify(IndexDescriptor::isIndexVersionSupported(_descriptor->version())); } -bool IndexAccessMethod::ignoreKeyTooLong(OperationContext* txn) { +bool IndexAccessMethod::ignoreKeyTooLong(OperationContext* opCtx) { // Ignore this error if we cannot write to the collection or if the user requested it const auto shouldRelaxConstraints = - repl::ReplicationCoordinator::get(txn)->shouldRelaxIndexConstraints( - txn, NamespaceString(_btreeState->ns())); + repl::ReplicationCoordinator::get(opCtx)->shouldRelaxIndexConstraints( + opCtx, NamespaceString(_btreeState->ns())); return shouldRelaxConstraints || !failIndexKeyTooLong.load(); } // Find the keys for obj, put them in the tree pointing to loc -Status IndexAccessMethod::insert(OperationContext* txn, +Status IndexAccessMethod::insert(OperationContext* opCtx, const BSONObj& obj, const RecordId& loc, const InsertDeleteOptions& options, @@ -135,7 +135,7 @@ Status IndexAccessMethod::insert(OperationContext* txn, Status ret = Status::OK(); for (BSONObjSet::const_iterator i = keys.begin(); i != keys.end(); ++i) { - Status status = _newInterface->insert(txn, *i, loc, options.dupsAllowed); + Status status = _newInterface->insert(opCtx, *i, loc, options.dupsAllowed); // Everything's OK, carry on. if (status.isOK()) { @@ -145,14 +145,14 @@ Status IndexAccessMethod::insert(OperationContext* txn, // Error cases. - if (status.code() == ErrorCodes::KeyTooLong && ignoreKeyTooLong(txn)) { + if (status.code() == ErrorCodes::KeyTooLong && ignoreKeyTooLong(opCtx)) { continue; } if (status.code() == ErrorCodes::DuplicateKeyValue) { // A document might be indexed multiple times during a background index build // if it moves ahead of the collection scan cursor (e.g. via an update). - if (!_btreeState->isReady(txn)) { + if (!_btreeState->isReady(opCtx)) { LOG(3) << "key " << *i << " already in index during background indexing (ok)"; continue; } @@ -160,7 +160,7 @@ Status IndexAccessMethod::insert(OperationContext* txn, // Clean up after ourselves. for (BSONObjSet::const_iterator j = keys.begin(); j != i; ++j) { - removeOneKey(txn, *j, loc, options.dupsAllowed); + removeOneKey(opCtx, *j, loc, options.dupsAllowed); *numInserted = 0; } @@ -168,18 +168,18 @@ Status IndexAccessMethod::insert(OperationContext* txn, } if (*numInserted > 1 || isMultikeyFromPaths(multikeyPaths)) { - _btreeState->setMultikey(txn, multikeyPaths); + _btreeState->setMultikey(opCtx, multikeyPaths); } return ret; } -void IndexAccessMethod::removeOneKey(OperationContext* txn, +void IndexAccessMethod::removeOneKey(OperationContext* opCtx, const BSONObj& key, const RecordId& loc, bool dupsAllowed) { try { - _newInterface->unindex(txn, key, loc, dupsAllowed); + _newInterface->unindex(opCtx, key, loc, dupsAllowed); } catch (AssertionException& e) { log() << "Assertion failure: _unindex failed " << _descriptor->indexNamespace(); log() << "Assertion failure: _unindex failed: " << redact(e) << " key:" << key.toString() @@ -188,18 +188,18 @@ void IndexAccessMethod::removeOneKey(OperationContext* txn, } } -std::unique_ptr<SortedDataInterface::Cursor> IndexAccessMethod::newCursor(OperationContext* txn, +std::unique_ptr<SortedDataInterface::Cursor> IndexAccessMethod::newCursor(OperationContext* opCtx, bool isForward) const { - return _newInterface->newCursor(txn, isForward); + return _newInterface->newCursor(opCtx, isForward); } std::unique_ptr<SortedDataInterface::Cursor> IndexAccessMethod::newRandomCursor( - OperationContext* txn) const { - return _newInterface->newRandomCursor(txn); + OperationContext* opCtx) const { + return _newInterface->newRandomCursor(opCtx); } // Remove the provided doc from the index. -Status IndexAccessMethod::remove(OperationContext* txn, +Status IndexAccessMethod::remove(OperationContext* opCtx, const BSONObj& obj, const RecordId& loc, const InsertDeleteOptions& options, @@ -214,25 +214,25 @@ Status IndexAccessMethod::remove(OperationContext* txn, getKeys(obj, options.getKeysMode, &keys, multikeyPaths); for (BSONObjSet::const_iterator i = keys.begin(); i != keys.end(); ++i) { - removeOneKey(txn, *i, loc, options.dupsAllowed); + removeOneKey(opCtx, *i, loc, options.dupsAllowed); ++*numDeleted; } return Status::OK(); } -Status IndexAccessMethod::initializeAsEmpty(OperationContext* txn) { - return _newInterface->initAsEmpty(txn); +Status IndexAccessMethod::initializeAsEmpty(OperationContext* opCtx) { + return _newInterface->initAsEmpty(opCtx); } -Status IndexAccessMethod::touch(OperationContext* txn, const BSONObj& obj) { +Status IndexAccessMethod::touch(OperationContext* opCtx, const BSONObj& obj) { BSONObjSet keys = SimpleBSONObjComparator::kInstance.makeBSONObjSet(); // There's no need to compute the prefixes of the indexed fields that cause the index to be // multikey when paging a document's index entries into memory. MultikeyPaths* multikeyPaths = nullptr; getKeys(obj, GetKeysMode::kEnforceConstraints, &keys, multikeyPaths); - std::unique_ptr<SortedDataInterface::Cursor> cursor(_newInterface->newCursor(txn)); + std::unique_ptr<SortedDataInterface::Cursor> cursor(_newInterface->newCursor(opCtx)); for (BSONObjSet::const_iterator i = keys.begin(); i != keys.end(); ++i) { cursor->seekExact(*i); } @@ -241,11 +241,11 @@ Status IndexAccessMethod::touch(OperationContext* txn, const BSONObj& obj) { } -Status IndexAccessMethod::touch(OperationContext* txn) const { - return _newInterface->touch(txn); +Status IndexAccessMethod::touch(OperationContext* opCtx) const { + return _newInterface->touch(opCtx); } -RecordId IndexAccessMethod::findSingle(OperationContext* txn, const BSONObj& requestedKey) const { +RecordId IndexAccessMethod::findSingle(OperationContext* opCtx, const BSONObj& requestedKey) const { // Generate the key for this index. BSONObj actualKey; if (_btreeState->getCollator()) { @@ -259,7 +259,7 @@ RecordId IndexAccessMethod::findSingle(OperationContext* txn, const BSONObj& req actualKey = requestedKey; } - std::unique_ptr<SortedDataInterface::Cursor> cursor(_newInterface->newCursor(txn)); + std::unique_ptr<SortedDataInterface::Cursor> cursor(_newInterface->newCursor(opCtx)); const auto requestedInfo = kDebugBuild ? SortedDataInterface::Cursor::kKeyAndLoc : SortedDataInterface::Cursor::kWantLoc; if (auto kv = cursor->seekExact(actualKey, requestedInfo)) { @@ -274,23 +274,23 @@ RecordId IndexAccessMethod::findSingle(OperationContext* txn, const BSONObj& req return RecordId(); } -Status IndexAccessMethod::validate(OperationContext* txn, +Status IndexAccessMethod::validate(OperationContext* opCtx, int64_t* numKeys, ValidateResults* fullResults) { long long keys = 0; - _newInterface->fullValidate(txn, &keys, fullResults); + _newInterface->fullValidate(opCtx, &keys, fullResults); *numKeys = keys; return Status::OK(); } -bool IndexAccessMethod::appendCustomStats(OperationContext* txn, +bool IndexAccessMethod::appendCustomStats(OperationContext* opCtx, BSONObjBuilder* output, double scale) const { - return _newInterface->appendCustomStats(txn, output, scale); + return _newInterface->appendCustomStats(opCtx, output, scale); } -long long IndexAccessMethod::getSpaceUsedBytes(OperationContext* txn) const { - return _newInterface->getSpaceUsedBytes(txn); +long long IndexAccessMethod::getSpaceUsedBytes(OperationContext* opCtx) const { + return _newInterface->getSpaceUsedBytes(opCtx); } pair<vector<BSONObj>, vector<BSONObj>> IndexAccessMethod::setDifference(const BSONObjSet& left, @@ -329,7 +329,7 @@ pair<vector<BSONObj>, vector<BSONObj>> IndexAccessMethod::setDifference(const BS return {std::move(onlyLeft), std::move(onlyRight)}; } -Status IndexAccessMethod::validateUpdate(OperationContext* txn, +Status IndexAccessMethod::validateUpdate(OperationContext* opCtx, const BSONObj& from, const BSONObj& to, const RecordId& record, @@ -358,7 +358,7 @@ Status IndexAccessMethod::validateUpdate(OperationContext* txn, return Status::OK(); } -Status IndexAccessMethod::update(OperationContext* txn, +Status IndexAccessMethod::update(OperationContext* opCtx, const UpdateTicket& ticket, int64_t* numInserted, int64_t* numDeleted) { @@ -374,17 +374,18 @@ Status IndexAccessMethod::update(OperationContext* txn, if (ticket.oldKeys.size() + ticket.added.size() - ticket.removed.size() > 1 || isMultikeyFromPaths(ticket.newMultikeyPaths)) { - _btreeState->setMultikey(txn, ticket.newMultikeyPaths); + _btreeState->setMultikey(opCtx, ticket.newMultikeyPaths); } for (size_t i = 0; i < ticket.removed.size(); ++i) { - _newInterface->unindex(txn, ticket.removed[i], ticket.loc, ticket.dupsAllowed); + _newInterface->unindex(opCtx, ticket.removed[i], ticket.loc, ticket.dupsAllowed); } for (size_t i = 0; i < ticket.added.size(); ++i) { - Status status = _newInterface->insert(txn, ticket.added[i], ticket.loc, ticket.dupsAllowed); + Status status = + _newInterface->insert(opCtx, ticket.added[i], ticket.loc, ticket.dupsAllowed); if (!status.isOK()) { - if (status.code() == ErrorCodes::KeyTooLong && ignoreKeyTooLong(txn)) { + if (status.code() == ErrorCodes::KeyTooLong && ignoreKeyTooLong(opCtx)) { // Ignore. continue; } @@ -399,8 +400,8 @@ Status IndexAccessMethod::update(OperationContext* txn, return Status::OK(); } -Status IndexAccessMethod::compact(OperationContext* txn) { - return this->_newInterface->compact(txn); +Status IndexAccessMethod::compact(OperationContext* opCtx) { + return this->_newInterface->compact(opCtx); } std::unique_ptr<IndexAccessMethod::BulkBuilder> IndexAccessMethod::initiateBulk( @@ -419,7 +420,7 @@ IndexAccessMethod::BulkBuilder::BulkBuilder(const IndexAccessMethod* index, BtreeExternalSortComparison(descriptor->keyPattern(), descriptor->version()))), _real(index) {} -Status IndexAccessMethod::BulkBuilder::insert(OperationContext* txn, +Status IndexAccessMethod::BulkBuilder::insert(OperationContext* opCtx, const BSONObj& obj, const RecordId& loc, const InsertDeleteOptions& options, @@ -455,7 +456,7 @@ Status IndexAccessMethod::BulkBuilder::insert(OperationContext* txn, } -Status IndexAccessMethod::commitBulk(OperationContext* txn, +Status IndexAccessMethod::commitBulk(OperationContext* opCtx, std::unique_ptr<BulkBuilder> bulk, bool mayInterrupt, bool dupsAllowed, @@ -464,38 +465,38 @@ Status IndexAccessMethod::commitBulk(OperationContext* txn, std::unique_ptr<BulkBuilder::Sorter::Iterator> i(bulk->_sorter->done()); - stdx::unique_lock<Client> lk(*txn->getClient()); - ProgressMeterHolder pm(*txn->setMessage_inlock("Index Bulk Build: (2/3) btree bottom up", - "Index: (2/3) BTree Bottom Up Progress", - bulk->_keysInserted, - 10)); + stdx::unique_lock<Client> lk(*opCtx->getClient()); + ProgressMeterHolder pm(*opCtx->setMessage_inlock("Index Bulk Build: (2/3) btree bottom up", + "Index: (2/3) BTree Bottom Up Progress", + bulk->_keysInserted, + 10)); lk.unlock(); std::unique_ptr<SortedDataBuilderInterface> builder; MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN { - WriteUnitOfWork wunit(txn); + WriteUnitOfWork wunit(opCtx); if (bulk->_everGeneratedMultipleKeys || isMultikeyFromPaths(bulk->_indexMultikeyPaths)) { - _btreeState->setMultikey(txn, bulk->_indexMultikeyPaths); + _btreeState->setMultikey(opCtx, bulk->_indexMultikeyPaths); } - builder.reset(_newInterface->getBulkBuilder(txn, dupsAllowed)); + builder.reset(_newInterface->getBulkBuilder(opCtx, dupsAllowed)); wunit.commit(); } - MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "setting index multikey flag", ""); + MONGO_WRITE_CONFLICT_RETRY_LOOP_END(opCtx, "setting index multikey flag", ""); while (i->more()) { if (mayInterrupt) { - txn->checkForInterrupt(); + opCtx->checkForInterrupt(); } - WriteUnitOfWork wunit(txn); + WriteUnitOfWork wunit(opCtx); // Improve performance in the btree-building phase by disabling rollback tracking. // This avoids copying all the written bytes to a buffer that is only used to roll back. // Note that this is safe to do, as this entire index-build-in-progress will be cleaned // up by the index system. - txn->recoveryUnit()->setRollbackWritesDisabled(); + opCtx->recoveryUnit()->setRollbackWritesDisabled(); // Get the next datum and add it to the builder. BulkBuilder::Sorter::Data d = i->next(); @@ -503,7 +504,7 @@ Status IndexAccessMethod::commitBulk(OperationContext* txn, if (!status.isOK()) { // Overlong key that's OK to skip? - if (status.code() == ErrorCodes::KeyTooLong && ignoreKeyTooLong(txn)) { + if (status.code() == ErrorCodes::KeyTooLong && ignoreKeyTooLong(opCtx)) { continue; } @@ -529,9 +530,9 @@ Status IndexAccessMethod::commitBulk(OperationContext* txn, pm.finished(); { - stdx::lock_guard<Client> lk(*txn->getClient()); - CurOp::get(txn)->setMessage_inlock("Index Bulk Build: (3/3) btree-middle", - "Index: (3/3) BTree Middle Progress"); + stdx::lock_guard<Client> lk(*opCtx->getClient()); + CurOp::get(opCtx)->setMessage_inlock("Index Bulk Build: (3/3) btree-middle", + "Index: (3/3) BTree Middle Progress"); } LOG(timer.seconds() > 10 ? 0 : 1) << "\t done building bottom layer, going to commit"; diff --git a/src/mongo/db/index/index_access_method.h b/src/mongo/db/index/index_access_method.h index b96260b11f8..9a41bf1961a 100644 --- a/src/mongo/db/index/index_access_method.h +++ b/src/mongo/db/index/index_access_method.h @@ -78,7 +78,7 @@ public: * * The behavior of the insertion can be specified through 'options'. */ - Status insert(OperationContext* txn, + Status insert(OperationContext* opCtx, const BSONObj& obj, const RecordId& loc, const InsertDeleteOptions& options, @@ -88,7 +88,7 @@ public: * Analogous to above, but remove the records instead of inserting them. * 'numDeleted' will be set to the number of keys removed from the index for the document. */ - Status remove(OperationContext* txn, + Status remove(OperationContext* opCtx, const BSONObj& obj, const RecordId& loc, const InsertDeleteOptions& options, @@ -104,7 +104,7 @@ public: * * There is no obligation to perform the update after performing validation. */ - Status validateUpdate(OperationContext* txn, + Status validateUpdate(OperationContext* opCtx, const BSONObj& from, const BSONObj& to, const RecordId& loc, @@ -123,7 +123,7 @@ public: * 'numInserted' will be set to the number of keys inserted into the index for the document. * 'numDeleted' will be set to the number of keys removed from the index for the document. */ - Status update(OperationContext* txn, + Status update(OperationContext* opCtx, const UpdateTicket& ticket, int64_t* numInserted, int64_t* numDeleted); @@ -131,12 +131,12 @@ public: /** * Returns an unpositioned cursor over 'this' index. */ - std::unique_ptr<SortedDataInterface::Cursor> newCursor(OperationContext* txn, + std::unique_ptr<SortedDataInterface::Cursor> newCursor(OperationContext* opCtx, bool isForward = true) const; /** * Returns a pseudo-random cursor over 'this' index. */ - std::unique_ptr<SortedDataInterface::Cursor> newRandomCursor(OperationContext* txn) const; + std::unique_ptr<SortedDataInterface::Cursor> newRandomCursor(OperationContext* opCtx) const; // ------ index level operations ------ @@ -146,7 +146,7 @@ public: * only called once for the lifetime of the index * if called multiple times, is an error */ - Status initializeAsEmpty(OperationContext* txn); + Status initializeAsEmpty(OperationContext* opCtx); /** * Try to page-in the pages that contain the keys generated from 'obj'. @@ -154,12 +154,12 @@ public: * appropriate pages are not swapped out. * See prefetch.cpp. */ - Status touch(OperationContext* txn, const BSONObj& obj); + Status touch(OperationContext* opCtx, const BSONObj& obj); /** * this pages in the entire index */ - Status touch(OperationContext* txn) const; + Status touch(OperationContext* opCtx) const; /** * Walk the entire index, checking the internal structure for consistency. @@ -167,7 +167,7 @@ public: * Return OK if the index is valid. */ - Status validate(OperationContext* txn, int64_t* numKeys, ValidateResults* fullResults); + Status validate(OperationContext* opCtx, int64_t* numKeys, ValidateResults* fullResults); /** * Add custom statistics about this index to BSON object builder, for display. @@ -176,21 +176,21 @@ public: * * Returns true if stats were appended. */ - bool appendCustomStats(OperationContext* txn, BSONObjBuilder* result, double scale) const; + bool appendCustomStats(OperationContext* opCtx, BSONObjBuilder* result, double scale) 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; + long long getSpaceUsedBytes(OperationContext* opCtx) const; - RecordId findSingle(OperationContext* txn, const BSONObj& key) const; + RecordId findSingle(OperationContext* opCtx, const BSONObj& key) const; /** * Attempt compaction to regain disk space if the indexed record store supports * compaction-in-place. */ - Status compact(OperationContext* txn); + Status compact(OperationContext* opCtx); // // Bulk operations support @@ -201,7 +201,7 @@ public: /** * Insert into the BulkBuilder as-if inserting into an IndexAccessMethod. */ - Status insert(OperationContext* txn, + Status insert(OperationContext* opCtx, const BSONObj& obj, const RecordId& loc, const InsertDeleteOptions& options, @@ -250,7 +250,7 @@ public: * @param dups - if NULL, error out on dups if not allowed * if not NULL, put the bad RecordIds there */ - Status commitBulk(OperationContext* txn, + Status commitBulk(OperationContext* opCtx, std::unique_ptr<BulkBuilder> bulk, bool mayInterrupt, bool dupsAllowed, @@ -306,13 +306,13 @@ protected: /** * Determines whether it's OK to ignore ErrorCodes::KeyTooLong for this OperationContext */ - bool ignoreKeyTooLong(OperationContext* txn); + bool ignoreKeyTooLong(OperationContext* opCtx); IndexCatalogEntry* _btreeState; // owned by IndexCatalogEntry const IndexDescriptor* _descriptor; private: - void removeOneKey(OperationContext* txn, + void removeOneKey(OperationContext* opCtx, const BSONObj& key, const RecordId& loc, bool dupsAllowed); |