[JAVA-762] authentication problem on Replica Set Created: 16/Feb/13  Updated: 11/Sep/19  Resolved: 21/Feb/13

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Minor - P4
Reporter: zhoumingyi Assignee: Unassigned
Resolution: Done Votes: 0
Labels: driver, replication
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

test environment:
1)win7 x64 enterprise version(debug server)
eclipse(with plugin com.sysdeo.eclipse.tomcat_3.3.0) + apache-tomcat-7.0.19

2)ubunto linux 12.04 x64 server (test server)
apache-tomcat-7.0.19

3)ubunto linux 12.04 x64 server (mongo replica set server * 3)
mongo db ver 2.2
the following command is called after replica set is build (without keyfile)
use image_db
db.addUser('testusr','testpwd')
db.createCollection('image_collection',

{autoIndexId:true}

)
db.image_db.ensureIndex(

{'name':1, 'userid':1, 'kind':1}

,

{backgroud:true}

)


Attachments: Text File sample code.txt    

 Description   

*******NOTE start*******
As i can't confirm that this is a driver problem
or tomcat problem
or just a misuse of driver.
Please just help me confirm that whether driver problem.

                • NOTE end ********

attached code runs normally when access a single mongo server(NOT a replica set )
but when i try to access replica set server, it pop a exception:(40 thread test)
java.lang.IllegalStateException: can't authenticate twice on the same database

i don't know why [m_DBAccess.isAuthenticated()]returns a false and [m_DBAccess.authenticate] pop this exception.
please help.

PS:
This only appearred in win 7 server(env 1), it does not appearred in linux server(env 2)

code backgroud
m_MongoDB is a static Mongo instance.
m_DBAccess is a DB instance that every thread will get a db instance by using [m_MongoDB.getDB("db_image")]
In my opinion, every thread has a different db object (although it point to the same db), so authentication of each thread is needed.
Am i right?



 Comments   
Comment by Jeffrey Yemin [ 21/Feb/13 ]

Yeah, I agree that the documentation on this is not stellar. I'll work on a fix.

Comment by zhoumingyi [ 21/Feb/13 ]

thank you for your reply, i know how to modify my code now.
Just one more question:
I failed to find the following sentence "All threads share the same DB instance for each unique database name." in java driver doc.
Am i ignore sth. while reading java docunment?
If so, please give me a the link of that.
Thanks~

Comment by Jeffrey Yemin [ 19/Feb/13 ]

Furthermore, it's possible that this is a race condition in your code (between the call to isAuthenticated and authenticate), which is another reason to authenticate in the same thread as creates the Mongo instance.

Comment by Jeffrey Yemin [ 19/Feb/13 ]

All threads share the same DB instance for each unique database name. So you only have to authenticate once. It's best to do that right after you create your Mongo instance and before that instance is distributed to other threads.

Comment by Jeffrey Yemin [ 19/Feb/13 ]

I moved this to the JAVA project since this is an issue with usage of the Java driver, not a server issue.

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