Skip to content

Commit

Permalink
SERVER-80293: Add summary fields to bulkWrite
Browse files Browse the repository at this point in the history
  • Loading branch information
seanzimm authored and Evergreen Agent committed Nov 9, 2023
1 parent d0de879 commit d160de1
Show file tree
Hide file tree
Showing 26 changed files with 382 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export const $config = (function() {
// Check if insert succeeded
var res = db.adminCommand(bulkWriteCmd);
assert.commandWorked(res);
assert.eq(res.numErrors, 0);
assert.eq(res.nErrors, 0);

jsTestLog('BulkWrite - Update tid:' + tid + ' currentTid:' + this.tid +
' collection:' + collNames);
Expand All @@ -311,7 +311,7 @@ export const $config = (function() {
nsInfo: [{ns: fullNs1}, {ns: fullNs2}]
};
res = db.adminCommand(bulkWriteCmd);
if (res.numErrors != 0) {
if (res.nErrors != 0) {
// Should only be possible for the first namespace to be renamed.
var err = res.cursor.firstBatch[0].code;
if (err == ErrorCodes.QueryPlanKilled) {
Expand All @@ -323,7 +323,7 @@ export const $config = (function() {
}
}
assert.commandWorked(res);
assert.eq(res.numErrors, 0);
assert.eq(res.nErrors, 0);

// Delete Data
jsTestLog('BulkWrite - Remove tid:' + tid + ' currentTid:' + this.tid +
Expand All @@ -339,7 +339,7 @@ export const $config = (function() {
};
res = db.adminCommand(bulkWriteCmd);
assert.commandWorked(res);
assert.eq(res.numErrors, 0);
assert.eq(res.nErrors, 0);
// Check guarantees IF NO CONCURRENT DROP is running.
assert.eq(countDocuments(coll, {generation: generation}), 0);
} finally {
Expand Down
8 changes: 4 additions & 4 deletions jstests/core/write/bulk/bulk_write.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var res = db.adminCommand({
});

assert.commandWorked(res);
assert.eq(res.numErrors, 0, "bulkWrite command response: " + tojson(res));
assert.eq(res.nErrors, 0, "bulkWrite command response: " + tojson(res));

assert.eq(coll.find().itcount(), 1);
assert.eq(coll1.find().itcount(), 0);
Expand All @@ -47,7 +47,7 @@ res = db.adminCommand({
});

assert.commandWorked(res);
assert.eq(res.numErrors, 0, "bulkWrite command response: " + tojson(res));
assert.eq(res.nErrors, 0, "bulkWrite command response: " + tojson(res));

assert.eq(coll.find().itcount(), 1);
assert.eq(coll1.find().itcount(), 1);
Expand All @@ -62,7 +62,7 @@ res = db.adminCommand({
});

assert.commandWorked(res);
assert.eq(res.numErrors, 0, "bulkWrite command response: " + tojson(res));
assert.eq(res.nErrors, 0, "bulkWrite command response: " + tojson(res));

assert.eq(coll.find().itcount(), 2);
assert.eq(coll1.find().itcount(), 0);
Expand All @@ -80,7 +80,7 @@ res = db.adminCommand({
});

assert.commandWorked(res);
assert.eq(res.numErrors, 0, "bulkWrite command response: " + tojson(res));
assert.eq(res.nErrors, 0, "bulkWrite command response: " + tojson(res));

assert.eq(1, coll.count({_id: 3}));

Expand Down
21 changes: 15 additions & 6 deletions jstests/core/write/bulk/bulk_write_delete_cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
* featureFlagBulkWriteCommand,
* ]
*/
import {cursorEntryValidator, cursorSizeValidator} from "jstests/libs/bulk_write_utils.js";
import {
cursorEntryValidator,
cursorSizeValidator,
summaryFieldsValidator
} from "jstests/libs/bulk_write_utils.js";

var coll = db.getCollection("coll");
var coll1 = db.getCollection("coll1");
Expand All @@ -27,7 +31,8 @@ var res = db.adminCommand({
});

assert.commandWorked(res);
assert.eq(res.numErrors, 0, "bulkWrite command response: " + tojson(res));
summaryFieldsValidator(
res, {nErrors: 0, nInserted: 1, nDeleted: 1, nMatched: 0, nModified: 0, nUpserted: 0});

cursorSizeValidator(res, 2);
cursorEntryValidator(res.cursor.firstBatch[0], {ok: 1, idx: 0, n: 1});
Expand All @@ -50,7 +55,8 @@ res = db.adminCommand({

assert.commandWorked(res);
cursorSizeValidator(res, 3);
assert.eq(res.numErrors, 0, "bulkWrite command response: " + tojson(res));
summaryFieldsValidator(
res, {nErrors: 0, nInserted: 2, nDeleted: 1, nMatched: 0, nModified: 0, nUpserted: 0});
cursorEntryValidator(res.cursor.firstBatch[0], {ok: 1, idx: 0, n: 1});
cursorEntryValidator(res.cursor.firstBatch[1], {ok: 1, idx: 1, n: 1});
cursorEntryValidator(res.cursor.firstBatch[2], {ok: 1, idx: 2, n: 1});
Expand All @@ -71,7 +77,8 @@ res = db.adminCommand({

assert.commandWorked(res);
cursorSizeValidator(res, 1);
assert.eq(res.numErrors, 0, "bulkWrite command response: " + tojson(res));
summaryFieldsValidator(
res, {nErrors: 0, nInserted: 0, nDeleted: 1, nMatched: 0, nModified: 0, nUpserted: 0});
cursorEntryValidator(res.cursor.firstBatch[0], {ok: 1, idx: 0, n: 1});
assert(!coll.findOne());

Expand All @@ -90,7 +97,8 @@ res = db.adminCommand({

assert.commandWorked(res);
cursorSizeValidator(res, 1);
assert.eq(res.numErrors, 0, "bulkWrite command response: " + tojson(res));
summaryFieldsValidator(
res, {nErrors: 0, nInserted: 0, nDeleted: 0, nMatched: 0, nModified: 0, nUpserted: 0});
cursorEntryValidator(res.cursor.firstBatch[0], {ok: 1, idx: 0, n: 0});
assert.eq("MongoDB", coll1.findOne().skey);

Expand All @@ -112,7 +120,8 @@ res = db.adminCommand({

assert.commandWorked(res);
cursorSizeValidator(res, 4);
assert.eq(res.numErrors, 0, "bulkWrite command response: " + tojson(res));
summaryFieldsValidator(
res, {nErrors: 0, nInserted: 3, nDeleted: 1, nMatched: 0, nModified: 0, nUpserted: 0});

cursorEntryValidator(res.cursor.firstBatch[0], {ok: 1, idx: 0, n: 1});
cursorEntryValidator(res.cursor.firstBatch[1], {ok: 1, idx: 1, n: 1});
Expand Down
9 changes: 7 additions & 2 deletions jstests/core/write/bulk/bulk_write_getMore.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
* featureFlagBulkWriteCommand,
* ]
*/
import {cursorEntryValidator, cursorSizeValidator} from "jstests/libs/bulk_write_utils.js";
import {
cursorEntryValidator,
cursorSizeValidator,
summaryFieldsValidator
} from "jstests/libs/bulk_write_utils.js";

var coll = db.getCollection("coll");
var coll1 = db.getCollection("coll1");
Expand All @@ -38,7 +42,8 @@ var res = db.adminCommand({

assert.commandWorked(res);
cursorSizeValidator(res, 1);
assert.eq(res.numErrors, 0, "bulkWrite command response: " + tojson(res));
summaryFieldsValidator(
res, {nErrors: 0, nInserted: 2, nDeleted: 0, nMatched: 0, nModified: 0, nUpserted: 0});

assert(res.cursor.id != 0,
"Unexpectedly found cursor ID 0 in bulkWrite command response: " + tojson(res));
Expand Down
12 changes: 9 additions & 3 deletions jstests/core/write/bulk/bulk_write_insert_cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
* featureFlagBulkWriteCommand,
* ]
*/
import {cursorEntryValidator, cursorSizeValidator} from "jstests/libs/bulk_write_utils.js";
import {
cursorEntryValidator,
cursorSizeValidator,
summaryFieldsValidator
} from "jstests/libs/bulk_write_utils.js";

var coll = db.getCollection("coll");
var coll1 = db.getCollection("coll1");
Expand All @@ -22,7 +26,8 @@ var res = db.adminCommand(

assert.commandWorked(res);
cursorSizeValidator(res, 1);
assert.eq(res.numErrors, 0, "bulkWrite command response: " + tojson(res));
summaryFieldsValidator(
res, {nErrors: 0, nInserted: 1, nDeleted: 0, nMatched: 0, nModified: 0, nUpserted: 0});

assert(res.cursor.id == 0,
"Unexpectedly found non-zero cursor ID in bulkWrite command response: " + tojson(res));
Expand All @@ -42,7 +47,8 @@ res = db.adminCommand({

assert.commandWorked(res);
cursorSizeValidator(res, 2);
assert.eq(res.numErrors, 0, "bulkWrite command response: " + tojson(res));
summaryFieldsValidator(
res, {nErrors: 0, nInserted: 2, nDeleted: 0, nMatched: 0, nModified: 0, nUpserted: 0});

assert(res.cursor.id == 0,
"Unexpectedly found non-zero cursor ID in bulkWrite command response: " + tojson(res));
Expand Down
10 changes: 5 additions & 5 deletions jstests/core/write/bulk/bulk_write_non_auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let res = db.adminCommand({

assert.commandWorked(res);
cursorSizeValidator(res, 1);
assert.eq(res.numErrors, 1, "bulkWrite command response: " + tojson(res));
assert.eq(res.nErrors, 1, "bulkWrite command response: " + tojson(res));

cursorEntryValidator(res.cursor.firstBatch[0],
{ok: 0, idx: 0, n: 0, nModified: 0, code: ErrorCodes.InvalidNamespace});
Expand All @@ -54,7 +54,7 @@ res = db.adminCommand({

assert.commandWorked(res);
cursorSizeValidator(res, 1);
assert.eq(res.numErrors, 1, "bulkWrite command response: " + tojson(res));
assert.eq(res.nErrors, 1, "bulkWrite command response: " + tojson(res));

cursorEntryValidator(res.cursor.firstBatch[0],
{ok: 0, idx: 0, n: 0, code: ErrorCodes.InvalidNamespace});
Expand All @@ -76,7 +76,7 @@ res = db.adminCommand({

assert.commandWorked(res);
cursorSizeValidator(res, 2);
assert.eq(res.numErrors, 1, "bulkWrite command response: " + tojson(res));
assert.eq(res.nErrors, 1, "bulkWrite command response: " + tojson(res));

cursorEntryValidator(res.cursor.firstBatch[0],
{ok: 0, idx: 0, n: 0, code: ErrorCodes.InvalidNamespace});
Expand All @@ -103,7 +103,7 @@ res = db.adminCommand({

assert.commandWorked(res);
cursorSizeValidator(res, 1);
assert.eq(res.numErrors, 1, "bulkWrite command response: " + tojson(res));
assert.eq(res.nErrors, 1, "bulkWrite command response: " + tojson(res));

cursorEntryValidator(res.cursor.firstBatch[0],
{ok: 0, idx: 0, n: 0, code: ErrorCodes.InvalidNamespace});
Expand Down Expand Up @@ -133,5 +133,5 @@ res = db.adminCommand({

assert.commandWorked(res);
cursorSizeValidator(res, 7);
assert.eq(res.numErrors, 3, "bulkWrite command response: " + tojson(res));
assert.eq(res.nErrors, 3, "bulkWrite command response: " + tojson(res));
coll.drop();
15 changes: 11 additions & 4 deletions jstests/core/write/bulk/bulk_write_non_retryable_cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
* featureFlagBulkWriteCommand,
* ]
*/
import {cursorEntryValidator, cursorSizeValidator} from "jstests/libs/bulk_write_utils.js";
import {
cursorEntryValidator,
cursorSizeValidator,
summaryFieldsValidator
} from "jstests/libs/bulk_write_utils.js";

var coll = db.getCollection("coll");
var coll1 = db.getCollection("coll1");
Expand All @@ -35,7 +39,8 @@ var res = db.adminCommand({

assert.commandWorked(res);
cursorSizeValidator(res, 3);
assert.eq(res.numErrors, 0, "bulkWrite command response: " + tojson(res));
summaryFieldsValidator(
res, {nErrors: 0, nInserted: 2, nDeleted: 0, nMatched: 2, nModified: 2, nUpserted: 0});

cursorEntryValidator(res.cursor.firstBatch[0], {ok: 1, idx: 0, n: 1});
cursorEntryValidator(res.cursor.firstBatch[1], {ok: 1, idx: 1, n: 1});
Expand All @@ -58,7 +63,8 @@ res = db.adminCommand({

assert.commandWorked(res);
cursorSizeValidator(res, 3);
assert.eq(res.numErrors, 0, "bulkWrite command response: " + tojson(res));
summaryFieldsValidator(
res, {nErrors: 0, nInserted: 2, nDeleted: 2, nMatched: 0, nModified: 0, nUpserted: 0});

cursorEntryValidator(res.cursor.firstBatch[0], {ok: 1, idx: 0, n: 1});
cursorEntryValidator(res.cursor.firstBatch[1], {ok: 1, idx: 1, n: 1});
Expand Down Expand Up @@ -97,7 +103,8 @@ res = db.adminCommand({

assert.commandWorked(res);
cursorSizeValidator(res, 5);
assert.eq(res.numErrors, 0, "bulkWrite command response: " + tojson(res));
summaryFieldsValidator(
res, {nErrors: 0, nInserted: 2, nDeleted: 1, nMatched: 2, nModified: 2, nUpserted: 0});

cursorEntryValidator(res.cursor.firstBatch[0], {ok: 1, idx: 0, n: 1});
cursorEntryValidator(res.cursor.firstBatch[1], {ok: 1, idx: 1, n: 1});
Expand Down
38 changes: 26 additions & 12 deletions jstests/core/write/bulk/bulk_write_non_transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
* featureFlagBulkWriteCommand,
* ]
*/
import {cursorEntryValidator, cursorSizeValidator} from "jstests/libs/bulk_write_utils.js";
import {
cursorEntryValidator,
cursorSizeValidator,
summaryFieldsValidator
} from "jstests/libs/bulk_write_utils.js";

var coll = db.getCollection("coll");
var coll1 = db.getCollection("coll1");
Expand Down Expand Up @@ -160,7 +164,8 @@ res = db.adminCommand({

assert.commandWorked(res);
cursorSizeValidator(res, 2);
assert.eq(res.numErrors, 1, "bulkWrite command response: " + tojson(res));
summaryFieldsValidator(
res, {nErrors: 1, nInserted: 0, nDeleted: 0, nMatched: 1, nModified: 0, nUpserted: 1});

cursorEntryValidator(res.cursor.firstBatch[0],
{ok: 0, idx: 0, n: 0, nModified: 0, code: ErrorCodes.ImmutableField});
Expand All @@ -184,7 +189,8 @@ res = db.adminCommand({

assert.commandWorked(res);
cursorSizeValidator(res, 1);
assert.eq(res.numErrors, 1, "bulkWrite command response: " + tojson(res));
summaryFieldsValidator(
res, {nErrors: 1, nInserted: 0, nDeleted: 0, nMatched: 0, nModified: 0, nUpserted: 0});

cursorEntryValidator(res.cursor.firstBatch[0],
{ok: 0, idx: 0, n: 0, nModified: 0, code: ErrorCodes.ImmutableField});
Expand Down Expand Up @@ -217,7 +223,8 @@ res = db.adminCommand({

assert.commandWorked(res);
cursorSizeValidator(res, 3);
assert.eq(res.numErrors, 1, "bulkWrite command response: " + tojson(res));
summaryFieldsValidator(
res, {nErrors: 1, nInserted: 2, nDeleted: 0, nMatched: 0, nModified: 0, nUpserted: 0});

assert.eq(res.cursor.id, 0);
cursorEntryValidator(res.cursor.firstBatch[0], {ok: 1, n: 1, idx: 0});
Expand Down Expand Up @@ -250,7 +257,8 @@ res = db.adminCommand({

assert.commandWorked(res);
cursorSizeValidator(res, 2);
assert.eq(res.numErrors, 1, "bulkWrite command response: " + tojson(res));
summaryFieldsValidator(
res, {nErrors: 1, nInserted: 1, nDeleted: 0, nMatched: 0, nModified: 0, nUpserted: 0});

assert.eq(res.cursor.id, 0);
cursorEntryValidator(res.cursor.firstBatch[0], {ok: 1, n: 1, idx: 0});
Expand Down Expand Up @@ -281,7 +289,8 @@ res = db.adminCommand({

assert.commandWorked(res);
cursorSizeValidator(res, 2);
assert.eq(res.numErrors, 1, "bulkWrite command response: " + tojson(res));
summaryFieldsValidator(
res, {nErrors: 1, nInserted: 1, nDeleted: 0, nMatched: 0, nModified: 0, nUpserted: 0});

assert.eq(res.cursor.id, 0);
cursorEntryValidator(res.cursor.firstBatch[0], {ok: 1, n: 1, idx: 0});
Expand Down Expand Up @@ -309,7 +318,8 @@ res = db.adminCommand({

assert.commandWorked(res);
cursorSizeValidator(res, 3);
assert.eq(res.numErrors, 1, "bulkWrite command response: " + tojson(res));
summaryFieldsValidator(
res, {nErrors: 1, nInserted: 2, nDeleted: 0, nMatched: 0, nModified: 0, nUpserted: 0});

assert.eq(res.cursor.id, 0);
cursorEntryValidator(res.cursor.firstBatch[0], {ok: 1, n: 1, idx: 0});
Expand All @@ -332,7 +342,7 @@ res = db.adminCommand({
bypassDocumentValidation: false,
});
assert.commandWorked(res);
assert.eq(res.numErrors, 1, "bulkWrite command response: " + tojson(res));
assert.eq(res.nErrors, 1, "bulkWrite command response: " + tojson(res));

assert.eq(0, coll.count({_id: 3}));
coll.drop();
Expand All @@ -350,7 +360,8 @@ res = db.adminCommand({

assert.commandWorked(res);
cursorSizeValidator(res, 3);
assert.eq(res.numErrors, 1, "bulkWrite command response: " + tojson(res));
summaryFieldsValidator(
res, {nErrors: 1, nInserted: 1, nDeleted: 0, nMatched: 1, nModified: 1, nUpserted: 0});

cursorEntryValidator(res.cursor.firstBatch[0], {ok: 1, idx: 0, n: 1});
cursorEntryValidator(res.cursor.firstBatch[1], {ok: 1, idx: 1, n: 1, nModified: 1});
Expand All @@ -375,7 +386,8 @@ res = db.adminCommand({

assert.commandWorked(res);
cursorSizeValidator(res, 1);
assert.eq(res.numErrors, 1, "bulkWrite command response: " + tojson(res));
summaryFieldsValidator(
res, {nErrors: 1, nInserted: 0, nDeleted: 0, nMatched: 0, nModified: 0, nUpserted: 0});

cursorEntryValidator(res.cursor.firstBatch[0], {ok: 0, idx: 0, n: 0, nModified: 0, code: 51198});
assert.eq(res.cursor.firstBatch[0].errmsg,
Expand All @@ -401,7 +413,8 @@ res = db.adminCommand({

assert.commandWorked(res);
cursorSizeValidator(res, 1);
assert.eq(res.numErrors, 1, "bulkWrite command response: " + tojson(res));
summaryFieldsValidator(
res, {nErrors: 1, nInserted: 0, nDeleted: 0, nMatched: 0, nModified: 0, nUpserted: 0});

cursorEntryValidator(res.cursor.firstBatch[0], {ok: 0, idx: 0, n: 0, nModified: 0, code: 9});
assert.eq(res.cursor.firstBatch[0].errmsg,
Expand All @@ -419,7 +432,8 @@ res = db.adminCommand({

assert.commandWorked(res, "bulkWrite command response: " + tojson(res));
cursorSizeValidator(res, 1);
assert.eq(res.numErrors, 1, "bulkWrite command response: " + tojson(res));
summaryFieldsValidator(
res, {nErrors: 1, nInserted: 1, nDeleted: 0, nMatched: 0, nModified: 0, nUpserted: 0});

assert(res.cursor.id == 0, "bulkWrite command response: " + tojson(res));
cursorEntryValidator(res.cursor.firstBatch[0], {ok: 0, n: 0, idx: 1, code: 11000});
Expand Down
Loading

0 comments on commit d160de1

Please sign in to comment.