[SERVER-19416] Executing "dbStats" fails: "exception: need a valid database name" (3.0 Server, 2.13 Java driver) Created: 15/Jul/15  Updated: 15/Jul/15  Resolved: 15/Jul/15

Status: Closed
Project: Core Server
Component/s: Diagnostics
Affects Version/s: 3.0.4
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Jan S. Assignee: Sam Kleinman (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: Windows
Steps To Reproduce:

Mongo mongo = new MongoClient();
DB db = mongo.getDB("TestDB"); // TestDB exists
BasicDBObject dbStats = new BasicDBObject("dbStats", "1");
dbStats.put("scale", 1);
CommandResult command = db.command(dbStats);
if (!command.ok()) {
	throw command.getException();
}

Output:

com.mongodb.CommandFailureException: { "serverUsed" : "127.0.0.1:27017" , "errmsg" : "exception: need a valid database name" , "code" : 28539 , "ok" : 0.0}

Participants:

 Description   

The combination mongo-java-driver-2.13.2 & MongoDB server 3.0.2/3.0.4 causes the dbStats command to fail:

com.mongodb.CommandFailureException:

{ "serverUsed" : "127.0.0.1:27017" , "errmsg" : "exception: need a valid database name" , "code" : 28539 , "ok" : 0.0}

END

The same code works for a MongoDB 2.x server using the same driver.



 Comments   
Comment by Jeffrey Yemin [ 15/Jul/15 ]

Jan,

The error message is confusing, but the root of the problem is an incorrectly created dbstats command. It should be:

new BasicDBObject("dbStats", 1)   // use integer instead of string.

as documented here.

It seems that starting with 3.0 the server is less permissive in this situation.

Regards,
Jeff

Comment by Jan S. [ 15/Jul/15 ]

For non-existing databases I agree.
However my "TestDB" has two collections with a few thousand objects in each collection, therefore it exists and is not empty...

Comment by Sam Kleinman (Inactive) [ 15/Jul/15 ]

Thanks so much for this report, I've looked into this some more and found that the mongod produces this error when it attempts to get a lock on a database that either doesn't exist or does not exist and doesn't have data. I was able to observe the effect reported here saw and reproduce the error you got in 3.0.4 using the shell (including the 2.6.10 shell); however, from looking at the implementation of dbStats for 2.6.10, it looks like previous versions handled requests for dbStats on databases that didn't exist differently.

Consider the following:

For 3.0.4:

db.getSiblingDB("nothing").stats()
{
	"db" : "nothing",
	"collections" : 0,
	"objects" : 0,
	"avgObjSize" : 0,
	"dataSize" : 0,
	"storageSize" : 0,
	"numExtents" : 0,
	"indexes" : 0,
	"indexSize" : 0,
	"fileSize" : 0,
	"ok" : 1
}
db.runCommand({dbStats: "nothing"})
{
	"errmsg" : "exception: need a valid database name",
	"code" : 28539,
	"ok" : 0
}

In 2.6.10 I got different results:

db.getSiblingDB("nothing").stats()
{
	"db" : "nothing",
	"collections" : 0,
	"objects" : 0,
	"avgObjSize" : 0,
	"dataSize" : 0,
	"storageSize" : 0,
	"numExtents" : 0,
	"indexes" : 0,
	"indexSize" : 0,
	"fileSize" : 0,
	"dataFileVersion" : {
		
	},
	"ok" : 1
}
db.runCommand({dbStats: "nothing"})
{
	"db" : "test",
	"collections" : 4,
	"objects" : 13,
	"avgObjSize" : 82.46153846153847,
	"dataSize" : 1072,
	"storageSize" : 28672,
	"numExtents" : 4,
	"indexes" : 3,
	"indexSize" : 24528,
	"fileSize" : 16777216,
	"nsSizeMB" : 16,
	"dataFileVersion" : {
		"major" : 4,
		"minor" : 22
	},
	"extentFreeList" : {
		"num" : 0,
		"totalSize" : 0
	},
	"ok" : 1
}

The newer behavior seems to make more sense from the perspective of the server, although it might make sense for the client to handle this situation differently.

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