[JAVA-120] Driver not catching "not master" error when running with replica pairs Created: 15/Jun/10  Updated: 29/Oct/10  Resolved: 18/Aug/10

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: 1.4, 2.0
Fix Version/s: 2.1

Type: Bug Priority: Major - P3
Reporter: Razvan Loghin Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

mongodb server 1.4.3 - driver 2.0


Attachments: Text File Response.java     Text File ServerError.java    

 Description   

I've been trying to an application against a replica pair of mongodb 1.4.3 servers with driver version 2.0 (also occurs on 1.4). I've noticed an issue when servers switch master/slave roles that the driver is not transitioning and instead the error message filters up through the application. Here is a sample stack trace:

com.mongodb.MongoException: error counting :

{ "" : "not master" , "ok" : 0.0}

at com.mongodb.DBCollection.getCount(DBCollection.java:524)
at com.mongodb.DBCollection.getCount(DBCollection.java:492)

This error will occur if the master of the pair is taken down then brought back up without the application being aware of it. At that point, the current server in the driver would be pointing to the slave server. So, the next request from the driver would get "not master" error.

After some investigation, I noticed that the problem appears to be in the way the error is caught. The driver expects errors to be in the format

{ "$err" : "....." }

, however, in this case what I am seeing is

{ "errmsg" : "not master" }

which doesn't get caught by Response.java as an error (so all the logic that is supposed to take place does not get triggered).

I've locally made changes to also take "errmsg" as a valid error and then the switch between master/slave works. I've attached the two modified files for driver 2.0. I'm not certain why this error isn't coming up as "$err" - which would seem reasonable.



 Comments   
Comment by auto [ 18/Aug/10 ]

Author:

{'login': 'erh', 'name': 'Eliot Horowitz', 'email': 'eliot@10gen.com'}

Message: fix catching of "not master" and error cleaning JAVA-120
http://github.com/mongodb/mongo-java-driver/commit/146f67510f123e0b984627fb7d667e1be4195dbb

Comment by Han [ 10/Aug/10 ]

I was troubled with the same problem in java driver 2.0 when i use replica set (1.6.0).

I insert 1000 object into a collection. After we finished 500 objects , there is a switch between primary and secondary (replica set), and the pending objects are lost.

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