diff options
Diffstat (limited to 'src/mongo/db/storage/mobile')
-rw-r--r-- | src/mongo/db/storage/mobile/mobile_index.cpp | 54 | ||||
-rw-r--r-- | src/mongo/db/storage/mobile/mobile_index.h | 8 | ||||
-rw-r--r-- | src/mongo/db/storage/mobile/mobile_index_test.cpp | 5 |
3 files changed, 44 insertions, 23 deletions
diff --git a/src/mongo/db/storage/mobile/mobile_index.cpp b/src/mongo/db/storage/mobile/mobile_index.cpp index 0eec0ce72d8..3c5000c4929 100644 --- a/src/mongo/db/storage/mobile/mobile_index.cpp +++ b/src/mongo/db/storage/mobile/mobile_index.cpp @@ -72,7 +72,11 @@ BSONObj stripFieldNames(const BSONObj& query) { MobileIndex::MobileIndex(OperationContext* opCtx, const IndexDescriptor* desc, const std::string& ident) - : _isUnique(desc->unique()), _ordering(Ordering::make(desc->keyPattern())), _ident(ident) {} + : _isUnique(desc->unique()), + _ordering(Ordering::make(desc->keyPattern())), + _ident(ident), + _collectionNamespace(desc->parentNS()), + _indexName(desc->indexName()) {} StatusWith<SpecialFormatInserted> MobileIndex::insert(OperationContext* opCtx, const BSONObj& key, @@ -109,7 +113,7 @@ StatusWith<SpecialFormatInserted> MobileIndex::doInsert(OperationContext* opCtx, // Return error if duplicate key inserted in a unique index. BSONObj bson = KeyString::toBson(key.getBuffer(), key.getSize(), _ordering, key.getTypeBits()); - return _dupKeyError(bson); + return dupKeyError(bson, _collectionNamespace, _indexName); } else { // A record with same key could already be present in a standard index, that is OK. This // can happen when building a background index while documents are being written in @@ -239,7 +243,7 @@ Status MobileIndex::dupKeyCheck(OperationContext* opCtx, invariant(_isUnique); if (_isDup(opCtx, key, recId)) - return _dupKeyError(key); + return dupKeyError(key, _collectionNamespace, _indexName); return Status::OK(); } @@ -273,18 +277,18 @@ bool MobileIndex::_isDup(OperationContext* opCtx, const BSONObj& key, RecordId r return isEntryFound; } -Status MobileIndex::_dupKeyError(const BSONObj& key) { - StringBuilder sb; - sb << "E11000 duplicate key error "; - sb << "index: " << _ident << " "; - sb << "dup key: " << key; - return Status(ErrorCodes::DuplicateKey, sb.str()); -} - class MobileIndex::BulkBuilderBase : public SortedDataBuilderInterface { public: - BulkBuilderBase(MobileIndex* index, OperationContext* opCtx, bool dupsAllowed) - : _index(index), _opCtx(opCtx), _dupsAllowed(dupsAllowed) {} + BulkBuilderBase(MobileIndex* index, + OperationContext* opCtx, + bool dupsAllowed, + const std::string& collectionNamespace, + const std::string& indexName) + : _index(index), + _opCtx(opCtx), + _dupsAllowed(dupsAllowed), + _collectionNamespace(collectionNamespace), + _indexName(indexName) {} virtual ~BulkBuilderBase() {} @@ -314,7 +318,7 @@ protected: Status _checkNextKey(const BSONObj& key) { const int cmp = key.woCompare(_lastKey, _index->getOrdering()); if (!_dupsAllowed && cmp == 0) { - return _index->_dupKeyError(key); + return dupKeyError(key, _collectionNamespace, _indexName); } else if (cmp < 0) { return Status(ErrorCodes::InternalError, "expected higher RecordId in bulk builder"); } @@ -328,6 +332,8 @@ protected: OperationContext* const _opCtx; BSONObj _lastKey; const bool _dupsAllowed; + const std::string _collectionNamespace; + const std::string _indexName; }; /** @@ -335,8 +341,12 @@ protected: */ class MobileIndex::BulkBuilderStandard final : public BulkBuilderBase { public: - BulkBuilderStandard(MobileIndex* index, OperationContext* opCtx, bool dupsAllowed) - : BulkBuilderBase(index, opCtx, dupsAllowed) {} + BulkBuilderStandard(MobileIndex* index, + OperationContext* opCtx, + bool dupsAllowed, + const std::string& collectionNamespace, + const std::string& indexName) + : BulkBuilderBase(index, opCtx, dupsAllowed, collectionNamespace, indexName) {} protected: StatusWith<SpecialFormatInserted> _addKey(const BSONObj& key, const RecordId& recId) override { @@ -351,8 +361,12 @@ protected: */ class MobileIndex::BulkBuilderUnique : public BulkBuilderBase { public: - BulkBuilderUnique(MobileIndex* index, OperationContext* opCtx, bool dupsAllowed) - : BulkBuilderBase(index, opCtx, dupsAllowed) { + BulkBuilderUnique(MobileIndex* index, + OperationContext* opCtx, + bool dupsAllowed, + const std::string& collectionNamespace, + const std::string& indexName) + : BulkBuilderBase(index, opCtx, dupsAllowed, collectionNamespace, indexName) { // Replication is not supported so dups are not allowed. invariant(!dupsAllowed); } @@ -652,7 +666,7 @@ MobileIndexStandard::MobileIndexStandard(OperationContext* opCtx, SortedDataBuilderInterface* MobileIndexStandard::getBulkBuilder(OperationContext* opCtx, bool dupsAllowed) { invariant(dupsAllowed); - return new BulkBuilderStandard(this, opCtx, dupsAllowed); + return new BulkBuilderStandard(this, opCtx, dupsAllowed, _collectionNamespace, _indexName); } std::unique_ptr<SortedDataInterface::Cursor> MobileIndexStandard::newCursor(OperationContext* opCtx, @@ -690,7 +704,7 @@ SortedDataBuilderInterface* MobileIndexUnique::getBulkBuilder(OperationContext* bool dupsAllowed) { // Replication is not supported so dups are not allowed. invariant(!dupsAllowed); - return new BulkBuilderUnique(this, opCtx, dupsAllowed); + return new BulkBuilderUnique(this, opCtx, dupsAllowed, _collectionNamespace, _indexName); } std::unique_ptr<SortedDataInterface::Cursor> MobileIndexUnique::newCursor(OperationContext* opCtx, diff --git a/src/mongo/db/storage/mobile/mobile_index.h b/src/mongo/db/storage/mobile/mobile_index.h index c7ef60d7061..69c3ee08bca 100644 --- a/src/mongo/db/storage/mobile/mobile_index.h +++ b/src/mongo/db/storage/mobile/mobile_index.h @@ -43,7 +43,11 @@ class MobileIndex : public SortedDataInterface { public: MobileIndex(OperationContext* opCtx, const IndexDescriptor* desc, const std::string& ident); - MobileIndex(bool isUnique, const Ordering& ordering, const std::string& ident); + MobileIndex(bool isUnique, + const Ordering& ordering, + const std::string& ident, + const std::string& collectionNamespace, + const std::string& indexName); virtual ~MobileIndex() {} @@ -135,6 +139,8 @@ protected: const Ordering _ordering; const KeyString::Version _keyStringVersion = KeyString::kLatestVersion; const std::string _ident; + const std::string _collectionNamespace; + const std::string _indexName; }; class MobileIndexStandard final : public MobileIndex { diff --git a/src/mongo/db/storage/mobile/mobile_index_test.cpp b/src/mongo/db/storage/mobile/mobile_index_test.cpp index 31419df65fb..4a2502509e2 100644 --- a/src/mongo/db/storage/mobile/mobile_index_test.cpp +++ b/src/mongo/db/storage/mobile/mobile_index_test.cpp @@ -60,9 +60,10 @@ public: fassert(37052, status); if (isUnique) { - return stdx::make_unique<MobileIndexUnique>(_ordering, ident); + return stdx::make_unique<MobileIndexUnique>( + _ordering, ident, "test.mobile", "indexName"); } - return stdx::make_unique<MobileIndexStandard>(_ordering, ident); + return stdx::make_unique<MobileIndexStandard>(_ordering, ident, "test.mobile", "indexName"); } std::unique_ptr<RecoveryUnit> newRecoveryUnit() { |