diff options
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/index/btree_based_access_method.cpp | 19 | ||||
-rw-r--r-- | src/mongo/db/index/btree_based_access_method.h | 3 | ||||
-rw-r--r-- | src/mongo/db/index/btree_based_bulk_access_method.cpp | 17 |
3 files changed, 21 insertions, 18 deletions
diff --git a/src/mongo/db/index/btree_based_access_method.cpp b/src/mongo/db/index/btree_based_access_method.cpp index d699440fb10..14bdceac1b5 100644 --- a/src/mongo/db/index/btree_based_access_method.cpp +++ b/src/mongo/db/index/btree_based_access_method.cpp @@ -64,6 +64,11 @@ namespace mongo { verify(0 == _descriptor->version() || 1 == _descriptor->version()); } + bool BtreeBasedAccessMethod::ignoreKeyTooLong(OperationContext *txn) { + // Ignore this error if we're on a secondary or if the user requested it + return !txn->isPrimaryFor(_btreeState->ns()) || !failIndexKeyTooLong; + } + // Find the keys for obj, put them in the tree pointing to loc Status BtreeBasedAccessMethod::insert(OperationContext* txn, const BSONObj& obj, @@ -88,19 +93,11 @@ namespace mongo { // Error cases. - if (ErrorCodes::KeyTooLong == status.code()) { - // Ignore this error if we're on a secondary. - if (!txn->isPrimaryFor(_btreeState->ns())) { - continue; - } - - // The user set a parameter to ignore key too long errors. - if (!failIndexKeyTooLong) { - continue; - } + if (status.code() == ErrorCodes::KeyTooLong && ignoreKeyTooLong(txn)) { + continue; } - if (ErrorCodes::DuplicateKeyValue == status.code()) { + 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)) { diff --git a/src/mongo/db/index/btree_based_access_method.h b/src/mongo/db/index/btree_based_access_method.h index 586d3d6523e..d788808c6e0 100644 --- a/src/mongo/db/index/btree_based_access_method.h +++ b/src/mongo/db/index/btree_based_access_method.h @@ -129,6 +129,9 @@ namespace mongo { virtual void getKeys(const BSONObj &obj, BSONObjSet *keys) = 0; + // Determines whether it's OK to ignore ErrorCodes::KeyTooLong for this OperationContext + bool ignoreKeyTooLong(OperationContext* txn); + IndexCatalogEntry* _btreeState; // owned by IndexCatalogEntry const IndexDescriptor* _descriptor; diff --git a/src/mongo/db/index/btree_based_bulk_access_method.cpp b/src/mongo/db/index/btree_based_bulk_access_method.cpp index 8434e1859e3..0c4b2f2ffb8 100644 --- a/src/mongo/db/index/btree_based_bulk_access_method.cpp +++ b/src/mongo/db/index/btree_based_bulk_access_method.cpp @@ -151,16 +151,19 @@ namespace mongo { Status status = builder->addKey(d.first, d.second); if (!status.isOK()) { - if (ErrorCodes::DuplicateKey != status.code()) { - return status; + // Overlong key that's OK to skip? + if (status.code() == ErrorCodes::KeyTooLong && _real->ignoreKeyTooLong(_txn)) { + continue; } - invariant(!dupsAllowed); // shouldn't be getting DupKey errors if dupsAllowed. + // Check if this is a duplicate that's OK to skip + if (status.code() == ErrorCodes::DuplicateKey) { + invariant(!dupsAllowed); // shouldn't be getting DupKey errors if dupsAllowed. - // If we're here it's a duplicate key. - if (dupsToDrop) { - dupsToDrop->insert(d.second); - continue; + if (dupsToDrop) { + dupsToDrop->insert(d.second); + continue; + } } return status; |