Skip to content

Commit 8d2e6aa

Browse files
milkieDan Pasette
authored andcommitted
SERVER-13496 do not abort replication on secondaries when index name conflicts (via 2.4.9)
(cherry picked from commit 0fbd76d) Conflicts: src/mongo/base/error_codes.err
1 parent c276857 commit 8d2e6aa

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

src/mongo/base/error_codes.err

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ error_code("RoleDataInconsistent", 80)
8383
error_code("NoClientContext", 81)
8484
error_code("NoProgressMade", 82)
8585
error_code("RemoteResultsUnavailable", 83)
86+
error_code("IndexOptionsConflict", 85 )
87+
error_code("IndexKeySpecsConflict", 86 )
8688

8789
# Non-sequential error codes (for compatibility only)
8890
error_code("NotMaster", 10107) #this comes from assert_util.h
@@ -93,3 +95,5 @@ error_code("OutOfDiskSpace", 14031 )
9395

9496
error_class("NetworkError", ["HostUnreachable", "HostNotFound"])
9597
error_class("Interruption", ["Interrupted", "InterruptedAtShutdown", "ExceededTimeLimit"])
98+
error_class("IndexCreationError", ["CannotCreateIndex", "IndexOptionsConflict",
99+
"IndexKeySpecsConflict", "IndexAlreadyExists"])

src/mongo/db/catalog/index_catalog.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ namespace mongo {
631631
// index already exists with same name
632632

633633
if ( !desc->keyPattern().equal( key ) )
634-
return Status( ErrorCodes::CannotCreateIndex,
634+
return Status( ErrorCodes::IndexKeySpecsConflict,
635635
str::stream() << "Trying to create an index "
636636
<< "with same name " << name
637637
<< " with different key spec " << key
@@ -641,10 +641,9 @@ namespace mongo {
641641
_getAccessMethodName( key ),
642642
spec );
643643
if ( !desc->areIndexOptionsEquivalent( &temp ) )
644-
return Status( ErrorCodes::CannotCreateIndex,
644+
return Status( ErrorCodes::IndexOptionsConflict,
645645
str::stream() << "Index with name: " << name
646-
<< " already exists with different options",
647-
IndexOptionsDiffer);
646+
<< " already exists with different options" );
648647

649648
// Index already exists with the same options, so no need to build a new
650649
// one (not an error). Most likely requested by a client using ensureIndex.
@@ -663,10 +662,9 @@ namespace mongo {
663662
_getAccessMethodName( key ),
664663
spec );
665664
if ( !desc->areIndexOptionsEquivalent( &temp ) )
666-
return Status( ErrorCodes::CannotCreateIndex,
665+
return Status( ErrorCodes::IndexOptionsConflict,
667666
str::stream() << "Index with pattern: " << key
668-
<< " already exists with different options",
669-
IndexOptionsDiffer );
667+
<< " already exists with different options" );
670668

671669
return Status( ErrorCodes::IndexAlreadyExists, name );
672670
}
@@ -690,7 +688,7 @@ namespace mongo {
690688
return Status( ErrorCodes::CannotCreateIndex,
691689
str::stream() << "only one text index per collection allowed, "
692690
<< "found existing text index \"" << textIndexes[0]->indexName()
693-
<< "\"");
691+
<< "\"" );
694692
}
695693
}
696694
return Status::OK();

src/mongo/db/repl/oplog.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,9 @@ namespace mongo {
520520
if ( status.isOK() ) {
521521
// yay
522522
}
523-
else if ( status.code() == ErrorCodes::CannotCreateIndex &&
524-
status.location() == IndexOptionsDiffer ) {
525-
// SERVER-13206
523+
else if ( status.code() == ErrorCodes::IndexOptionsConflict ||
524+
status.code() == ErrorCodes::IndexKeySpecsConflict ) {
525+
// SERVER-13206, SERVER-13496
526526
// 2.4 (and earlier) will add an ensureIndex to an oplog if its ok or not
527527
// so in 2.6+ where we do stricter validation, it will fail
528528
// but we shouldn't care as the primary is responsible

src/mongo/util/assert_util.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ namespace mongo {
3737
NotMasterOrSecondaryCode = 13436, // uassert( 13436 )
3838
NotMasterNoSlaveOkCode = 13435, // uassert( 13435 )
3939
NotMaster = 10107, // uassert( 10107 )
40-
IndexOptionsDiffer = 17427 // uassert( 17427 )
4140
};
4241

4342
class MONGO_CLIENT_API AssertionCount {

0 commit comments

Comments
 (0)