summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-07-18 16:30:39 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-07-24 11:00:05 -0400
commitffe425ee16d9c597732350dfe6de73b2fd9305d0 (patch)
tree5c285e67e654e63abd9971eef8a09a24b7059e3c /src/mongo
parent13915db6589720b7c8cabd9663f023b2db49c401 (diff)
downloadmongo-ffe425ee16d9c597732350dfe6de73b2fd9305d0.tar.gz
SERVER-28752 Get rid of all usages of Batched Insert/Update/Delete Request outside of BatchedCommandRequest
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/commands/user_management_commands.cpp64
-rw-r--r--src/mongo/db/ops/write_ops.h6
-rw-r--r--src/mongo/db/ops/write_ops_parsers.cpp11
-rw-r--r--src/mongo/db/repl/replication_info.cpp4
-rw-r--r--src/mongo/db/s/shard_metadata_util.cpp172
-rw-r--r--src/mongo/db/s/shard_metadata_util_test.cpp1
-rw-r--r--src/mongo/s/commands/cluster_is_master_cmd.cpp27
-rw-r--r--src/mongo/s/commands/cluster_write.cpp26
-rw-r--r--src/mongo/s/ns_targeter.h3
-rw-r--r--src/mongo/s/write_ops/batch_write_op.cpp2
-rw-r--r--src/mongo/s/write_ops/batch_write_op_test.cpp118
-rw-r--r--src/mongo/s/write_ops/batched_command_request.cpp2
-rw-r--r--src/mongo/s/write_ops/batched_command_request.h3
-rw-r--r--src/mongo/s/write_ops/write_op_test.cpp1
14 files changed, 125 insertions, 315 deletions
diff --git a/src/mongo/db/commands/user_management_commands.cpp b/src/mongo/db/commands/user_management_commands.cpp
index c358b3957d6..d1d188c1274 100644
--- a/src/mongo/db/commands/user_management_commands.cpp
+++ b/src/mongo/db/commands/user_management_commands.cpp
@@ -62,13 +62,11 @@
#include "mongo/db/dbdirectclient.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/operation_context.h"
+#include "mongo/db/ops/write_ops.h"
#include "mongo/db/service_context.h"
#include "mongo/platform/unordered_set.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/write_ops/batched_command_response.h"
-#include "mongo/s/write_ops/batched_delete_request.h"
-#include "mongo/s/write_ops/batched_insert_request.h"
-#include "mongo/s/write_ops/batched_update_request.h"
#include "mongo/stdx/functional.h"
#include "mongo/stdx/mutex.h"
#include "mongo/util/log.h"
@@ -79,8 +77,6 @@
namespace mongo {
-namespace str = mongoutils::str;
-
using std::endl;
using std::string;
using std::stringstream;
@@ -271,12 +267,14 @@ Status insertAuthzDocument(OperationContext* opCtx,
try {
DBDirectClient client(opCtx);
- BatchedInsertRequest req;
- req.setNS(collectionName);
- req.addToDocuments(document);
-
BSONObj res;
- client.runCommand(collectionName.db().toString(), req.toBSON(), res);
+ client.runCommand(collectionName.db().toString(),
+ [&] {
+ write_ops::Insert insertOp(collectionName);
+ insertOp.setDocuments({document});
+ return insertOp.toBSON({});
+ }(),
+ res);
BatchedCommandResponse response;
std::string errmsg;
@@ -305,18 +303,21 @@ Status updateAuthzDocuments(OperationContext* opCtx,
try {
DBDirectClient client(opCtx);
- auto doc = stdx::make_unique<BatchedUpdateDocument>();
- doc->setQuery(query);
- doc->setUpdateExpr(updatePattern);
- doc->setMulti(multi);
- doc->setUpsert(upsert);
-
- BatchedUpdateRequest req;
- req.setNS(collectionName);
- req.addToUpdates(doc.release());
-
BSONObj res;
- client.runCommand(collectionName.db().toString(), req.toBSON(), res);
+ client.runCommand(collectionName.db().toString(),
+ [&] {
+ write_ops::Update updateOp(collectionName);
+ updateOp.setUpdates({[&] {
+ write_ops::UpdateOpEntry entry;
+ entry.setQ(query);
+ entry.setU(updatePattern);
+ entry.setMulti(multi);
+ entry.setUpsert(upsert);
+ return entry;
+ }()});
+ return updateOp.toBSON({});
+ }(),
+ res);
BatchedCommandResponse response;
std::string errmsg;
@@ -375,16 +376,19 @@ Status removeAuthzDocuments(OperationContext* opCtx,
try {
DBDirectClient client(opCtx);
- auto doc = stdx::make_unique<BatchedDeleteDocument>();
- doc->setQuery(query);
- doc->setLimit(0);
-
- BatchedDeleteRequest req;
- req.setNS(collectionName);
- req.addToDeletes(doc.release());
-
BSONObj res;
- client.runCommand(collectionName.db().toString(), req.toBSON(), res);
+ client.runCommand(collectionName.db().toString(),
+ [&] {
+ write_ops::Delete deleteOp(collectionName);
+ deleteOp.setDeletes({[&] {
+ write_ops::DeleteOpEntry entry;
+ entry.setQ(query);
+ entry.setMulti(true);
+ return entry;
+ }()});
+ return deleteOp.toBSON({});
+ }(),
+ res);
BatchedCommandResponse response;
std::string errmsg;
diff --git a/src/mongo/db/ops/write_ops.h b/src/mongo/db/ops/write_ops.h
index e52b9c64eb9..5463bb9a0e2 100644
--- a/src/mongo/db/ops/write_ops.h
+++ b/src/mongo/db/ops/write_ops.h
@@ -54,6 +54,12 @@ public:
namespace write_ops {
+// Limit of the number of operations that can be included in a single write command. This is an
+// attempt to avoid a large number of errors resulting in a reply that exceeds 16MB. It doesn't
+// fully ensure that goal, but it reduces the probability of it happening. This limit should not be
+// used if the protocol changes to avoid the 16MB limit on reply size.
+const size_t kMaxWriteBatchSize{1000};
+
/**
* Retrieves the statement id for the write at the specified position in the write batch entries
* array.
diff --git a/src/mongo/db/ops/write_ops_parsers.cpp b/src/mongo/db/ops/write_ops_parsers.cpp
index 76ef8f85551..b4e4b9157a7 100644
--- a/src/mongo/db/ops/write_ops_parsers.cpp
+++ b/src/mongo/db/ops/write_ops_parsers.cpp
@@ -46,20 +46,15 @@ using write_ops::DeleteOpEntry;
namespace {
-// The specified limit to the number of operations that can be included in a single write command.
-// This is an attempt to avoid a large number of errors resulting in a reply that exceeds 16MB. It
-// doesn't fully ensure that goal, but it reduces the probability of it happening. This limit should
-// not be used if the protocol changes to avoid the 16MB limit on reply size.
-const size_t kMaxWriteBatchSize = 1000;
-
template <class T>
void checkOpCountForCommand(const T& op, size_t numOps) {
uassert(ErrorCodes::InvalidLength,
- str::stream() << "Write batch sizes must be between 1 and " << kMaxWriteBatchSize
+ str::stream() << "Write batch sizes must be between 1 and "
+ << write_ops::kMaxWriteBatchSize
<< ". Got "
<< numOps
<< " operations.",
- numOps != 0 && numOps <= kMaxWriteBatchSize);
+ numOps != 0 && numOps <= write_ops::kMaxWriteBatchSize);
const auto& stmtIds = op.getWriteCommandBase().getStmtIds();
uassert(ErrorCodes::InvalidLength,
diff --git a/src/mongo/db/repl/replication_info.cpp b/src/mongo/db/repl/replication_info.cpp
index 3af818ebd15..af7db98cf92 100644
--- a/src/mongo/db/repl/replication_info.cpp
+++ b/src/mongo/db/repl/replication_info.cpp
@@ -41,6 +41,7 @@
#include "mongo/db/jsobj.h"
#include "mongo/db/lasterror.h"
#include "mongo/db/namespace_string.h"
+#include "mongo/db/ops/write_ops.h"
#include "mongo/db/query/internal_plans.h"
#include "mongo/db/repl/is_master_response.h"
#include "mongo/db/repl/master_slave.h"
@@ -56,7 +57,6 @@
#include "mongo/executor/network_interface.h"
#include "mongo/rpc/metadata/client_metadata.h"
#include "mongo/rpc/metadata/client_metadata_ismaster.h"
-#include "mongo/s/write_ops/batched_command_request.h"
#include "mongo/util/map_util.h"
namespace mongo {
@@ -353,7 +353,7 @@ public:
result.appendNumber("maxBsonObjectSize", BSONObjMaxUserSize);
result.appendNumber("maxMessageSizeBytes", MaxMessageSizeBytes);
- result.appendNumber("maxWriteBatchSize", BatchedCommandRequest::kMaxWriteBatchSize);
+ result.appendNumber("maxWriteBatchSize", write_ops::kMaxWriteBatchSize);
result.appendDate("localTime", jsTime());
result.append("maxWireVersion", WireSpec::instance().incoming.maxWireVersion);
diff --git a/src/mongo/db/s/shard_metadata_util.cpp b/src/mongo/db/s/shard_metadata_util.cpp
index 1d73bbed89f..7b3afbb9ea1 100644
--- a/src/mongo/db/s/shard_metadata_util.cpp
+++ b/src/mongo/db/s/shard_metadata_util.cpp
@@ -32,13 +32,13 @@
#include "mongo/client/dbclientinterface.h"
#include "mongo/db/dbdirectclient.h"
+#include "mongo/db/ops/write_ops.h"
#include "mongo/db/write_concern_options.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/rpc/unique_message.h"
#include "mongo/s/catalog/type_chunk.h"
#include "mongo/s/catalog/type_shard_collection.h"
#include "mongo/s/chunk_version.h"
-#include "mongo/s/write_ops/batched_command_request.h"
#include "mongo/s/write_ops/batched_command_response.h"
#include "mongo/stdx/memory.h"
@@ -185,41 +185,26 @@ Status updateShardCollectionsEntry(OperationContext* opCtx,
invariant(!update.hasField(ShardCollectionType::lastRefreshedCollectionVersion()));
}
- // Want to modify the document, not replace it.
- BSONObjBuilder updateBuilder;
- updateBuilder.append("$set", update);
- std::unique_ptr<BatchedUpdateDocument> updateDoc(new BatchedUpdateDocument());
- updateDoc->setQuery(query);
- updateDoc->setUpdateExpr(updateBuilder.obj());
- updateDoc->setUpsert(upsert);
-
- std::unique_ptr<BatchedUpdateRequest> updateRequest(new BatchedUpdateRequest());
- updateRequest->addToUpdates(updateDoc.release());
-
- BatchedCommandRequest request(updateRequest.release());
- request.setNS(NamespaceString(ShardCollectionType::ConfigNS));
- request.setWriteConcern(kLocalWriteConcern.toBSON());
- BSONObj cmdObj = request.toBSON();
-
try {
DBDirectClient client(opCtx);
- rpc::UniqueReply commandResponse =
- client.runCommand(OpMsgRequest::fromDBAndBody("config", cmdObj));
- BSONObj responseReply = commandResponse->getCommandReply().getOwned();
-
- Status commandStatus =
- getStatusFromWriteCommandResponse(commandResponse->getCommandReply());
- if (!commandStatus.isOK()) {
- return commandStatus;
- }
+ auto commandResponse = client.runCommand([&] {
+ write_ops::Update updateOp(NamespaceString{ShardCollectionType::ConfigNS});
+ updateOp.setUpdates({[&] {
+ write_ops::UpdateOpEntry entry;
+ entry.setQ(query);
+ // Want to modify the document, not replace it
+ entry.setU(BSON("$set" << update));
+ entry.setUpsert(upsert);
+ return entry;
+ }()});
+ return updateOp.serialize({});
+ }());
+ uassertStatusOK(getStatusFromWriteCommandResponse(commandResponse->getCommandReply()));
return Status::OK();
} catch (const DBException& ex) {
- return {ex.toStatus().code(),
- str::stream() << "Failed to apply the update '" << request.toString()
- << "' to config.collections"
- << causedBy(ex.toStatus())};
+ return ex.toStatus();
}
}
@@ -229,22 +214,20 @@ StatusWith<std::vector<ChunkType>> readShardChunks(OperationContext* opCtx,
const BSONObj& sort,
boost::optional<long long> limit,
const OID& epoch) {
- // Query to retrieve the chunks.
- Query fullQuery(query);
- fullQuery.sort(sort);
-
try {
+ Query fullQuery(query);
+ fullQuery.sort(sort);
+
DBDirectClient client(opCtx);
- std::string chunkMetadataNs = ChunkType::ShardNSPrefix + nss.ns();
+ const std::string chunkMetadataNs = ChunkType::ShardNSPrefix + nss.ns();
+
std::unique_ptr<DBClientCursor> cursor =
client.query(chunkMetadataNs, fullQuery, limit.get_value_or(0));
-
- if (!cursor) {
- return {ErrorCodes::OperationFailed,
- str::stream() << "Failed to establish a cursor for reading " << chunkMetadataNs
- << " from local storage"};
- }
+ uassert(ErrorCodes::OperationFailed,
+ str::stream() << "Failed to establish a cursor for reading " << chunkMetadataNs
+ << " from local storage",
+ cursor);
std::vector<ChunkType> chunks;
while (cursor->more()) {
@@ -256,6 +239,7 @@ StatusWith<std::vector<ChunkType>> readShardChunks(OperationContext* opCtx,
<< "' due to "
<< statusWithChunk.getStatus().reason()};
}
+
chunks.push_back(std::move(statusWithChunk.getValue()));
}
@@ -319,43 +303,28 @@ Status updateShardChunks(OperationContext* opCtx,
// ("_id") between (chunk.min, chunk.max].
//
// query: { "_id" : {"$gte": chunk.min, "$lt": chunk.max}}
- auto deleteDocs(stdx::make_unique<BatchedDeleteDocument>());
- deleteDocs->setQuery(BSON(ChunkType::minShardID << BSON(
- "$gte" << chunk.getMin() << "$lt" << chunk.getMax())));
- deleteDocs->setLimit(0);
-
- auto deleteRequest(stdx::make_unique<BatchedDeleteRequest>());
- deleteRequest->addToDeletes(deleteDocs.release());
-
- BatchedCommandRequest batchedDeleteRequest(deleteRequest.release());
- batchedDeleteRequest.setNS(chunkMetadataNss);
- const BSONObj deleteCmdObj = batchedDeleteRequest.toBSON();
-
- rpc::UniqueReply deleteCommandResponse =
- client.runCommand(OpMsgRequest::fromDBAndBody(chunkMetadataNss.db(), deleteCmdObj));
-
- auto deleteStatus =
- getStatusFromWriteCommandResponse(deleteCommandResponse->getCommandReply());
- if (!deleteStatus.isOK()) {
- return deleteStatus;
- }
-
- // Now the document can be expected to cleanly insert without overlap.
- auto insert(stdx::make_unique<BatchedInsertRequest>());
- insert->addToDocuments(chunk.toShardBSON());
-
- BatchedCommandRequest insertRequest(insert.release());
- insertRequest.setNS(chunkMetadataNss);
- const BSONObj insertCmdObj = insertRequest.toBSON();
-
- rpc::UniqueReply insertCommandResponse =
- client.runCommand(OpMsgRequest::fromDBAndBody(chunkMetadataNss.db(), insertCmdObj));
-
- auto insertStatus =
- getStatusFromWriteCommandResponse(insertCommandResponse->getCommandReply());
- if (!insertStatus.isOK()) {
- return insertStatus;
- }
+ auto deleteCommandResponse = client.runCommand([&] {
+ write_ops::Delete deleteOp(chunkMetadataNss);
+ deleteOp.setDeletes({[&] {
+ write_ops::DeleteOpEntry entry;
+ entry.setQ(BSON(ChunkType::minShardID
+ << BSON("$gte" << chunk.getMin() << "$lt" << chunk.getMax())));
+ entry.setMulti(true);
+ return entry;
+ }()});
+ return deleteOp.serialize({});
+ }());
+ uassertStatusOK(
+ getStatusFromWriteCommandResponse(deleteCommandResponse->getCommandReply()));
+
+ // Now the document can be expected to cleanly insert without overlap
+ auto insertCommandResponse = client.runCommand([&] {
+ write_ops::Insert insertOp(chunkMetadataNss);
+ insertOp.setDocuments({chunk.toShardBSON()});
+ return insertOp.serialize({});
+ }());
+ uassertStatusOK(
+ getStatusFromWriteCommandResponse(insertCommandResponse->getCommandReply()));
}
return Status::OK();
@@ -365,39 +334,30 @@ Status updateShardChunks(OperationContext* opCtx,
}
Status dropChunksAndDeleteCollectionsEntry(OperationContext* opCtx, const NamespaceString& nss) {
- NamespaceString chunkMetadataNss(ChunkType::ShardNSPrefix + nss.ns());
-
try {
DBDirectClient client(opCtx);
- // Delete the collections collection entry matching 'nss'.
- auto deleteDocs(stdx::make_unique<BatchedDeleteDocument>());
- deleteDocs->setQuery(BSON(ShardCollectionType::uuid << nss.ns()));
- deleteDocs->setLimit(0);
-
- auto deleteRequest(stdx::make_unique<BatchedDeleteRequest>());
- deleteRequest->addToDeletes(deleteDocs.release());
-
- BatchedCommandRequest batchedDeleteRequest(deleteRequest.release());
- batchedDeleteRequest.setNS(NamespaceString(ShardCollectionType::ConfigNS));
- const BSONObj deleteCmdObj = batchedDeleteRequest.toBSON();
-
- rpc::UniqueReply deleteCommandResponse =
- client.runCommand(OpMsgRequest::fromDBAndBody("config", deleteCmdObj));
-
- auto deleteStatus =
- getStatusFromWriteCommandResponse(deleteCommandResponse->getCommandReply());
- if (!deleteStatus.isOK()) {
- return deleteStatus;
- }
-
- // Drop the config.chunks.ns collection specified by 'chunkMetadataNss'.
+ auto deleteCommandResponse = client.runCommand([&] {
+ write_ops::Delete deleteOp(
+ NamespaceString{NamespaceString::kShardConfigCollectionsCollectionName});
+ deleteOp.setDeletes({[&] {
+ write_ops::DeleteOpEntry entry;
+ entry.setQ(BSON(ShardCollectionType::uuid << nss.ns()));
+ entry.setMulti(true);
+ return entry;
+ }()});
+ return deleteOp.serialize({});
+ }());
+ uassertStatusOK(
+ getStatusFromWriteCommandResponse(deleteCommandResponse->getCommandReply()));
+
+ // Drop the corresponding config.chunks.ns collection
BSONObj result;
- bool isOK = client.dropCollection(chunkMetadataNss.ns(), kLocalWriteConcern, &result);
- if (!isOK) {
+ if (!client.dropCollection(
+ ChunkType::ShardNSPrefix + nss.ns(), kLocalWriteConcern, &result)) {
Status status = getStatusFromCommandResult(result);
- if (!status.isOK() && status.code() != ErrorCodes::NamespaceNotFound) {
- return status;
+ if (status != ErrorCodes::NamespaceNotFound) {
+ uassertStatusOK(status);
}
}
diff --git a/src/mongo/db/s/shard_metadata_util_test.cpp b/src/mongo/db/s/shard_metadata_util_test.cpp
index 4523ce960bf..d242684034d 100644
--- a/src/mongo/db/s/shard_metadata_util_test.cpp
+++ b/src/mongo/db/s/shard_metadata_util_test.cpp
@@ -39,7 +39,6 @@
#include "mongo/s/catalog/type_chunk.h"
#include "mongo/s/catalog/type_shard_collection.h"
#include "mongo/s/shard_server_test_fixture.h"
-#include "mongo/s/write_ops/batched_command_request.h"
#include "mongo/unittest/unittest.h"
namespace mongo {
diff --git a/src/mongo/s/commands/cluster_is_master_cmd.cpp b/src/mongo/s/commands/cluster_is_master_cmd.cpp
index 0209981de08..979ab6f531c 100644
--- a/src/mongo/s/commands/cluster_is_master_cmd.cpp
+++ b/src/mongo/s/commands/cluster_is_master_cmd.cpp
@@ -31,13 +31,12 @@
#include "mongo/db/client.h"
#include "mongo/db/commands.h"
#include "mongo/db/operation_context.h"
+#include "mongo/db/ops/write_ops.h"
#include "mongo/db/server_options.h"
#include "mongo/db/server_parameters.h"
#include "mongo/db/wire_version.h"
#include "mongo/rpc/metadata/client_metadata.h"
#include "mongo/rpc/metadata/client_metadata_ismaster.h"
-#include "mongo/s/grid.h"
-#include "mongo/s/write_ops/batched_command_request.h"
#include "mongo/transport/message_compressor_manager.h"
#include "mongo/util/map_util.h"
@@ -48,30 +47,28 @@ class CmdIsMaster : public BasicCommand {
public:
CmdIsMaster() : BasicCommand("isMaster", "ismaster") {}
-
- virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
+ bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
}
- virtual bool slaveOk() const {
+ bool slaveOk() const override {
return true;
}
- virtual void help(std::stringstream& help) const {
+ void help(std::stringstream& help) const override {
help << "test if this is master half of a replica pair";
}
- virtual void addRequiredPrivileges(const std::string& dbname,
- const BSONObj& cmdObj,
- std::vector<Privilege>* out) {
+ void addRequiredPrivileges(const std::string& dbname,
+ const BSONObj& cmdObj,
+ std::vector<Privilege>* out) override {
// No auth required
}
- virtual bool run(OperationContext* opCtx,
- const std::string& dbname,
- const BSONObj& cmdObj,
- BSONObjBuilder& result) {
-
+ bool run(OperationContext* opCtx,
+ const std::string& dbname,
+ const BSONObj& cmdObj,
+ BSONObjBuilder& result) override {
auto& clientMetadataIsMasterState = ClientMetadataIsMasterState::get(opCtx->getClient());
bool seenIsMaster = clientMetadataIsMasterState.hasSeenIsMaster();
if (!seenIsMaster) {
@@ -105,7 +102,7 @@ public:
result.append("msg", "isdbgrid");
result.appendNumber("maxBsonObjectSize", BSONObjMaxUserSize);
result.appendNumber("maxMessageSizeBytes", MaxMessageSizeBytes);
- result.appendNumber("maxWriteBatchSize", BatchedCommandRequest::kMaxWriteBatchSize);
+ result.appendNumber("maxWriteBatchSize", write_ops::kMaxWriteBatchSize);
result.appendDate("localTime", jsTime());
// Mongos tries to keep exactly the same version range of the server for which
diff --git a/src/mongo/s/commands/cluster_write.cpp b/src/mongo/s/commands/cluster_write.cpp
index 98ededc1323..174d9773a0b 100644
--- a/src/mongo/s/commands/cluster_write.cpp
+++ b/src/mongo/s/commands/cluster_write.cpp
@@ -209,32 +209,6 @@ void ClusterWriter::write(OperationContext* opCtx,
const BatchedCommandRequest* request = idRequest ? idRequest.get() : &origRequest;
const NamespaceString& nss = request->getNS();
- if (!nss.isValid()) {
- toBatchError(Status(ErrorCodes::InvalidNamespace, nss.ns() + " is not a valid namespace"),
- response);
- return;
- }
-
- if (!NamespaceString::validCollectionName(nss.coll())) {
- toBatchError(
- Status(ErrorCodes::BadValue, str::stream() << "invalid collection name " << nss.coll()),
- response);
- return;
- }
-
- if (request->sizeWriteOps() == 0u) {
- toBatchError(Status(ErrorCodes::InvalidLength, "no write ops were included in the batch"),
- response);
- return;
- }
-
- if (request->sizeWriteOps() > BatchedCommandRequest::kMaxWriteBatchSize) {
- toBatchError(Status(ErrorCodes::InvalidLength,
- str::stream() << "exceeded maximum write batch size of "
- << BatchedCommandRequest::kMaxWriteBatchSize),
- response);
- return;
- }
std::string errMsg;
if (request->isInsertIndexRequest() && !request->isValidIndexRequest(&errMsg)) {
diff --git a/src/mongo/s/ns_targeter.h b/src/mongo/s/ns_targeter.h
index 194514a44f3..3f160d1e810 100644
--- a/src/mongo/s/ns_targeter.h
+++ b/src/mongo/s/ns_targeter.h
@@ -38,8 +38,7 @@
#include "mongo/db/namespace_string.h"
#include "mongo/s/chunk_version.h"
#include "mongo/s/shard_id.h"
-#include "mongo/s/write_ops/batched_delete_document.h"
-#include "mongo/s/write_ops/batched_update_document.h"
+#include "mongo/s/write_ops/batched_command_request.h"
namespace mongo {
diff --git a/src/mongo/s/write_ops/batch_write_op.cpp b/src/mongo/s/write_ops/batch_write_op.cpp
index c888c4e32cc..91840004242 100644
--- a/src/mongo/s/write_ops/batch_write_op.cpp
+++ b/src/mongo/s/write_ops/batch_write_op.cpp
@@ -127,7 +127,7 @@ bool wouldMakeBatchesTooBig(const std::vector<TargetedWrite*>& writes,
const BatchSize& batchSize = seenIt->second;
- if (batchSize.numOps >= static_cast<int>(BatchedCommandRequest::kMaxWriteBatchSize)) {
+ if (batchSize.numOps >= static_cast<int>(write_ops::kMaxWriteBatchSize)) {
// Too many items in batch
return true;
}
diff --git a/src/mongo/s/write_ops/batch_write_op_test.cpp b/src/mongo/s/write_ops/batch_write_op_test.cpp
index aa5c4cfede3..2460990457e 100644
--- a/src/mongo/s/write_ops/batch_write_op_test.cpp
+++ b/src/mongo/s/write_ops/batch_write_op_test.cpp
@@ -32,7 +32,6 @@
#include "mongo/db/operation_context_noop.h"
#include "mongo/s/write_ops/batch_write_op.h"
#include "mongo/s/write_ops/batched_command_request.h"
-#include "mongo/s/write_ops/batched_delete_document.h"
#include "mongo/s/write_ops/mock_ns_targeter.h"
#include "mongo/s/write_ops/write_error_detail.h"
#include "mongo/unittest/unittest.h"
@@ -1629,122 +1628,5 @@ TEST(WriteOpLimitTests, OneBigOneSmall) {
ASSERT(batchOp.isFinished());
}
-TEST(WriteOpLimitTests, TooManyOps) {
- //
- // Batch of 1002 documents
- //
-
- OperationContextNoop opCtx;
- NamespaceString nss("foo.bar");
- ShardEndpoint endpoint(ShardId("shard"), ChunkVersion::IGNORED());
- MockNSTargeter targeter;
- initTargeterFullRange(nss, endpoint, &targeter);
-
- BatchedCommandRequest request(BatchedCommandRequest::BatchType_Delete);
- request.setNS(nss);
-
- // Add 2 more than the maximum to the batch
- for (size_t i = 0; i < BatchedCommandRequest::kMaxWriteBatchSize + 2u; ++i) {
- request.getDeleteRequest()->addToDeletes(buildDelete(BSON("x" << 2), 0));
- }
-
- BatchWriteOp batchOp(&opCtx, request);
-
- OwnedPointerMap<ShardId, TargetedWriteBatch> targetedOwned;
- std::map<ShardId, TargetedWriteBatch*>& targeted = targetedOwned.mutableMap();
- ASSERT_OK(batchOp.targetBatch(targeter, false, &targeted));
- ASSERT_EQUALS(targeted.size(), 1u);
- ASSERT_EQUALS(targeted.begin()->second->getWrites().size(), 1000u);
-
- BatchedCommandResponse response;
- buildResponse(1, &response);
-
- batchOp.noteBatchResponse(*targeted.begin()->second, response, NULL);
- ASSERT(!batchOp.isFinished());
-
- targetedOwned.clear();
-
- ASSERT_OK(batchOp.targetBatch(targeter, false, &targeted));
- ASSERT_EQUALS(targeted.size(), 1u);
- ASSERT_EQUALS(targeted.begin()->second->getWrites().size(), 2u);
-
- batchOp.noteBatchResponse(*targeted.begin()->second, response, NULL);
- ASSERT(batchOp.isFinished());
-}
-
-TEST(WriteOpLimitTests, UpdateOverheadIncluded) {
- //
- // Tests that the overhead of the extra fields in an update x 1000 is included in our size
- // calculation
- //
-
- OperationContextNoop opCtx;
- NamespaceString nss("foo.bar");
- ShardEndpoint endpoint(ShardId("shard"), ChunkVersion::IGNORED());
- MockNSTargeter targeter;
- initTargeterFullRange(nss, endpoint, &targeter);
-
- int updateDataBytes =
- BSONObjMaxUserSize / static_cast<int>(BatchedCommandRequest::kMaxWriteBatchSize);
-
- std::string dataString(updateDataBytes -
- BSON("x" << 1 << "data"
- << "")
- .objsize(),
- 'x');
-
- BatchedCommandRequest request(BatchedCommandRequest::BatchType_Update);
- request.setNS(nss);
-
- // Add the maximum number of updates
- int estSizeBytes = 0;
- for (size_t i = 0; i < BatchedCommandRequest::kMaxWriteBatchSize; ++i) {
- BatchedUpdateDocument* updateDoc = new BatchedUpdateDocument;
- updateDoc->setQuery(BSON("x" << 1 << "data" << dataString));
- updateDoc->setUpdateExpr(BSONObj());
- updateDoc->setMulti(false);
- updateDoc->setUpsert(false);
- request.getUpdateRequest()->addToUpdates(updateDoc);
- estSizeBytes += updateDoc->toBSON().objsize();
- }
-
- ASSERT_GREATER_THAN(estSizeBytes, BSONObjMaxInternalSize);
-
- BatchWriteOp batchOp(&opCtx, request);
-
- OwnedPointerMap<ShardId, TargetedWriteBatch> targetedOwned;
- std::map<ShardId, TargetedWriteBatch*>& targeted = targetedOwned.mutableMap();
- ASSERT_OK(batchOp.targetBatch(targeter, false, &targeted));
- ASSERT_EQUALS(targeted.size(), 1u);
- ASSERT_LESS_THAN(targeted.begin()->second->getWrites().size(), 1000u);
-
- {
- BatchedCommandRequest childRequest(BatchedCommandRequest::BatchType_Update);
- batchOp.buildBatchRequest(*targeted.begin()->second, &childRequest);
- ASSERT_LESS_THAN(childRequest.toBSON().objsize(), BSONObjMaxInternalSize);
- }
-
- BatchedCommandResponse response;
- buildResponse(1, &response);
-
- batchOp.noteBatchResponse(*targeted.begin()->second, response, NULL);
- ASSERT(!batchOp.isFinished());
-
- targetedOwned.clear();
-
- ASSERT_OK(batchOp.targetBatch(targeter, false, &targeted));
- ASSERT_EQUALS(targeted.size(), 1u);
- ASSERT_LESS_THAN(targeted.begin()->second->getWrites().size(), 1000u);
-
- {
- BatchedCommandRequest childRequest(BatchedCommandRequest::BatchType_Update);
- batchOp.buildBatchRequest(*targeted.begin()->second, &childRequest);
- ASSERT_LESS_THAN(childRequest.toBSON().objsize(), BSONObjMaxInternalSize);
- }
-
- batchOp.noteBatchResponse(*targeted.begin()->second, response, NULL);
- ASSERT(batchOp.isFinished());
-}
-
} // namespace
} // namespace mongo
diff --git a/src/mongo/s/write_ops/batched_command_request.cpp b/src/mongo/s/write_ops/batched_command_request.cpp
index 1fe28b91889..d4a86b20c1d 100644
--- a/src/mongo/s/write_ops/batched_command_request.cpp
+++ b/src/mongo/s/write_ops/batched_command_request.cpp
@@ -37,8 +37,6 @@
namespace mongo {
-const size_t BatchedCommandRequest::kMaxWriteBatchSize = 1000;
-
const BSONField<BSONObj> writeConcern("writeConcern");
BatchedCommandRequest::BatchedCommandRequest(BatchType batchType) : _batchType(batchType) {
diff --git a/src/mongo/s/write_ops/batched_command_request.h b/src/mongo/s/write_ops/batched_command_request.h
index f791fa7e0a7..6916d051a0e 100644
--- a/src/mongo/s/write_ops/batched_command_request.h
+++ b/src/mongo/s/write_ops/batched_command_request.h
@@ -50,9 +50,6 @@ class NamespaceString;
*/
class BatchedCommandRequest {
public:
- // Maximum number of write ops supported per batch
- static const size_t kMaxWriteBatchSize;
-
enum BatchType { BatchType_Insert, BatchType_Update, BatchType_Delete, BatchType_Unknown };
BatchedCommandRequest(BatchType batchType);
diff --git a/src/mongo/s/write_ops/write_op_test.cpp b/src/mongo/s/write_ops/write_op_test.cpp
index b780a79a344..6df88541da0 100644
--- a/src/mongo/s/write_ops/write_op_test.cpp
+++ b/src/mongo/s/write_ops/write_op_test.cpp
@@ -32,7 +32,6 @@
#include "mongo/base/owned_pointer_vector.h"
#include "mongo/db/operation_context_noop.h"
#include "mongo/s/write_ops/batched_command_request.h"
-#include "mongo/s/write_ops/batched_delete_document.h"
#include "mongo/s/write_ops/mock_ns_targeter.h"
#include "mongo/s/write_ops/write_error_detail.h"
#include "mongo/s/write_ops/write_op.h"