1 
2 /**
3  *    Copyright (C) 2018-present MongoDB, Inc.
4  *
5  *    This program is free software: you can redistribute it and/or modify
6  *    it under the terms of the Server Side Public License, version 1,
7  *    as published by MongoDB, Inc.
8  *
9  *    This program is distributed in the hope that it will be useful,
10  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *    Server Side Public License for more details.
13  *
14  *    You should have received a copy of the Server Side Public License
15  *    along with this program. If not, see
16  *    <http://www.mongodb.com/licensing/server-side-public-license>.
17  *
18  *    As a special exception, the copyright holders give permission to link the
19  *    code of portions of this program with the OpenSSL library under certain
20  *    conditions as described in each individual source file and distribute
21  *    linked combinations including the program with the OpenSSL library. You
22  *    must comply with the Server Side Public License in all respects for
23  *    all of the code used other than as permitted herein. If you modify file(s)
24  *    with this exception, you may extend this exception to your version of the
25  *    file(s), but you are not obligated to do so. If you do not wish to do so,
26  *    delete this exception statement from your version. If you delete this
27  *    exception statement from all source files in the program, then also delete
28  *    it in the license file.
29  */
30 
31 #pragma once
32 
33 #include <boost/optional.hpp>
34 #include <string>
35 
36 #include "mongo/base/status.h"
37 #include "mongo/base/status_with.h"
38 #include "mongo/db/clientcursor.h"
39 #include "mongo/db/namespace_string.h"
40 #include "mongo/util/time_support.h"
41 
42 namespace mongo {
43 
44 struct GetMoreRequest {
45     static const char kGetMoreCommandName[];
46 
47     /**
48      * Construct an empty request.
49      */
50     GetMoreRequest();
51 
52     /**
53      * Construct from values for each field.
54      */
55     GetMoreRequest(NamespaceString namespaceString,
56                    CursorId id,
57                    boost::optional<long long> sizeOfBatch,
58                    boost::optional<Milliseconds> awaitDataTimeout,
59                    boost::optional<long long> term,
60                    boost::optional<repl::OpTime> lastKnownCommittedOpTime);
61 
62     /**
63      * Construct a GetMoreRequest from the command specification and db name.
64      */
65     static StatusWith<GetMoreRequest> parseFromBSON(const std::string& dbname,
66                                                     const BSONObj& cmdObj);
67 
68     /**
69      * Serializes this object into a BSON representation. Fields that are not set will not be
70      * part of the the serialized object.
71      */
72     BSONObj toBSON() const;
73 
74     static NamespaceString parseNs(const std::string& dbname, const BSONObj& cmdObj);
75 
76     const NamespaceString nss;
77     const CursorId cursorid;
78 
79     // The batch size is optional. If not provided, we will put as many documents into the batch
80     // as fit within the byte limit.
81     const boost::optional<long long> batchSize;
82 
83     // The number of milliseconds for which a getMore on a tailable, awaitData query should block.
84     const boost::optional<Milliseconds> awaitDataTimeout;
85 
86     // Only internal queries from replication will typically have a term.
87     const boost::optional<long long> term;
88 
89     // Only internal queries from replication will have a last known committed optime.
90     const boost::optional<repl::OpTime> lastKnownCommittedOpTime;
91 
92 private:
93     /**
94      * Returns a non-OK status if there are semantic errors in the parsed request
95      * (e.g. a negative batchSize).
96      */
97     Status isValid() const;
98 };
99 
100 }  // namespace mongo
101