summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2015-06-10 15:04:34 -0400
committerBenety Goh <benety@mongodb.com>2015-06-18 15:26:58 -0400
commit94543115f64345f3bb74b2508b1b319d6b6cf68d (patch)
treebbda2a18e71651ff71f02abc970dc825d7b968b9 /src
parent2a20332297dc32a87433416413bb098ebac19e2f (diff)
downloadmongo-94543115f64345f3bb74b2508b1b319d6b6cf68d.tar.gz
SERVER-18036 fixed NamespaceString usage in some commands, especially in cases where the only purpose is to extract the database name
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/commands/index_filter_commands_test.cpp2
-rw-r--r--src/mongo/db/commands/list_indexes.cpp5
-rw-r--r--src/mongo/db/commands/plan_cache_commands_test.cpp2
-rw-r--r--src/mongo/db/query/getmore_request.cpp4
-rw-r--r--src/mongo/db/query/getmore_request_test.cpp8
-rw-r--r--src/mongo/rpc/legacy_request.cpp2
-rw-r--r--src/mongo/s/d_state.cpp4
-rw-r--r--src/mongo/s/strategy.cpp6
-rw-r--r--src/mongo/s/version_manager.cpp3
9 files changed, 18 insertions, 18 deletions
diff --git a/src/mongo/db/commands/index_filter_commands_test.cpp b/src/mongo/db/commands/index_filter_commands_test.cpp
index baeb4b985a7..0994e4c89cf 100644
--- a/src/mongo/db/commands/index_filter_commands_test.cpp
+++ b/src/mongo/db/commands/index_filter_commands_test.cpp
@@ -48,7 +48,7 @@ namespace {
using std::string;
using std::vector;
- static const char* ns = "somebogusns";
+ static const char* ns = "test.t";
/**
* Utility function to get list of index filters from the query settings.
diff --git a/src/mongo/db/commands/list_indexes.cpp b/src/mongo/db/commands/list_indexes.cpp
index 6cdee4785fd..f020f87c43d 100644
--- a/src/mongo/db/commands/list_indexes.cpp
+++ b/src/mongo/db/commands/list_indexes.cpp
@@ -99,12 +99,13 @@ namespace mongo {
str::stream() << "Argument to listIndexes must be of type String, not "
<< typeName(first.type()),
first.type() == String);
- const NamespaceString ns(parseNs(dbname, cmdObj));
+ StringData collectionName = first.valueStringData();
uassert(
28529,
str::stream() << "Argument to listIndexes must be a collection name, "
<< "not the empty string",
- !ns.coll().empty());
+ !collectionName.empty());
+ const NamespaceString ns(dbname, collectionName);
const long long defaultBatchSize = std::numeric_limits<long long>::max();
long long batchSize;
diff --git a/src/mongo/db/commands/plan_cache_commands_test.cpp b/src/mongo/db/commands/plan_cache_commands_test.cpp
index abdc2f53a94..ec6a5ea7967 100644
--- a/src/mongo/db/commands/plan_cache_commands_test.cpp
+++ b/src/mongo/db/commands/plan_cache_commands_test.cpp
@@ -50,7 +50,7 @@ namespace {
using std::string;
using std::vector;
- static const char* ns = "somebogusns";
+ static const char* ns = "test.t";
/**
* Tests for planCacheListQueryShapes
diff --git a/src/mongo/db/query/getmore_request.cpp b/src/mongo/db/query/getmore_request.cpp
index eaf31a22f50..678276f8467 100644
--- a/src/mongo/db/query/getmore_request.cpp
+++ b/src/mongo/db/query/getmore_request.cpp
@@ -31,9 +31,11 @@
#include "mongo/platform/basic.h"
#include "mongo/db/query/getmore_request.h"
+#include "mongo/db/namespace_string.h"
#include <boost/optional.hpp>
+#include "mongo/util/assert_util.h"
#include "mongo/util/stringutils.h"
namespace mongo {
@@ -80,6 +82,8 @@ namespace mongo {
// static
StatusWith<GetMoreRequest> GetMoreRequest::parseFromBSON(const std::string& dbname,
const BSONObj& cmdObj) {
+ invariant(!dbname.empty());
+
// Required fields.
boost::optional<CursorId> cursorid;
boost::optional<std::string> fullns;
diff --git a/src/mongo/db/query/getmore_request_test.cpp b/src/mongo/db/query/getmore_request_test.cpp
index db596c416b3..bd2f8c8b242 100644
--- a/src/mongo/db/query/getmore_request_test.cpp
+++ b/src/mongo/db/query/getmore_request_test.cpp
@@ -89,14 +89,6 @@ namespace {
ASSERT_EQUALS(ErrorCodes::TypeMismatch, result.getStatus().code());
}
- TEST(GetMoreRequestTest, parseFromBSONInvalidDbName) {
- StatusWith<GetMoreRequest> result = GetMoreRequest::parseFromBSON(
- "",
- BSON("getMore" << CursorId(123) << "collection" << "coll"));
- ASSERT_NOT_OK(result.getStatus());
- ASSERT_EQUALS(ErrorCodes::BadValue, result.getStatus().code());
- }
-
TEST(GetMoreRequestTest, parseFromBSONInvalidCursorId) {
StatusWith<GetMoreRequest> result = GetMoreRequest::parseFromBSON(
"db",
diff --git a/src/mongo/rpc/legacy_request.cpp b/src/mongo/rpc/legacy_request.cpp
index 613cfe35ea1..e4f09257257 100644
--- a/src/mongo/rpc/legacy_request.cpp
+++ b/src/mongo/rpc/legacy_request.cpp
@@ -42,7 +42,7 @@ namespace rpc {
: _message(std::move(message))
, _dbMessage(*message)
, _queryMessage(_dbMessage)
- , _database(NamespaceString(_queryMessage.ns).db().toString()) {
+ , _database(nsToDatabase(_queryMessage.ns)) {
std::tie(_upconvertedCommandArgs, _upconvertedMetadata) = uassertStatusOK(
rpc::upconvertRequestMetadata(std::move(_queryMessage.query),
diff --git a/src/mongo/s/d_state.cpp b/src/mongo/s/d_state.cpp
index 8475777b76c..89c5f2d52c8 100644
--- a/src/mongo/s/d_state.cpp
+++ b/src/mongo/s/d_state.cpp
@@ -1083,7 +1083,7 @@ namespace mongo {
// we can run on a slave up to here
if (!repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(
- NamespaceString(ns).db())) {
+ nsToDatabase(ns))) {
result.append( "errmsg" , "not master" );
result.append( "note" , "from post init in setShardVersion" );
return false;
@@ -1362,7 +1362,7 @@ namespace mongo {
return true;
if (!repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(
- NamespaceString(ns).db())) {
+ nsToDatabase(ns))) {
// right now connections to secondaries aren't versioned at all
return true;
}
diff --git a/src/mongo/s/strategy.cpp b/src/mongo/s/strategy.cpp
index 784bca5c545..1cdbff82fab 100644
--- a/src/mongo/s/strategy.cpp
+++ b/src/mongo/s/strategy.cpp
@@ -87,7 +87,11 @@ namespace mongo {
static bool doShardedIndexQuery(Request& r, const QuerySpec& qSpec) {
// Extract the ns field from the query, which may be embedded within the "query" or
// "$query" field.
- const NamespaceString indexNSSQuery(qSpec.filter()["ns"].str());
+ auto nsField = qSpec.filter()["ns"];
+ if (nsField.eoo()) {
+ return false;
+ }
+ const NamespaceString indexNSSQuery(nsField.str());
auto status = grid.catalogCache()->getDatabase(indexNSSQuery.db().toString());
if (!status.isOK()) {
diff --git a/src/mongo/s/version_manager.cpp b/src/mongo/s/version_manager.cpp
index 967ce82d308..de33cbb6626 100644
--- a/src/mongo/s/version_manager.cpp
+++ b/src/mongo/s/version_manager.cpp
@@ -283,8 +283,7 @@ namespace mongo {
return initShardVersionEmptyNS(conn_in);
}
- const NamespaceString nss(ns);
- auto status = grid.catalogCache()->getDatabase(nss.db().toString());
+ auto status = grid.catalogCache()->getDatabase(nsToDatabase(ns));
if (!status.isOK()) {
return false;
}