diff options
author | Matthew Saltz <matthew.saltz@mongodb.com> | 2022-08-30 19:58:33 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-08-30 21:49:51 +0000 |
commit | 135eefc1bd00a5ab5c97ba679805dc150c9429ec (patch) | |
tree | 1e6c504466b1326896a1fac6320f34c7e82cfe1e /jstests | |
parent | 36b8246daa269b1a21d63d3f0e11c31b274e6703 (diff) | |
download | mongo-135eefc1bd00a5ab5c97ba679805dc150c9429ec.tar.gz |
SERVER-68556 Allow transactions on timeseries buckets collections
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/core/timeseries/libs/timeseries.js | 6 | ||||
-rw-r--r-- | jstests/core/txns/no_writes_to_system_collections_in_txn.js | 4 | ||||
-rw-r--r-- | jstests/core/txns/txn_ops_allowed_on_buckets_coll.js | 62 |
3 files changed, 69 insertions, 3 deletions
diff --git a/jstests/core/timeseries/libs/timeseries.js b/jstests/core/timeseries/libs/timeseries.js index 975a799ca9b..0aadae1998a 100644 --- a/jstests/core/timeseries/libs/timeseries.js +++ b/jstests/core/timeseries/libs/timeseries.js @@ -190,7 +190,7 @@ var TimeseriesTest = class { static ensureDataIsDistributedIfSharded(coll, splitPointDate) { const db = coll.getDB(); - const buckets = db["system.buckets." + coll.getName()]; + const buckets = db[this.getBucketsCollName(coll.getName())]; if (FixtureHelpers.isSharded(buckets)) { const timeFieldName = db.getCollectionInfos({name: coll.getName()})[0].options.timeseries.timeField; @@ -239,4 +239,8 @@ var TimeseriesTest = class { } } } + + static getBucketsCollName(collName) { + return `system.buckets.${collName}`; + } }; diff --git a/jstests/core/txns/no_writes_to_system_collections_in_txn.js b/jstests/core/txns/no_writes_to_system_collections_in_txn.js index f82f339a7a6..bd709edd59b 100644 --- a/jstests/core/txns/no_writes_to_system_collections_in_txn.js +++ b/jstests/core/txns/no_writes_to_system_collections_in_txn.js @@ -33,12 +33,12 @@ assert.commandWorked(systemColl.insert({name: 0}, {writeConcern: {w: "majority"} session.startTransaction({readConcern: {level: "snapshot"}}); let error = assert.throws(() => systemColl.findAndModify({query: {}, update: {}})); -assert.commandFailedWithCode(error, 50781); +assert.commandFailedWithCode(error, 50791); assert.commandFailedWithCode(session.abortTransaction_forTesting(), ErrorCodes.NoSuchTransaction); session.startTransaction({readConcern: {level: "snapshot"}}); error = assert.throws(() => systemColl.findAndModify({query: {}, remove: true})); -assert.commandFailedWithCode(error, 50781); +assert.commandFailedWithCode(error, 50791); assert.commandFailedWithCode(session.abortTransaction_forTesting(), ErrorCodes.NoSuchTransaction); session.startTransaction({readConcern: {level: "snapshot"}}); diff --git a/jstests/core/txns/txn_ops_allowed_on_buckets_coll.js b/jstests/core/txns/txn_ops_allowed_on_buckets_coll.js new file mode 100644 index 00000000000..4af433edefc --- /dev/null +++ b/jstests/core/txns/txn_ops_allowed_on_buckets_coll.js @@ -0,0 +1,62 @@ +/** + * Tests that transactions are able to write to the time-series buckets collection. + * + * @tags: [ + * uses_transactions, + * uses_snapshot_read_concern + * ] + */ +(function() { +"use strict"; + +load("jstests/core/timeseries/libs/timeseries.js"); // For 'TimeseriesTest'. + +const session = db.getMongo().startSession(); + +// Use a custom database, to avoid conflict with other tests that use the system.buckets.foo +// collection. +const testDB = session.getDatabase("timeseries_buckets_writes_in_txn"); +assert.commandWorked(testDB.dropDatabase()); + +// Access a collection prefixed with system.buckets, to mimic doing a +// transaction on a timeseries buckets collection. +const systemColl = testDB.getCollection(TimeseriesTest.getBucketsCollName("foo")); + +// Ensure that a collection exists with at least one document. +assert.commandWorked(systemColl.insert({name: 0}, {writeConcern: {w: "majority"}})); + +session.startTransaction({readConcern: {level: "snapshot"}}); + +jsTestLog("Test writing to the collection."); + +jsTestLog("Testing findAndModify."); + +// These findAndModify operations would throw if they failed. +systemColl.findAndModify({query: {}, update: {}}); +systemColl.findAndModify({query: {}, remove: true}); + +jsTestLog("Testing insert."); +assert.commandWorked(systemColl.insert({name: "new"})); + +jsTestLog("Testing update."); +assert.commandWorked(systemColl.update({name: 0}, {$set: {name: "foo"}})); +assert.commandWorked( + systemColl.update({name: "nonexistent"}, {$set: {name: "foo"}}, {upsert: true})); + +jsTestLog("Testing remove."); +assert.commandWorked(systemColl.remove({name: 0})); +assert.commandWorked(systemColl.remove({_id: {$exists: true}})); + +// Insert a document to be read by the subsequent commands. +assert.commandWorked(systemColl.insert({name: "new"})); + +jsTestLog("Test reading from the collection."); + +jsTestLog("Testing find."); +assert.eq(systemColl.find().itcount(), 1); + +jsTestLog("Testing aggregate."); +assert.eq(systemColl.aggregate([{$match: {}}]).itcount(), 1); + +assert.commandWorked(session.commitTransaction_forTesting()); +}()); |