summaryrefslogtreecommitdiff
path: root/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl.cpp
diff options
context:
space:
mode:
authorXiangyu Yao <xiangyu.yao@mongodb.com>2018-09-10 17:53:51 -0400
committerXiangyu Yao <xiangyu.yao@mongodb.com>2018-09-13 13:24:55 -0400
commit061d13d34af2d75f1b3597b1a60478a60a97e7c7 (patch)
treea18808c119a6d24b10c4544e75b6088c7ca43b2b /src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl.cpp
parentacc2f4f010aee30505c0fab0c46d5faee84390d9 (diff)
downloadmongo-061d13d34af2d75f1b3597b1a60478a60a97e7c7.tar.gz
SERVER-37070 Improve duplicate key error messages for all storage engines
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.cpp48
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