Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-20796

Warning on replica that collection lacks a unique index on _id, though index is present

    • Type: Icon: Bug Bug
    • Resolution: Incomplete
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.9, 2.6.10
    • Component/s: Replication
    • None
    • ALL

      I set up a replica against a master server. The master has a few databases.
      After initial resync, I get the following warnings on replica:

      Server has startup warnings: 
      2015-09-14T09:33:23.616-0400 [initandlisten] WARNING: the collection 'sffs03.e' lacks a unique index on _id. This index is needed for replication to function properly
      2015-09-14T09:33:23.616-0400 [initandlisten] 	 To fix this, you need to create a unique index on _id. See http://dochub.mongodb.org/core/build-replica-set-indexes
      2015-09-14T09:33:28.493-0400 [initandlisten] WARNING: the collection 'sffs05.e' lacks a unique index on _id. This index is needed for replication to function properly
      2015-09-14T09:33:28.493-0400 [initandlisten] 	 To fix this, you need to create a unique index on _id. See http://dochub.mongodb.org/core/build-replica-set-indexes
      2015-09-14T09:33:34.136-0400 [initandlisten] WARNING: the collection 'sf.catalog' lacks a unique index on _id. This index is needed for replication to function properly
      2015-09-14T09:33:34.136-0400 [initandlisten] 	 To fix this, you need to create a unique index on _id. See http://dochub.mongodb.org/core/build-replica-set-indexes
      2015-09-14T09:33:34.136-0400 [initandlisten] WARNING: the collection 'sf.jobs' lacks a unique index on _id. This index is needed for replication to function properly
      2015-09-14T09:33:34.136-0400 [initandlisten] 	 To fix this, you need to create a unique index on _id. See http://dochub.mongodb.org/core/build-replica-set-indexes
      2015-09-14T09:33:34.136-0400 [initandlisten] WARNING: the collection 'sf.migrator' lacks a unique index on _id. This index is needed for replication to function properly
      2015-09-14T09:33:34.136-0400 [initandlisten] 	 To fix this, you need to create a unique index on _id. See http://dochub.mongodb.org/core/build-replica-set-indexes
      2015-09-14T09:33:34.136-0400 [initandlisten] WARNING: the collection 'sf.v_fs06' lacks a unique index on _id. This index is needed for replication to function properly
      2015-09-14T09:33:34.136-0400 [initandlisten] 	 To fix this, you need to create a unique index on _id. See http://dochub.mongodb.org/core/build-replica-set-indexes
      2015-09-14T09:33:34.136-0400 [initandlisten] WARNING: the collection 'sf.v_jeremytest' lacks a unique index on _id. This index is needed for replication to function properly
      2015-09-14T09:33:34.136-0400 [initandlisten] 	 To fix this, you need to create a unique index on _id. See http://dochub.mongodb.org/core/build-replica-set-indexes
      2015-09-14T09:33:34.250-0400 [initandlisten] WARNING: the collection 'sffs06_new.e' lacks a unique index on _id. This index is needed for replication to function properly
      2015-09-14T09:33:34.250-0400 [initandlisten] 	 To fix this, you need to create a unique index on _id. See http://dochub.mongodb.org/core/build-replica-set-indexes
      

      The warnings are not correct as the collections have default indexes on _id, and it's not possible to insert a document with duplicated _id on master:

      sf0:PRIMARY> use sffs03
      switched to db sffs03
      sf0:PRIMARY> db.e.insert({ "_id" : ObjectId("55c4c48c7c738904a2390306"), "zip": 1})
      WriteResult({
      	"nInserted" : 0,
      	"writeError" : {
      		"code" : 11000,
      		"errmsg" : "insertDocument :: caused by :: 11000 E11000 duplicate key error index: sffs03.e.$_id_  dup key: { : ObjectId('55c4c48c7c738904a2390306') }"
      	}
      })
      sf0:PRIMARY> db.e.getIndexes()
      [
      	{
      		"v" : 1,
      		"key" : {
      			"_id" : 1
      		},
      		"name" : "_id_",
      		"ns" : "sffs03.e"
      	},
      ...
      

      The indexes are visible on replica:

      sf0:SECONDARY> db.e.getIndexes()
      [
      	{
      		"v" : 1,
      		"key" : {
      			"_id" : 1
      		},
      		"name" : "_id_",
      		"ns" : "sffs03.e"
      	},
      ...
      

      If I create a new database, the replica does not complain, so it seems there is something off with the old databases, though they have been created with the default setting, and _id index was not dropped.

      sf0:PRIMARY> use uniqe_index
      switched to db uniqe_index
      sf0:PRIMARY> db.e.insert({'ala': 1, 'kot': 2})
      WriteResult({ "nInserted" : 1 })
      sf0:PRIMARY> db.e.getIndexes()
      [
      	{
      		"v" : 1,
      		"key" : {
      			"_id" : 1
      		},
      		"name" : "_id_",
      		"ns" : "uniqe_index.e"
      	}
      ]
      sf0:PRIMARY> db.e.find()
      { "_id" : ObjectId("561505583903c78e99111195"), "ala" : 1, "kot" : 2 }
      sf0:PRIMARY> db.e.insert({"_id" : ObjectId("561505583903c78e99111195"), 'ala': 2, 'kot': 3})
      WriteResult({
      	"nInserted" : 0,
      	"writeError" : {
      		"code" : 11000,
      		"errmsg" : "insertDocument :: caused by :: 11000 E11000 duplicate key error index: uniqe_index.e.$_id_  dup key: { : ObjectId('561505583903c78e99111195') }"
      	}
      })
      

      I'm not sure if any of it matters, but all of the information for completeness.

      There is a lot of data in the DBs:

      sf0:SECONDARY> show dbs
      sf          1539.202GB
      sffs03       157.877GB
      sffs05      1407.267GB
      sffs06_new   451.733GB
      admin          (empty)
      local         50.054GB
      test           (empty)
      

      and setting up the replica fails sometimes (probably because the oplog is too small).

      Replication configuration

      sf0:PRIMARY> rs.config()
      {
      	"_id" : "sf0",
      	"version" : 4,
      	"members" : [
      		{
      			"_id" : 0,
      			"host" : "host07:27017"
      		},
      		{
      			"_id" : 1,
      			"host" : "host06:27017",
      			"votes" : 0,
      			"priority" : 0
      		}
      	]
      }
      

      Replication status:

      sf0:PRIMARY> rs.printReplicationInfo()
      configured oplog size:   47797.726318359375MB
      log length start to end: 257988secs (71.66hrs)
      oplog first event time:  Sun Oct 04 2015 11:22:16 GMT-0400 (EDT)
      oplog last event time:   Wed Oct 07 2015 11:02:04 GMT-0400 (EDT)
      now:                     Wed Oct 07 2015 11:02:24 GMT-0400 (EDT)
      

      Master is running:

      db version v2.6.9
      2015-10-07T11:12:25.873-0400 git version: df313bc75aa94d192330cb92756fc486ea604e64
      

      Replica is running:

      db version v2.6.10
      2015-10-07T11:12:19.453-0400 git version: 5901dbfb49d16eaef6f2c2c50fba534d23ac7f6c
      

        1. mongod.log-SERVER-20796.log.bz2.1
          143.05 MB
        2. mongod.log-SERVER-20796.log.bz2.2
          126.33 MB

            Assignee:
            wan.bachtiar@mongodb.com Wan Bachtiar
            Reporter:
            gozdal Marcin Gozdalik
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: