[JAVA-2928] Detect if transactions are not supported by the server Created: 15/Aug/18  Updated: 28/Oct/23  Resolved: 24/Jan/19

Status: Closed
Project: Java Driver
Component/s: Transaction Management
Affects Version/s: None
Fix Version/s: 3.11.0

Type: Improvement Priority: Major - P3
Reporter: Ross Lawley Assignee: John Stewart (Inactive)
Resolution: Fixed Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

When running:

ClientSession clientSession = mongoClient.startSession();
clientSession.startTransaction();
collection.insertOne(clientSession, Document.parse("{_id: 1, a: 1}"));
collection.insertOne(clientSession, Document.parse("{_id: 2, a: 1}"));
clientSession.commitTransaction();
clientSession.close();

Against a 3.6 replicaset or sharded cluster the user gets the following error:

Exception in thread "main" com.mongodb.MongoCommandException: Command failed with error 40415 (Location40415): 'BSON field 'insert.startTransaction' is an unknown field.' on server localhost:27017. The full response is { "operationTime" : { "$timestamp" : { "t" : 1534322289, "i" : 4 } }, "ok" : 0.0, "errmsg" : "BSON field 'insert.startTransaction' is an unknown field.", "code" : 40415, "codeName" : "Location40415", "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1534322289, "i" : 4 } }, "signature" : { "hash" : { "$binary" : "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "$type" : "00" }, "keyId" : { "$numberLong" : "0" } } } }

Its quite unclear as to what the cause of the actual issue is.

For other scenarios the errors are much clearer:

  • Single Node: com.mongodb.MongoClientException: Sessions are not supported by the MongoDB cluster to which this client is connected
  • Sharded cluster: com.mongodb.MongoCommandException: Command failed with error 50841 (Location50841): 'Multi-document transactions cannot be run in a sharded cluster.'

The spec states:

startTransaction SHOULD report an error if the driver can detect that transactions are not supported by the deployment.

A wire check would allow for clearer error messages for users trying to use transactions on an older server.



 Comments   
Comment by Jeffrey Yemin [ 25/Jan/19 ]

commit 668ccb549d8bbb803cfac20598a0a23189fbc11e (HEAD -> master, mongodb/master)
Author: John Stewart <john.stewart@mongodb.com>
Date: Fri Jan 11 19:21:32 2019 -0500

detect if transactions are not supported by the server

Comment by mongdb-test [ 10/Dec/18 ]

hi,Is there any solution?

Generated at Thu Feb 08 08:58:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.