diff options
author | Xiangyu Yao <xiangyu.yao@mongodb.com> | 2018-09-13 13:52:39 -0400 |
---|---|---|
committer | Xiangyu Yao <xiangyu.yao@mongodb.com> | 2018-09-13 14:07:10 -0400 |
commit | 7c13a75b928ace3f65c9553352689dc0a6d0ca83 (patch) | |
tree | 87870158925b882389442fd05bc97824f68a8e6f /src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl.cpp | |
parent | 04da23e18226418856e85a9dcfecafef81488de3 (diff) | |
download | mongo-7c13a75b928ace3f65c9553352689dc0a6d0ca83.tar.gz |
SERVER-37070 Improve duplicate key error messages for all storage enginesr4.1.3
Diffstat (limited to 'src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl.cpp')
-rw-r--r-- | src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl.cpp | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl.cpp b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl.cpp index 1f7b8a02f26..aafbf42a148 100644 --- a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl.cpp +++ b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl.cpp @@ -70,15 +70,6 @@ BSONObj stripFieldNames(const BSONObj& query) { typedef std::set<IndexKeyEntry, IndexEntryComparison> IndexSet; -// taken from btree_logic.cpp -Status dupKeyError(const BSONObj& key) { - StringBuilder sb; - sb << "E11000 duplicate key error "; - // sb << "index: " << _indexName << " "; // TODO - sb << "dup key: " << key; - return Status(ErrorCodes::DuplicateKey, sb.str()); -} - bool isDup(const IndexSet& data, const BSONObj& key, RecordId loc) { const IndexSet::const_iterator it = data.find(IndexKeyEntry(key, RecordId())); if (it == data.end()) @@ -90,11 +81,17 @@ bool isDup(const IndexSet& data, const BSONObj& key, RecordId loc) { class EphemeralForTestBtreeBuilderImpl : public SortedDataBuilderInterface { public: - EphemeralForTestBtreeBuilderImpl(IndexSet* data, long long* currentKeySize, bool dupsAllowed) + EphemeralForTestBtreeBuilderImpl(IndexSet* data, + long long* currentKeySize, + bool dupsAllowed, + const std::string& collectionNamespace, + const std::string& indexName) : _data(data), _currentKeySize(currentKeySize), _dupsAllowed(dupsAllowed), - _comparator(_data->key_comp()) { + _comparator(_data->key_comp()), + _collectionNamespace(collectionNamespace), + _indexName(indexName) { invariant(_data->empty()); } @@ -111,7 +108,7 @@ public: return Status(ErrorCodes::InternalError, "expected ascending (key, RecordId) order in bulk builder"); } else if (!_dupsAllowed && cmp == 0 && loc != _last->loc) { - return dupKeyError(key); + return dupKeyError(key, _collectionNamespace, _indexName); } } @@ -129,16 +126,27 @@ private: IndexEntryComparison _comparator; // used by the bulk builder to detect duplicate keys IndexSet::const_iterator _last; // or (key, RecordId) ordering violations + + const std::string _collectionNamespace; + const std::string _indexName; }; class EphemeralForTestBtreeImpl : public SortedDataInterface { public: - EphemeralForTestBtreeImpl(IndexSet* data, bool isUnique) : _data(data), _isUnique(isUnique) { + EphemeralForTestBtreeImpl(IndexSet* data, + bool isUnique, + const std::string& collectionNamespace, + const std::string& indexName) + : _data(data), + _isUnique(isUnique), + _collectionNamespace(collectionNamespace), + _indexName(indexName) { _currentKeySize = 0; } virtual SortedDataBuilderInterface* getBulkBuilder(OperationContext* opCtx, bool dupsAllowed) { - return new EphemeralForTestBtreeBuilderImpl(_data, &_currentKeySize, dupsAllowed); + return new EphemeralForTestBtreeBuilderImpl( + _data, &_currentKeySize, dupsAllowed, _collectionNamespace, _indexName); } virtual StatusWith<SpecialFormatInserted> insert(OperationContext* opCtx, @@ -151,7 +159,7 @@ public: // TODO optimization: save the iterator from the dup-check to speed up insert if (!dupsAllowed && isDup(*_data, key, loc)) - return dupKeyError(key); + return dupKeyError(key, _collectionNamespace, _indexName); IndexKeyEntry entry(key.getOwned(), loc); if (_data->insert(entry).second) { @@ -197,7 +205,7 @@ public: virtual Status dupKeyCheck(OperationContext* opCtx, const BSONObj& key, const RecordId& loc) { invariant(!hasFieldNames(key)); if (isDup(*_data, key, loc)) - return dupKeyError(key); + return dupKeyError(key, _collectionNamespace, _indexName); return Status::OK(); } @@ -492,6 +500,9 @@ private: IndexSet* _data; long long _currentKeySize; const bool _isUnique; + + const std::string _collectionNamespace; + const std::string _indexName; }; } // namespace @@ -499,12 +510,15 @@ private: // factories. We don't actually modify it. SortedDataInterface* getEphemeralForTestBtreeImpl(const Ordering& ordering, bool isUnique, + const std::string& collectionNamespace, + const std::string& indexName, std::shared_ptr<void>* dataInOut) { invariant(dataInOut); if (!*dataInOut) { *dataInOut = std::make_shared<IndexSet>(IndexEntryComparison(ordering)); } - return new EphemeralForTestBtreeImpl(static_cast<IndexSet*>(dataInOut->get()), isUnique); + return new EphemeralForTestBtreeImpl( + static_cast<IndexSet*>(dataInOut->get()), isUnique, collectionNamespace, indexName); } } // namespace mongo |