summaryrefslogtreecommitdiff
path: root/src/mongo/db/index
diff options
context:
space:
mode:
authorGeert Bosch <geert@mongodb.com>2014-12-11 14:35:13 -0500
committerGeert Bosch <geert@mongodb.com>2014-12-11 18:29:47 -0500
commita6ac4e68c240e99ada7dddb333bb2b5e5220c49c (patch)
treeffd63e4220e6dd26b63ba356db35d757191c2e4c /src/mongo/db/index
parent0279923636be460e3027152d83ed1c790cd536fc (diff)
downloadmongo-a6ac4e68c240e99ada7dddb333bb2b5e5220c49c.tar.gz
SERVER-16497: Allow suppressing KeyTooLong errors in foreground index build
Diffstat (limited to 'src/mongo/db/index')
-rw-r--r--src/mongo/db/index/btree_based_access_method.cpp19
-rw-r--r--src/mongo/db/index/btree_based_access_method.h3
-rw-r--r--src/mongo/db/index/btree_based_bulk_access_method.cpp17
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;