From 8d2e6aab88f62bd718fc262315b98c60af89a6bd Mon Sep 17 00:00:00 2001 From: Eric Milkie Date: Wed, 16 Apr 2014 16:46:09 -0400 Subject: SERVER-13496 do not abort replication on secondaries when index name conflicts (via 2.4.9) (cherry picked from commit 0fbd76d233e213e43f53b8882c4dd3c71897a7f3) Conflicts: src/mongo/base/error_codes.err --- src/mongo/base/error_codes.err | 4 ++++ src/mongo/db/catalog/index_catalog.cpp | 14 ++++++-------- src/mongo/db/repl/oplog.cpp | 6 +++--- src/mongo/util/assert_util.h | 1 - 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/mongo/base/error_codes.err b/src/mongo/base/error_codes.err index 6549426e68b..42784e4c0e8 100644 --- a/src/mongo/base/error_codes.err +++ b/src/mongo/base/error_codes.err @@ -83,6 +83,8 @@ error_code("RoleDataInconsistent", 80) error_code("NoClientContext", 81) error_code("NoProgressMade", 82) error_code("RemoteResultsUnavailable", 83) +error_code("IndexOptionsConflict", 85 ) +error_code("IndexKeySpecsConflict", 86 ) # Non-sequential error codes (for compatibility only) error_code("NotMaster", 10107) #this comes from assert_util.h @@ -93,3 +95,5 @@ error_code("OutOfDiskSpace", 14031 ) error_class("NetworkError", ["HostUnreachable", "HostNotFound"]) error_class("Interruption", ["Interrupted", "InterruptedAtShutdown", "ExceededTimeLimit"]) +error_class("IndexCreationError", ["CannotCreateIndex", "IndexOptionsConflict", + "IndexKeySpecsConflict", "IndexAlreadyExists"]) diff --git a/src/mongo/db/catalog/index_catalog.cpp b/src/mongo/db/catalog/index_catalog.cpp index c2561597700..65f6cdb0e91 100644 --- a/src/mongo/db/catalog/index_catalog.cpp +++ b/src/mongo/db/catalog/index_catalog.cpp @@ -631,7 +631,7 @@ namespace mongo { // index already exists with same name if ( !desc->keyPattern().equal( key ) ) - return Status( ErrorCodes::CannotCreateIndex, + return Status( ErrorCodes::IndexKeySpecsConflict, str::stream() << "Trying to create an index " << "with same name " << name << " with different key spec " << key @@ -641,10 +641,9 @@ namespace mongo { _getAccessMethodName( key ), spec ); if ( !desc->areIndexOptionsEquivalent( &temp ) ) - return Status( ErrorCodes::CannotCreateIndex, + return Status( ErrorCodes::IndexOptionsConflict, str::stream() << "Index with name: " << name - << " already exists with different options", - IndexOptionsDiffer); + << " already exists with different options" ); // Index already exists with the same options, so no need to build a new // one (not an error). Most likely requested by a client using ensureIndex. @@ -663,10 +662,9 @@ namespace mongo { _getAccessMethodName( key ), spec ); if ( !desc->areIndexOptionsEquivalent( &temp ) ) - return Status( ErrorCodes::CannotCreateIndex, + return Status( ErrorCodes::IndexOptionsConflict, str::stream() << "Index with pattern: " << key - << " already exists with different options", - IndexOptionsDiffer ); + << " already exists with different options" ); return Status( ErrorCodes::IndexAlreadyExists, name ); } @@ -690,7 +688,7 @@ namespace mongo { return Status( ErrorCodes::CannotCreateIndex, str::stream() << "only one text index per collection allowed, " << "found existing text index \"" << textIndexes[0]->indexName() - << "\""); + << "\"" ); } } return Status::OK(); diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index c9912315a4a..5ec26d17fea 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -520,9 +520,9 @@ namespace mongo { if ( status.isOK() ) { // yay } - else if ( status.code() == ErrorCodes::CannotCreateIndex && - status.location() == IndexOptionsDiffer ) { - // SERVER-13206 + else if ( status.code() == ErrorCodes::IndexOptionsConflict || + status.code() == ErrorCodes::IndexKeySpecsConflict ) { + // SERVER-13206, SERVER-13496 // 2.4 (and earlier) will add an ensureIndex to an oplog if its ok or not // so in 2.6+ where we do stricter validation, it will fail // but we shouldn't care as the primary is responsible diff --git a/src/mongo/util/assert_util.h b/src/mongo/util/assert_util.h index 2b9aa181b9c..377510ae3f2 100644 --- a/src/mongo/util/assert_util.h +++ b/src/mongo/util/assert_util.h @@ -37,7 +37,6 @@ namespace mongo { NotMasterOrSecondaryCode = 13436, // uassert( 13436 ) NotMasterNoSlaveOkCode = 13435, // uassert( 13435 ) NotMaster = 10107, // uassert( 10107 ) - IndexOptionsDiffer = 17427 // uassert( 17427 ) }; class MONGO_CLIENT_API AssertionCount { -- cgit v1.2.1