diff options
author | Henrik Edin <henrik.edin@mongodb.com> | 2021-03-30 15:42:53 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-06-03 23:57:49 +0000 |
commit | 97b91fd47ea9e3e4b0f5a5e1b9e21a41f13d522f (patch) | |
tree | 2f434645f05769c411e89d5520acfc483b890340 | |
parent | f53c59e2a9e597fbcdf0632559a81963994f9734 (diff) | |
download | mongo-97b91fd47ea9e3e4b0f5a5e1b9e21a41f13d522f.tar.gz |
SERVER-54489 Limit 'errors' and 'warnings' fields in validation result to 2MB each to reduce the probability to go over the size limit in the response.
(cherry picked from commit 3ba3ab4f46e939f9d428a511cb24b1d142dea534)
-rw-r--r-- | src/mongo/db/commands/validate.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/mongo/db/commands/validate.cpp b/src/mongo/db/commands/validate.cpp index ff22256383c..f5eb8dd06f1 100644 --- a/src/mongo/db/commands/validate.cpp +++ b/src/mongo/db/commands/validate.cpp @@ -197,10 +197,23 @@ public: results.warnings.push_back( "Some checks omitted for speed. use {full:true} option to do more thorough scan."); } - result.appendBool("valid", results.valid); - result.append("warnings", results.warnings); - result.append("errors", results.errors); + + static constexpr std::size_t kMaxErrorWarningSizeBytes = 2 * 1024 * 1024; + auto appendRangeSizeLimited = [&result](StringData fieldName, const auto& values) { + std::size_t usedSize = 0; + BSONArrayBuilder arr(result.subarrayStart(fieldName)); + for (auto it = values.begin(), end = values.end(); + it != end && usedSize < kMaxErrorWarningSizeBytes; + ++it) { + arr.append(*it); + usedSize += it->size(); + } + }; + + appendRangeSizeLimited("warnings"_sd, results.warnings); + appendRangeSizeLimited("errors"_sd, results.errors); + result.append("extraIndexEntries", results.extraIndexEntries); result.append("missingIndexEntries", results.missingIndexEntries); |