[JAVA-401] "not master" MongoException when using GridFS with a direction connection to a secondary Created: 26/Jul/11  Updated: 17/Aug/13  Resolved: 18/Jun/13

Status: Closed
Project: Java Driver
Component/s: GridFS
Affects Version/s: 2.6.3
Fix Version/s: 2.11.2, 2.12.0

Type: Bug Priority: Minor - P4
Reporter: go Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

linux 64, replica set.


Attachments: Text File mongo.log    
Issue Links:
Related
is related to JAVA-790 Wrong type for option 'unique' in Gri... Closed

 Description   

I got an Exception "not master" when i read from the secondary.
In the GridFS structure method, when the files collections count less
then 1000, mongodb will to ensure standard indexes. but secondary is
not allow write operations.
so, how do i read files from a secondary?



 Comments   
Comment by auto [ 18/Jun/13 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-401: Catch and log exception on ensuring indices for GridFS collections. Exceptions can happen if the MongoClient is a direct connection to a secondary, so this can happen under normal circumstances.
Branch: 2.11.x
https://github.com/mongodb/mongo-java-driver/commit/7d0c537188d86a27b21e658eecd40232b5b18ea8

Comment by auto [ 18/Jun/13 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-401: Catch and log exception on ensuring indices for GridFS collections. Exceptions can happen if the MongoClient is a direct connection to a secondary, so this can happen under normal circumstances.
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/595b30b45c31771f46a7fbfb8ff519e4820560e3

Comment by Scott Hernandez (Inactive) [ 10/Jan/13 ]

Yes, or verify the connection is to a primary/master here: https://github.com/mongodb/mongo-java-driver/blob/master/src/main/com/mongodb/gridfs/GridFS.java#L93

Comment by Jeffrey Yemin [ 28/Apr/12 ]

The workaround for this is to provide a seed list instead of a single server, so that a replica set connection is established. Then call DB.slaveOk() on the gridfs database to ensure reads from secondaries.

To fix this, the most straightforward thing to do is to surround the calls to ensureIndex with a try-catch of MongoException, since a failure to create the index is not a failure condition.

Comment by Daniel Pasette (Inactive) [ 08/Aug/11 ]

This comes from thread in mongo-user: http://groups.google.com/group/mongodb-user/browse_thread/thread/ec4df92c7c4d1857

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