summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/find_common.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/query/find_common.h')
-rw-r--r--src/mongo/db/query/find_common.h28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/mongo/db/query/find_common.h b/src/mongo/db/query/find_common.h
index 45f60d2fd51..d38d580bdd2 100644
--- a/src/mongo/db/query/find_common.h
+++ b/src/mongo/db/query/find_common.h
@@ -89,7 +89,7 @@ public:
// This max may be exceeded by epsilon for output documents that approach the maximum user
// document size. That is, if we must return a BSONObjMaxUserSize document, then the total
// response size will be BSONObjMaxUserSize plus the amount of size required for the message
- // header and the cursor response "envelope". (The envolope contains namespace and cursor id
+ // header and the cursor response "envelope". (The envelope contains namespace and cursor id
// info.)
static const size_t kMaxBytesToReturnToClientAtOnce;
@@ -148,6 +148,32 @@ public:
static std::size_t getBytesToReserveForGetMoreReply(bool isTailable,
size_t firstResultSize,
size_t batchSize);
+
+ /**
+ * Tracker of a size of a server response presented as a BSON array. Facilitates limiting the
+ * server response size to 16MB + certain epsilon. Accounts for array element and it's overhead
+ * size. Does not account for response "envelope" size.
+ */
+ class BSONArrayResponseSizeTracker {
+ // Upper bound of BSON array element overhead.
+ static const size_t kPerDocumentOverheadBytesUpperBound;
+
+ public:
+ /**
+ * Returns true only if 'document' can be added to the BSON array without violating the
+ * overall response size limit or if it is the first document.
+ */
+ bool haveSpaceForNext(const BSONObj& document);
+
+ /**
+ * Records that 'document' was added to the response.
+ */
+ void add(const BSONObj& document);
+
+ private:
+ std::size_t _numberOfDocuments{0};
+ std::size_t _bsonArraySizeInBytes{0};
+ };
};
} // namespace mongo