summaryrefslogtreecommitdiff
path: root/src/mongo/db/ftdc
diff options
context:
space:
mode:
authorJonathan Reams <jbreams@mongodb.com>2019-03-27 12:06:48 -0400
committerJonathan Reams <jbreams@mongodb.com>2019-04-06 12:40:33 -0400
commit83383eb160f904c699b399ac59ccbbf103ad6102 (patch)
treed82abc4d7f7f10181b103461c936682813787e56 /src/mongo/db/ftdc
parent652d22504d2990b2322aefc272b489e731edd789 (diff)
downloadmongo-83383eb160f904c699b399ac59ccbbf103ad6102.tar.gz
SERVER-40356 Make ConstDataRange constructable from any byte-like type
Diffstat (limited to 'src/mongo/db/ftdc')
-rw-r--r--src/mongo/db/ftdc/block_compressor.cpp4
-rw-r--r--src/mongo/db/ftdc/decompressor.cpp52
-rw-r--r--src/mongo/db/ftdc/file_reader.cpp2
3 files changed, 15 insertions, 43 deletions
diff --git a/src/mongo/db/ftdc/block_compressor.cpp b/src/mongo/db/ftdc/block_compressor.cpp
index c128dcf115e..ed7b80d5e4b 100644
--- a/src/mongo/db/ftdc/block_compressor.cpp
+++ b/src/mongo/db/ftdc/block_compressor.cpp
@@ -74,7 +74,7 @@ StatusWith<ConstDataRange> BlockCompressor::compress(ConstDataRange source) {
return {ErrorCodes::ZLibError, str::stream() << "deflateEnd failed with " << err};
}
- return ConstDataRange(reinterpret_cast<char*>(_buffer.data()), stream.total_out);
+ return ConstDataRange(_buffer.data(), stream.total_out);
}
StatusWith<ConstDataRange> BlockCompressor::uncompress(ConstDataRange source,
@@ -112,7 +112,7 @@ StatusWith<ConstDataRange> BlockCompressor::uncompress(ConstDataRange source,
return {ErrorCodes::ZLibError, str::stream() << "inflateEnd failed with " << err};
}
- return ConstDataRange(reinterpret_cast<char*>(_buffer.data()), stream.total_out);
+ return ConstDataRange(_buffer.data(), stream.total_out);
}
} // namespace mongo
diff --git a/src/mongo/db/ftdc/decompressor.cpp b/src/mongo/db/ftdc/decompressor.cpp
index 3bba4db89e4..363064df5e6 100644
--- a/src/mongo/db/ftdc/decompressor.cpp
+++ b/src/mongo/db/ftdc/decompressor.cpp
@@ -42,19 +42,14 @@
namespace mongo {
-StatusWith<std::vector<BSONObj>> FTDCDecompressor::uncompress(ConstDataRange buf) {
+StatusWith<std::vector<BSONObj>> FTDCDecompressor::uncompress(ConstDataRange buf) try {
ConstDataRangeCursor compressedDataRange(buf);
// Read the length of the uncompressed buffer
- auto swUncompressedLength = compressedDataRange.readAndAdvance<LittleEndian<std::uint32_t>>();
- if (!swUncompressedLength.isOK()) {
- return {swUncompressedLength.getStatus()};
- }
+ auto uncompressedLength = compressedDataRange.readAndAdvance<LittleEndian<std::uint32_t>>();
// Now uncompress the data
// Limit size of the buffer we need zlib
- auto uncompressedLength = swUncompressedLength.getValue();
-
if (uncompressedLength > 10000000) {
return Status(ErrorCodes::InvalidLength, "Metrics chunk has exceeded the allowable size.");
}
@@ -68,28 +63,13 @@ StatusWith<std::vector<BSONObj>> FTDCDecompressor::uncompress(ConstDataRange buf
ConstDataRangeCursor cdc = statusUncompress.getValue();
// The document is not part of any checksum so we must validate it is correct
- auto swRef = cdc.readAndAdvance<Validated<BSONObj>>();
- if (!swRef.isOK()) {
- return {swRef.getStatus()};
- }
-
- BSONObj ref = swRef.getValue();
+ BSONObj ref = cdc.readAndAdvance<Validated<BSONObj>>();
// Read count of metrics
- auto swMetricsCount = cdc.readAndAdvance<LittleEndian<std::uint32_t>>();
- if (!swMetricsCount.isOK()) {
- return {swMetricsCount.getStatus()};
- }
-
- std::uint32_t metricsCount = swMetricsCount.getValue();
+ auto metricsCount = cdc.readAndAdvance<LittleEndian<std::uint32_t>>();
// Read count of samples
- auto swSampleCount = cdc.readAndAdvance<LittleEndian<std::uint32_t>>();
- if (!swSampleCount.isOK()) {
- return {swSampleCount.getStatus()};
- }
-
- std::uint32_t sampleCount = swSampleCount.getValue();
+ auto sampleCount = cdc.readAndAdvance<LittleEndian<std::uint32_t>>();
// Limit size of the buffer we need for metrics and samples
if (metricsCount * sampleCount > 1000000) {
@@ -138,23 +118,13 @@ StatusWith<std::vector<BSONObj>> FTDCDecompressor::uncompress(ConstDataRange buf
continue;
}
- auto swDelta = cdrc.readAndAdvance<FTDCVarInt>();
-
- if (!swDelta.isOK()) {
- return swDelta.getStatus();
- }
-
- if (swDelta.getValue() == 0) {
- auto swZero = cdrc.readAndAdvance<FTDCVarInt>();
-
- if (!swZero.isOK()) {
- return swDelta.getStatus();
- }
-
- zeroesCount = swZero.getValue();
+ auto delta = cdrc.readAndAdvance<FTDCVarInt>();
+ if (delta == 0) {
+ auto zero = cdrc.readAndAdvance<FTDCVarInt>();
+ zeroesCount = zero;
}
- deltas[FTDCCompressor::getArrayOffset(sampleCount, j, i)] = swDelta.getValue();
+ deltas[FTDCCompressor::getArrayOffset(sampleCount, j, i)] = delta;
}
}
@@ -179,6 +149,8 @@ StatusWith<std::vector<BSONObj>> FTDCDecompressor::uncompress(ConstDataRange buf
}
return {docs};
+} catch (const DBException& e) {
+ return e.toStatus();
}
} // namespace mongo
diff --git a/src/mongo/db/ftdc/file_reader.cpp b/src/mongo/db/ftdc/file_reader.cpp
index 9a1ada5628a..a5851680a49 100644
--- a/src/mongo/db/ftdc/file_reader.cpp
+++ b/src/mongo/db/ftdc/file_reader.cpp
@@ -202,7 +202,7 @@ StatusWith<BSONObj> FTDCFileReader::readDocument() {
ConstDataRange cdr(_buffer.data(), _buffer.data() + bsonLength);
// TODO: Validated only validates objects based on a flag which is the default at the moment
- auto swl = cdr.read<Validated<BSONObj>>();
+ auto swl = cdr.readNoThrow<Validated<BSONObj>>();
if (!swl.isOK()) {
return swl.getStatus();
}