Info
When a very large number of documents matches the query the count of deleted documents can overflow and become negative.
I have reproduced this with 3.2.10. It works correctly in 3.4.6.
This ticket might be a duplicate, but I couldn't find a ticket for this.
Top User Comments
charlie.swanson commented on Fri, 21 Jul 2017 16:08:06 +0000:
I'm actually going to re-open this. While attempting to find which version this was fixed in, I realized there are actually many types involved in tracking how many deletes occurred on master, including:
On mongod:
local variable n in serializeReply, which uses a 'long long'.
SingleWriteResult (generated by the IDL file), which uses a 'long', which it looks like IDL translates to an int64_t.
The information on the SingleWriteResult looks to be filled out by requesting the number of deleted things from the DeleteStage, which does so by consulting it's DeleteStats, which uses a size_t
On mongos:
BatchWriteOp, which uses a 'int'
BatchCommandResponse, which uses a 'long long'
So it looks like all the types on mongod are ok (though the size_t should probably be replaced with a uint64_t, just to be sure). However, this is probably still a problem on mongos, and may still be a problem for update (or insert?).
rstam if you're concerned with just a single mongod, it looks like this was likely fixed by SERVER-23128, which deleted the offending WriteOpStats which was storing an int.
rstam commented on Fri, 21 Jul 2017 14:38:44 +0000:
It would be helpful to users to know exactly which version this was fixed in.
ian@10gen.com commented on Fri, 21 Jul 2017 14:35:33 +0000:
Since this is already fixed in 3.4 and is simply a reporting error, we have no plans to fix this in 3.2.
Steps to Reproduce
Create a collection named "test" with 2,147,483,648 documents. That's one more than the largest possible positive number that can be represented with a 32 bit signed integer.
Run the following command:
db.runCommand({ delete : "test", deletes : [ { q : {}, limit : 0 } ] })
The expected result is:
{ "ok" : 1, "n" : 2147483648 }
The actual result is:
{ "ok" : 1, "n" : -2147483648 }