[JAVA-523] Can't get serverStatus from a mongod server in sharded cluster with authentication enabled Created: 16/Feb/12  Updated: 07/Mar/12  Resolved: 01/Mar/12

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

Type: Bug Priority: Major - P3
Reporter: Yi Tian Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: authentication, cluster, sharding
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Mac OS 10.7.3
mongodb 2.0.2
java-driver 2.7.3



 Description   

I set up a sharded cluster with every mongod process started with "--keyFile" option.

mongos: port 27017
config: port 27019
mongod: shard1 primary port 27200
mongod: shard1 secondary port 27201
mongod: shard2 primary port 27202
mongod: shard2 secondary port 27203

then, I found I can't connect to mongod and get the serverStatus via java-driver.

my code is like this:

Mongo mongo = new Mongo("localhost", 27200);
DB testDB = mongo.getDB("test");
CommandResult resp = testDB.command("serverStatus");
System.out.println(resp);

the result is :

{ "serverUsed" : "localhost:27200" , "errmsg" : "need to login" , "ok" : 0.0}

but if I run 'mongo' in my console to connect to localhost:27200, I can get the serverStatus result without authentication.



 Comments   
Comment by Yi Tian [ 01/Mar/12 ]

Sorry, I make a mistake, I forgot to set test database sharding enabled and create user in test database.
Please close this issue, and sorry for wasting your time.

Comment by Yi Tian [ 28/Feb/12 ]

Here is how to reproduce this issue.
First, set up the cluster with authentication disabled.(set up data and log folder first)
~/mongodb/bin/mongod --shardsvr --replSet shard1 --dbpath ~/mongodb/data/shard11 --oplogSize 100 --logpath ~/mongodb/log/mongod11.log --logappend --fork --port 27200
~/mongodb/bin/mongod --shardsvr --replSet shard1 --dbpath ~/mongodb/data/shard12 --oplogSize 100 --logpath ~/mongodb/log/mongod12.log --logappend --fork --port 27201
~/mongodb/bin/mongod --shardsvr --replSet shard2 --dbpath ~/mongodb/data/shard21 --oplogSize 100 --logpath ~/mongodb/log/mongod21.log --logappend --fork --port 27202
~/mongodb/bin/mongod --shardsvr --replSet shard2 --dbpath ~/mongodb/data/shard22 --oplogSize 100 --logpath ~/mongodb/log/mongod22.log --logappend --fork --port 27203
~/mongodb/bin/mongod --configsvr --dbpath ~/mongodb/data/config --logpath ~/mongodb/log/config.log --logappend --fork
sleep 15
~/mongodb/bin/mongo localhost:27200 --quiet --eval "printjson(config={_id:'shard1',members:[{_id:0,host:'localhost:27200'},{_id: 1, host:'localhost:27201'}]});printjson(rs.initiate(config));"
~/mongodb/bin/mongo localhost:27202 --quiet --eval "printjson(config={_id:'shard2',members:[{_id:0,host:'localhost:27202'},{_id: 1, host:'localhost:27203'}]});printjson(rs.initiate(config));"
sleep 15
~/mongodb/bin/mongos --configdb localhost:27019 --logpath ~/mongodb/log/mongos.log --logappend --fork
sleep 15
~/mongodb/bin/mongo localhost:27017/admin --eval "printjson(db.runCommand(

{addshard:\"shard1/localhost:27200,localhost:27201\",name:\"s1\"}

))"
~/mongodb/bin/mongo localhost:27017/admin --eval "printjson(db.runCommand(

{addshard:\"shard2/localhost:27202,localhost:27203\",name:\"s2\"}

))"
~/mongodb/bin/mongo localhost:27017/admin --eval "printjson(db.addUser(\"admin\",\"admin\"))"

Secondly, stop all processes, and restart them with authentication enabled.

~/mongodb/bin/mongod --keyFile ~/mongodb/bin/key --shardsvr --replSet shard1 --dbpath ~/mongodb/data/shard11 --oplogSize 100 --logpath ~/mongodb/log/mongod11.log --logappend --fork --port 27200
~/mongodb/bin/mongod --keyFile ~/mongodb/bin/key --shardsvr --replSet shard1 --dbpath ~/mongodb/data/shard12 --oplogSize 100 --logpath ~/mongodb/log/mongod12.log --logappend --fork --port 27201
~/mongodb/bin/mongod --keyFile ~/mongodb/bin/key --shardsvr --replSet shard2 --dbpath ~/mongodb/data/shard21 --oplogSize 100 --logpath ~/mongodb/log/mongod21.log --logappend --fork --port 27202
~/mongodb/bin/mongod --keyFile ~/mongodb/bin/key --shardsvr --replSet shard2 --dbpath ~/mongodb/data/shard22 --oplogSize 100 --logpath ~/mongodb/log/mongod22.log --logappend --fork --port 27203
~/mongodb/bin/mongod --keyFile ~/mongodb/bin/key --configsvr --dbpath ~/mongodb/data/config --logpath ~/mongodb/log/config.log --logappend --fork
sleep 15
~/mongodb/bin/mongos --keyFile ~/mongodb/bin/key --configdb localhost:27019 --logpath ~/mongodb/log/mongos.log --logappend --fork

Then run the java code i mentioned. you will get

{ "serverUsed" : "localhost:27200" , "errmsg" : "need to login" , "ok" : 0.0}

but when you excute "mongo localhost:27200 --eval 'printjson(db.serverStatus())'" in your console, you will get the correct result.

Finally, Here is the result you asked:
dentakeshimatoMacBook-Pro:bin tianyi$ ./mongo localhost:27200
MongoDB shell version: 2.0.2
connecting to: localhost:27200/test
PRIMARY> db.isMaster()
{
"setName" : "shard1",
"ismaster" : true,
"secondary" : false,
"hosts" : [
"localhost:27200",
"localhost:27201"
],
"primary" : "localhost:27200",
"me" : "localhost:27200",
"maxBsonObjectSize" : 16777216,
"ok" : 1
}
PRIMARY> db.adminCommand("getCmdLineOpts")
{
"argv" : [
"/Users/tianyi/mongodb/bin/mongod",
"--keyFile",
"/Users/tianyi/mongodb/bin/key",
"--shardsvr",
"--replSet",
"shard1",
"--dbpath",
"/Users/tianyi/mongodb/data/shard11",
"--oplogSize",
"100",
"--logpath",
"/Users/tianyi/mongodb/log/mongod11.log",
"--logappend",
"--fork",
"--port",
"27200"
],
"parsed" :

{ "dbpath" : "/Users/tianyi/mongodb/data/shard11", "fork" : true, "keyFile" : "/Users/tianyi/mongodb/bin/key", "logappend" : true, "logpath" : "/Users/tianyi/mongodb/log/mongod11.log", "oplogSize" : 100, "port" : 27200, "replSet" : "shard1", "shardsvr" : true }

,
"ok" : 1
}

Comment by Scott Hernandez (Inactive) [ 27/Feb/12 ]

This doesn't sound correct; I can't reproduce this. Can you run db.isMaster() and db.adminCommand("getCmdLineOpts") on the primary?

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