summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorXiangyu Yao <xiangyu.yao@mongodb.com>2018-09-13 13:51:27 -0400
committerXiangyu Yao <xiangyu.yao@mongodb.com>2018-09-13 13:51:27 -0400
commit2fe3f4abbaf9f1dddf8116d27c6395b966f877e3 (patch)
tree7d1eaae684a3730cba518778f8d56bee69ab14cb /src
parentcff86d0ddae1218236d82a198f9d51a5cd703726 (diff)
downloadmongo-2fe3f4abbaf9f1dddf8116d27c6395b966f877e3.tar.gz
Revert "SERVER-37070 Improve duplicate key error messages for all storage engines"
This reverts commit 061d13d34af2d75f1b3597b1a60478a60a97e7c7.
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/storage/biggie/biggie_kv_engine.cpp6
-rw-r--r--src/mongo/db/storage/biggie/biggie_sorted_impl.cpp32
-rw-r--r--src/mongo/db/storage/biggie/biggie_sorted_impl.h18
-rw-r--r--src/mongo/db/storage/biggie/biggie_sorted_impl_test.cpp3
-rw-r--r--src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl.cpp48
-rw-r--r--src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl.h2
-rw-r--r--src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_engine.cpp7
-rw-r--r--src/mongo/db/storage/mobile/mobile_index.cpp54
-rw-r--r--src/mongo/db/storage/mobile/mobile_index.h8
-rw-r--r--src/mongo/db/storage/mobile/mobile_index_test.cpp5
-rw-r--r--src/mongo/db/storage/sorted_data_interface.h14
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp21
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_index.h2
13 files changed, 78 insertions, 142 deletions
diff --git a/src/mongo/db/storage/biggie/biggie_kv_engine.cpp b/src/mongo/db/storage/biggie/biggie_kv_engine.cpp
index 7c79a822d03..b99d45ccd1c 100644
--- a/src/mongo/db/storage/biggie/biggie_kv_engine.cpp
+++ b/src/mongo/db/storage/biggie/biggie_kv_engine.cpp
@@ -94,11 +94,7 @@ Status KVEngine::createSortedDataInterface(OperationContext* opCtx,
mongo::SortedDataInterface* KVEngine::getSortedDataInterface(OperationContext* opCtx,
StringData ident,
const IndexDescriptor* desc) {
- return new SortedDataInterface(Ordering::make(desc->keyPattern()),
- desc->unique(),
- ident,
- desc->parentNS(),
- desc->indexName());
+ return new SortedDataInterface(Ordering::make(desc->keyPattern()), desc->unique(), ident);
}
diff --git a/src/mongo/db/storage/biggie/biggie_sorted_impl.cpp b/src/mongo/db/storage/biggie/biggie_sorted_impl.cpp
index e7ce7750c79..6dc78eb4e06 100644
--- a/src/mongo/db/storage/biggie/biggie_sorted_impl.cpp
+++ b/src/mongo/db/storage/biggie/biggie_sorted_impl.cpp
@@ -83,6 +83,13 @@ BSONObj stripFieldNames(const BSONObj& obj) {
return bob.obj();
}
+Status dupKeyError(const BSONObj& key) {
+ StringBuilder sb;
+ sb << "E11000 duplicate key error ";
+ sb << "dup key: " << key;
+ return Status(ErrorCodes::DuplicateKey, sb.str());
+}
+
// This function converts a key and an ordering to a KeyString.
std::unique_ptr<KeyString> keyToKeyString(const BSONObj& key, Ordering order) {
KeyString::Version version = KeyString::Version::V1;
@@ -213,17 +220,13 @@ int compareTwoKeys(
SortedDataBuilderInterface::SortedDataBuilderInterface(OperationContext* opCtx,
bool dupsAllowed,
Ordering order,
- const std::string& prefix,
- const std::string& identEnd,
- const std::string& collectionNamespace,
- const std::string& indexName)
+ std::string prefix,
+ std::string identEnd)
: _opCtx(opCtx),
_dupsAllowed(dupsAllowed),
_order(order),
_prefix(prefix),
_identEnd(identEnd),
- _collectionNamespace(collectionNamespace),
- _indexName(indexName),
_hasLast(false),
_lastKeyToString(""),
_lastRID(-1) {}
@@ -258,7 +261,7 @@ StatusWith<SpecialFormatInserted> SortedDataBuilderInterface::addKey(const BSONO
"expected ascending (key, RecordId) order in bulk builder");
}
if (!_dupsAllowed && twoKeyCmp == 0 && twoRIDCmp != 0) {
- return dupKeyError(key, _collectionNamespace, _indexName);
+ return dupKeyError(key);
}
std::string workingCopyInsertKey = combineKeyAndRID(key, loc, _prefix, _order);
@@ -280,25 +283,18 @@ StatusWith<SpecialFormatInserted> SortedDataBuilderInterface::addKey(const BSONO
SortedDataBuilderInterface* SortedDataInterface::getBulkBuilder(OperationContext* opCtx,
bool dupsAllowed) {
- return new SortedDataBuilderInterface(
- opCtx, dupsAllowed, _order, _prefix, _identEnd, _collectionNamespace, _indexName);
+ return new SortedDataBuilderInterface(opCtx, dupsAllowed, _order, _prefix, _identEnd);
}
// We append \1 to all idents we get, and therefore the KeyString with ident + \0 will only be
// before elements in this ident, and the KeyString with ident + \2 will only be after elements in
// this ident.
-SortedDataInterface::SortedDataInterface(const Ordering& ordering,
- bool isUnique,
- StringData ident,
- const std::string& collectionNamespace,
- const std::string& indexName)
+SortedDataInterface::SortedDataInterface(const Ordering& ordering, bool isUnique, StringData ident)
: _order(ordering),
// All entries in this ident will have a prefix of ident + \1.
_prefix(ident.toString().append(1, '\1')),
// Therefore, the string ident + \2 will be greater than all elements in this ident.
_identEnd(ident.toString().append(1, '\2')),
- _collectionNamespace(collectionNamespace),
- _indexName(indexName),
_isUnique(isUnique) {
// This is the string representation of the KeyString before elements in this ident, which is
// ident + \0. This is before all elements in this ident.
@@ -344,7 +340,7 @@ StatusWith<SpecialFormatInserted> SortedDataInterface::insert(OperationContext*
auto ks1 = keyToKeyString(ike.key, _order);
auto ks2 = keyToKeyString(key, _order);
if (ks1->compare(*ks2) == 0 && ike.loc.repr() != loc.repr()) {
- return dupKeyError(key, _collectionNamespace, _indexName);
+ return dupKeyError(key);
}
}
}
@@ -402,7 +398,7 @@ Status SortedDataInterface::dupKeyCheck(OperationContext* opCtx,
lowerBoundIterator->first.compare(_KSForIdentEnd) < 0 &&
lowerBoundIterator->first.compare(
combineKeyAndRID(key, RecordId::max(), _prefix, _order)) <= 0) {
- return dupKeyError(key, _collectionNamespace, _indexName);
+ return dupKeyError(key);
}
return Status::OK();
}
diff --git a/src/mongo/db/storage/biggie/biggie_sorted_impl.h b/src/mongo/db/storage/biggie/biggie_sorted_impl.h
index 09a049981c4..8ebf74a8c93 100644
--- a/src/mongo/db/storage/biggie/biggie_sorted_impl.h
+++ b/src/mongo/db/storage/biggie/biggie_sorted_impl.h
@@ -41,10 +41,8 @@ public:
SortedDataBuilderInterface(OperationContext* opCtx,
bool dupsAllowed,
Ordering order,
- const std::string& prefix,
- const std::string& identEnd,
- const std::string& collectionNamespace,
- const std::string& indexName);
+ std::string prefix,
+ std::string identEnd);
SpecialFormatInserted commit(bool mayInterrupt) override;
virtual StatusWith<SpecialFormatInserted> addKey(const BSONObj& key, const RecordId& loc);
@@ -56,9 +54,6 @@ private:
// Prefix and identEnd for the ident.
std::string _prefix;
std::string _identEnd;
- // Index metadata.
- const std::string _collectionNamespace;
- const std::string _indexName;
// Whether or not we've already added something before.
bool _hasLast;
// This is the KeyString of the last key added.
@@ -72,11 +67,7 @@ public:
// Truncate is not required at the time of writing but will be when the truncate command is
// created
Status truncate(OperationContext* opCtx);
- SortedDataInterface(const Ordering& ordering,
- bool isUnique,
- StringData ident,
- const std::string& collectionNamespace,
- const std::string& indexName);
+ SortedDataInterface(const Ordering& ordering, bool isUnique, StringData ident);
virtual SortedDataBuilderInterface* getBulkBuilder(OperationContext* opCtx,
bool dupsAllowed) override;
virtual StatusWith<SpecialFormatInserted> insert(OperationContext* opCtx,
@@ -177,9 +168,6 @@ private:
// These two are the same as before.
std::string _prefix;
std::string _identEnd;
- // Index metadata.
- const std::string _collectionNamespace;
- const std::string _indexName;
// These are the keystring representations of the _prefix and the _identEnd.
std::string _KSForIdentStart;
std::string _KSForIdentEnd;
diff --git a/src/mongo/db/storage/biggie/biggie_sorted_impl_test.cpp b/src/mongo/db/storage/biggie/biggie_sorted_impl_test.cpp
index 68a82231ddd..6fdcb589627 100644
--- a/src/mongo/db/storage/biggie/biggie_sorted_impl_test.cpp
+++ b/src/mongo/db/storage/biggie/biggie_sorted_impl_test.cpp
@@ -47,8 +47,7 @@ private:
public:
SortedDataInterfaceTestHarnessHelper() : _order(Ordering::make(BSONObj())) {}
std::unique_ptr<mongo::SortedDataInterface> newSortedDataInterface(bool unique) final {
- return std::make_unique<SortedDataInterface>(
- _order, unique, "ident"_sd, "test.biggie", "indexName");
+ return std::make_unique<SortedDataInterface>(_order, unique, "ident"_sd);
}
std::unique_ptr<mongo::RecoveryUnit> newRecoveryUnit() final {
//! not correct lol
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 aafbf42a148..1f7b8a02f26 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,6 +70,15 @@ 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())
@@ -81,17 +90,11 @@ bool isDup(const IndexSet& data, const BSONObj& key, RecordId loc) {
class EphemeralForTestBtreeBuilderImpl : public SortedDataBuilderInterface {
public:
- EphemeralForTestBtreeBuilderImpl(IndexSet* data,
- long long* currentKeySize,
- bool dupsAllowed,
- const std::string& collectionNamespace,
- const std::string& indexName)
+ EphemeralForTestBtreeBuilderImpl(IndexSet* data, long long* currentKeySize, bool dupsAllowed)
: _data(data),
_currentKeySize(currentKeySize),
_dupsAllowed(dupsAllowed),
- _comparator(_data->key_comp()),
- _collectionNamespace(collectionNamespace),
- _indexName(indexName) {
+ _comparator(_data->key_comp()) {
invariant(_data->empty());
}
@@ -108,7 +111,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, _collectionNamespace, _indexName);
+ return dupKeyError(key);
}
}
@@ -126,27 +129,16 @@ 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,
- const std::string& collectionNamespace,
- const std::string& indexName)
- : _data(data),
- _isUnique(isUnique),
- _collectionNamespace(collectionNamespace),
- _indexName(indexName) {
+ EphemeralForTestBtreeImpl(IndexSet* data, bool isUnique) : _data(data), _isUnique(isUnique) {
_currentKeySize = 0;
}
virtual SortedDataBuilderInterface* getBulkBuilder(OperationContext* opCtx, bool dupsAllowed) {
- return new EphemeralForTestBtreeBuilderImpl(
- _data, &_currentKeySize, dupsAllowed, _collectionNamespace, _indexName);
+ return new EphemeralForTestBtreeBuilderImpl(_data, &_currentKeySize, dupsAllowed);
}
virtual StatusWith<SpecialFormatInserted> insert(OperationContext* opCtx,
@@ -159,7 +151,7 @@ public:
// TODO optimization: save the iterator from the dup-check to speed up insert
if (!dupsAllowed && isDup(*_data, key, loc))
- return dupKeyError(key, _collectionNamespace, _indexName);
+ return dupKeyError(key);
IndexKeyEntry entry(key.getOwned(), loc);
if (_data->insert(entry).second) {
@@ -205,7 +197,7 @@ public:
virtual Status dupKeyCheck(OperationContext* opCtx, const BSONObj& key, const RecordId& loc) {
invariant(!hasFieldNames(key));
if (isDup(*_data, key, loc))
- return dupKeyError(key, _collectionNamespace, _indexName);
+ return dupKeyError(key);
return Status::OK();
}
@@ -500,9 +492,6 @@ private:
IndexSet* _data;
long long _currentKeySize;
const bool _isUnique;
-
- const std::string _collectionNamespace;
- const std::string _indexName;
};
} // namespace
@@ -510,15 +499,12 @@ 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, collectionNamespace, indexName);
+ return new EphemeralForTestBtreeImpl(static_cast<IndexSet*>(dataInOut->get()), isUnique);
}
} // namespace mongo
diff --git a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl.h b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl.h
index 57432888662..9d44e3e80cd 100644
--- a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl.h
+++ b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl.h
@@ -43,8 +43,6 @@ class IndexCatalogEntry;
*/
SortedDataInterface* getEphemeralForTestBtreeImpl(const Ordering& ordering,
bool isUnique,
- const std::string& collectionNamespace,
- const std::string& indexName,
std::shared_ptr<void>* dataInOut);
} // namespace mongo
diff --git a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_engine.cpp b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_engine.cpp
index b8814c3bdd0..0bc0f4f8412 100644
--- a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_engine.cpp
+++ b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_engine.cpp
@@ -89,11 +89,8 @@ SortedDataInterface* EphemeralForTestEngine::getSortedDataInterface(OperationCon
StringData ident,
const IndexDescriptor* desc) {
stdx::lock_guard<stdx::mutex> lk(_mutex);
- return getEphemeralForTestBtreeImpl(Ordering::make(desc->keyPattern()),
- desc->unique(),
- desc->parentNS(),
- desc->indexName(),
- &_dataMap[ident]);
+ return getEphemeralForTestBtreeImpl(
+ Ordering::make(desc->keyPattern()), desc->unique(), &_dataMap[ident]);
}
Status EphemeralForTestEngine::dropIdent(OperationContext* opCtx, StringData ident) {
diff --git a/src/mongo/db/storage/mobile/mobile_index.cpp b/src/mongo/db/storage/mobile/mobile_index.cpp
index 3c5000c4929..0eec0ce72d8 100644
--- a/src/mongo/db/storage/mobile/mobile_index.cpp
+++ b/src/mongo/db/storage/mobile/mobile_index.cpp
@@ -72,11 +72,7 @@ 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),
- _collectionNamespace(desc->parentNS()),
- _indexName(desc->indexName()) {}
+ : _isUnique(desc->unique()), _ordering(Ordering::make(desc->keyPattern())), _ident(ident) {}
StatusWith<SpecialFormatInserted> MobileIndex::insert(OperationContext* opCtx,
const BSONObj& key,
@@ -113,7 +109,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, _collectionNamespace, _indexName);
+ return _dupKeyError(bson);
} 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
@@ -243,7 +239,7 @@ Status MobileIndex::dupKeyCheck(OperationContext* opCtx,
invariant(_isUnique);
if (_isDup(opCtx, key, recId))
- return dupKeyError(key, _collectionNamespace, _indexName);
+ return _dupKeyError(key);
return Status::OK();
}
@@ -277,18 +273,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,
- const std::string& collectionNamespace,
- const std::string& indexName)
- : _index(index),
- _opCtx(opCtx),
- _dupsAllowed(dupsAllowed),
- _collectionNamespace(collectionNamespace),
- _indexName(indexName) {}
+ BulkBuilderBase(MobileIndex* index, OperationContext* opCtx, bool dupsAllowed)
+ : _index(index), _opCtx(opCtx), _dupsAllowed(dupsAllowed) {}
virtual ~BulkBuilderBase() {}
@@ -318,7 +314,7 @@ protected:
Status _checkNextKey(const BSONObj& key) {
const int cmp = key.woCompare(_lastKey, _index->getOrdering());
if (!_dupsAllowed && cmp == 0) {
- return dupKeyError(key, _collectionNamespace, _indexName);
+ return _index->_dupKeyError(key);
} else if (cmp < 0) {
return Status(ErrorCodes::InternalError, "expected higher RecordId in bulk builder");
}
@@ -332,8 +328,6 @@ protected:
OperationContext* const _opCtx;
BSONObj _lastKey;
const bool _dupsAllowed;
- const std::string _collectionNamespace;
- const std::string _indexName;
};
/**
@@ -341,12 +335,8 @@ protected:
*/
class MobileIndex::BulkBuilderStandard final : public BulkBuilderBase {
public:
- BulkBuilderStandard(MobileIndex* index,
- OperationContext* opCtx,
- bool dupsAllowed,
- const std::string& collectionNamespace,
- const std::string& indexName)
- : BulkBuilderBase(index, opCtx, dupsAllowed, collectionNamespace, indexName) {}
+ BulkBuilderStandard(MobileIndex* index, OperationContext* opCtx, bool dupsAllowed)
+ : BulkBuilderBase(index, opCtx, dupsAllowed) {}
protected:
StatusWith<SpecialFormatInserted> _addKey(const BSONObj& key, const RecordId& recId) override {
@@ -361,12 +351,8 @@ protected:
*/
class MobileIndex::BulkBuilderUnique : public BulkBuilderBase {
public:
- BulkBuilderUnique(MobileIndex* index,
- OperationContext* opCtx,
- bool dupsAllowed,
- const std::string& collectionNamespace,
- const std::string& indexName)
- : BulkBuilderBase(index, opCtx, dupsAllowed, collectionNamespace, indexName) {
+ BulkBuilderUnique(MobileIndex* index, OperationContext* opCtx, bool dupsAllowed)
+ : BulkBuilderBase(index, opCtx, dupsAllowed) {
// Replication is not supported so dups are not allowed.
invariant(!dupsAllowed);
}
@@ -666,7 +652,7 @@ MobileIndexStandard::MobileIndexStandard(OperationContext* opCtx,
SortedDataBuilderInterface* MobileIndexStandard::getBulkBuilder(OperationContext* opCtx,
bool dupsAllowed) {
invariant(dupsAllowed);
- return new BulkBuilderStandard(this, opCtx, dupsAllowed, _collectionNamespace, _indexName);
+ return new BulkBuilderStandard(this, opCtx, dupsAllowed);
}
std::unique_ptr<SortedDataInterface::Cursor> MobileIndexStandard::newCursor(OperationContext* opCtx,
@@ -704,7 +690,7 @@ SortedDataBuilderInterface* MobileIndexUnique::getBulkBuilder(OperationContext*
bool dupsAllowed) {
// Replication is not supported so dups are not allowed.
invariant(!dupsAllowed);
- return new BulkBuilderUnique(this, opCtx, dupsAllowed, _collectionNamespace, _indexName);
+ return new BulkBuilderUnique(this, opCtx, dupsAllowed);
}
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 69c3ee08bca..c7ef60d7061 100644
--- a/src/mongo/db/storage/mobile/mobile_index.h
+++ b/src/mongo/db/storage/mobile/mobile_index.h
@@ -43,11 +43,7 @@ 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,
- const std::string& collectionNamespace,
- const std::string& indexName);
+ MobileIndex(bool isUnique, const Ordering& ordering, const std::string& ident);
virtual ~MobileIndex() {}
@@ -139,8 +135,6 @@ 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 4a2502509e2..31419df65fb 100644
--- a/src/mongo/db/storage/mobile/mobile_index_test.cpp
+++ b/src/mongo/db/storage/mobile/mobile_index_test.cpp
@@ -60,10 +60,9 @@ public:
fassert(37052, status);
if (isUnique) {
- return stdx::make_unique<MobileIndexUnique>(
- _ordering, ident, "test.mobile", "indexName");
+ return stdx::make_unique<MobileIndexUnique>(_ordering, ident);
}
- return stdx::make_unique<MobileIndexStandard>(_ordering, ident, "test.mobile", "indexName");
+ return stdx::make_unique<MobileIndexStandard>(_ordering, ident);
}
std::unique_ptr<RecoveryUnit> newRecoveryUnit() {
diff --git a/src/mongo/db/storage/sorted_data_interface.h b/src/mongo/db/storage/sorted_data_interface.h
index 4b720468344..74355bc96f9 100644
--- a/src/mongo/db/storage/sorted_data_interface.h
+++ b/src/mongo/db/storage/sorted_data_interface.h
@@ -52,20 +52,6 @@ struct ValidateResults;
enum SpecialFormatInserted { NoSpecialFormatInserted = 0, LongTypeBitsInserted = 1 };
/**
- * Returns the formatted error status about the duplicate key.
- */
-inline Status dupKeyError(const BSONObj& key,
- const std::string& collectionNamespace,
- const std::string& indexName) {
- StringBuilder sb;
- sb << "E11000 duplicate key error";
- sb << " collection: " << collectionNamespace;
- sb << " index: " << indexName;
- sb << " dup key: " << key;
- return Status(ErrorCodes::DuplicateKey, sb.str());
-}
-
-/**
* This is the uniform interface for storing indexes and supporting point queries as well as range
* queries. The actual implementation is up to the storage engine. All the storage engines must
* support an index key size up to the maximum document size.
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp
index f260ffe13e0..8043c206ebe 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp
@@ -114,6 +114,15 @@ const int kDataFormatV4KeyStringV1UniqueIndexVersionV2 = 12;
const int kMinimumIndexVersion = kDataFormatV1KeyStringV0IndexVersionV1;
const int kMaximumIndexVersion = kDataFormatV4KeyStringV1UniqueIndexVersionV2;
+Status WiredTigerIndex::dupKeyError(const BSONObj& key) {
+ StringBuilder sb;
+ sb << "E11000 duplicate key error";
+ sb << " collection: " << _collectionNamespace;
+ sb << " index: " << _indexName;
+ sb << " dup key: " << key;
+ return Status(ErrorCodes::DuplicateKey, sb.str());
+}
+
void WiredTigerIndex::setKey(WT_CURSOR* cursor, const WT_ITEM* item) {
if (_prefix == KVPrefix::kNotPrefixed) {
cursor->set_key(cursor, item);
@@ -413,7 +422,7 @@ Status WiredTigerIndex::dupKeyCheck(OperationContext* opCtx,
WT_CURSOR* c = curwrap.get();
if (isDup(opCtx, c, key, id))
- return dupKeyError(key, _collectionNamespace, _indexName);
+ return dupKeyError(key);
return Status::OK();
}
@@ -681,7 +690,7 @@ private:
if (cmp == 0) {
// Duplicate found!
if (!_dupsAllowed) {
- return dupKeyError(newKey, _idx->collectionNamespace(), _idx->indexName());
+ return _idx->dupKeyError(newKey);
}
} else {
// _previousKey.isEmpty() is only true on the first call to addKey().
@@ -728,7 +737,7 @@ private:
} else {
// Dup found!
if (!_dupsAllowed) {
- return dupKeyError(newKey, _idx->collectionNamespace(), _idx->indexName());
+ return _idx->dupKeyError(newKey);
}
// If we get here, we are in the weird mode where dups are allowed on a unique
@@ -1397,7 +1406,7 @@ StatusWith<SpecialFormatInserted> WiredTigerIndexUnique::_insertTimestampUnsafe(
}
if (!dupsAllowed)
- return dupKeyError(key, _collectionNamespace, _indexName);
+ return dupKeyError(key);
if (!insertedId) {
// This id is higher than all currently in the index for this key
@@ -1443,7 +1452,7 @@ StatusWith<SpecialFormatInserted> WiredTigerIndexUnique::_insertTimestampSafe(
// An entry with prefix key already exists. This can happen only during rolling upgrade when
// both timestamp unsafe and timestamp safe index format keys could be present.
if (ret == WT_DUPLICATE_KEY) {
- return dupKeyError(key, _collectionNamespace, _indexName);
+ return dupKeyError(key);
}
invariantWTOK(ret);
@@ -1456,7 +1465,7 @@ StatusWith<SpecialFormatInserted> WiredTigerIndexUnique::_insertTimestampSafe(
// Second phase looks up for existence of key to avoid insertion of duplicate key
if (isDup(opCtx, c, key, id))
- return dupKeyError(key, _collectionNamespace, _indexName);
+ return dupKeyError(key);
}
// Now create the table key/value, the actual data record.
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_index.h b/src/mongo/db/storage/wiredtiger/wiredtiger_index.h
index 47f8aff0bb3..2b5e1ba3e07 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_index.h
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_index.h
@@ -155,6 +155,8 @@ public:
virtual bool unique() const = 0;
virtual bool isTimestampSafeUniqueIdx() const = 0;
+ Status dupKeyError(const BSONObj& key);
+
protected:
virtual StatusWith<SpecialFormatInserted> _insert(OperationContext* opCtx,
WT_CURSOR* c,