[JAVA-364] MapReduceOutput sometimes returns empty results in a replica set when SLAVE_OK=true Created: 02/Jun/11  Updated: 25/Jun/13  Resolved: 12/Aug/11

Status: Closed
Project: Java Driver
Component/s: Cluster Management
Affects Version/s: 2.6.1
Fix Version/s: 2.7

Type: Bug Priority: Critical - P2
Reporter: Tal Liron Assignee: Antoine Girbal
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to JAVA-404 Allow inline M/R w/SlaveOk go to seco... Closed
Backwards Compatibility: Fully Compatible

 Description   

After debugging this, I found that the map-reduce output collection is written to the master, but if you connected to the replica set with SLAVE_OK=true, you may very well be reading from a slave node before the output collection has been synced there, which will indeed give you empty results.

The workaround I put in my code is to ensure that the output collection never has the SLAVE_OK=true option, no matter what connection options were set. However, I suggest putting this in the MapReduceOutput code. This could be added to the constructor:

_coll = db.getCollection( _collname );
if (_coll != null) _coll.setOptions(_coll.getOptions() & ~Bytes.QUERYOPTION_SLAVEOK);

I have tested similar code with my applications, and it has indeed made this bug go away!



 Comments   
Comment by auto [ 12/Aug/11 ]

Author:

{u'login': u'agirbal', u'name': u'agirbal', u'email': u'antoine@10gen.com'}

Message: JAVA-364: MapReduceOutput sometimes returns empty results in a replica set when SLAVE_OK=true
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/81aa6c5a34ccf088d6680f9d801ef38ef0c057e2

Comment by Antoine Girbal [ 12/Aug/11 ]

Hey Tal, thanks for report and fix.
It's in trunk now.

Comment by Tal Liron [ 10/Aug/11 ]

Version 2.6.5 just came out, and still my incredibly simple patch has not been applied since version 2.6.1.

Generated at Thu Feb 08 08:52:06 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.