diff options
author | Benety Goh <benety@mongodb.com> | 2015-06-18 18:18:38 -0400 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2015-06-19 13:41:00 -0400 |
commit | 54e8c6b505d8a53014677ae0a1579695229022aa (patch) | |
tree | 7d39eec93ca532b08f7413dd7388af322000d53e /src/mongo | |
parent | 2c37d0b687509b1960d6cd49b332e8e235abe691 (diff) | |
download | mongo-54e8c6b505d8a53014677ae0a1579695229022aa.tar.gz |
SERVER-18036 removed NamespaceString construction from DBClientCursor
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/client/dbclientcursor.cpp | 71 | ||||
-rw-r--r-- | src/mongo/client/dbclientcursor.h | 74 |
2 files changed, 93 insertions, 52 deletions
diff --git a/src/mongo/client/dbclientcursor.cpp b/src/mongo/client/dbclientcursor.cpp index f30cd35b963..058c74ed74e 100644 --- a/src/mongo/client/dbclientcursor.cpp +++ b/src/mongo/client/dbclientcursor.cpp @@ -94,10 +94,6 @@ namespace { } // namespace - void DBClientCursor::_finishConsInit() { - _originalHost = _client->getServerAddress(); - } - int DBClientCursor::nextBatchSize() { if ( nToReturn == 0 ) @@ -112,8 +108,6 @@ namespace { void DBClientCursor::_assembleInit( Message& toSend ) { // If we haven't gotten a cursorId yet, we need to issue a new query or command. if ( !cursorId ) { - auto nss = NamespaceString(ns); - // HACK: // Unfortunately, this code is used by the shell to run commands, // so we need to allow the shell to send invalid options so that we can @@ -124,9 +118,9 @@ namespace { bool hasValidNToReturnForCommand = (nToReturn == 1 || nToReturn == -1); bool hasValidFlagsForCommand = !(opts & mongo::QueryOption_Exhaust); - if (nss.isCommand() && hasValidNToReturnForCommand && hasValidFlagsForCommand) { + if (_isCommand && hasValidNToReturnForCommand && hasValidFlagsForCommand) { toSend = *assembleCommandRequest(_client, - nss.db(), + nsToDatabaseSubstring(ns), opts, query); return; @@ -294,9 +288,8 @@ namespace { } void DBClientCursor::dataReceived( bool& retry, string& host ) { - NamespaceString nss(ns); // If this is a reply to our initial command request. - if (nss.isCommand() && cursorId == 0) { + if (_isCommand && cursorId == 0) { commandDataReceived(); return; } @@ -459,6 +452,64 @@ namespace { _lazyHost = ""; } + DBClientCursor::DBClientCursor(DBClientBase* client, + const std::string& ns, + const BSONObj& query, + int nToReturn, + int nToSkip, + const BSONObj* fieldsToReturn, + int queryOptions, + int batchSize) + : DBClientCursor(client, + ns, + query, + 0, // cursorId + nToReturn, + nToSkip, + fieldsToReturn, + queryOptions, + batchSize) {} + + DBClientCursor::DBClientCursor(DBClientBase* client, + const std::string& ns, + long long cursorId, + int nToReturn, + int queryOptions) + : DBClientCursor(client, + ns, + BSONObj(), // query + cursorId, + nToReturn, + 0, // nToSkip + nullptr, // fieldsToReturn + queryOptions, + 0) {} // batchSize + + DBClientCursor::DBClientCursor(DBClientBase* client, + const std::string& ns, + const BSONObj& query, + long long cursorId, + int nToReturn, + int nToSkip, + const BSONObj* fieldsToReturn, + int queryOptions, + int batchSize) + : _client(client), + _originalHost(_client->getServerAddress()), + ns(ns), + _isCommand(nsIsFull(ns) ? nsToCollectionSubstring(ns) == "$cmd" : false), + query(query), + nToReturn(nToReturn), + haveLimit(nToReturn > 0 && !(queryOptions & QueryOption_CursorTailable)), + nToSkip(nToSkip), + fieldsToReturn(fieldsToReturn), + opts(queryOptions), + batchSize(batchSize == 1 ? 2 : batchSize), + resultFlags(0), + cursorId(cursorId), + _ownCursor(true), + wasError(false) {} + DBClientCursor::~DBClientCursor() { DESTRUCTOR_GUARD ( diff --git a/src/mongo/client/dbclientcursor.h b/src/mongo/client/dbclientcursor.h index 6f125063b60..1e110a4d317 100644 --- a/src/mongo/client/dbclientcursor.h +++ b/src/mongo/client/dbclientcursor.h @@ -31,6 +31,7 @@ #include <stack> +#include "mongo/base/disallow_copying.h" #include "mongo/client/dbclientinterface.h" #include "mongo/db/jsobj.h" #include "mongo/db/json.h" @@ -56,6 +57,7 @@ namespace mongo { /** Queries return a cursor object */ class DBClientCursor : public DBClientCursorInterface { + MONGO_DISALLOW_COPYING(DBClientCursor); public: /** If true, safe to call next(). Requests more from server if necessary. */ bool more(); @@ -135,39 +137,20 @@ namespace mongo { /// Change batchSize after construction. Can change after requesting first batch. void setBatchSize(int newBatchSize) { batchSize = newBatchSize; } - DBClientCursor( DBClientBase* client, const std::string &_ns, BSONObj _query, int _nToReturn, - int _nToSkip, const BSONObj *_fieldsToReturn, int queryOptions , int bs ) : - _client(client), - ns(_ns), - query(_query), - nToReturn(_nToReturn), - haveLimit( _nToReturn > 0 && !(queryOptions & QueryOption_CursorTailable)), - nToSkip(_nToSkip), - fieldsToReturn(_fieldsToReturn), - opts(queryOptions), - batchSize(bs==1?2:bs), - resultFlags(0), - cursorId(), - _ownCursor( true ), - wasError( false ) { - _finishConsInit(); - } - - DBClientCursor( DBClientBase* client, const std::string &_ns, long long _cursorId, int _nToReturn, int options ) : - _client(client), - ns(_ns), - nToReturn( _nToReturn ), - haveLimit( _nToReturn > 0 && !(options & QueryOption_CursorTailable)), - nToSkip(0), - fieldsToReturn(0), - opts( options ), - batchSize(0), - resultFlags(0), - cursorId(_cursorId), - _ownCursor(true), - wasError(false) { - _finishConsInit(); - } + DBClientCursor(DBClientBase* client, + const std::string& ns, + const BSONObj& query, + int nToReturn, + int nToSkip, + const BSONObj* fieldsToReturn, + int queryOptions, + int bs); + + DBClientCursor(DBClientBase* client, + const std::string& ns, + long long cursorId, + int nToReturn, + int options ); virtual ~DBClientCursor(); @@ -215,17 +198,29 @@ namespace mongo { Batch() : m( new Message() ), nReturned(), pos(), data() { } }; + /** + * For exhaust. Used in DBClientConnection. + */ + void exhaustReceiveMore(); + private: - friend class DBClientBase; - friend class DBClientConnection; + DBClientCursor(DBClientBase* client, + const std::string& ns, + const BSONObj& query, + long long cursorId, + int nToReturn, + int nToSkip, + const BSONObj* fieldsToReturn, + int queryOptions, + int bs); int nextBatchSize(); - void _finishConsInit(); Batch batch; DBClientBase* _client; std::string _originalHost; - std::string ns; + const std::string ns; + const bool _isCommand; BSONObj query; int nToReturn; bool haveLimit; @@ -252,15 +247,10 @@ namespace mongo { void commandDataReceived(); void requestMore(); - void exhaustReceiveMore(); // for exhaust // Don't call from a virtual function void _assertIfNull() const { uassert(13348, "connection died", this); } - // non-copyable , non-assignable - DBClientCursor( const DBClientCursor& ); - DBClientCursor& operator=( const DBClientCursor& ); - // init pieces void _assembleInit( Message& toSend ); }; |