[SERVER-19687] immediate collection count doesn't get correct result if new document is inserted Created: 31/Jul/15  Updated: 13/Aug/15  Resolved: 13/Aug/15

Status: Closed
Project: Core Server
Component/s: Index Maintenance, Write Ops
Affects Version/s: 3.0.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Morgan Cheng Assignee: Ramon Fernandez Marina
Resolution: Cannot Reproduce Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Steps To Reproduce:

These steps are not guaranteed to reproduce this bug.

1) create a collection with a lot of documents named test;
2) create a index

db.test.ensureIndex({name: 1}, {background: true});


3) make sure the index built is done;
4) insert one more document

db.test.save({name: 'morgan'});


5) immediately count documents by

db.test.count({name: 'morgan'});

Expected result:
step 5) should always get correct counting;

Actual result:
step 5) has a chance to get wrong counting just like step 4) is not performed.

Participants:

 Description   

It is hard to reproduce, but I have this issue identified multiple times in production environment.

One operation insert a document into a collection host in only one mongod with write concern 1. After got the write success response, a count with condition is issued to the same mongod. Surely, the count response should include the newly-inserted document. However, sometimes it just doesn't have the new document counted.

Just my guessing: If the indexing of the count condition is performed in background, there is possibility that collection indexing is not updated when insert operation returns OK even with write concern 1. If count operation depends on the index, then a immediate count operation could return result without the newly-inserted document counted.



 Comments   
Comment by Ramon Fernandez Marina [ 13/Aug/15 ]

morgan.chengmo@gmail.com, we tried my repro above again using save() and with some other variations, but we were still unable to reproduce the behavior you describe so I'm going to close this ticket.

If there's some more details you can provide about how your application works and triggers this behavior feel free to post it here so we can investigate further.

Regards,
Ramón.

Comment by Ramon Fernandez Marina [ 06/Aug/15 ]

Hi morgan.chengmo@gmail.com, I tried the following to reproduce:

db.foo.drop()
db.foo.ensureIndex({x: 1}, {background: true});
 
for (i=1; i<=100000; i++) {
    db.foo.insert({x:1});
    assert.eq(db.foo.count(), i, "Count failed")
}

but no luck. What storage engine are you using? What kind of deployment are you running, stand-alone, replicated, sharded? Are there any other details you can provide that may help us reproduce the behavior you describe?

Thanks,
Ramón.

Comment by Morgan Cheng [ 31/Jul/15 ]

Damn, the default action of Enter keypress in this JIRA instance is really annoying. It takes me three times to finally post a whole bug.

Generated at Thu Feb 08 03:51:45 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.