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

Unique index becomes inconsistent with collection data

    • ALL
    • Hide

      Try scenario described in the description above.

      Show
      Try scenario described in the description above.

      I'm using an unique index:

          {
              "v" : 1,
              "unique" : true,
              "key" : {
                  "state.agent" : 1
              },
              "name" : "state.agent_1",
              "ns" : "live.tasks.active",
              "partialFilterExpression" : {
                  "state.value" : "assigned"
              },
              "background" : true
          }
      

      My applications works in a way that many times an update (using $set and $unset) is sent that should be rejected with an ""E11000 duplicate key error collection: live.tasks.active index: state.agent_1" because of duplicate value in the above index.
      After running for ~20 days I realized that above index has become inconsistent with collection data in a way that a query using _id show's a document that should be in this index:

      db.tasks.active.find({_id:ObjectId("57bea0f21ebfd0b31f32da1c")})

      but a query that shows all data in the index doesn't show that document:

      db.tasks.active.find({"state.value":"assigned"}, {"state.agent": 1})

      I have tried to do a db.tasks.active.reIndex(), but it failed with a message that db.tasks.active contains duplicate values for an above index so that above index cannot be re-added.
      It seems that because of an error sometimes a duplicate index value is allowed to enter into a collection document instead of returing ""E11000 duplicate key error collection: live.tasks.active index: state.agent_1".
      I suspect that after this an index becomes inconsistent: isn't updated everytime as it should.

      Most times I do get E11000, but from time to time update doesn't return an error (as it should) and updates a document making a duplicate index key entry that is not visible in the index itself.

        1. repro.sh
          2 kB
          David Hows

            Assignee:
            milkie@mongodb.com Eric Milkie
            Reporter:
            sime Šimun Mikecin
            Votes:
            3 Vote for this issue
            Watchers:
            20 Start watching this issue

              Created:
              Updated:
              Resolved: