Error on startup from using Java API

82 views
Skip to first unread message

Leif Mortenson

unread,
Apr 2, 2011, 8:36:17 AM4/2/11
to mongod...@googlegroups.com
Hi all,
We have a system under development and every once in a while when we
start up our application, I get the following error in the logs:

jvm 1 | 2011/04/02 21:25:33 | Apr 2, 2011 9:25:33 PM
com.mongodb.ReplicaSetStatus$Node update
jvm 1 | 2011/04/02 21:25:33 | SEVERE: can't update node: 127.0.0.1:27017
jvm 1 | 2011/04/02 21:25:33 | java.lang.IllegalArgumentException:
need a connector: admin
jvm 1 | 2011/04/02 21:25:33 | at
com.mongodb.DBApiLayer.<init>(DBApiLayer.java:86)
jvm 1 | 2011/04/02 21:25:33 | at com.mongodb.Mongo.getDB(Mongo.java:319)
jvm 1 | 2011/04/02 21:25:33 | at
com.mongodb.ReplicaSetStatus$Node.update(ReplicaSetStatus.java:149)
jvm 1 | 2011/04/02 21:25:33 | at
com.mongodb.ReplicaSetStatus.updateAll(ReplicaSetStatus.java:314)
jvm 1 | 2011/04/02 21:25:33 | at
com.mongodb.ReplicaSetStatus$Updater.run(ReplicaSetStatus.java:263)

After this happens, the Mongo instance seems to be working fine so I
am not sure what it is. There is nothing out of the ordinary in the
mongod console.

The debugString() from the Mongo instance is "DBTCPConnector: replica
set : [127.0.0.1:27017]"

I am running Mongo 1.8.0. The Java driver is 2.5.2.

Do you have any idea what could be causing this? Please let me know
if there is any other information I can provide.

Thanks in advance,
Leif

Nat

unread,
Apr 2, 2011, 8:40:20 AM4/2/11
to mongod...@googlegroups.com
Can you show your connection string and the result from ismaster command?
--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.

Leif Mortenson

unread,
Apr 2, 2011, 9:02:32 AM4/2/11
to mongod...@googlegroups.com, Nat
Nat,
Thanks for your quick reply. It seems like you are always on the
list. Thank you.

The Mongo instance is set up with code like the following. Simplified
to remove our config parsing.

---
List<ServerAddress> serverAddresses = new ArrayList<ServerAddress>();
ServerAddress serverAddress = new ServerAddress( "127.0.0.1", 27017 );
serverAddresses.add( serverAddress );

MongoOptions options = new MongoOptions();
options.autoConnectRetry = true;
options.connectionsPerHost = 10;
options.threadsAllowedToBlockForConnectionMultiplier = 5;
options.maxWaitTime = 120000;
options.connectTimeout = 0;
options.socketTimeout = 0;

m_mongo = new Mongo( serverAddresses, options );
m_mongo.slaveOk();

m_db = m_mongo.getDB( "myapp" );

CommandResult result = m_db.command( "ismaster" );
System.out.println( result );
---

We currently only have a single server running.

The output of the above is:
---
{ "ismaster" : true , "maxBsonObjectSize" : 16777216 , "ok" : 1.0}
---

Cheers,
Leif

Nat

unread,
Apr 2, 2011, 11:13:56 AM4/2/11
to mongodb-user
you can use this one instead then so that you can specify your option.
The reason you are getting an error because you use an api for
replicaset where you just want to connect to a standalone server.
http://api.mongodb.org/java/2.6-pre-/com/mongodb/Mongo.html#Mongo(com.mongodb.ServerAddress,
com.mongodb.MongoOptions)

On Apr 2, 9:02 pm, Leif Mortenson <leif.morten...@tanukisoftware.com>
wrote:

Leif Mortenson

unread,
Apr 2, 2011, 2:22:27 PM4/2/11
to mongod...@googlegroups.com, Nat
Nat,
Thank you. I had not looked at the source to see that the single
ServerAddress vs multi-ServerAddress constructors were working
differently. I thought that it would internally locate all servers
from whatever initial servers you told it about. By allowing more
than one I thought that it simply avoided problems if the first server
was down.

I have modified my code as follows:
---
if ( serverAddresses.size() == 1 )
{
// This constructor puts the Mongo instance into
single server mode.
m_mongo = new Mongo( serverAddresses.get( 0 ), options );
}
else
{
// This constructor puts the Mongo instance into
replica set mode.


m_mongo = new Mongo( serverAddresses, options );
}

---
I'll give this a try for a while and see how it works.

The javadocs could probably use some more explanation to make their
behavior a bit clearer.

Thanks again,
Leif

Leif Mortenson

unread,
Jun 1, 2011, 3:26:58 AM6/1/11
to mongod...@googlegroups.com
Nat,
This thread is a bit old. But we are now running tests against a
replicaset with 4 nodes. If I connect using either a single server,
or specifying all 4, I am still getting the following error almost
every time:

jvm 1 | SEVERE: can't update node: test1.tsl.local:27017
jvm 1 | java.lang.IllegalArgumentException: need a connector: admin
jvm 1 | at com.mongodb.DBApiLayer.<init>(DBApiLayer.java:86)
jvm 1 | at com.mongodb.Mongo.getDB(Mongo.java:319)
jvm 1 | at com.mongodb.ReplicaSetStatus$Node.update(ReplicaSetStatus.java:149)
jvm 1 | at com.mongodb.ReplicaSetStatus.updateAll(ReplicaSetStatus.java:314)
jvm 1 | at com.mongodb.ReplicaSetStatus$Updater.run(ReplicaSetStatus.java:263)

I am still using the 2.5.2 Java driver.

Do you have any ideas as to what might be causing this? The
application seems to work fine after this error has been logged.

Cheers,
Leif

On Sun, Apr 3, 2011 at 12:13 AM, Nat <nat....@gmail.com> wrote:

Nat

unread,
Jun 1, 2011, 3:41:38 AM6/1/11
to mongod...@googlegroups.com
I think your replSet might be configured with invalid server name. Can you do rs.conf()?

Leif Mortenson

unread,
Jun 1, 2011, 4:09:33 AM6/1/11
to mongod...@googlegroups.com
Nat,
Thanks for the quick reply. This is what I get:

---
myapp:PRIMARY> rs.conf();
{
"_id" : "myapp",
"version" : 4,
"members" : [
{
"_id" : 0,
"host" : "myapp-test1.ttt.local:27017"
},
{
"_id" : 1,
"host" : "myapp-test2.ttt.local"
},
{
"_id" : 2,
"host" : "myapp-test3.ttt.local"
},
{
"_id" : 3,
"host" : "myapp-test4.ttt.local"
}
]
}
myapp:PRIMARY>
---

I am not sure why only the first host has the port. That was the
original one that I ran rs.initiate() on. Then I ran
rs.add("myapp-test2.ttt.local") for each of the other nodes.

I went through and double checked my mongodb.conf files and they all say:
replSet = myapp

Please let me know if there is anything else I can provide.

Cheers,
Leif

Nat

unread,
Jun 1, 2011, 4:28:26 AM6/1/11
to mongod...@googlegroups.com
If the port is not provided, it will be defaulted to 27017. Did you make sure that you can resolve DNS names for all the hosts you see? If it can, make sure you can access all hosts from the client.

Leif Mortenson

unread,
Jun 1, 2011, 4:47:23 AM6/1/11
to mongod...@googlegroups.com
Nat,
I double checked and I am able to start my application when it is
pointed to any one of the four nodes. In each case it resolves
correctly.

The nodes are also able to see eachother fine as can be seen from the
replicaset status regardless of which node is the master. I also
tried to resolve all hosts from all nodes manually just to be sure and
it all looks fine.

The error does not get dumped every time I start. This morning it was
almost every time, but now it is about 1 in 10 times. No idea what
changed there. When I was just doing the above test, I got a
slightly different error:
---
jvm 1 | Jun 1, 2011 5:43:30 PM com.mongodb.ReplicaSetStatus$Node update
jvm 1 | SEVERE: can't update node: myapp-test3.ttt.local:27017


jvm 1 | java.lang.IllegalArgumentException: need a connector: admin
jvm 1 | at com.mongodb.DBApiLayer.<init>(DBApiLayer.java:86)
jvm 1 | at com.mongodb.Mongo.getDB(Mongo.java:319)
jvm 1 | at com.mongodb.ReplicaSetStatus$Node.update(ReplicaSetStatus.java:149)
jvm 1 | at com.mongodb.ReplicaSetStatus.updateAll(ReplicaSetStatus.java:314)
jvm 1 | at com.mongodb.ReplicaSetStatus$Updater.run(ReplicaSetStatus.java:263)

jvm 1 | Jun 1, 2011 5:43:30 PM com.mongodb.ReplicaSetStatus$Updater run
jvm 1 | WARNING: couldn't do update pass
jvm 1 | java.lang.NullPointerException
jvm 1 | at com.mongodb.ReplicaSetStatus$Updater.run(ReplicaSetStatus.java:275)
---

Cheers,
Leif

Nat

unread,
Jun 1, 2011, 5:00:22 AM6/1/11
to mongod...@googlegroups.com
If it's not consistent, it could happen because of something else. Can you send me your connection code? Are you running it inside any J2EE container? 

Leif Mortenson

unread,
Jun 1, 2011, 5:20:06 AM6/1/11
to mongod...@googlegroups.com
Nat,
Sure no problem. It was the same code as we had discussed earlier in
this coversation. Here it is again:

---
List<ServerAddress> serverAddresses = new ArrayList<ServerAddress>();

serverAddresses.add( new ServerAddress( "myapp-test1.ttt.local", 27017 ) );
// Same if the following are also uncommented.
//serverAddresses.add( new ServerAddress( "myapp-test2.ttt.local", 27017 ) );
//serverAddresses.add( new ServerAddress( "myapp-test3.ttt.local", 27017 ) );
//serverAddresses.add( new ServerAddress( "myapp-test4.ttt.local", 27017 ) );

MongoOptions options = new MongoOptions();
options.autoConnectRetry = true;
options.connectionsPerHost = 10;
options.threadsAllowedToBlockForConnectionMultiplier = 5;
options.maxWaitTime = 120000;
options.connectTimeout = 0;
options.socketTimeout = 0;

m_mongo = new Mongo( serverAddresses, options );
m_mongo.slaveOk();

m_db = m_mongo.getDB( "myapp" );

---

Cheers,
Leif

Nat

unread,
Jun 1, 2011, 5:26:17 AM6/1/11
to mongod...@googlegroups.com
I think Scott can confirm it. I think there is a concurrency issue where if you have multiple CPU, your replication set update thread can start up before your main thread finish constructing Mongo object resulting in what you experience. If that's the case, the error should appear once at startup only.

Leif Mortenson

unread,
Jun 1, 2011, 6:28:10 AM6/1/11
to mongod...@googlegroups.com
Nat,
Yes, I am only seeing this on startup. I think I found the bug:
https://jira.mongodb.org/browse/JAVA-362
Sorry I didn't notice it earlier. Thanks for your help.

Cheers,
Leif

Nat

unread,
Jun 1, 2011, 6:33:20 AM6/1/11
to mongod...@googlegroups.com
Awesome. I didn't see that one either. Try to upgrade to the latest code then.
-----Original Message-----
From: Leif Mortenson <leif.mo...@tanukisoftware.com>
Sender: mongod...@googlegroups.com
Date: Wed, 1 Jun 2011 19:28:10
To: <mongod...@googlegroups.com>
Reply-To: mongod...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages