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

$snapshot can return duplicates on 3.2 in the case of an MMAPv1 document move

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.2.0-rc4
    • Affects Version/s: 3.2.0-rc2
    • Component/s: Querying
    • None
    • Fully Compatible
    • ALL
    • QuInt C (11/23/15)

      The $snapshot option doesn't seem to be working in 3.2.

      The following Go test case works in every other release, but in 3.2 it breaks with "Error: seen duplicated key: 3". The test consists in exercising a worst case scenario where documents are resized (grown) beyond the padding and thus moved forwards, in reverse order, while doing a forward iteration.

       func (s *S) TestFindIterSnapshot(c *C) {
              session, err := mgo.Dial("localhost:40001")
              c.Assert(err, IsNil)
              defer session.Close()
      
              // Insane amounts of logging otherwise due to the
              // amount of data being shuffled.
              mgo.SetDebug(false)
              defer mgo.SetDebug(true)
      
              coll := session.DB("mydb").C("mycoll")
      
              var a [1024000]byte
      
              for n := 0; n < 10; n++ {
                      err := coll.Insert(M{"_id": n, "n": n, "a1": &a})
                      c.Assert(err, IsNil)
              }
      
              query := coll.Find(M{"n": M{"$gt": -1}}).Batch(2).Prefetch(0)
              query.Snapshot()
              iter := query.Iter()
      
              seen := map[int]bool{}
              result := struct {
                      Id int "_id"
              }{}
              for iter.Next(&result) {
                      if len(seen) == 2 {
                              // Grow all entries so that they have to move.
                              // Backwards so that the order is inverted.
                              for n := 10; n >= 0; n-- {
                                      _, err := coll.Upsert(M{"_id": n}, M{"$set": M{"a2": &a}})
                                      c.Assert(err, IsNil)
                              }
                      }
                      if seen[result.Id] {
                              c.Fatalf("seen duplicated key: %d", result.Id)
                      }
                      seen[result.Id] = true
              }
              c.Assert(iter.Close(), IsNil)
      }
      

      Test was performed using the mmapv1 storage engine.

        1. SnapshotTest.go
          1 kB
        2. snapShotJs.log
          113 kB
        3. snapshotTest.js
          0.6 kB

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            niemeyer Gustavo Niemeyer
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved: