[SERVER-10231] Creating an index on system.indexes breaks initial sync of secondary Created: 16/Jul/13  Updated: 11/Jul/16  Resolved: 04/Sep/13

Status: Closed
Project: Core Server
Component/s: Replication
Affects Version/s: 2.4.5
Fix Version/s: 2.4.10, 2.5.3

Type: Bug Priority: Major - P3
Reporter: Mathias Stearn Assignee: Matt Dannenberg
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Related
related to SERVER-10230 Shouldn't be possible to create index... Closed
is related to SERVER-14999 db.system.indexes.dropIndexes() crash... Closed
Backwards Compatibility: Minor Change
Operating System: ALL
Participants:

 Description   
Issue Status as of March 28, 2014

ISSUE SUMMARY
Indexes cannot be created on the internal system.indexes collection. Attempting to build an index on this collection responds with an error (code 13143), but still inserts a corresponding entry into the system.indexes collection. Secondary nodes that attempt to initial sync from a node with such an entry fail to create the index and abort the initial sync (after several retries).

USER IMPACT
This mostly affects users that create indexes dynamically on all collections and do not explicitly exclude the system.indexes collection. Furthermore, the error may not be noticed for some time, as the invalid index has no immediate effect on a replica set but only affects initial sync of a secondary.

SOLUTION
The fix is to explicitly check and throw an assertion if an index build on system.indexes is attempted. This assertion aborts the index build before the entry is inserted into the system.indexes collection.

WORKAROUNDS
Users should not build an index on the system.indexes collection. In environments with dynamic index creation, one should take precautionary steps to explicitly check and avoid building an index on system.indexes. To remove any accidentally-created index entries on system.indexes, use the following command: db.system.indexes.dropIndexes()

AFFECTED VERSIONS
All recent production releases up to version 2.4.9 are affected.

PATCHES
The fix is included in the 2.4.10 production release and the 2.5.3 development version, which will evolve into the 2.6.0 production release.

Original Description

It claims it isn't allowed, but it still gets inserted into system.indexes without actually creating the index.

> use breakMyDb
switched to db breakMyDb
> db.system.indexes.ensureIndex({_id:1}, {unique:true})
{
        "err" : "can't create index on system.indexes",
        "code" : 13143,
        "n" : 0,
        "connectionId" : 1,
        "ok" : 1
}
> db.system.indexes.find()
{ "v" : 1, "key" : { "_id" : 1 }, "ns" : "breakMyDb.system.indexes", "name" : "_id_" }



 Comments   
Comment by Githook User [ 09/Mar/14 ]

Author:

{u'username': u'dannenberg', u'name': u'matt dannenberg', u'email': u'matt.dannenberg@10gen.com'}

Message: SERVER-10231 disallow creation of indexes on system.indexes

Conflicts:
src/mongo/db/index.cpp
src/mongo/db/namespacestring.h
Branch: v2.4
https://github.com/mongodb/mongo/commit/73695a99c1c1f19fc795f7a636787364e1f7b30d

Comment by auto [ 04/Sep/13 ]

Author:

{u'username': u'dannenberg', u'name': u'matt dannenberg', u'email': u'matt.dannenberg@10gen.com'}

Message: SERVER-10231 disallow creation of indexes on system.indexes
Branch: master
https://github.com/mongodb/mongo/commit/9dc48cc9760f84b1482f57b3bfd6d241d0910901

Comment by Thomas Rueckstiess [ 19/Aug/13 ]

Attempting this also breaks initial sync of secondary nodes:

Mon Aug 19 10:53:46.052 [rsSync] ERROR: error: exception cloning object in test.system.indexes can't create index on system.indexes obj:{ key: { hash: 1.0 }, ns: "test.system.indexes", name: "hash_1" }
replSet initial sync exception: 13143 can't create index on system.indexes 8 attempts remaining

I tested on 2.2.3 and 2.4.5, failure in both cases.

Generated at Thu Feb 08 03:22:38 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.