summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2017-03-31 21:11:55 -0400
committerMathias Stearn <mathias@10gen.com>2017-04-12 08:57:12 -0400
commit3c7f43bc2cf5419b4061bd55351a1894a0e32152 (patch)
tree6bb35fe4cc6444298e127af1eaeb3fa83f02495d
parentc739baf5366cbd987bf61acc29a54f56e209a3b7 (diff)
downloadmongo-3c7f43bc2cf5419b4061bd55351a1894a0e32152.tar.gz
SERVER-28508 Delete unused DocumentRange rpc cruft
-rw-r--r--etc/log_redaction.audit2
-rw-r--r--src/mongo/rpc/SConscript17
-rw-r--r--src/mongo/rpc/command_reply.cpp9
-rw-r--r--src/mongo/rpc/command_reply.h14
-rw-r--r--src/mongo/rpc/command_reply_builder.cpp15
-rw-r--r--src/mongo/rpc/command_reply_builder.h4
-rw-r--r--src/mongo/rpc/command_reply_test.cpp23
-rw-r--r--src/mongo/rpc/command_request.cpp10
-rw-r--r--src/mongo/rpc/command_request.h14
-rw-r--r--src/mongo/rpc/command_request_builder.cpp13
-rw-r--r--src/mongo/rpc/command_request_builder.h5
-rw-r--r--src/mongo/rpc/command_request_builder_test.cpp6
-rw-r--r--src/mongo/rpc/command_request_test.cpp23
-rw-r--r--src/mongo/rpc/document_range.cpp108
-rw-r--r--src/mongo/rpc/document_range.h98
-rw-r--r--src/mongo/rpc/legacy_reply.cpp5
-rw-r--r--src/mongo/rpc/legacy_reply.h14
-rw-r--r--src/mongo/rpc/legacy_reply_builder.cpp12
-rw-r--r--src/mongo/rpc/legacy_reply_builder.h4
-rw-r--r--src/mongo/rpc/legacy_request.cpp5
-rw-r--r--src/mongo/rpc/legacy_request.h13
-rw-r--r--src/mongo/rpc/legacy_request_builder.cpp12
-rw-r--r--src/mongo/rpc/legacy_request_builder.h4
-rw-r--r--src/mongo/rpc/reply_builder_interface.h15
-rw-r--r--src/mongo/rpc/reply_builder_test.cpp8
-rw-r--r--src/mongo/rpc/reply_interface.h13
-rw-r--r--src/mongo/rpc/request_builder_interface.h13
-rw-r--r--src/mongo/rpc/request_interface.h13
28 files changed, 4 insertions, 488 deletions
diff --git a/etc/log_redaction.audit b/etc/log_redaction.audit
index 0d5d97e764c..2914841d2a0 100644
--- a/etc/log_redaction.audit
+++ b/etc/log_redaction.audit
@@ -2256,8 +2256,6 @@
20160711:ramon:src/mongo/rpc/command_request_builder.h:0
20160711:ramon:src/mongo/rpc/command_request_builder_test.cpp:0
20160711:ramon:src/mongo/rpc/command_request_test.cpp:0
-20160711:ramon:src/mongo/rpc/document_range.cpp:0
-20160711:ramon:src/mongo/rpc/document_range.h:0
20160711:ramon:src/mongo/rpc/factory.cpp:0
20160711:ramon:src/mongo/rpc/factory.h:0
20160711:ramon:src/mongo/rpc/get_status_from_command_result.cpp:0
diff --git a/src/mongo/rpc/SConscript b/src/mongo/rpc/SConscript
index 558458be062..9d4e9de72a3 100644
--- a/src/mongo/rpc/SConscript
+++ b/src/mongo/rpc/SConscript
@@ -21,19 +21,6 @@ env.Library(
env.Library(
target=[
- 'document_range',
- ],
- source=[
- 'document_range.cpp'
- ],
- LIBDEPS=[
- '$BUILD_DIR/mongo/base',
- '$BUILD_DIR/mongo/db/server_options_core',
- ],
-)
-
-env.Library(
- target=[
'protocol',
],
source=[
@@ -88,7 +75,6 @@ env.Library(
'command_request_builder.cpp',
],
LIBDEPS=[
- 'document_range',
'$BUILD_DIR/mongo/util/net/network',
],
)
@@ -102,7 +88,6 @@ env.Library(
'legacy_request_builder.cpp',
],
LIBDEPS=[
- 'document_range',
'metadata',
'$BUILD_DIR/mongo/db/dbmessage',
'$BUILD_DIR/mongo/util/net/network',
@@ -119,7 +104,6 @@ env.Library(
'reply_builder_interface.cpp',
],
LIBDEPS=[
- 'document_range',
'$BUILD_DIR/mongo/util/net/network',
],
)
@@ -134,7 +118,6 @@ env.Library(
],
LIBDEPS=[
'command_reply',
- 'document_range',
'metadata',
'object_check',
'$BUILD_DIR/mongo/util/net/network',
diff --git a/src/mongo/rpc/command_reply.cpp b/src/mongo/rpc/command_reply.cpp
index 25a0ce58195..c5ff1b9ab78 100644
--- a/src/mongo/rpc/command_reply.cpp
+++ b/src/mongo/rpc/command_reply.cpp
@@ -57,7 +57,7 @@ CommandReply::CommandReply(const Message* message) : _message(message) {
_commandReply.shareOwnershipWith(message->sharedBuffer());
_metadata = uassertStatusOK(cur.readAndAdvance<Validated<BSONObj>>()).val;
_metadata.shareOwnershipWith(message->sharedBuffer());
- _outputDocs = DocumentRange(cur.data(), messageEnd);
+ uassert(40420, "OP_COMMAND reply contains trailing bytes following metadata", cur.empty());
}
const BSONObj& CommandReply::getMetadata() const {
@@ -68,10 +68,6 @@ const BSONObj& CommandReply::getCommandReply() const {
return _commandReply;
}
-DocumentRange CommandReply::getOutputDocs() const {
- return _outputDocs;
-}
-
Protocol CommandReply::getProtocol() const {
return rpc::Protocol::kOpCommandV1;
}
@@ -79,8 +75,7 @@ Protocol CommandReply::getProtocol() const {
bool operator==(const CommandReply& lhs, const CommandReply& rhs) {
SimpleBSONObjComparator bsonComparator;
return bsonComparator.evaluate(lhs._metadata == rhs._metadata) &&
- bsonComparator.evaluate(lhs._commandReply == rhs._commandReply) &&
- (lhs._outputDocs == rhs._outputDocs);
+ bsonComparator.evaluate(lhs._commandReply == rhs._commandReply);
}
bool operator!=(const CommandReply& lhs, const CommandReply& rhs) {
diff --git a/src/mongo/rpc/command_reply.h b/src/mongo/rpc/command_reply.h
index 1e092d6db5d..e1fb849f063 100644
--- a/src/mongo/rpc/command_reply.h
+++ b/src/mongo/rpc/command_reply.h
@@ -29,7 +29,6 @@
#pragma once
#include "mongo/db/jsobj.h"
-#include "mongo/rpc/document_range.h"
#include "mongo/rpc/reply_interface.h"
namespace mongo {
@@ -68,18 +67,6 @@ public:
*/
const BSONObj& getCommandReply() const final;
- /**
- * A variable number of BSON documents returned by the command. It is valid for the
- * returned range to be empty.
- *
- * Example usage:
- *
- * for (auto&& doc : reply.getOutputDocs()) {
- * ... do stuff with doc
- * }
- */
- DocumentRange getOutputDocs() const final;
-
Protocol getProtocol() const final;
friend bool operator==(const CommandReply& lhs, const CommandReply& rhs);
@@ -90,7 +77,6 @@ private:
BSONObj _metadata;
BSONObj _commandReply;
- DocumentRange _outputDocs;
};
} // namespace rpc
diff --git a/src/mongo/rpc/command_reply_builder.cpp b/src/mongo/rpc/command_reply_builder.cpp
index 5d35e3a803d..b47b0545c80 100644
--- a/src/mongo/rpc/command_reply_builder.cpp
+++ b/src/mongo/rpc/command_reply_builder.cpp
@@ -70,21 +70,6 @@ CommandReplyBuilder& CommandReplyBuilder::setMetadata(const BSONObj& metadata) {
return *this;
}
-
-Status CommandReplyBuilder::addOutputDocs(DocumentRange outputDocs) {
- invariant(_state == State::kOutputDocs);
- auto rangeData = outputDocs.data();
- auto dataSize = rangeData.length();
- _builder.appendBuf(rangeData.data(), dataSize);
- return Status::OK();
-}
-
-Status CommandReplyBuilder::addOutputDoc(const BSONObj& outputDoc) {
- invariant(_state == State::kOutputDocs);
- outputDoc.appendSelfToBufBuilder(_builder);
- return Status::OK();
-}
-
Protocol CommandReplyBuilder::getProtocol() const {
return rpc::Protocol::kOpCommandV1;
}
diff --git a/src/mongo/rpc/command_reply_builder.h b/src/mongo/rpc/command_reply_builder.h
index d37b8fb36e3..b990ca3d8fa 100644
--- a/src/mongo/rpc/command_reply_builder.h
+++ b/src/mongo/rpc/command_reply_builder.h
@@ -32,7 +32,6 @@
#include "mongo/base/status.h"
#include "mongo/db/jsobj.h"
-#include "mongo/rpc/document_range.h"
#include "mongo/rpc/protocol.h"
#include "mongo/rpc/reply_builder_interface.h"
#include "mongo/util/net/message.h"
@@ -62,9 +61,6 @@ public:
CommandReplyBuilder& setMetadata(const BSONObj& metadata) final;
- Status addOutputDocs(DocumentRange outputDocs) final;
- Status addOutputDoc(const BSONObj& outputDoc) final;
-
Protocol getProtocol() const final;
void reset() final;
diff --git a/src/mongo/rpc/command_reply_test.cpp b/src/mongo/rpc/command_reply_test.cpp
index 26d6fc51c6b..7ef9a29b46b 100644
--- a/src/mongo/rpc/command_reply_test.cpp
+++ b/src/mongo/rpc/command_reply_test.cpp
@@ -87,33 +87,10 @@ TEST_F(ReplyTest, ParseAllFields) {
auto metadata = metadataBob.done();
writeObj(metadata);
- BSONObjBuilder outputDoc1Bob{};
- outputDoc1Bob.append("meep", "boop").append("meow", "chirp");
- auto outputDoc1 = outputDoc1Bob.done();
- writeObj(outputDoc1);
-
- BSONObjBuilder outputDoc2Bob{};
- outputDoc1Bob.append("bleep", "bop").append("woof", "squeak");
- auto outputDoc2 = outputDoc2Bob.done();
- writeObj(outputDoc2);
-
rpc::CommandReply opCmdReply{buildMessage()};
ASSERT_BSONOBJ_EQ(opCmdReply.getMetadata(), metadata);
ASSERT_BSONOBJ_EQ(opCmdReply.getCommandReply(), commandReply);
-
- auto outputDocRange = opCmdReply.getOutputDocs();
- auto outputDocRangeIter = outputDocRange.begin();
-
- ASSERT_BSONOBJ_EQ(*outputDocRangeIter, outputDoc1);
- // can't use assert equals since we don't have an op to print the iter.
- ASSERT_FALSE(outputDocRangeIter == outputDocRange.end());
- ++outputDocRangeIter;
- ASSERT_BSONOBJ_EQ(*outputDocRangeIter, outputDoc2);
- ASSERT_FALSE(outputDocRangeIter == outputDocRange.end());
- ++outputDocRangeIter;
-
- ASSERT_TRUE(outputDocRangeIter == outputDocRange.end());
}
TEST_F(ReplyTest, EmptyMessageThrows) {
diff --git a/src/mongo/rpc/command_request.cpp b/src/mongo/rpc/command_request.cpp
index 32a82ee388f..024b8ebe9c1 100644
--- a/src/mongo/rpc/command_request.cpp
+++ b/src/mongo/rpc/command_request.cpp
@@ -112,8 +112,7 @@ CommandRequest::CommandRequest(const Message* message) : _message(message) {
uassertStatusOK(cur.readAndAdvance<>(&obj));
_metadata = std::move(obj.val);
-
- _inputDocs = DocumentRange{cur.data(), messageEnd};
+ uassert(40419, "OP_COMMAND request contains trailing bytes following metadata", cur.empty());
}
StringData CommandRequest::getDatabase() const {
@@ -132,15 +131,10 @@ const BSONObj& CommandRequest::getCommandArgs() const {
return _commandArgs;
}
-DocumentRange CommandRequest::getInputDocs() const {
- return _inputDocs;
-}
-
bool operator==(const CommandRequest& lhs, const CommandRequest& rhs) {
return (lhs._database == rhs._database) && (lhs._commandName == rhs._commandName) &&
SimpleBSONObjComparator::kInstance.evaluate(lhs._metadata == rhs._metadata) &&
- SimpleBSONObjComparator::kInstance.evaluate(lhs._commandArgs == rhs._commandArgs) &&
- (lhs._inputDocs == rhs._inputDocs);
+ SimpleBSONObjComparator::kInstance.evaluate(lhs._commandArgs == rhs._commandArgs);
}
bool operator!=(const CommandRequest& lhs, const CommandRequest& rhs) {
diff --git a/src/mongo/rpc/command_request.h b/src/mongo/rpc/command_request.h
index a39d7374533..92106915143 100644
--- a/src/mongo/rpc/command_request.h
+++ b/src/mongo/rpc/command_request.h
@@ -30,7 +30,6 @@
#include "mongo/base/string_data.h"
#include "mongo/db/jsobj.h"
-#include "mongo/rpc/document_range.h"
#include "mongo/rpc/protocol.h"
#include "mongo/rpc/request_interface.h"
@@ -74,18 +73,6 @@ public:
*/
const BSONObj& getCommandArgs() const final;
- /**
- * A variable number of BSON documents to pass to the command. It is valid for
- * the returned range to be empty.
- *
- * Example usage:
- *
- * for (auto&& doc : req.getInputDocs()) {
- * ... do stuff with doc
- * }
- */
- DocumentRange getInputDocs() const final;
-
Protocol getProtocol() const final;
friend bool operator==(const CommandRequest& lhs, const CommandRequest& rhs);
@@ -97,7 +84,6 @@ private:
StringData _commandName;
BSONObj _commandArgs;
BSONObj _metadata;
- DocumentRange _inputDocs;
};
} // namespace rpc
diff --git a/src/mongo/rpc/command_request_builder.cpp b/src/mongo/rpc/command_request_builder.cpp
index 88b6097aa64..11b25beef6e 100644
--- a/src/mongo/rpc/command_request_builder.cpp
+++ b/src/mongo/rpc/command_request_builder.cpp
@@ -75,19 +75,6 @@ CommandRequestBuilder& CommandRequestBuilder::setMetadata(BSONObj metadata) {
return *this;
}
-CommandRequestBuilder& CommandRequestBuilder::addInputDocs(DocumentRange inputDocs) {
- invariant(_state == State::kInputDocs);
- auto rangeData = inputDocs.data();
- _builder.appendBuf(rangeData.data(), rangeData.length());
- return *this;
-}
-
-CommandRequestBuilder& CommandRequestBuilder::addInputDoc(BSONObj inputDoc) {
- invariant(_state == State::kInputDocs);
- inputDoc.appendSelfToBufBuilder(_builder);
- return *this;
-}
-
Protocol CommandRequestBuilder::getProtocol() const {
return rpc::Protocol::kOpCommandV1;
}
diff --git a/src/mongo/rpc/command_request_builder.h b/src/mongo/rpc/command_request_builder.h
index e6519988d1d..7eb3db408b5 100644
--- a/src/mongo/rpc/command_request_builder.h
+++ b/src/mongo/rpc/command_request_builder.h
@@ -32,7 +32,6 @@
#include "mongo/base/string_data.h"
#include "mongo/db/jsobj.h"
-#include "mongo/rpc/document_range.h"
#include "mongo/rpc/protocol.h"
#include "mongo/rpc/request_builder_interface.h"
#include "mongo/util/net/message.h"
@@ -66,10 +65,6 @@ public:
CommandRequestBuilder& setMetadata(BSONObj metadata) final;
- CommandRequestBuilder& addInputDocs(DocumentRange inputDocs) final;
-
- CommandRequestBuilder& addInputDoc(BSONObj inputDoc) final;
-
Protocol getProtocol() const final;
/**
diff --git a/src/mongo/rpc/command_request_builder_test.cpp b/src/mongo/rpc/command_request_builder_test.cpp
index 6a8b7211ab9..7e96f06b184 100644
--- a/src/mongo/rpc/command_request_builder_test.cpp
+++ b/src/mongo/rpc/command_request_builder_test.cpp
@@ -31,7 +31,6 @@
#include "mongo/db/jsobj.h"
#include "mongo/rpc/command_request.h"
#include "mongo/rpc/command_request_builder.h"
-#include "mongo/rpc/document_range.h"
#include "mongo/unittest/unittest.h"
namespace {
@@ -67,15 +66,12 @@ TEST(RequestBuilder, RoundTrip) {
inputDoc2.appendSelfToBufBuilder(inputDocs);
inputDoc3.appendSelfToBufBuilder(inputDocs);
- rpc::DocumentRange inputDocRange{inputDocs.buf(), inputDocs.buf() + inputDocs.len()};
-
rpc::CommandRequestBuilder r;
auto msg = r.setDatabase(databaseName)
.setCommandName(commandName)
.setCommandArgs(commandArgs)
.setMetadata(metadata)
- .addInputDocs(inputDocRange)
.done();
rpc::CommandRequest parsed(&msg);
@@ -84,8 +80,6 @@ TEST(RequestBuilder, RoundTrip) {
ASSERT_EQUALS(parsed.getCommandName(), commandName);
ASSERT_BSONOBJ_EQ(parsed.getMetadata(), metadata);
ASSERT_BSONOBJ_EQ(parsed.getCommandArgs(), commandArgs);
- // need ostream overloads for ASSERT_EQUALS
- ASSERT_TRUE(parsed.getInputDocs() == inputDocRange);
}
} // namespace
diff --git a/src/mongo/rpc/command_request_test.cpp b/src/mongo/rpc/command_request_test.cpp
index d0f4e61fddb..45717a339ea 100644
--- a/src/mongo/rpc/command_request_test.cpp
+++ b/src/mongo/rpc/command_request_test.cpp
@@ -74,16 +74,6 @@ TEST(CommandRequest, ParseAllFields) {
auto metadata = metadataBob.done();
writeObj(metadata);
- BSONObjBuilder inputDoc1Bob{};
- inputDoc1Bob.append("meep", "boop").append("meow", "chirp");
- auto inputDoc1 = inputDoc1Bob.done();
- writeObj(inputDoc1);
-
- BSONObjBuilder inputDoc2Bob{};
- inputDoc1Bob.append("bleep", "bop").append("woof", "squeak");
- auto inputDoc2 = inputDoc2Bob.done();
- writeObj(inputDoc2);
-
Message toSend;
toSend.setData(dbCommand, opCommandData.data(), opCommandData.size());
@@ -93,19 +83,6 @@ TEST(CommandRequest, ParseAllFields) {
ASSERT_EQUALS(opCmd.getDatabase(), database);
ASSERT_BSONOBJ_EQ(opCmd.getMetadata(), metadata);
ASSERT_BSONOBJ_EQ(opCmd.getCommandArgs(), commandArgs);
-
- auto inputDocRange = opCmd.getInputDocs();
- auto inputDocRangeIter = inputDocRange.begin();
-
- ASSERT_BSONOBJ_EQ(*inputDocRangeIter, inputDoc1);
- // can't use assert equals since we don't have an op to print the iter.
- ASSERT_FALSE(inputDocRangeIter == inputDocRange.end());
- ++inputDocRangeIter;
- ASSERT_BSONOBJ_EQ(*inputDocRangeIter, inputDoc2);
- ASSERT_FALSE(inputDocRangeIter == inputDocRange.end());
- ++inputDocRangeIter;
-
- ASSERT_TRUE(inputDocRangeIter == inputDocRange.end());
}
TEST(CommandRequest, InvalidNSThrows) {
diff --git a/src/mongo/rpc/document_range.cpp b/src/mongo/rpc/document_range.cpp
deleted file mode 100644
index fd525a5e244..00000000000
--- a/src/mongo/rpc/document_range.cpp
+++ /dev/null
@@ -1,108 +0,0 @@
-/**
- * Copyright (C) 2015 MongoDB Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the GNU Affero General Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#include "mongo/platform/basic.h"
-
-#include "mongo/rpc/document_range.h"
-
-#include <algorithm>
-#include <cstring>
-#include <tuple>
-#include <utility>
-
-#include "mongo/base/data_type_validated.h"
-#include "mongo/rpc/object_check.h"
-#include "mongo/util/assert_util.h"
-
-namespace mongo {
-namespace rpc {
-
-DocumentRange::DocumentRange(const char* begin, const char* end) : _range{begin, end} {}
-
-DocumentRange::const_iterator DocumentRange::begin() const {
- return const_iterator{ConstDataRangeCursor{_range}};
-}
-
-DocumentRange::const_iterator DocumentRange::end() const {
- return const_iterator{};
-}
-
-ConstDataRange DocumentRange::data() const {
- return _range;
-}
-
-bool operator==(const DocumentRange& lhs, const DocumentRange& rhs) {
- // We might want to change this to use std::equal in the future if
- // we ever allow non-contigious document ranges
- return (lhs._range.length() == rhs._range.length()) &&
- (std::memcmp(lhs._range.data(), rhs._range.data(), lhs._range.length()) == 0);
-}
-
-bool operator!=(const DocumentRange& lhs, const DocumentRange& rhs) {
- return !(lhs == rhs);
-}
-
-DocumentRange::const_iterator::const_iterator(ConstDataRangeCursor cursor) : _cursor{cursor} {
- operator++();
-}
-
-DocumentRange::const_iterator::reference DocumentRange::const_iterator::operator*() const {
- return _obj;
-}
-
-DocumentRange::const_iterator::pointer DocumentRange::const_iterator::operator->() const {
- return &_obj;
-}
-
-DocumentRange::const_iterator& DocumentRange::const_iterator::operator++() {
- if (_cursor.length() == 0) {
- *this = const_iterator{};
- } else {
- _obj = uassertStatusOK(_cursor.readAndAdvance<Validated<BSONObj>>()).val;
- }
- return *this;
-}
-
-DocumentRange::const_iterator DocumentRange::const_iterator::operator++(int) {
- auto pre = const_iterator{_cursor};
- operator++();
- return pre;
-}
-
-bool operator==(const DocumentRange::const_iterator& lhs,
- const DocumentRange::const_iterator& rhs) {
- return lhs._cursor == rhs._cursor;
-}
-
-bool operator!=(const DocumentRange::const_iterator& lhs,
- const DocumentRange::const_iterator& rhs) {
- return !(lhs == rhs);
-}
-
-} // namespace rpc
-} // namespace mongo
diff --git a/src/mongo/rpc/document_range.h b/src/mongo/rpc/document_range.h
deleted file mode 100644
index 95d23d82b4c..00000000000
--- a/src/mongo/rpc/document_range.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/**
- * Copyright (C) 2015 MongoDB Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the GNU Affero General Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#pragma once
-
-#include <cstddef>
-#include <iterator>
-
-#include "mongo/base/data_range.h"
-#include "mongo/base/data_range_cursor.h"
-#include "mongo/db/jsobj.h"
-
-namespace mongo {
-namespace rpc {
-
-/**
- * A read-only view over a sequence of BSON documents.
- *
- * TODO:
- * - Handle document validation
- * - Currently this only supports a contiguous buffer of BSON documents,
- * in the future it should support non-contiguous buffers as well.
- */
-class DocumentRange {
-public:
- class const_iterator;
-
- DocumentRange() = default;
-
- DocumentRange(const char* begin, const char* end);
-
- const_iterator begin() const;
- const_iterator end() const;
-
- // Get a ConstDataRange over the underlying raw buffer.
- ConstDataRange data() const;
-
- // Deep equality of all documents in both ranges.
- friend bool operator==(const DocumentRange& lhs, const DocumentRange& rhs);
- friend bool operator!=(const DocumentRange& lhs, const DocumentRange& rhs);
-
-private:
- ConstDataRange _range{nullptr, nullptr};
-};
-
-class DocumentRange::const_iterator : public std::iterator<std::forward_iterator_tag,
- BSONObj,
- std::ptrdiff_t,
- const BSONObj*,
- const BSONObj&> {
-public:
- const_iterator() = default;
-
- reference operator*() const;
- pointer operator->() const;
-
- const_iterator& operator++();
- const_iterator operator++(int);
-
- friend bool operator==(const const_iterator&, const const_iterator&);
- friend bool operator!=(const const_iterator&, const const_iterator&);
-
-private:
- // The only way to get a non-end iterator is from DocumentRange begin().
- friend class DocumentRange;
- explicit const_iterator(ConstDataRangeCursor cursor);
-
- ConstDataRangeCursor _cursor{nullptr, nullptr};
- BSONObj _obj;
-};
-
-} // namespace rpc
-} // namespace mongo
diff --git a/src/mongo/rpc/legacy_reply.cpp b/src/mongo/rpc/legacy_reply.cpp
index 97aef06c4ca..a300a8dafc7 100644
--- a/src/mongo/rpc/legacy_reply.cpp
+++ b/src/mongo/rpc/legacy_reply.cpp
@@ -78,7 +78,6 @@ LegacyReply::LegacyReply(const Message* message) : _message(std::move(message))
std::tie(_commandReply, _metadata) =
uassertStatusOK(rpc::upconvertReplyMetadata(BSONObj(qr.data())));
- _outputDocs = DocumentRange{};
return;
}
@@ -90,10 +89,6 @@ const BSONObj& LegacyReply::getCommandReply() const {
return _commandReply;
}
-DocumentRange LegacyReply::getOutputDocs() const {
- return _outputDocs;
-}
-
Protocol LegacyReply::getProtocol() const {
return rpc::Protocol::kOpQuery;
}
diff --git a/src/mongo/rpc/legacy_reply.h b/src/mongo/rpc/legacy_reply.h
index 7d3d222f59d..84d5ecea201 100644
--- a/src/mongo/rpc/legacy_reply.h
+++ b/src/mongo/rpc/legacy_reply.h
@@ -30,7 +30,6 @@
#include "mongo/db/dbmessage.h"
#include "mongo/db/jsobj.h"
-#include "mongo/rpc/document_range.h"
#include "mongo/rpc/protocol.h"
#include "mongo/rpc/reply_interface.h"
@@ -61,18 +60,6 @@ public:
*/
const BSONObj& getCommandReply() const final;
- /**
- * A variable number of BSON documents returned by the command. It is valid for the
- * returned range to be empty.
- *
- * Example usage:
- *
- * for (auto&& doc : reply.getOutputDocs()) {
- * ... do stuff with doc
- * }
- */
- DocumentRange getOutputDocs() const final;
-
Protocol getProtocol() const final;
private:
@@ -81,7 +68,6 @@ private:
BSONObj _commandReply{}; // will hold unowned
BSONObj _metadata{};
BufBuilder _docBuffer{};
- DocumentRange _outputDocs{};
};
} // namespace rpc
diff --git a/src/mongo/rpc/legacy_reply_builder.cpp b/src/mongo/rpc/legacy_reply_builder.cpp
index 1f494f87afb..5f4d3cfe3d1 100644
--- a/src/mongo/rpc/legacy_reply_builder.cpp
+++ b/src/mongo/rpc/legacy_reply_builder.cpp
@@ -106,18 +106,6 @@ LegacyReplyBuilder& LegacyReplyBuilder::setMetadata(const BSONObj& metadata) {
return *this;
}
-Status LegacyReplyBuilder::addOutputDocs(DocumentRange docs) {
- invariant(_state == State::kOutputDocs);
- // no op
- return Status::OK();
-}
-
-Status LegacyReplyBuilder::addOutputDoc(const BSONObj& bson) {
- invariant(_state == State::kOutputDocs);
- // no op
- return Status::OK();
-}
-
Protocol LegacyReplyBuilder::getProtocol() const {
return rpc::Protocol::kOpQuery;
}
diff --git a/src/mongo/rpc/legacy_reply_builder.h b/src/mongo/rpc/legacy_reply_builder.h
index 6d0c40a8a42..beb7806147c 100644
--- a/src/mongo/rpc/legacy_reply_builder.h
+++ b/src/mongo/rpc/legacy_reply_builder.h
@@ -32,7 +32,6 @@
#include "mongo/base/status.h"
#include "mongo/bson/util/builder.h"
-#include "mongo/rpc/document_range.h"
#include "mongo/rpc/protocol.h"
#include "mongo/rpc/reply_builder_interface.h"
#include "mongo/util/net/message.h"
@@ -57,9 +56,6 @@ public:
LegacyReplyBuilder& setMetadata(const BSONObj& metadata) final;
- Status addOutputDocs(DocumentRange outputDocs) final;
- Status addOutputDoc(const BSONObj& outputDoc) final;
-
void reset() final;
Message done() final;
diff --git a/src/mongo/rpc/legacy_request.cpp b/src/mongo/rpc/legacy_request.cpp
index f9b7fe41c77..932da2e8cc4 100644
--- a/src/mongo/rpc/legacy_request.cpp
+++ b/src/mongo/rpc/legacy_request.cpp
@@ -71,11 +71,6 @@ const BSONObj& LegacyRequest::getCommandArgs() const {
return _upconvertedCommandArgs;
}
-DocumentRange LegacyRequest::getInputDocs() const {
- // return an empty document range.
- return DocumentRange{};
-}
-
Protocol LegacyRequest::getProtocol() const {
return rpc::Protocol::kOpQuery;
}
diff --git a/src/mongo/rpc/legacy_request.h b/src/mongo/rpc/legacy_request.h
index 9312c59639d..f943114e358 100644
--- a/src/mongo/rpc/legacy_request.h
+++ b/src/mongo/rpc/legacy_request.h
@@ -31,7 +31,6 @@
#include "mongo/base/string_data.h"
#include "mongo/db/dbmessage.h"
#include "mongo/db/jsobj.h"
-#include "mongo/rpc/document_range.h"
#include "mongo/rpc/protocol.h"
#include "mongo/rpc/request_interface.h"
@@ -76,18 +75,6 @@ public:
*/
const BSONObj& getCommandArgs() const final;
- /**
- * A variable number of BSON documents to pass to the command. It is valid for
- * the returned range to be empty.
- *
- * Example usage:
- *
- * for (auto&& doc : req.getInputDocs()) {
- * ... do stuff with doc
- * }
- */
- DocumentRange getInputDocs() const final;
-
Protocol getProtocol() const final;
private:
diff --git a/src/mongo/rpc/legacy_request_builder.cpp b/src/mongo/rpc/legacy_request_builder.cpp
index 137d410fc2b..49034f94eb6 100644
--- a/src/mongo/rpc/legacy_request_builder.cpp
+++ b/src/mongo/rpc/legacy_request_builder.cpp
@@ -89,18 +89,6 @@ LegacyRequestBuilder& LegacyRequestBuilder::setMetadata(BSONObj metadata) {
return *this;
}
-LegacyRequestBuilder& LegacyRequestBuilder::addInputDocs(DocumentRange inputDocs) {
- invariant(_state == State::kInputDocs);
- // no op
- return *this;
-}
-
-LegacyRequestBuilder& LegacyRequestBuilder::addInputDoc(BSONObj inputDoc) {
- invariant(_state == State::kInputDocs);
- // no op
- return *this;
-}
-
Protocol LegacyRequestBuilder::getProtocol() const {
return rpc::Protocol::kOpQuery;
}
diff --git a/src/mongo/rpc/legacy_request_builder.h b/src/mongo/rpc/legacy_request_builder.h
index 09a31e95079..26bcb9903f1 100644
--- a/src/mongo/rpc/legacy_request_builder.h
+++ b/src/mongo/rpc/legacy_request_builder.h
@@ -32,7 +32,6 @@
#include "mongo/base/string_data.h"
#include "mongo/db/jsobj.h"
-#include "mongo/rpc/document_range.h"
#include "mongo/rpc/request_builder_interface.h"
#include "mongo/util/net/message.h"
@@ -51,9 +50,6 @@ public:
LegacyRequestBuilder& setMetadata(BSONObj metadata) final;
LegacyRequestBuilder& setCommandArgs(BSONObj commandArgs) final;
- LegacyRequestBuilder& addInputDocs(DocumentRange inputDocs) final;
- LegacyRequestBuilder& addInputDoc(BSONObj inputDoc) final;
-
Protocol getProtocol() const final;
Message done() final;
diff --git a/src/mongo/rpc/reply_builder_interface.h b/src/mongo/rpc/reply_builder_interface.h
index 196556af3ae..b2631bfaf0e 100644
--- a/src/mongo/rpc/reply_builder_interface.h
+++ b/src/mongo/rpc/reply_builder_interface.h
@@ -41,7 +41,6 @@ class BSONObjBuilder;
class Message;
namespace rpc {
-class DocumentRange;
/**
* Constructs an RPC Reply.
@@ -89,20 +88,6 @@ public:
const BSONObj& extraErrorInfo);
/**
- * Add a range of output documents to the reply. This method can be called multiple times
- * before calling done(). A non OK status indicates that the message does not have
- * enough space to store ouput documents.
- */
- virtual Status addOutputDocs(DocumentRange outputDocs) = 0;
-
- /**
- * Add a single output document to the reply. This method can be called multiple times
- * before calling done(). A non OK status indicates that the message does not have
- * enough space to store ouput documents.
- */
- virtual Status addOutputDoc(const BSONObj& outputDoc) = 0;
-
- /**
* Gets the protocol used to serialize this reply. This should be used for validity checks
* only - runtime behavior changes should be implemented with polymorphism.
*/
diff --git a/src/mongo/rpc/reply_builder_test.cpp b/src/mongo/rpc/reply_builder_test.cpp
index 4aa6a9758e0..7be0b2f0dbe 100644
--- a/src/mongo/rpc/reply_builder_test.cpp
+++ b/src/mongo/rpc/reply_builder_test.cpp
@@ -33,7 +33,6 @@
#include "mongo/db/json.h"
#include "mongo/rpc/command_reply.h"
#include "mongo/rpc/command_reply_builder.h"
-#include "mongo/rpc/document_range.h"
#include "mongo/rpc/legacy_reply.h"
#include "mongo/rpc/legacy_reply_builder.h"
#include "mongo/unittest/death_test.h"
@@ -180,19 +179,12 @@ void testRoundTrip(rpc::ReplyBuilderInterface& replyBuilder) {
outputDoc1.appendSelfToBufBuilder(outputDocs);
outputDoc2.appendSelfToBufBuilder(outputDocs);
outputDoc3.appendSelfToBufBuilder(outputDocs);
- rpc::DocumentRange outputDocRange{outputDocs.buf(), outputDocs.buf() + outputDocs.len()};
- if (replyBuilder.getProtocol() != rpc::Protocol::kOpQuery) {
- replyBuilder.addOutputDocs(outputDocRange);
- }
auto msg = replyBuilder.done();
T parsed(&msg);
ASSERT_BSONOBJ_EQ(parsed.getMetadata(), metadata);
- if (replyBuilder.getProtocol() != rpc::Protocol::kOpQuery) {
- ASSERT_TRUE(parsed.getOutputDocs() == outputDocRange);
- }
}
} // namespace
diff --git a/src/mongo/rpc/reply_interface.h b/src/mongo/rpc/reply_interface.h
index 7786c57cb26..a5e72255d6e 100644
--- a/src/mongo/rpc/reply_interface.h
+++ b/src/mongo/rpc/reply_interface.h
@@ -36,7 +36,6 @@ class BSONObj;
class Message;
namespace rpc {
-class DocumentRange;
/**
* An immutable view of an RPC Reply.
@@ -59,18 +58,6 @@ public:
virtual const BSONObj& getCommandReply() const = 0;
/**
- * A variable number of BSON documents returned by the command. It is valid for the
- * returned range to be empty.
- *
- * Example usage:
- *
- * for (auto&& doc : reply.getOutputDocs()) {
- * ... do stuff with doc
- * }
- */
- virtual DocumentRange getOutputDocs() const = 0;
-
- /**
* Gets the protocol used to deserialize this reply. This should be used for validity
* checks only - runtime behavior changes should be implemented with polymorphism.
*/
diff --git a/src/mongo/rpc/request_builder_interface.h b/src/mongo/rpc/request_builder_interface.h
index beaf27b7823..aef872cb0b4 100644
--- a/src/mongo/rpc/request_builder_interface.h
+++ b/src/mongo/rpc/request_builder_interface.h
@@ -39,7 +39,6 @@ class BSONObj;
class StringData;
namespace rpc {
-class DocumentRange;
/**
* Constructs an RPC request.
@@ -80,18 +79,6 @@ public:
virtual RequestBuilderInterface& setCommandArgs(BSONObj commandArgs) = 0;
/**
- * Add a range of input documents to the request. This method can be called multiple times
- * before calling done().
- */
- virtual RequestBuilderInterface& addInputDocs(DocumentRange inputDocs) = 0;
-
- /**
- * Add a single output document to the request. This method can be called multiple times
- * before calling done().
- */
- virtual RequestBuilderInterface& addInputDoc(BSONObj inputDoc) = 0;
-
- /**
* Gets the protocol used to serialize this request. This should only be used for asserts,
* and not for runtime behavior changes, which should be handled with polymorphism.
*/
diff --git a/src/mongo/rpc/request_interface.h b/src/mongo/rpc/request_interface.h
index b5395012416..b2edfb8dba3 100644
--- a/src/mongo/rpc/request_interface.h
+++ b/src/mongo/rpc/request_interface.h
@@ -37,7 +37,6 @@ class Message;
class StringData;
namespace rpc {
-class DocumentRange;
/**
* An immutable view of an RPC message.
@@ -71,18 +70,6 @@ public:
virtual const BSONObj& getCommandArgs() const = 0;
/**
- * A variable number of BSON documents to pass to the command. It is valid for
- * the returned range to be empty.
- *
- * Example usage:
- *
- * for (auto&& doc : req.getInputDocs()) {
- * ... do stuff with doc
- * }
- */
- virtual DocumentRange getInputDocs() const = 0;
-
- /**
* Gets the RPC protocol used to deserialize this message. This should only be used for
* asserts, and not for runtime behavior changes, which should be handled with polymorphism.
*/