diff options
author | Gregory Noma <gregory.noma@gmail.com> | 2021-02-09 10:28:32 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-02-09 16:23:40 +0000 |
commit | f1b8a15fe45c24df25e5f6b1ead5022bc56f9e3b (patch) | |
tree | bc66908909750a671b373250957669fcb5bd78ca | |
parent | 2a1c62250ab5c9f089a2e4699d454ed326057b82 (diff) | |
download | mongo-f1b8a15fe45c24df25e5f6b1ead5022bc56f9e3b.tar.gz |
SERVER-54268 Append nInserted for {ordered: true} time-series inserts
3 files changed, 37 insertions, 16 deletions
diff --git a/jstests/noPassthrough/timeseries_insert_ordered_false.js b/jstests/noPassthrough/timeseries_insert_ordered_false.js index 5db2fbc7b3f..e38147f9467 100644 --- a/jstests/noPassthrough/timeseries_insert_ordered_false.js +++ b/jstests/noPassthrough/timeseries_insert_ordered_false.js @@ -23,19 +23,29 @@ const bucketsColl = testDB.getCollection('system.buckets.' + coll.getName()); const timeFieldName = 'time'; const metaFieldName = 'meta'; -coll.drop(); -assert.commandWorked(testDB.createCollection( - coll.getName(), {timeseries: {timeField: timeFieldName, metaField: metaFieldName}})); -assert.contains(bucketsColl.getName(), testDB.getCollectionNames()); +const resetColl = function() { + coll.drop(); + assert.commandWorked(testDB.createCollection( + coll.getName(), {timeseries: {timeField: timeFieldName, metaField: metaFieldName}})); + assert.contains(bucketsColl.getName(), testDB.getCollectionNames()); +}; +resetColl(); -const fp = configureFailPoint(conn, 'failTimeseriesInsert', {metadata: 'fail'}); +configureFailPoint(conn, 'failTimeseriesInsert', {metadata: 'fail'}); const docs = [ {_id: 0, [timeFieldName]: ISODate()}, - {_id: 1, [timeFieldName]: ISODate(), [metaFieldName]: 'fail'}, - {_id: 2, [timeFieldName]: ISODate()} + {_id: 1, [timeFieldName]: ISODate()}, + {_id: 2, [timeFieldName]: ISODate()}, ]; -const res = assert.commandFailed(coll.insert(docs, {ordered: false})); + +let res = assert.commandWorked(coll.insert(docs, {ordered: false})); +assert.eq(res.nInserted, 3, 'Invalid insert result: ' + tojson(res)); +assert.docEq(coll.find().sort({_id: 1}).toArray(), docs); +resetColl(); + +docs[1][metaFieldName] = 'fail'; +res = assert.commandFailed(coll.insert(docs, {ordered: false})); jsTestLog('Checking insert result: ' + tojson(res)); assert.eq(res.nInserted, 2); assert.eq(res.getWriteErrors().length, 1); diff --git a/jstests/noPassthrough/timeseries_insert_ordered_true.js b/jstests/noPassthrough/timeseries_insert_ordered_true.js index 2a0b432161f..d444981cbb4 100644 --- a/jstests/noPassthrough/timeseries_insert_ordered_true.js +++ b/jstests/noPassthrough/timeseries_insert_ordered_true.js @@ -23,19 +23,29 @@ const bucketsColl = testDB.getCollection('system.buckets.' + coll.getName()); const timeFieldName = 'time'; const metaFieldName = 'meta'; -coll.drop(); -assert.commandWorked(testDB.createCollection( - coll.getName(), {timeseries: {timeField: timeFieldName, metaField: metaFieldName}})); -assert.contains(bucketsColl.getName(), testDB.getCollectionNames()); +const resetColl = function() { + coll.drop(); + assert.commandWorked(testDB.createCollection( + coll.getName(), {timeseries: {timeField: timeFieldName, metaField: metaFieldName}})); + assert.contains(bucketsColl.getName(), testDB.getCollectionNames()); +}; +resetColl(); -const fp = configureFailPoint(conn, 'failTimeseriesInsert', {metadata: 'fail'}); +configureFailPoint(conn, 'failTimeseriesInsert', {metadata: 'fail'}); const docs = [ {_id: 0, [timeFieldName]: ISODate()}, - {_id: 1, [timeFieldName]: ISODate(), [metaFieldName]: 'fail'}, - {_id: 2, [timeFieldName]: ISODate()} + {_id: 1, [timeFieldName]: ISODate()}, + {_id: 2, [timeFieldName]: ISODate()}, ]; -const res = assert.commandFailed(coll.insert(docs, {ordered: true})); + +let res = assert.commandWorked(coll.insert(docs, {ordered: true})); +assert.eq(res.nInserted, 3, 'Invalid insert result: ' + tojson(res)); +assert.docEq(coll.find().sort({_id: 1}).toArray(), docs); +resetColl(); + +docs[1][metaFieldName] = 'fail'; +res = assert.commandFailed(coll.insert(docs, {ordered: true})); jsTestLog('Checking insert result: ' + tojson(res)); assert.eq(res.nInserted, 1); assert.eq(res.getWriteErrors().length, 1); diff --git a/src/mongo/db/commands/write_commands/write_commands.cpp b/src/mongo/db/commands/write_commands/write_commands.cpp index 6a704cad9e5..ff84f0897e1 100644 --- a/src/mongo/db/commands/write_commands/write_commands.cpp +++ b/src/mongo/db/commands/write_commands/write_commands.cpp @@ -835,6 +835,7 @@ public: auto& baseReply = insertReply->getWriteReplyBase(); if (_batch.getOrdered()) { + baseReply.setN(_batch.getDocuments().size()); for (size_t i = 0; i < _batch.getDocuments().size(); ++i) { _performTimeseriesWritesSubset(opCtx, i, 1, &errors, &opTime, &electionId); if (!errors.empty()) { |