diff options
Diffstat (limited to 'src/mongo/client/dbclient_cursor.h')
-rw-r--r-- | src/mongo/client/dbclient_cursor.h | 120 |
1 files changed, 21 insertions, 99 deletions
diff --git a/src/mongo/client/dbclient_cursor.h b/src/mongo/client/dbclient_cursor.h index 520b1c1236c..f13f861d96c 100644 --- a/src/mongo/client/dbclient_cursor.h +++ b/src/mongo/client/dbclient_cursor.h @@ -31,10 +31,8 @@ #include <stack> -#include "mongo/client/query.h" +#include "mongo/client/read_preference.h" #include "mongo/db/dbmessage.h" -#include "mongo/db/jsobj.h" -#include "mongo/db/json.h" #include "mongo/db/namespace_string.h" #include "mongo/db/query/find_command_gen.h" #include "mongo/rpc/message.h" @@ -61,30 +59,26 @@ public: bool secondaryOk, bool useExhaust); + /** + * Constructs a 'DBClientCursor' that will be opened by issuing the find command described by + * 'findRequest'. + */ DBClientCursor(DBClientBase* client, - const NamespaceStringOrUUID& nsOrUuid, - const BSONObj& filter, - const Query& querySettings, - int limit, - int nToSkip, - const BSONObj* fieldsToReturn, - int queryOptions, - int bs, - boost::optional<BSONObj> readConcernObj = boost::none); + FindCommandRequest findRequest, + const ReadPreferenceSetting& readPref, + bool isExhaust); + /** + * Constructs a 'DBClientCursor' from a pre-existing cursor id. + */ DBClientCursor(DBClientBase* client, const NamespaceStringOrUUID& nsOrUuid, long long cursorId, - int limit, - int options, + bool isExhaust, std::vector<BSONObj> initialBatch = {}, boost::optional<Timestamp> operationTime = boost::none, boost::optional<BSONObj> postBatchResumeToken = boost::none); - DBClientCursor(DBClientBase* client, - FindCommandRequest findRequest, - const ReadPreferenceSetting& readPref); - virtual ~DBClientCursor(); /** @@ -169,11 +163,11 @@ public: } bool tailable() const { - return (_opts & QueryOption_CursorTailable) != 0; + return _findRequest && _findRequest->getTailable(); } bool tailableAwaitData() const { - return tailable() && (_opts & QueryOption_AwaitData); + return tailable() && _findRequest->getAwaitData(); } /** @@ -276,21 +270,6 @@ protected: Batch _batch; private: - DBClientCursor(DBClientBase* client, - const NamespaceStringOrUUID& nsOrUuid, - const BSONObj& filter, - const Query& querySettings, - long long cursorId, - int limit, - int nToSkip, - const BSONObj* fieldsToReturn, - int queryOptions, - int bs, - std::vector<BSONObj> initialBatch, - boost::optional<BSONObj> readConcernObj, - boost::optional<Timestamp> operationTime, - boost::optional<BSONObj> postBatchResumeToken = boost::none); - void dataReceived(const Message& reply) { bool retry; std::string lazyHost; @@ -311,13 +290,6 @@ private: Message assembleInit(); Message assembleGetMore(); - /** - * Constructs the initial find commmand request based on a legacy OP_QUERY-style description of - * the find operation. Only used if the caller constructed the 'DBClientCursor' with the legacy - * API. - */ - Message initFromLegacyRequest(); - DBClientBase* _client; std::string _originalHost; NamespaceStringOrUUID _nsOrUuid; @@ -335,32 +307,16 @@ private: bool _connectionHasPendingReplies = false; int _lastRequestId = 0; - int _batchSize; - int _limit = 0; + int _batchSize = 0; - // If the caller describes the find command being executed by this cursor as a - // 'FindCommandRequest', then that request object and the associated read preference are set - // here. Otherwise, if the caller uses the legacy OP_QUERY-inspired API, these members are - // default-initialized but never used. + // A description of the find command provided by the caller which is used to open the cursor. + // + // Has a value of boost::none if the caller constructed this cursor using a pre-existing cursor + // id. boost::optional<FindCommandRequest> _findRequest; - ReadPreferenceSetting _readPref; - // These data members are only used if the cursor was constructed using the legacy - // OP_QUERY-inspired API. If the cursor was constructed using the 'FindCommandRequest'-based - // API, these are initialized to their default values but never used. - BSONObj _filter; - Query _querySettings; - int _nToSkip = 0; - const BSONObj* _fieldsToReturn = nullptr; - boost::optional<BSONObj> _readConcernObj; - - // This has the same meaning as the flags bit vector from the no-longer-supported OP_QUERY wire - // protocol message. However, it is initialized even if the caller constructed the cursor using - // the 'FindCommandRequest`-based API. - // - // We should eventually stop using the OP_QUERY flags bit vector in server code, since OP_QUERY - // is no longer supported. - int _opts; + ReadPreferenceSetting _readPref; + bool _isExhaust; Milliseconds _awaitDataTimeout = Milliseconds{0}; boost::optional<long long> _term; @@ -369,38 +325,4 @@ private: boost::optional<BSONObj> _postBatchResumeToken; }; -/** iterate over objects in current batch only - will not cause a network call - */ -class DBClientCursorBatchIterator { -public: - DBClientCursorBatchIterator(DBClientCursor& c) : _c(c), _n() {} - bool moreInCurrentBatch() { - return _c.moreInCurrentBatch(); - } - BSONObj nextSafe() { - massert(13383, "BatchIterator empty", moreInCurrentBatch()); - ++_n; - return _c.nextSafe(); - } - int n() const { - return _n; - } - // getNamespaceString() will return the NamespaceString returned by the 'find' command. - const NamespaceString& getNamespaceString() { - return _c.getNamespaceString(); - } - - long long getCursorId() const { - return _c.getCursorId(); - } - - boost::optional<BSONObj> getPostBatchResumeToken() const { - return _c.getPostBatchResumeToken(); - } - -private: - DBClientCursor& _c; - int _n; -}; - } // namespace mongo |