Skip to content

Commit

Permalink
fix(transactions): fix sharded transaction error logic
Browse files Browse the repository at this point in the history
Fixed the logic so that startTransaction will not error on
sharded transactions on mongodb > 4.2.0
  • Loading branch information
daprahamian committed Aug 13, 2019
1 parent bcf6358 commit 083e18a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/core/sessions.js
Expand Up @@ -18,7 +18,7 @@ const resolveClusterTime = require('./topologies/shared').resolveClusterTime;
const isSharded = require('./wireprotocol/shared').isSharded;
const maxWireVersion = require('./utils').maxWireVersion;

const MAX_FOR_TRANSACTIONS = 7;
const minWireVersionForShardedTransactions = 8;

function assertAlive(session, callback) {
if (session.serverSession == null) {
Expand Down Expand Up @@ -191,8 +191,9 @@ class ClientSession extends EventEmitter {

const topologyMaxWireVersion = maxWireVersion(this.topology);
if (
isSharded(this.topology) ||
(topologyMaxWireVersion != null && topologyMaxWireVersion < MAX_FOR_TRANSACTIONS)
isSharded(this.topology) &&
(topologyMaxWireVersion == null ||
topologyMaxWireVersion < minWireVersionForShardedTransactions)
) {
throw new MongoError('Transactions are not supported on sharded clusters in MongoDB < 4.2.');
}
Expand Down
2 changes: 1 addition & 1 deletion test/functional/transactions_tests.js
Expand Up @@ -71,7 +71,7 @@ describe('Transactions', function() {

describe('startTransaction', function() {
it('should error if transactions are not supported', {
metadata: { requires: { topology: ['sharded'], mongodb: '>4.0.0' } },
metadata: { requires: { topology: ['sharded'], mongodb: '4.0.x' } },
test: function(done) {
const configuration = this.configuration;
const client = configuration.newClient(configuration.writeConcernMax(), { poolSize: 1 });
Expand Down

0 comments on commit 083e18a

Please sign in to comment.