number of updated docs may be wrong

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Duplicate
    • Priority: Major - P3
    • None
    • Affects Version/s: 2.0.5
    • Component/s: None
    • None
    • Environment:
      Linux 64 Bit
    • ALL
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      Independent on the used driver (java or perl), we may get a wrong number of updated docs.

      We are running MongoDB v2.0.5, 64 Bit Linux, 5 shards each 3 nodes.
      Shardkey is _id.

      Selecting the concerned documents through mongos looks fine:

       
      mongos> db.offer.find({_id:{$in:[1059301595,1059301637]}},{clusterId:1})
      { "_id" : NumberLong(1059301595), "clusterId" : NumberLong("10071732130") }
      { "_id" : NumberLong(1059301637), "clusterId" : NumberLong("10071732130") }
      mongos> db.offer.count({_id:{$in:[1059301595,1059301637]}},{clusterId:1})
      2
      

      Both documents are located on shard 5. There are no orphan docs on the other shards.

      Step 1) connect to mongos to update these 2 docs -> OK (numer of updated docs = 2)
      Step 2) connect to the primary of shard 5 to to update these 2 docs -> OK (numer of updated docs = 2)
      Step 3) connect to mongos to to update these 2 docs -> FAILED (mongo reports that 4 docs have been updated, even though there are only 2 such documents)

      It seems that mongo did not only found 2 docs on shard 5. Mongo counted also 1 doc on shard 1 and shard 4 (see below), even though there are not such documents.

      My logs to the above steps:

       
      Step 1)
       perl -MMongoDB -MData::Dump=pp -e 'my $conn = MongoDB::Connection->new(host => "mongodb://sx210:27018"); my $coll = $conn->get_database("offerStore")->get_collection("offer"); my @ids = ("1059301595","1059301637"); @ids = map { 0+$_ } @ids; my $return = $coll->update({ _id => { q[$in] => \@ids }},{ q[$set] => { clusterId => 10071732130 }},{ safe => 1, multiple => 1 }); print pp($return) ."\n";'
      {
        connectionId => 930083,
        err => undef,
        lastOp => 5760590994173067268,
        n => 2,
        ok => 1,
      ...
      
      Step 2)
       perl -MMongoDB -MData::Dump=pp -e 'my $conn = MongoDB::Connection->new(host => "mongodb://s209:27018"); my $coll = $conn->get_database("offerStore")->get_collection("offer"); my @ids = ("1059301595","1059301637"); @ids = map { 0+$_ } @ids; my $return = $coll->update({ _id => { q[$in] => \@ids }},{ q[$set] => { clusterId => 10071732130 }},{ safe => 1, multiple => 1 }); print pp($return) ."\n";'
      {
        connectionId => 930105,
        err => undef,
        lastOp => 5760591024237838361,
        n => 2,
        ok => 1,
      ...
      
      Step 3)
      perl -MMongoDB -MData::Dump=pp -e 'my $conn = MongoDB::Connection->new(host => "mongodb://sx210:27018"); my $coll = $conn->get_database("offerStore")->get_collection("offer"); my @ids = ("1059301595","1059301637"); @ids = map { 0+$_ } @ids; my $return = $coll->update({ _id => { q[$in] => \@ids }},{ q[$set] => { clusterId => 10071732130 }},{ safe => 1, multiple => 1 }); print pp($return) ."\n";'
      do {
        my $a = {
          err => undef,
          n => 4,
          ok => 1,
          shardRawGLE => {
            "offerStoreDE1/s118:27018,s126:27018,s131:27018" => {
                                                                  connectionId => 974213,
                                                                  err => undef,
                                                                  lastOp => 5760594412967034883,
                                                                  n => 1,
                                                                  ok => 1,
                                                                  updatedExisting => bless(do{\(my $o = 1)}, "boolean"),
                                                                  wtime => 0,
                                                                },
            "offerStoreDE2/s120:27018,s127:27018,s136:27018" => {
                                                                  connectionId => 299967,
                                                                  err => undef,
                                                                  lastOp => 0,
                                                                  n => 0,
                                                                  ok => 1,
                                                                  wnote => "no write has been done on this connection",
                                                                  wtime => 0,
                                                                },
            "offerStoreDE3/s117:27018,s124:27018,s129:27018" => {
                                                                  connectionId => 744569,
                                                                  err => undef,
                                                                  lastOp => 0,
                                                                  n => 0,
                                                                  ok => 1,
                                                                  wnote => "no write has been done on this connection",
                                                                  wtime => 0,
                                                                },
            "offerStoreDE4/s115:27018,s125:27018,s132:27018" => {
                                                                  connectionId => 586373,
                                                                  err => undef,
                                                                  lastOp => 5760594679255007242,
                                                                  n => 1,
                                                                  ok => 1,
                                                                  updatedExisting => 'fix',
                                                                  wtime => 0,
                                                                },
            "offerStoreDE5/s128:27018,s135:27018,s209:27018" => {
                                                                  connectionId => 930971,
                                                                  err => undef,
                                                                  lastOp => 5760594915478208515,
                                                                  n => 2,
                                                                  ok => 1,
                                                                  updatedExisting => 'fix',
                                                                  wtime => 0,
                                                                },
          },
          shards => [
            "offerStoreDE1/s118:27018,s126:27018,s131:27018",
            "offerStoreDE2/s120:27018,s127:27018,s136:27018",
            "offerStoreDE3/s117:27018,s124:27018,s129:27018",
            "offerStoreDE4/s115:27018,s125:27018,s132:27018",
            "offerStoreDE5/s128:27018,s135:27018,s209:27018",
          ],
          updatedExisting => 'fix',
        };
        $a->{shardRawGLE}{"offerStoreDE4/s115:27018,s125:27018,s132:27018"}{updatedExisting} = \${$a->{shardRawGLE}{"offerStoreDE1/s118:27018,s126:27018,s131:27018"}{updatedExisting}};
        $a->{shardRawGLE}{"offerStoreDE5/s128:27018,s135:27018,s209:27018"}{updatedExisting} = \${$a->{shardRawGLE}{"offerStoreDE1/s118:27018,s126:27018,s131:27018"}{updatedExisting}};
        $a->{updatedExisting} = \${$a->{shardRawGLE}{"offerStoreDE1/s118:27018,s126:27018,s131:27018"}{updatedExisting}};
        $a;
      }
      

      We can reproduce it at any time.
      The java driver WriteResult.getN() method produces the same result:

      final ServerAddress address =  new ServerAddress("sx210",27018);//router
      //final ServerAddress address =  new ServerAddress("s209",27018);//shard5
      final Mongo m = new Mongo(address);
      m.setReadPreference(ReadPreference.PRIMARY);
      final BasicDBObject query = new BasicDBObject();
      query.put("_id", new BasicDBObject("$in", Lists.newArrayList(1059301595l, 1059301637l)));
      
      final DBObject set = new BasicDBObject();
      set.put("clusterId", 10071732130l);
      final DBObject updates = new BasicDBObject("$set", set);
      final DB db = m.getDB("offerStore");
      
      final WriteResult wr = db.getCollection("offer").update(query, updates, false, true);
      final int updated = wr.getN(); 
      
      log.info("updated {}", Integer.valueOf(updated));
      

            Assignee:
            Scott Hernandez (Inactive)
            Reporter:
            Kay Agahd
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: