Skip to content

Commit b0dc17e

Browse files
committed
CXX-175 check for double executed, convert wc error to soft
1 parent fb2fef8 commit b0dc17e

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

src/mongo/client/bulk_operation_builder.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace mongo {
3535
: _client(client)
3636
, _ns(ns)
3737
, _ordered(ordered)
38+
, _executed(false)
3839
{}
3940

4041
BulkOperationBuilder::~BulkOperationBuilder() {
@@ -53,9 +54,13 @@ namespace mongo {
5354
}
5455

5556
void BulkOperationBuilder::execute(const WriteConcern* wc, std::vector<BSONObj>* results) {
57+
uassert(0, "Bulk operations cannot be executed twice", !_executed);
58+
5659
if (!_ordered)
5760
std::sort(_write_operations.begin(), _write_operations.end(), compare);
61+
5862
_client->_write(_ns, _write_operations, _ordered, wc, results);
63+
_executed = true;
5964
}
6065

6166
void BulkOperationBuilder::enqueue(WriteOperation* operation) {

src/mongo/client/bulk_operation_builder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ namespace mongo {
103103
DBClientBase* const _client;
104104
const std::string _ns;
105105
const bool _ordered;
106+
bool _executed;
106107
std::vector<WriteOperation*> _write_operations;
107108

108109
void enqueue(WriteOperation* const operation);

src/mongo/client/command_writer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ namespace mongo {
110110
BSONObj result;
111111
bool commandWorked = _client->runCommand(nsToDatabase(ns), command->obj(), result);
112112

113-
// TODO: writeConcernError should be a soft error
114-
if (!commandWorked || result.hasField("writeErrors") || result.hasField("writeConcernError")) {
113+
if (!commandWorked || result.hasField("writeErrors")) {
115114
throw OperationException(result);
116115
}
117116

0 commit comments

Comments
 (0)